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 
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 USBUARTISO_TX_DRV_BUFFER_SIZE 100
71 #define USBUARTISO_RX_DRV_BUFFER_SIZE 300
72  // usbuartiso_cmd
74 
89 #define USBUARTISO_MAP_MIKROBUS( cfg, mikrobus ) \
90  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
91  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
92  cfg.slp = MIKROBUS( mikrobus, MIKROBUS_AN ); \
93  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
94  cfg.pwr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
95  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
96  // usbuartiso_map // usbuartiso
99 
104 typedef struct
105 {
106  // Output pins
107  digital_out_t cts;
108  digital_out_t pwr;
110  // Input pins
111  digital_in_t slp;
112  digital_in_t rts;
114  // Modules
115  uart_t uart;
117  // Buffers
118  uint8_t uart_rx_buffer[ USBUARTISO_RX_DRV_BUFFER_SIZE ];
119  uint8_t uart_tx_buffer[ USBUARTISO_TX_DRV_BUFFER_SIZE ];
121 } usbuartiso_t;
122 
127 typedef struct
128 {
129  // Communication gpio pins
130  pin_name_t rx_pin;
131  pin_name_t tx_pin;
133  // Additional gpio pins
134  pin_name_t slp;
135  pin_name_t cts;
136  pin_name_t pwr;
137  pin_name_t rts;
139  // Static variable
140  uint32_t baud_rate;
142  uart_data_bits_t data_bit;
143  uart_parity_t parity_bit;
144  uart_stop_bits_t stop_bit;
147 
152 typedef enum
153 {
155  USBUARTISO_ERROR = -1
156 
158 
175 
190 
202 
215 err_t usbuartiso_generic_write ( usbuartiso_t *ctx, uint8_t *data_in, uint16_t len );
216 
229 err_t usbuartiso_generic_read ( usbuartiso_t *ctx, uint8_t *data_out, uint16_t len );
230 
242 
254 
267 
278 
289 void usbuartiso_clear_to_send ( usbuartiso_t *ctx, uint8_t cts );
290 
291 #ifdef __cplusplus
292 }
293 #endif
294 #endif // USBUARTISO_H
295  // usbuartiso
297 
298 // ------------------------------------------------------------------------ END
usbuartiso_t::uart
uart_t uart
Definition: usbuartiso.h:115
USBUARTISO_OK
@ USBUARTISO_OK
Definition: usbuartiso.h:154
usbuartiso_cfg_t::tx_pin
pin_name_t tx_pin
Definition: usbuartiso.h:131
USBUARTISO_TX_DRV_BUFFER_SIZE
#define USBUARTISO_TX_DRV_BUFFER_SIZE
USB UART ISO driver buffer size.
Definition: usbuartiso.h:70
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:143
usbuartiso_t::rts
digital_in_t rts
Definition: usbuartiso.h:112
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:130
usbuartiso_t::slp
digital_in_t slp
Definition: usbuartiso.h:111
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:137
usbuartiso_cfg_t::baud_rate
uint32_t baud_rate
Definition: usbuartiso.h:140
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:71
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:141
usbuartiso_t::cts
digital_out_t cts
Definition: usbuartiso.h:107
usbuartiso_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: usbuartiso.h:142
usbuartiso_cfg_t::pwr
pin_name_t pwr
Definition: usbuartiso.h:136
usbuartiso_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: usbuartiso.h:144
usbuartiso_return_value_t
usbuartiso_return_value_t
USB UART ISO Click return value data.
Definition: usbuartiso.h:153
usbuartiso_t::pwr
digital_out_t pwr
Definition: usbuartiso.h:108
usbuartiso_cfg_t
USB UART ISO Click configuration object.
Definition: usbuartiso.h:128
usbuartiso_cfg_t::slp
pin_name_t slp
Definition: usbuartiso.h:134
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:105
usbuartiso_cfg_t::cts
pin_name_t cts
Definition: usbuartiso.h:135
usbuartiso_power_on
void usbuartiso_power_on(usbuartiso_t *ctx)
USB UART ISO power on function.
USBUARTISO_ERROR
@ USBUARTISO_ERROR
Definition: usbuartiso.h:155
usbuartiso_default_cfg
void usbuartiso_default_cfg(usbuartiso_t *ctx)
USB UART ISO default configuration function.