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 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
70 #define DRV_BUFFER_SIZE 200
71  // rs2323_cmd
73 
88 #define RS2323_MAP_MIKROBUS( cfg, mikrobus ) \
89  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
90  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
91  cfg.shd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
92  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
93  cfg.on = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
94  cfg.sta = MIKROBUS( mikrobus, MIKROBUS_INT );
95  // rs2323_map // rs2323
98 
103 typedef struct
104 {
105  // Output pins
106  digital_out_t shd;
107  digital_out_t en;
108  digital_out_t on;
110  // Input pins
111  digital_in_t sta;
113  // Modules
114  uart_t uart;
116  // Buffers
117  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
118  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
120 } rs2323_t;
121 
126 typedef struct
127 {
128  // Communication gpio pins
129  pin_name_t rx_pin;
130  pin_name_t tx_pin;
132  // Additional gpio pins
133  pin_name_t shd;
134  pin_name_t en;
135  pin_name_t on;
136  pin_name_t sta;
138  // Static variable
139  uint32_t baud_rate;
141  uart_data_bits_t data_bit;
142  uart_parity_t parity_bit;
143  uart_stop_bits_t stop_bit;
145 } rs2323_cfg_t;
146 
151 typedef enum
152 {
154  RS2323_ERROR = -1
155 
157 
174 
188 err_t rs2323_init ( rs2323_t *ctx, rs2323_cfg_t *cfg );
189 
202 err_t rs2323_generic_write ( rs2323_t *ctx, char *data_buf, uint16_t len );
203 
216 err_t rs2323_generic_read ( rs2323_t *ctx, char *data_buf, uint16_t max_len );
217 
227 void rs2323_set_shutdown_pin ( rs2323_t *ctx, uint8_t state );
228 
238 void rs2323_set_enable_pin ( rs2323_t *ctx, uint8_t state );
239 
249 void rs2323_set_online_pin ( rs2323_t *ctx, uint8_t state );
250 
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif // RS2323_H
265  // rs2323
267 
268 // ------------------------------------------------------------------------ END
rs2323_t::sta
digital_in_t sta
Definition: rs2323.h:111
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:135
rs2323_cfg_t::sta
pin_name_t sta
Definition: rs2323.h:136
rs2323_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs2323.h:143
rs2323_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs2323.h:129
RS2323_OK
@ RS2323_OK
Definition: rs2323.h:153
rs2323_cfg_t
RS232 3 Click configuration object.
Definition: rs2323.h:127
RS2323_ERROR
@ RS2323_ERROR
Definition: rs2323.h:154
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:107
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:70
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:152
rs2323_cfg_t::shd
pin_name_t shd
Definition: rs2323.h:133
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:140
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:106
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:104
rs2323_cfg_t::en
pin_name_t en
Definition: rs2323.h:134
rs2323_t::on
digital_out_t on
Definition: rs2323.h:108
rs2323_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs2323.h:130
rs2323_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs2323.h:141
rs2323_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs2323.h:139
rs2323_t::uart
uart_t uart
Definition: rs2323.h:114
rs2323_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs2323.h:142