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
32extern "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
85 // 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
109 // usbuart5_map
110 // usbuart5
111
116typedef 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
139typedef 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
164typedef enum
165{
167 USBUART5_ERROR = -1
168
170
181
198
213
225
238err_t usbuart5_generic_write ( usbuart5_t *ctx, char *data_in, uint16_t len );
239
252err_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
317 // usbuart5
318
319// ------------------------------------------------------------------------ END
#define USBUART5_RX_DRV_BUFFER_SIZE
Definition usbuart5.h:83
#define USBUART5_TX_DRV_BUFFER_SIZE
USB UART 5 driver buffer size.
Definition usbuart5.h:82
uint8_t usbuart5_get_suspend_state(usbuart5_t *ctx)
USB UART 5 get USB Suspend state function.
err_t usbuart5_init(usbuart5_t *ctx, usbuart5_cfg_t *cfg)
USB UART 5 initialization function.
err_t usbuart5_generic_write(usbuart5_t *ctx, char *data_in, uint16_t len)
USB UART 5 data writing function.
void usbuart5_set_cts_pin(usbuart5_t *ctx, usbuart5_pin_state_t state)
USB UART 5 set cts pin state function.
void usbuart5_cfg_setup(usbuart5_cfg_t *cfg)
USB UART 5 configuration object setup function.
err_t usbuart5_generic_read(usbuart5_t *ctx, char *data_out, uint16_t len)
USB UART 5 data reading function.
void usbuart5_default_cfg(usbuart5_t *ctx)
USB UART 5 default configuration function.
void usbuart5_reset_device(usbuart5_t *ctx)
USB UART 5 reset the device function.
void usbuart5_enable_device(usbuart5_t *ctx)
USB UART 5 enable the device function.
uint8_t usbuart5_get_rts_pin(usbuart5_t *ctx)
USB UART 5 get rts pin state function.
USB UART 5 Click configuration object.
Definition usbuart5.h:140
pin_name_t rts
Definition usbuart5.h:149
uint32_t baud_rate
Definition usbuart5.h:152
pin_name_t spd
Definition usbuart5.h:146
pin_name_t cts
Definition usbuart5.h:148
bool uart_blocking
Definition usbuart5.h:153
uart_data_bits_t data_bit
Definition usbuart5.h:154
pin_name_t tx_pin
Definition usbuart5.h:143
pin_name_t rx_pin
Definition usbuart5.h:142
uart_stop_bits_t stop_bit
Definition usbuart5.h:156
uart_parity_t parity_bit
Definition usbuart5.h:155
pin_name_t rst
Definition usbuart5.h:147
USB UART 5 Click context object.
Definition usbuart5.h:117
digital_in_t spd
Definition usbuart5.h:123
uart_t uart
Definition usbuart5.h:127
digital_in_t rts
Definition usbuart5.h:124
digital_out_t rst
Definition usbuart5.h:119
digital_out_t cts
Definition usbuart5.h:120
usbuart5_pin_state_t
USB UART 5 Click pin state.
Definition usbuart5.h:176
@ USBUART5_PIN_STATE_HIGH
Definition usbuart5.h:178
@ USBUART5_PIN_STATE_LOW
Definition usbuart5.h:177
usbuart5_return_value_t
USB UART 5 Click return value data.
Definition usbuart5.h:165
@ USBUART5_OK
Definition usbuart5.h:166
@ USBUART5_ERROR
Definition usbuart5.h:167