rs2322  2.0.0.0
rs2322.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef RS2322_H
36 #define RS2322_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define RS2322_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.dtr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
56  cfg.dcd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
57  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
59  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
60 
66 #define RS2322_RETVAL uint8_t
67 
68 #define RS2322_OK 0x00
69 #define RS2322_INIT_ERROR 0xFF
70 
76 #define DRV_RX_BUFFER_SIZE 500
77  // End group macro
80 // --------------------------------------------------------------- PUBLIC TYPES
88 typedef struct
89 {
90  // Output pins
91 
92  digital_out_t dcd;
93  digital_out_t cts;
94  digital_out_t ri;
95 
96  // Input pins
97 
98  digital_in_t dtr;
99  digital_in_t rts;
100 
101  // Modules
102 
103  uart_t uart;
104 
105  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
106  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
107 
108 } rs2322_t;
109 
113 typedef struct
114 {
115  // Communication gpio pins
116 
117  pin_name_t rx_pin;
118  pin_name_t tx_pin;
119 
120  // Additional gpio pins
121 
122  pin_name_t dtr;
123  pin_name_t dcd;
124  pin_name_t cts;
125  pin_name_t ri;
126  pin_name_t rts;
127 
128  // static variable
129 
130  uint32_t baud_rate; // Clock speed.
132  uart_data_bits_t data_bit; // Data bits.
133  uart_parity_t parity_bit; // Parity bit.
134  uart_stop_bits_t stop_bit; // Stop bits.
135 
136 } rs2322_cfg_t;
137 
141 typedef uint8_t rs2322_error_t;
142  // End types group
144 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
145 
151 #ifdef __cplusplus
152 extern "C"{
153 #endif
154 
163 void rs2322_cfg_setup ( rs2322_cfg_t *cfg );
164 
173 
180 void rs2322_generic_write ( rs2322_t *ctx, char *data_buf, uint16_t len );
181 
189 int16_t rs2322_generic_read ( rs2322_t *ctx, char *data_buf, uint16_t max_len );
190 
199 void rs2322_set_dcd ( rs2322_t *ctx, uint8_t state );
200 
209 void rs2322_set_cts ( rs2322_t *ctx, uint8_t state );
210 
219 void rs2322_set_ri ( rs2322_t *ctx, uint8_t state );
220 
228 uint8_t rs2322_get_rts ( rs2322_t *ctx );
229 
237 uint8_t rs2322_get_dtr ( rs2322_t *ctx );
238 
245 void rs2322_send_command ( rs2322_t *ctx, char *command );
246 
247 #ifdef __cplusplus
248 }
249 #endif
250 #endif // _RS2322_H_
251  // End public_function group
254 
255 // ------------------------------------------------------------------------- END
rs2322_t
Click ctx object definition.
Definition: rs2322.h:88
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rs2322.h:76
rs2322_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs2322.h:132
rs2322_t::cts
digital_out_t cts
Definition: rs2322.h:93
rs2322_set_ri
void rs2322_set_ri(rs2322_t *ctx, uint8_t state)
This function sets RI pin state.
rs2322_send_command
void rs2322_send_command(rs2322_t *ctx, char *command)
Function for send command.
rs2322_t::rts
digital_in_t rts
Definition: rs2322.h:99
rs2322_error_t
uint8_t rs2322_error_t
Error type.
Definition: rs2322.h:141
rs2322_get_dtr
uint8_t rs2322_get_dtr(rs2322_t *ctx)
This function get DTR pin state.
rs2322_cfg_t::cts
pin_name_t cts
Definition: rs2322.h:124
rs2322_init
RS2322_RETVAL rs2322_init(rs2322_t *ctx, rs2322_cfg_t *cfg)
Initialization function.
rs2322_t::uart
uart_t uart
Definition: rs2322.h:103
RS2322_RETVAL
#define RS2322_RETVAL
Definition: rs2322.h:66
rs2322_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs2322.h:117
rs2322_cfg_t
Click configuration structure definition.
Definition: rs2322.h:113
rs2322_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs2322.h:130
rs2322_cfg_t::rts
pin_name_t rts
Definition: rs2322.h:126
rs2322_t::dcd
digital_out_t dcd
Definition: rs2322.h:92
rs2322_t::dtr
digital_in_t dtr
Definition: rs2322.h:98
rs2322_cfg_t::uart_blocking
bool uart_blocking
Definition: rs2322.h:131
rs2322_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs2322.h:134
rs2322_t::ri
digital_out_t ri
Definition: rs2322.h:94
rs2322_cfg_t::dtr
pin_name_t dtr
Definition: rs2322.h:122
rs2322_generic_read
int16_t rs2322_generic_read(rs2322_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
rs2322_cfg_t::ri
pin_name_t ri
Definition: rs2322.h:125
rs2322_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs2322.h:133
rs2322_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs2322.h:118
rs2322_set_cts
void rs2322_set_cts(rs2322_t *ctx, uint8_t state)
This function sets CTS pin state.
rs2322_generic_write
void rs2322_generic_write(rs2322_t *ctx, char *data_buf, uint16_t len)
Generic write function.
rs2322_cfg_t::dcd
pin_name_t dcd
Definition: rs2322.h:123
rs2322_get_rts
uint8_t rs2322_get_rts(rs2322_t *ctx)
This function get RST pin state.
rs2322_set_dcd
void rs2322_set_dcd(rs2322_t *ctx, uint8_t state)
This function sets DCD pin state.
rs2322_cfg_setup
void rs2322_cfg_setup(rs2322_cfg_t *cfg)
Config Object Initialization function.