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
32 extern "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  // 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  // rs2323_map // rs2323
102 
107 typedef 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 
130 typedef 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;
149 } rs2323_cfg_t;
150 
155 typedef enum
156 {
158  RS2323_ERROR = -1
159 
161 
178 
192 err_t rs2323_init ( rs2323_t *ctx, rs2323_cfg_t *cfg );
193 
206 err_t rs2323_generic_write ( rs2323_t *ctx, char *data_buf, uint16_t len );
207 
220 err_t rs2323_generic_read ( rs2323_t *ctx, char *data_buf, uint16_t max_len );
221 
231 void rs2323_set_shutdown_pin ( rs2323_t *ctx, uint8_t state );
232 
242 void rs2323_set_enable_pin ( rs2323_t *ctx, uint8_t state );
243 
253 void rs2323_set_online_pin ( rs2323_t *ctx, uint8_t state );
254 
264 
265 #ifdef __cplusplus
266 }
267 #endif
268 #endif // RS2323_H
269  // rs2323
271 
272 // ------------------------------------------------------------------------ END
rs2323_t::sta
digital_in_t sta
Definition: rs2323.h:115
rs2323_set_shutdown_pin
void rs2323_set_shutdown_pin(rs2323_t *ctx, uint8_t state)
RS232 3 set shutdown pin function.
rs2323_cfg_t::on
pin_name_t on
Definition: rs2323.h:139
rs2323_cfg_t::sta
pin_name_t sta
Definition: rs2323.h:140
rs2323_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs2323.h:147
rs2323_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs2323.h:133
RS2323_OK
@ RS2323_OK
Definition: rs2323.h:157
rs2323_cfg_t
RS232 3 Click configuration object.
Definition: rs2323.h:131
RS2323_ERROR
@ RS2323_ERROR
Definition: rs2323.h:158
rs2323_generic_write
err_t rs2323_generic_write(rs2323_t *ctx, char *data_buf, uint16_t len)
RS232 3 data writing function.
rs2323_t::en
digital_out_t en
Definition: rs2323.h:111
rs2323_cfg_setup
void rs2323_cfg_setup(rs2323_cfg_t *cfg)
RS232 3 configuration object setup function.
rs2323_generic_read
err_t rs2323_generic_read(rs2323_t *ctx, char *data_buf, uint16_t max_len)
RS232 3 data reading function.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
RS232 3 driver buffer size.
Definition: rs2323.h:74
rs2323_get_status_pin
uint8_t rs2323_get_status_pin(rs2323_t *ctx)
RS232 3 get status pin function.
rs2323_return_value_t
rs2323_return_value_t
RS232 3 Click return value data.
Definition: rs2323.h:156
rs2323_cfg_t::shd
pin_name_t shd
Definition: rs2323.h:137
rs2323_set_online_pin
void rs2323_set_online_pin(rs2323_t *ctx, uint8_t state)
RS232 3 set online pin function.
rs2323_cfg_t::uart_blocking
bool uart_blocking
Definition: rs2323.h:144
rs2323_init
err_t rs2323_init(rs2323_t *ctx, rs2323_cfg_t *cfg)
RS232 3 initialization function.
rs2323_t::shd
digital_out_t shd
Definition: rs2323.h:110
rs2323_set_enable_pin
void rs2323_set_enable_pin(rs2323_t *ctx, uint8_t state)
RS232 3 set enable pin function.
rs2323_t
RS232 3 Click context object.
Definition: rs2323.h:108
rs2323_cfg_t::en
pin_name_t en
Definition: rs2323.h:138
rs2323_t::on
digital_out_t on
Definition: rs2323.h:112
rs2323_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs2323.h:134
rs2323_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs2323.h:145
rs2323_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs2323.h:143
rs2323_t::uart
uart_t uart
Definition: rs2323.h:118
rs2323_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs2323.h:146