rs2323 2.0.0.0
rs2323.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 RS2323_H
29#define RS2323_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 DRV_BUFFER_SIZE 200
75
76 // rs2323_cmd
77
92#define RS2323_MAP_MIKROBUS( cfg, mikrobus ) \
93 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
94 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
95 cfg.shd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
96 cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
97 cfg.on = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
98 cfg.sta = MIKROBUS( mikrobus, MIKROBUS_INT );
99
100 // rs2323_map
101 // rs2323
102
107typedef struct
108{
109 // Output pins
110 digital_out_t shd;
111 digital_out_t en;
112 digital_out_t on;
114 // Input pins
115 digital_in_t sta;
117 // Modules
118 uart_t uart;
120 // Buffers
121 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
122 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
124} rs2323_t;
125
130typedef struct
131{
132 // Communication gpio pins
133 pin_name_t rx_pin;
134 pin_name_t tx_pin;
136 // Additional gpio pins
137 pin_name_t shd;
138 pin_name_t en;
139 pin_name_t on;
140 pin_name_t sta;
142 // Static variable
143 uint32_t baud_rate;
145 uart_data_bits_t data_bit;
146 uart_parity_t parity_bit;
147 uart_stop_bits_t stop_bit;
150
155typedef enum
156{
158 RS2323_ERROR = -1
159
161
178
192err_t rs2323_init ( rs2323_t *ctx, rs2323_cfg_t *cfg );
193
206err_t rs2323_generic_write ( rs2323_t *ctx, char *data_buf, uint16_t len );
207
220err_t rs2323_generic_read ( rs2323_t *ctx, char *data_buf, uint16_t max_len );
221
231void rs2323_set_shutdown_pin ( rs2323_t *ctx, uint8_t state );
232
242void rs2323_set_enable_pin ( rs2323_t *ctx, uint8_t state );
243
253void rs2323_set_online_pin ( rs2323_t *ctx, uint8_t state );
254
264
265#ifdef __cplusplus
266}
267#endif
268#endif // RS2323_H
269
270 // rs2323
271
272// ------------------------------------------------------------------------ END
#define DRV_BUFFER_SIZE
RS232 3 driver buffer size.
Definition rs2323.h:74
void rs2323_set_enable_pin(rs2323_t *ctx, uint8_t state)
RS232 3 set enable pin function.
err_t rs2323_generic_write(rs2323_t *ctx, char *data_buf, uint16_t len)
RS232 3 data writing function.
err_t rs2323_generic_read(rs2323_t *ctx, char *data_buf, uint16_t max_len)
RS232 3 data reading function.
void rs2323_cfg_setup(rs2323_cfg_t *cfg)
RS232 3 configuration object setup function.
void rs2323_set_online_pin(rs2323_t *ctx, uint8_t state)
RS232 3 set online pin function.
uint8_t rs2323_get_status_pin(rs2323_t *ctx)
RS232 3 get status pin function.
void rs2323_set_shutdown_pin(rs2323_t *ctx, uint8_t state)
RS232 3 set shutdown pin function.
err_t rs2323_init(rs2323_t *ctx, rs2323_cfg_t *cfg)
RS232 3 initialization function.
rs2323_return_value_t
RS232 3 Click return value data.
Definition rs2323.h:156
@ RS2323_OK
Definition rs2323.h:157
@ RS2323_ERROR
Definition rs2323.h:158
RS232 3 Click configuration object.
Definition rs2323.h:131
pin_name_t sta
Definition rs2323.h:140
uint32_t baud_rate
Definition rs2323.h:143
bool uart_blocking
Definition rs2323.h:144
uart_data_bits_t data_bit
Definition rs2323.h:145
pin_name_t on
Definition rs2323.h:139
pin_name_t tx_pin
Definition rs2323.h:134
pin_name_t rx_pin
Definition rs2323.h:133
pin_name_t shd
Definition rs2323.h:137
uart_stop_bits_t stop_bit
Definition rs2323.h:147
pin_name_t en
Definition rs2323.h:138
uart_parity_t parity_bit
Definition rs2323.h:146
RS232 3 Click context object.
Definition rs2323.h:108
digital_in_t sta
Definition rs2323.h:115
digital_out_t on
Definition rs2323.h:112
uart_t uart
Definition rs2323.h:118
digital_out_t en
Definition rs2323.h:111
digital_out_t shd
Definition rs2323.h:110