uartmux4  2.1.0.0
uartmux4.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 UARTMUX4_H
29 #define UARTMUX4_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
60 #define UARTMUX4_TX_DRV_BUFFER_SIZE 100
61 #define UARTMUX4_RX_DRV_BUFFER_SIZE 300
62  // uartmux4_cmd
64 
79 #define UARTMUX4_MAP_MIKROBUS( cfg, mikrobus ) \
80  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
81  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
82  cfg.sw = MIKROBUS( mikrobus, MIKROBUS_RST )
83  // uartmux4_map // uartmux4
86 
91 typedef struct
92 {
93  // Output pins
94  digital_out_t sw;
96  // Modules
97  uart_t uart;
99  // Buffers
100  uint8_t uart_rx_buffer[ UARTMUX4_RX_DRV_BUFFER_SIZE ];
101  uint8_t uart_tx_buffer[ UARTMUX4_TX_DRV_BUFFER_SIZE ];
103 } uartmux4_t;
104 
109 typedef struct
110 {
111  // Communication gpio pins
112  pin_name_t rx_pin;
113  pin_name_t tx_pin;
115  // Additional gpio pins
116  pin_name_t sw;
118  // Static variable
119  uint32_t baud_rate;
121  uart_data_bits_t data_bit;
122  uart_parity_t parity_bit;
123  uart_stop_bits_t stop_bit;
126 
131 typedef enum
132 {
134  UARTMUX4_ERROR = -1
135 
137 
154 
169 
182 err_t uartmux4_generic_write ( uartmux4_t *ctx, uint8_t *data_in, uint16_t len );
183 
196 err_t uartmux4_generic_read ( uartmux4_t *ctx, uint8_t *data_out, uint16_t len );
197 
209 
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 #endif // UARTMUX4_H
226  // uartmux4
228 
229 // ------------------------------------------------------------------------ END
UARTMUX4_ERROR
@ UARTMUX4_ERROR
Definition: uartmux4.h:134
uartmux4_init
err_t uartmux4_init(uartmux4_t *ctx, uartmux4_cfg_t *cfg)
UART MUX 4 initialization function.
uartmux4_cfg_t::sw
pin_name_t sw
Definition: uartmux4.h:116
uartmux4_generic_read
err_t uartmux4_generic_read(uartmux4_t *ctx, uint8_t *data_out, uint16_t len)
UART MUX 4 data reading function.
uartmux4_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: uartmux4.h:122
uartmux4_enable_uart1
void uartmux4_enable_uart1(uartmux4_t *ctx)
UART MUX 4 enable the UART 1 function.
uartmux4_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: uartmux4.h:123
uartmux4_t
UART MUX 4 Click context object.
Definition: uartmux4.h:92
uartmux4_cfg_t::tx_pin
pin_name_t tx_pin
Definition: uartmux4.h:113
uartmux4_enable_uart2
void uartmux4_enable_uart2(uartmux4_t *ctx)
UART MUX 4 enable the UART 2 function.
UARTMUX4_OK
@ UARTMUX4_OK
Definition: uartmux4.h:133
uartmux4_t::uart
uart_t uart
Definition: uartmux4.h:97
uartmux4_cfg_t
UART MUX 4 Click configuration object.
Definition: uartmux4.h:110
UARTMUX4_RX_DRV_BUFFER_SIZE
#define UARTMUX4_RX_DRV_BUFFER_SIZE
Definition: uartmux4.h:61
uartmux4_generic_write
err_t uartmux4_generic_write(uartmux4_t *ctx, uint8_t *data_in, uint16_t len)
UART MUX 4 data writing function.
uartmux4_cfg_setup
void uartmux4_cfg_setup(uartmux4_cfg_t *cfg)
UART MUX 4 configuration object setup function.
uartmux4_return_value_t
uartmux4_return_value_t
UART MUX 4 Click return value data.
Definition: uartmux4.h:132
uartmux4_t::sw
digital_out_t sw
Definition: uartmux4.h:94
uartmux4_cfg_t::rx_pin
pin_name_t rx_pin
Definition: uartmux4.h:112
uartmux4_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: uartmux4.h:121
uartmux4_cfg_t::uart_blocking
bool uart_blocking
Definition: uartmux4.h:120
uartmux4_cfg_t::baud_rate
uint32_t baud_rate
Definition: uartmux4.h:119
UARTMUX4_TX_DRV_BUFFER_SIZE
#define UARTMUX4_TX_DRV_BUFFER_SIZE
UART MUX 4 driver buffer size.
Definition: uartmux4.h:60