usbuart2  2.0.0.0
usbuart2.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef USBUART2_H
29 #define USBUART2_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
60 #define USBUART2_MODE_SLEEP 1
61 #define USBUART2_MODE_NORMAL 0
62 
63 #define USBUART2_CTS_ACTIVE 1
64 #define USBUART2_CTS_NO_ACTIVE 0
65 
66 #define USBUART2_POWER_ON 1
67 #define USBUART2_POWER_OFF 0
68 
74 #define DRV_BUFFER_SIZE 500
75  // usbuart2_set
77 
92 #define USBUART2_MAP_MIKROBUS( cfg, mikrobus ) \
93  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
94  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
95  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_RST ); \
96  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_CS ); \
97  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
98  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
99  // usbuart2_map // usbuart2
102 
107 typedef struct
108 {
109  // Output pins
110 
111  digital_out_t cts;
112  digital_out_t slp;
113  digital_out_t pwr;
114  // Input pins
115 
116  digital_in_t rts;
117 
118  // Modules
119  uart_t uart;
121  // Buffers
122  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
123  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
125 } usbuart2_t;
126 
131 typedef struct
132 {
133  // Communication gpio pins
134  pin_name_t rx_pin;
135  pin_name_t tx_pin;
137  // Additional gpio pins
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  uint32_t baud_rate;
146  uart_data_bits_t data_bit;
147  uart_parity_t parity_bit;
148  uart_stop_bits_t stop_bit;
151 
156 typedef enum
157 {
159  USBUART2_ERROR = -1
160 
162 
179 
195 
209 void usbuart2_generic_write ( usbuart2_t *ctx, char *data_buf, uint16_t len );
210 
224 uint32_t usbuart2_generic_read ( usbuart2_t *ctx, char *data_buf, uint16_t max_len );
225 
234 void usbuart2_pwr_ctrl ( usbuart2_t *ctx, uint8_t state );
235 
244 void usbuart2_set_cts ( usbuart2_t *ctx, uint8_t state );
245 
254 void usbuart2_set_mode ( usbuart2_t *ctx, uint8_t mode );
255 
262 uint8_t usbuart2_get_rts ( usbuart2_t *ctx );
263 
271 void usbuart2_send_command ( usbuart2_t *ctx, char *command );
272 #ifdef __cplusplus
273 }
274 #endif
275 #endif // USBUART2_H
276  // usbuart2
278 
279 // ------------------------------------------------------------------------ END
usbuart2_set_cts
void usbuart2_set_cts(usbuart2_t *ctx, uint8_t state)
Set CTS (Clear to send)
usbuart2_cfg_t::baud_rate
uint32_t baud_rate
Definition: usbuart2.h:144
usbuart2_cfg_setup
void usbuart2_cfg_setup(usbuart2_cfg_t *cfg)
USB UART 2 configuration object setup function.
usbuart2_t::pwr
digital_out_t pwr
Definition: usbuart2.h:113
usbuart2_cfg_t
USB UART 2 Click configuration object.
Definition: usbuart2.h:132
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
USB UART 2 driver buffer size.
Definition: usbuart2.h:74
usbuart2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: usbuart2.h:146
usbuart2_cfg_t::slp
pin_name_t slp
Definition: usbuart2.h:139
USBUART2_OK
@ USBUART2_OK
Definition: usbuart2.h:158
usbuart2_return_value_t
usbuart2_return_value_t
USB UART 2 Click return value data.
Definition: usbuart2.h:157
usbuart2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: usbuart2.h:134
usbuart2_t::uart
uart_t uart
Definition: usbuart2.h:119
USBUART2_ERROR
@ USBUART2_ERROR
Definition: usbuart2.h:159
usbuart2_generic_write
void usbuart2_generic_write(usbuart2_t *ctx, char *data_buf, uint16_t len)
USB UART 2 data writing function.
usbuart2_pwr_ctrl
void usbuart2_pwr_ctrl(usbuart2_t *ctx, uint8_t state)
Power control.
usbuart2_cfg_t::uart_blocking
bool uart_blocking
Definition: usbuart2.h:145
usbuart2_cfg_t::rts
pin_name_t rts
Definition: usbuart2.h:141
usbuart2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: usbuart2.h:135
usbuart2_t::slp
digital_out_t slp
Definition: usbuart2.h:112
usbuart2_t::cts
digital_out_t cts
Definition: usbuart2.h:111
usbuart2_generic_read
uint32_t usbuart2_generic_read(usbuart2_t *ctx, char *data_buf, uint16_t max_len)
USB UART 2 data reading function.
usbuart2_t
USB UART 2 Click context object.
Definition: usbuart2.h:108
usbuart2_t::rts
digital_in_t rts
Definition: usbuart2.h:116
usbuart2_set_mode
void usbuart2_set_mode(usbuart2_t *ctx, uint8_t mode)
Set device mode.
usbuart2_init
err_t usbuart2_init(usbuart2_t *ctx, usbuart2_cfg_t *cfg)
USB UART 2 initialization function.
usbuart2_cfg_t::cts
pin_name_t cts
Definition: usbuart2.h:138
usbuart2_get_rts
uint8_t usbuart2_get_rts(usbuart2_t *ctx)
Set device mode.
usbuart2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: usbuart2.h:148
usbuart2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: usbuart2.h:147
usbuart2_send_command
void usbuart2_send_command(usbuart2_t *ctx, char *command)
Function for send command.
usbuart2_cfg_t::pwr
pin_name_t pwr
Definition: usbuart2.h:140