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
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 // TODO -- dodati makroe koji definisu adrese registara
60  // uartmux2_reg
62 
83 #define DRV_BUFFER_SIZE 200
84  // uartmux2_set
86 
97 #define UARTMUX2_SUCCESS 0
98 #define UARTMUX2_ERROR -1
99 
100  // status
102 
113 #define UARTMUX2_OP_MODE_NORMAL 0x00
114 #define UARTMUX2_OP_MODE_POWER_DOWN 0x01
115 
116  // op_mode
118 
129 #define UARTMUX2_CHANNEL_0 0
130 #define UARTMUX2_CHANNEL_1 1
131 #define UARTMUX2_CHANNEL_2 2
132 #define UARTMUX2_CHANNEL_3 3
133 
134  // mux_ch
136 
151 #define UARTMUX2_MAP_MIKROBUS( cfg, mikrobus ) \
152  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
153  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
154  cfg.off = MIKROBUS( mikrobus, MIKROBUS_AN ); \
155  cfg.a1 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
156  cfg.a0 = MIKROBUS( mikrobus, MIKROBUS_CS ); \
157  cfg.on = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
158  cfg.inv = MIKROBUS( mikrobus, MIKROBUS_INT );
159  // uartmux2_map // uartmux2
162 
167 typedef struct
168 {
169  // Output pins
170 
171  digital_out_t off;
172  digital_out_t a1;
173  digital_out_t a0;
174  digital_out_t on;
176  // Input pins
177 
178  digital_in_t inv;
180  // Modules
181 
182  uart_t uart;
184  // Buffers
185 
186  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
187  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
189 } uartmux2_t;
190 
195 typedef struct
196 {
197  // Communication gpio pins
198 
199  pin_name_t rx_pin;
200  pin_name_t tx_pin;
202  // Additional gpio pins
203 
204  pin_name_t off;
205  pin_name_t a1;
206  pin_name_t a0;
207  pin_name_t on;
208  pin_name_t inv;
210  // Static variable
211 
212  uint32_t baud_rate;
214  uart_data_bits_t data_bit;
215  uart_parity_t parity_bit;
216  uart_stop_bits_t stop_bit;
219 
236 
252 
264 
278 err_t uartmux2_generic_write ( uartmux2_t *ctx, char *data_buf, uint16_t len );
279 
293 err_t uartmux2_generic_read ( uartmux2_t *ctx, char *data_buf, uint16_t max_len );
294 
310 err_t uartmux2_set_operation_mode ( uartmux2_t *ctx, uint8_t op_mode );
311 
329 err_t uartmux2_set_channel ( uartmux2_t *ctx, uint8_t mux_ch );
330 
343 err_t uartmux2_send_data ( uartmux2_t *ctx, char *tx_data );
344 
358 
359 #ifdef __cplusplus
360 }
361 #endif
362 #endif // UARTMUX2_H
363  // uartmux2
365 
366 // ------------------------------------------------------------------------ END
uartmux2_set_operation_mode
err_t uartmux2_set_operation_mode(uartmux2_t *ctx, uint8_t op_mode)
UART MUX 2 set operation mode function.
uartmux2_cfg_t::baud_rate
uint32_t baud_rate
Definition: uartmux2.h:212
uartmux2_default_cfg
void uartmux2_default_cfg(uartmux2_t *ctx)
UART MUX 2 default configuration function.
uartmux2_cfg_t::a0
pin_name_t a0
Definition: uartmux2.h:206
uartmux2_cfg_t::on
pin_name_t on
Definition: uartmux2.h:207
uartmux2_set_channel
err_t uartmux2_set_channel(uartmux2_t *ctx, uint8_t mux_ch)
UART MUX 2 set channel function.
uartmux2_cfg_setup
void uartmux2_cfg_setup(uartmux2_cfg_t *cfg)
UART MUX 2 configuration object setup function.
uartmux2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: uartmux2.h:215
uartmux2_t::on
digital_out_t on
Definition: uartmux2.h:174
uartmux2_generic_read
err_t uartmux2_generic_read(uartmux2_t *ctx, char *data_buf, uint16_t max_len)
UART MUX 2 data reading function.
uartmux2_t::off
digital_out_t off
Definition: uartmux2.h:171
uartmux2_cfg_t::a1
pin_name_t a1
Definition: uartmux2.h:205
uartmux2_t::a0
digital_out_t a0
Definition: uartmux2.h:173
uartmux2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: uartmux2.h:200
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
UART MUX 2 description setting.
Definition: uartmux2.h:83
uartmux2_t::uart
uart_t uart
Definition: uartmux2.h:182
uartmux2_cfg_t::off
pin_name_t off
Definition: uartmux2.h:204
uartmux2_init
err_t uartmux2_init(uartmux2_t *ctx, uartmux2_cfg_t *cfg)
UART MUX 2 initialization function.
uartmux2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: uartmux2.h:216
uartmux2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: uartmux2.h:199
uartmux2_t
UART MUX 2 Click context object.
Definition: uartmux2.h:168
uartmux2_cfg_t::inv
pin_name_t inv
Definition: uartmux2.h:208
uartmux2_generic_write
err_t uartmux2_generic_write(uartmux2_t *ctx, char *data_buf, uint16_t len)
UART MUX 2 data writing function.
uartmux2_t::inv
digital_in_t inv
Definition: uartmux2.h:178
uartmux2_send_data
err_t uartmux2_send_data(uartmux2_t *ctx, char *tx_data)
UART MUX 2 data writing function.
uartmux2_cfg_t::uart_blocking
bool uart_blocking
Definition: uartmux2.h:213
uartmux2_cfg_t
UART MUX 2 Click configuration object.
Definition: uartmux2.h:196
uartmux2_get_inv_status
uint8_t uartmux2_get_inv_status(uartmux2_t *ctx)
UART MUX 2 get INV pin status function.
uartmux2_t::a1
digital_out_t a1
Definition: uartmux2.h:172
uartmux2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: uartmux2.h:214