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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
60 #define DRV_BUFFER_SIZE 200
61  // rs2323_cmd
63 
78 #define RS2323_MAP_MIKROBUS( cfg, mikrobus ) \
79  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
80  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
81  cfg.shd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
82  cfg.en = MIKROBUS( mikrobus, MIKROBUS_CS ); \
83  cfg.on = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
84  cfg.sta = MIKROBUS( mikrobus, MIKROBUS_INT );
85  // rs2323_map // rs2323
88 
93 typedef struct
94 {
95  // Output pins
96  digital_out_t shd;
97  digital_out_t en;
98  digital_out_t on;
100  // Input pins
101  digital_in_t sta;
103  // Modules
104  uart_t uart;
106  // Buffers
107  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
108  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
110 } rs2323_t;
111 
116 typedef struct
117 {
118  // Communication gpio pins
119  pin_name_t rx_pin;
120  pin_name_t tx_pin;
122  // Additional gpio pins
123  pin_name_t shd;
124  pin_name_t en;
125  pin_name_t on;
126  pin_name_t sta;
128  // Static variable
129  uint32_t baud_rate;
131  uart_data_bits_t data_bit;
132  uart_parity_t parity_bit;
133  uart_stop_bits_t stop_bit;
135 } rs2323_cfg_t;
136 
141 typedef enum
142 {
144  RS2323_ERROR = -1
145 
147 
164 
178 err_t rs2323_init ( rs2323_t *ctx, rs2323_cfg_t *cfg );
179 
192 err_t rs2323_generic_write ( rs2323_t *ctx, char *data_buf, uint16_t len );
193 
206 err_t rs2323_generic_read ( rs2323_t *ctx, char *data_buf, uint16_t max_len );
207 
217 void rs2323_set_shutdown_pin ( rs2323_t *ctx, uint8_t state );
218 
228 void rs2323_set_enable_pin ( rs2323_t *ctx, uint8_t state );
229 
239 void rs2323_set_online_pin ( rs2323_t *ctx, uint8_t state );
240 
250 
251 #ifdef __cplusplus
252 }
253 #endif
254 #endif // RS2323_H
255  // rs2323
257 
258 // ------------------------------------------------------------------------ END
rs2323_t::sta
digital_in_t sta
Definition: rs2323.h:101
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:125
rs2323_cfg_t::sta
pin_name_t sta
Definition: rs2323.h:126
rs2323_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs2323.h:133
rs2323_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs2323.h:119
RS2323_OK
@ RS2323_OK
Definition: rs2323.h:143
rs2323_cfg_t
RS232 3 Click configuration object.
Definition: rs2323.h:117
RS2323_ERROR
@ RS2323_ERROR
Definition: rs2323.h:144
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:97
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:60
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:142
rs2323_cfg_t::shd
pin_name_t shd
Definition: rs2323.h:123
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:130
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:96
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:94
rs2323_cfg_t::en
pin_name_t en
Definition: rs2323.h:124
rs2323_t::on
digital_out_t on
Definition: rs2323.h:98
rs2323_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs2323.h:120
rs2323_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs2323.h:131
rs2323_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs2323.h:129
rs2323_t::uart
uart_t uart
Definition: rs2323.h:104
rs2323_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs2323.h:132