usbuart  2.0.0.0
usbuart.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef USBUART_H
36 #define USBUART_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define USBUART_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_RST );\
57  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_PWM );\
59  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
60 
66 #define USBUART_RETVAL uint8_t
67 
68 #define USBUART_OK 0x00
69 #define USBUART_INIT_ERROR 0xFF
70 
76 #define USBUART_POWER_ON 1
77 #define USBUART_POWER_OFF 0
78 
84 #define USBUART_CTS_ACTIVE 1
85 #define USBUART_CTS_NO_ACTIVE 0
86 
92 #define USBUART_MODE_SLEEP 1
93 #define USBUART_MODE_NORMAL 0
94  // End group macro
97 // --------------------------------------------------------------- PUBLIC TYPES
103 typedef uart_data_t usbuart_data_t;
104 
108 typedef struct
109 {
110  // Output pins
111 
112  digital_out_t cts;
113  digital_out_t slp;
114  digital_out_t pwr;
115 
116  // Input pins
117 
118  digital_in_t rts;
119 
120  // Modules
121 
122  uart_t uart;
123 
124 } usbuart_t;
125 
129 typedef struct
130 {
131  // Communication gpio pins
132 
133  pin_name_t rx_pin;
134  pin_name_t tx_pin;
135 
136  // Additional gpio pins
137 
138  pin_name_t cts;
139  pin_name_t slp;
140  pin_name_t pwr;
141  pin_name_t rts;
142 
143  // static variable
144 
145  hal_uart_baudrate_t baud_rate; // Clock speed.
146  hal_uart_data_bits_t data_bit; // Data bits.
147  hal_uart_parity_bit_t parity_bit; // Parity bit.
148  hal_uart_stop_bits_t stop_bit; // Stop bits.
149 
150 } usbuart_cfg_t;
151  // End types group
153 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
154 
160 #ifdef __cplusplus
161 extern "C"{
162 #endif
163 
172 void usbuart_cfg_setup ( usbuart_cfg_t *cfg );
173 
182 
190 void usbuart_default_cfg ( usbuart_t *ctx );
191 
201 void usbuart_generic_multi_write ( usbuart_t *ctx, usbuart_data_t *data_buf, uart_length_t len );
202 
212 void usbuart_generic_multi_read ( usbuart_t *ctx, usbuart_data_t *data_buf, uart_length_t len );
213 
214 
224 
234 
241 void usbuart_pwr_ctrl ( usbuart_t *ctx, uint8_t state );
242 
249 void usbuart_set_cts ( usbuart_t *ctx, uint8_t state );
250 
257 void usbuart_set_mode ( usbuart_t *ctx, uint8_t mode );
258 
265 uint8_t usbuart_get_rts ( usbuart_t *ctx );
266 
267 #ifdef __cplusplus
268 }
269 #endif
270 #endif // _USBUART_H_
271  // End public_function group
274 
275 // ------------------------------------------------------------------------- END
usbuart_cfg_t::data_bit
hal_uart_data_bits_t data_bit
Definition: usbuart.h:146
usbuart_cfg_t::parity_bit
hal_uart_parity_bit_t parity_bit
Definition: usbuart.h:147
usbuart_cfg_t::slp
pin_name_t slp
Definition: usbuart.h:139
usbuart_generic_multi_write
void usbuart_generic_multi_write(usbuart_t *ctx, usbuart_data_t *data_buf, uart_length_t len)
Generic multi write function.
usbuart_default_cfg
void usbuart_default_cfg(usbuart_t *ctx)
Click Default Configuration function.
USBUART_RETVAL
#define USBUART_RETVAL
Definition: usbuart.h:66
usbuart_cfg_t::rx_pin
pin_name_t rx_pin
Definition: usbuart.h:133
usbuart_cfg_t::tx_pin
pin_name_t tx_pin
Definition: usbuart.h:134
usbuart_cfg_t::rts
pin_name_t rts
Definition: usbuart.h:141
usbuart_generic_single_read
usbuart_data_t usbuart_generic_single_read(usbuart_t *ctx)
Generic single read function.
usbuart_set_cts
void usbuart_set_cts(usbuart_t *ctx, uint8_t state)
Set CTS (Clear to send)
usbuart_cfg_t
Click configuration structure definition.
Definition: usbuart.h:129
usbuart_set_mode
void usbuart_set_mode(usbuart_t *ctx, uint8_t mode)
Set device mode.
usbuart_generic_single_write
void usbuart_generic_single_write(usbuart_t *ctx, usbuart_data_t tx_data)
Generic single write function.
usbuart_cfg_t::cts
pin_name_t cts
Definition: usbuart.h:138
usbuart_t::rts
digital_in_t rts
Definition: usbuart.h:118
usbuart_init
USBUART_RETVAL usbuart_init(usbuart_t *ctx, usbuart_cfg_t *cfg)
Initialization function.
usbuart_data_t
uart_data_t usbuart_data_t
Definition: usbuart.h:103
usbuart_t
Click ctx object definition.
Definition: usbuart.h:108
usbuart_get_rts
uint8_t usbuart_get_rts(usbuart_t *ctx)
Set device mode.
usbuart_t::pwr
digital_out_t pwr
Definition: usbuart.h:114
usbuart_generic_multi_read
void usbuart_generic_multi_read(usbuart_t *ctx, usbuart_data_t *data_buf, uart_length_t len)
Generic multi read function.
usbuart_pwr_ctrl
void usbuart_pwr_ctrl(usbuart_t *ctx, uint8_t state)
Power control.
usbuart_cfg_setup
void usbuart_cfg_setup(usbuart_cfg_t *cfg)
Config Object Initialization function.
usbuart_cfg_t::baud_rate
hal_uart_baudrate_t baud_rate
Definition: usbuart.h:145
usbuart_cfg_t::stop_bit
hal_uart_stop_bits_t stop_bit
Definition: usbuart.h:148
usbuart_cfg_t::pwr
pin_name_t pwr
Definition: usbuart.h:140
usbuart_t::uart
uart_t uart
Definition: usbuart.h:122
usbuart_t::cts
digital_out_t cts
Definition: usbuart.h:112
usbuart_t::slp
digital_out_t slp
Definition: usbuart.h:113