usbuart5  2.1.0.0
usbuart5.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 USBUART5_H
29 #define USBUART5_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_uart.h"
52 
74 #define USBUART5_SUSPEND_MODE_DISABLE 0
75 #define USBUART5_SUSPEND_MODE_ENABLE 1
76 
82 #define USBUART5_TX_DRV_BUFFER_SIZE 100
83 #define USBUART5_RX_DRV_BUFFER_SIZE 300
84  // usbuart5_cmd
86 
101 #define USBUART5_MAP_MIKROBUS( cfg, mikrobus ) \
102  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
103  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
104  cfg.spd = MIKROBUS( mikrobus, MIKROBUS_AN ); \
105  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
106  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
107  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_INT );
108  // usbuart5_map // usbuart5
111 
116 typedef struct
117 {
118  // Output pins
119  digital_out_t rst;
120  digital_out_t cts;
122  // Input pins
123  digital_in_t spd;
124  digital_in_t rts;
126  // Modules
127  uart_t uart;
129  // Buffers
130  char uart_rx_buffer[ USBUART5_RX_DRV_BUFFER_SIZE ];
131  char uart_tx_buffer[ USBUART5_TX_DRV_BUFFER_SIZE ];
133 } usbuart5_t;
134 
139 typedef struct
140 {
141  // Communication gpio pins
142  pin_name_t rx_pin;
143  pin_name_t tx_pin;
145  // Additional gpio pins
146  pin_name_t spd;
147  pin_name_t rst;
148  pin_name_t cts;
149  pin_name_t rts;
151  // Static variable
152  uint32_t baud_rate;
154  uart_data_bits_t data_bit;
155  uart_parity_t parity_bit;
156  uart_stop_bits_t stop_bit;
159 
164 typedef enum
165 {
167  USBUART5_ERROR = -1
168 
170 
175 typedef enum
176 {
179 
181 
198 
213 
225 
238 err_t usbuart5_generic_write ( usbuart5_t *ctx, char *data_in, uint16_t len );
239 
252 err_t usbuart5_generic_read ( usbuart5_t *ctx, char *data_out, uint16_t len );
253 
265 
277 
288 
301 
311 
312 #ifdef __cplusplus
313 }
314 #endif
315 #endif // USBUART5_H
316  // usbuart5
318 
319 // ------------------------------------------------------------------------ END
usbuart5_cfg_t
USB UART 5 Click configuration object.
Definition: usbuart5.h:140
usbuart5_t::spd
digital_in_t spd
Definition: usbuart5.h:123
usbuart5_set_cts_pin
void usbuart5_set_cts_pin(usbuart5_t *ctx, usbuart5_pin_state_t state)
USB UART 5 set cts pin state function.
usbuart5_t::rst
digital_out_t rst
Definition: usbuart5.h:119
usbuart5_get_rts_pin
uint8_t usbuart5_get_rts_pin(usbuart5_t *ctx)
USB UART 5 get rts pin state function.
usbuart5_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: usbuart5.h:155
usbuart5_generic_write
err_t usbuart5_generic_write(usbuart5_t *ctx, char *data_in, uint16_t len)
USB UART 5 data writing function.
usbuart5_t::uart
uart_t uart
Definition: usbuart5.h:127
usbuart5_t
USB UART 5 Click context object.
Definition: usbuart5.h:117
usbuart5_cfg_setup
void usbuart5_cfg_setup(usbuart5_cfg_t *cfg)
USB UART 5 configuration object setup function.
usbuart5_default_cfg
void usbuart5_default_cfg(usbuart5_t *ctx)
USB UART 5 default configuration function.
usbuart5_cfg_t::rst
pin_name_t rst
Definition: usbuart5.h:147
USBUART5_ERROR
@ USBUART5_ERROR
Definition: usbuart5.h:167
usbuart5_generic_read
err_t usbuart5_generic_read(usbuart5_t *ctx, char *data_out, uint16_t len)
USB UART 5 data reading function.
usbuart5_cfg_t::rts
pin_name_t rts
Definition: usbuart5.h:149
USBUART5_TX_DRV_BUFFER_SIZE
#define USBUART5_TX_DRV_BUFFER_SIZE
USB UART 5 driver buffer size.
Definition: usbuart5.h:82
usbuart5_cfg_t::baud_rate
uint32_t baud_rate
Definition: usbuart5.h:152
usbuart5_get_suspend_state
uint8_t usbuart5_get_suspend_state(usbuart5_t *ctx)
USB UART 5 get USB Suspend state function.
usbuart5_init
err_t usbuart5_init(usbuart5_t *ctx, usbuart5_cfg_t *cfg)
USB UART 5 initialization function.
USBUART5_OK
@ USBUART5_OK
Definition: usbuart5.h:166
usbuart5_cfg_t::tx_pin
pin_name_t tx_pin
Definition: usbuart5.h:143
usbuart5_cfg_t::spd
pin_name_t spd
Definition: usbuart5.h:146
usbuart5_t::rts
digital_in_t rts
Definition: usbuart5.h:124
usbuart5_cfg_t::cts
pin_name_t cts
Definition: usbuart5.h:148
usbuart5_t::cts
digital_out_t cts
Definition: usbuart5.h:120
usbuart5_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: usbuart5.h:156
usbuart5_pin_state_t
usbuart5_pin_state_t
USB UART 5 Click pin state.
Definition: usbuart5.h:176
USBUART5_RX_DRV_BUFFER_SIZE
#define USBUART5_RX_DRV_BUFFER_SIZE
Definition: usbuart5.h:83
usbuart5_cfg_t::uart_blocking
bool uart_blocking
Definition: usbuart5.h:153
USBUART5_PIN_STATE_LOW
@ USBUART5_PIN_STATE_LOW
Definition: usbuart5.h:177
usbuart5_return_value_t
usbuart5_return_value_t
USB UART 5 Click return value data.
Definition: usbuart5.h:165
USBUART5_PIN_STATE_HIGH
@ USBUART5_PIN_STATE_HIGH
Definition: usbuart5.h:178
usbuart5_reset_device
void usbuart5_reset_device(usbuart5_t *ctx)
USB UART 5 reset the device function.
usbuart5_cfg_t::rx_pin
pin_name_t rx_pin
Definition: usbuart5.h:142
usbuart5_enable_device
void usbuart5_enable_device(usbuart5_t *ctx)
USB UART 5 enable the device function.
usbuart5_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: usbuart5.h:154