usbuartiso  2.1.0.0
usbuartiso.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 USBUARTISO_H
29 #define USBUARTISO_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 USBUARTISO_TX_DRV_BUFFER_SIZE 100
75 #define USBUARTISO_RX_DRV_BUFFER_SIZE 300
76  // usbuartiso_cmd
78 
93 #define USBUARTISO_MAP_MIKROBUS( cfg, mikrobus ) \
94  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
95  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
96  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
97  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
98  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
99  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
100  // usbuartiso_map // usbuartiso
103 
108 typedef struct
109 {
110  // Output pins
111  digital_out_t cts;
112  digital_out_t pwr;
114  // Input pins
115  digital_in_t slp;
116  digital_in_t rts;
118  // Modules
119  uart_t uart;
121  // Buffers
122  uint8_t uart_rx_buffer[ USBUARTISO_RX_DRV_BUFFER_SIZE ];
123  uint8_t uart_tx_buffer[ USBUARTISO_TX_DRV_BUFFER_SIZE ];
125 } usbuartiso_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 slp;
139  pin_name_t cts;
140  pin_name_t pwr;
141  pin_name_t rts;
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  USBUARTISO_ERROR = -1
160 
162 
179 
194 
206 
219 err_t usbuartiso_generic_write ( usbuartiso_t *ctx, uint8_t *data_in, uint16_t len );
220 
233 err_t usbuartiso_generic_read ( usbuartiso_t *ctx, uint8_t *data_out, uint16_t len );
234 
246 
258 
271 
282 
293 void usbuartiso_clear_to_send ( usbuartiso_t *ctx, uint8_t cts );
294 
295 #ifdef __cplusplus
296 }
297 #endif
298 #endif // USBUARTISO_H
299  // usbuartiso
301 
302 // ------------------------------------------------------------------------ END
usbuartiso_t::uart
uart_t uart
Definition: usbuartiso.h:119
USBUARTISO_OK
@ USBUARTISO_OK
Definition: usbuartiso.h:158
usbuartiso_cfg_t::tx_pin
pin_name_t tx_pin
Definition: usbuartiso.h:135
USBUARTISO_TX_DRV_BUFFER_SIZE
#define USBUARTISO_TX_DRV_BUFFER_SIZE
USB UART ISO driver buffer size.
Definition: usbuartiso.h:74
usbuartiso_request_to_send
uint8_t usbuartiso_request_to_send(usbuartiso_t *ctx)
USB UART ISO request to send function.
usbuartiso_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: usbuartiso.h:147
usbuartiso_t::rts
digital_in_t rts
Definition: usbuartiso.h:116
usbuartiso_get_slp_ind
uint8_t usbuartiso_get_slp_ind(usbuartiso_t *ctx)
USB UART ISO sleep indicator function.
usbuartiso_clear_to_send
void usbuartiso_clear_to_send(usbuartiso_t *ctx, uint8_t cts)
USB UART ISO clear to send function.
usbuartiso_cfg_t::rx_pin
pin_name_t rx_pin
Definition: usbuartiso.h:134
usbuartiso_t::slp
digital_in_t slp
Definition: usbuartiso.h:115
usbuartiso_cfg_setup
void usbuartiso_cfg_setup(usbuartiso_cfg_t *cfg)
USB UART ISO configuration object setup function.
usbuartiso_cfg_t::rts
pin_name_t rts
Definition: usbuartiso.h:141
usbuartiso_cfg_t::baud_rate
uint32_t baud_rate
Definition: usbuartiso.h:144
usbuartiso_power_off
void usbuartiso_power_off(usbuartiso_t *ctx)
USB UART ISO power off function.
USBUARTISO_RX_DRV_BUFFER_SIZE
#define USBUARTISO_RX_DRV_BUFFER_SIZE
Definition: usbuartiso.h:75
usbuartiso_generic_write
err_t usbuartiso_generic_write(usbuartiso_t *ctx, uint8_t *data_in, uint16_t len)
USB UART ISO data writing function.
usbuartiso_cfg_t::uart_blocking
bool uart_blocking
Definition: usbuartiso.h:145
usbuartiso_t::cts
digital_out_t cts
Definition: usbuartiso.h:111
usbuartiso_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: usbuartiso.h:146
usbuartiso_cfg_t::pwr
pin_name_t pwr
Definition: usbuartiso.h:140
usbuartiso_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: usbuartiso.h:148
usbuartiso_return_value_t
usbuartiso_return_value_t
USB UART ISO Click return value data.
Definition: usbuartiso.h:157
usbuartiso_t::pwr
digital_out_t pwr
Definition: usbuartiso.h:112
usbuartiso_cfg_t
USB UART ISO Click configuration object.
Definition: usbuartiso.h:132
usbuartiso_cfg_t::slp
pin_name_t slp
Definition: usbuartiso.h:138
usbuartiso_generic_read
err_t usbuartiso_generic_read(usbuartiso_t *ctx, uint8_t *data_out, uint16_t len)
USB UART ISO data reading function.
usbuartiso_init
err_t usbuartiso_init(usbuartiso_t *ctx, usbuartiso_cfg_t *cfg)
USB UART ISO initialization function.
usbuartiso_t
USB UART ISO Click context object.
Definition: usbuartiso.h:109
usbuartiso_cfg_t::cts
pin_name_t cts
Definition: usbuartiso.h:139
usbuartiso_power_on
void usbuartiso_power_on(usbuartiso_t *ctx)
USB UART ISO power on function.
USBUARTISO_ERROR
@ USBUARTISO_ERROR
Definition: usbuartiso.h:159
usbuartiso_default_cfg
void usbuartiso_default_cfg(usbuartiso_t *ctx)
USB UART ISO default configuration function.