uartmux2 2.0.0.0
uartmux2.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 UARTMUX2_H
29#define UARTMUX2_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
73// TODO -- dodati makroe koji definisu adrese registara
74
75 // uartmux2_reg
76
97#define DRV_BUFFER_SIZE 200
98
99 // uartmux2_set
100
111#define UARTMUX2_SUCCESS 0
112#define UARTMUX2_ERROR -1
113
114
115 // status
116
127#define UARTMUX2_OP_MODE_NORMAL 0x00
128#define UARTMUX2_OP_MODE_POWER_DOWN 0x01
129
130
131 // op_mode
132
143#define UARTMUX2_CHANNEL_0 0
144#define UARTMUX2_CHANNEL_1 1
145#define UARTMUX2_CHANNEL_2 2
146#define UARTMUX2_CHANNEL_3 3
147
148
149 // mux_ch
150
165#define UARTMUX2_MAP_MIKROBUS( cfg, mikrobus ) \
166 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
167 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
168 cfg.off = MIKROBUS( mikrobus, MIKROBUS_AN ); \
169 cfg.a1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
170 cfg.a0 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
171 cfg.on = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
172 cfg.inv = MIKROBUS( mikrobus, MIKROBUS_INT );
173
174 // uartmux2_map
175 // uartmux2
176
181typedef struct
182{
183 // Output pins
184
185 digital_out_t off;
186 digital_out_t a1;
187 digital_out_t a0;
188 digital_out_t on;
190 // Input pins
191
192 digital_in_t inv;
194 // Modules
195
196 uart_t uart;
198 // Buffers
199
200 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
201 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
203} uartmux2_t;
204
209typedef struct
210{
211 // Communication gpio pins
212
213 pin_name_t rx_pin;
214 pin_name_t tx_pin;
216 // Additional gpio pins
217
218 pin_name_t off;
219 pin_name_t a1;
220 pin_name_t a0;
221 pin_name_t on;
222 pin_name_t inv;
224 // Static variable
225
226 uint32_t baud_rate;
228 uart_data_bits_t data_bit;
229 uart_parity_t parity_bit;
230 uart_stop_bits_t stop_bit;
233
250
266
278
292err_t uartmux2_generic_write ( uartmux2_t *ctx, char *data_buf, uint16_t len );
293
307err_t uartmux2_generic_read ( uartmux2_t *ctx, char *data_buf, uint16_t max_len );
308
324err_t uartmux2_set_operation_mode ( uartmux2_t *ctx, uint8_t op_mode );
325
343err_t uartmux2_set_channel ( uartmux2_t *ctx, uint8_t mux_ch );
344
357err_t uartmux2_send_data ( uartmux2_t *ctx, char *tx_data );
358
372
373#ifdef __cplusplus
374}
375#endif
376#endif // UARTMUX2_H
377
378 // uartmux2
379
380// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
UART MUX 2 description setting.
Definition uartmux2.h:97
err_t uartmux2_generic_write(uartmux2_t *ctx, char *data_buf, uint16_t len)
UART MUX 2 data writing function.
err_t uartmux2_init(uartmux2_t *ctx, uartmux2_cfg_t *cfg)
UART MUX 2 initialization function.
err_t uartmux2_send_data(uartmux2_t *ctx, char *tx_data)
UART MUX 2 data writing function.
err_t uartmux2_generic_read(uartmux2_t *ctx, char *data_buf, uint16_t max_len)
UART MUX 2 data reading function.
void uartmux2_default_cfg(uartmux2_t *ctx)
UART MUX 2 default configuration function.
err_t uartmux2_set_channel(uartmux2_t *ctx, uint8_t mux_ch)
UART MUX 2 set channel function.
err_t uartmux2_set_operation_mode(uartmux2_t *ctx, uint8_t op_mode)
UART MUX 2 set operation mode function.
void uartmux2_cfg_setup(uartmux2_cfg_t *cfg)
UART MUX 2 configuration object setup function.
uint8_t uartmux2_get_inv_status(uartmux2_t *ctx)
UART MUX 2 get INV pin status function.
UART MUX 2 Click configuration object.
Definition uartmux2.h:210
uint32_t baud_rate
Definition uartmux2.h:226
pin_name_t a0
Definition uartmux2.h:220
bool uart_blocking
Definition uartmux2.h:227
uart_data_bits_t data_bit
Definition uartmux2.h:228
pin_name_t on
Definition uartmux2.h:221
pin_name_t inv
Definition uartmux2.h:222
pin_name_t tx_pin
Definition uartmux2.h:214
pin_name_t off
Definition uartmux2.h:218
pin_name_t rx_pin
Definition uartmux2.h:213
uart_stop_bits_t stop_bit
Definition uartmux2.h:230
pin_name_t a1
Definition uartmux2.h:219
uart_parity_t parity_bit
Definition uartmux2.h:229
UART MUX 2 Click context object.
Definition uartmux2.h:182
digital_out_t a0
Definition uartmux2.h:187
digital_out_t a1
Definition uartmux2.h:186
digital_out_t on
Definition uartmux2.h:188
uart_t uart
Definition uartmux2.h:196
digital_in_t inv
Definition uartmux2.h:192
digital_out_t off
Definition uartmux2.h:185