usbuart4  2.0.0.0
usbuart4.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 USBUART4_H
29 #define USBUART4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
70 #define USBUART4_MODE_SLEEP 1
71 #define USBUART4_MODE_NORMAL 0
72 
73 #define USBUART4_CTS_ACTIVE 1
74 #define USBUART4_CTS_NO_ACTIVE 0
75 
76 #define USBUART4_POWER_ON 1
77 #define USBUART4_POWER_OFF 0
78 
84 #define DRV_BUFFER_SIZE 500
85  // usbuart4_set
87 
102 #define USBUART4_MAP_MIKROBUS( cfg, mikrobus ) \
103  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
104  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
105  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_RST ); \
106  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_CS ); \
107  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
108  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
109  // usbuart4_map // usbuart4
112 
117 typedef struct
118 {
119  // Output pins
120 
121  digital_out_t cts;
122  digital_out_t slp;
123  digital_out_t pwr;
124  // Input pins
125 
126  digital_in_t rts;
127 
128  // Modules
129  uart_t uart;
131  // Buffers
132  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
133  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
135 } usbuart4_t;
136 
141 typedef struct
142 {
143  // Communication gpio pins
144  pin_name_t rx_pin;
145  pin_name_t tx_pin;
147  // Additional gpio pins
148  pin_name_t cts;
149  pin_name_t slp;
150  pin_name_t pwr;
151  pin_name_t rts;
152 
153  // Static variable
154  uint32_t baud_rate;
156  uart_data_bits_t data_bit;
157  uart_parity_t parity_bit;
158  uart_stop_bits_t stop_bit;
161 
166 typedef enum
167 {
169  USBUART4_ERROR = -1
170 
172 
189 
205 
219 void usbuart4_generic_write ( usbuart4_t *ctx, char *data_buf, uint16_t len );
220 
234 uint32_t usbuart4_generic_read ( usbuart4_t *ctx, char *data_buf, uint16_t max_len );
235 
244 void usbuart4_pwr_ctrl ( usbuart4_t *ctx, uint8_t state );
245 
254 void usbuart4_set_cts ( usbuart4_t *ctx, uint8_t state );
255 
264 void usbuart4_set_mode ( usbuart4_t *ctx, uint8_t mode );
265 
272 uint8_t usbuart4_get_rts ( usbuart4_t *ctx );
273 
281 void usbuart4_send_command ( usbuart4_t *ctx, char *command );
282 #ifdef __cplusplus
283 }
284 #endif
285 #endif // USBUART4_H
286  // usbuart4
288 
289 // ------------------------------------------------------------------------ END
usbuart4_cfg_t::cts
pin_name_t cts
Definition: usbuart4.h:148
usbuart4_cfg_t
USB UART 4 Click configuration object.
Definition: usbuart4.h:142
USBUART4_ERROR
@ USBUART4_ERROR
Definition: usbuart4.h:169
usbuart4_cfg_t::pwr
pin_name_t pwr
Definition: usbuart4.h:150
usbuart4_cfg_t::uart_blocking
bool uart_blocking
Definition: usbuart4.h:155
usbuart4_generic_write
void usbuart4_generic_write(usbuart4_t *ctx, char *data_buf, uint16_t len)
USB UART 4 data writing function.
usbuart4_cfg_t::baud_rate
uint32_t baud_rate
Definition: usbuart4.h:154
usbuart4_t::cts
digital_out_t cts
Definition: usbuart4.h:121
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
USB UART 4 driver buffer size.
Definition: usbuart4.h:84
usbuart4_return_value_t
usbuart4_return_value_t
USB UART 4 Click return value data.
Definition: usbuart4.h:167
usbuart4_t::rts
digital_in_t rts
Definition: usbuart4.h:126
usbuart4_init
err_t usbuart4_init(usbuart4_t *ctx, usbuart4_cfg_t *cfg)
USB UART 4 initialization function.
usbuart4_cfg_setup
void usbuart4_cfg_setup(usbuart4_cfg_t *cfg)
USB UART 4 configuration object setup function.
usbuart4_t
USB UART 4 Click context object.
Definition: usbuart4.h:118
usbuart4_t::pwr
digital_out_t pwr
Definition: usbuart4.h:123
usbuart4_cfg_t::rts
pin_name_t rts
Definition: usbuart4.h:151
usbuart4_generic_read
uint32_t usbuart4_generic_read(usbuart4_t *ctx, char *data_buf, uint16_t max_len)
USB UART 4 data reading function.
usbuart4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: usbuart4.h:158
usbuart4_set_mode
void usbuart4_set_mode(usbuart4_t *ctx, uint8_t mode)
Set device mode.
usbuart4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: usbuart4.h:157
usbuart4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: usbuart4.h:145
usbuart4_pwr_ctrl
void usbuart4_pwr_ctrl(usbuart4_t *ctx, uint8_t state)
Power control.
usbuart4_set_cts
void usbuart4_set_cts(usbuart4_t *ctx, uint8_t state)
Set CTS (Clear to send)
usbuart4_cfg_t::slp
pin_name_t slp
Definition: usbuart4.h:149
usbuart4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: usbuart4.h:144
usbuart4_t::uart
uart_t uart
Definition: usbuart4.h:129
usbuart4_get_rts
uint8_t usbuart4_get_rts(usbuart4_t *ctx)
Set device mode.
usbuart4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: usbuart4.h:156
USBUART4_OK
@ USBUART4_OK
Definition: usbuart4.h:168
usbuart4_send_command
void usbuart4_send_command(usbuart4_t *ctx, char *command)
Function for send command.
usbuart4_t::slp
digital_out_t slp
Definition: usbuart4.h:122