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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_uart.h"
55 
56 // -------------------------------------------------------------- PUBLIC MACROS
66 #define RS2322_MAP_MIKROBUS( cfg, mikrobus ) \
67  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69  cfg.dtr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70  cfg.dcd = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72  cfg.ri = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
74 
80 #define RS2322_RETVAL uint8_t
81 
82 #define RS2322_OK 0x00
83 #define RS2322_INIT_ERROR 0xFF
84 
90 #define DRV_RX_BUFFER_SIZE 500
91  // End group macro
94 // --------------------------------------------------------------- PUBLIC TYPES
102 typedef struct
103 {
104  // Output pins
105 
106  digital_out_t dcd;
107  digital_out_t cts;
108  digital_out_t ri;
109 
110  // Input pins
111 
112  digital_in_t dtr;
113  digital_in_t rts;
114 
115  // Modules
116 
117  uart_t uart;
118 
119  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
120  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
121 
122 } rs2322_t;
123 
127 typedef struct
128 {
129  // Communication gpio pins
130 
131  pin_name_t rx_pin;
132  pin_name_t tx_pin;
133 
134  // Additional gpio pins
135 
136  pin_name_t dtr;
137  pin_name_t dcd;
138  pin_name_t cts;
139  pin_name_t ri;
140  pin_name_t rts;
141 
142  // static variable
143 
144  uint32_t baud_rate; // Clock speed.
146  uart_data_bits_t data_bit; // Data bits.
147  uart_parity_t parity_bit; // Parity bit.
148  uart_stop_bits_t stop_bit; // Stop bits.
149 
150 } rs2322_cfg_t;
151 
155 typedef uint8_t rs2322_error_t;
156  // End types group
158 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
159 
165 #ifdef __cplusplus
166 extern "C"{
167 #endif
168 
178 
187 
194 void rs2322_generic_write ( rs2322_t *ctx, char *data_buf, uint16_t len );
195 
203 int16_t rs2322_generic_read ( rs2322_t *ctx, char *data_buf, uint16_t max_len );
204 
213 void rs2322_set_dcd ( rs2322_t *ctx, uint8_t state );
214 
223 void rs2322_set_cts ( rs2322_t *ctx, uint8_t state );
224 
233 void rs2322_set_ri ( rs2322_t *ctx, uint8_t state );
234 
242 uint8_t rs2322_get_rts ( rs2322_t *ctx );
243 
251 uint8_t rs2322_get_dtr ( rs2322_t *ctx );
252 
259 void rs2322_send_command ( rs2322_t *ctx, char *command );
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif // _RS2322_H_
265  // End public_function group
268 
269 // ------------------------------------------------------------------------- END
rs2322_t
Click ctx object definition.
Definition: rs2322.h:103
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rs2322.h:90
rs2322_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs2322.h:146
rs2322_t::cts
digital_out_t cts
Definition: rs2322.h:107
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:113
rs2322_error_t
uint8_t rs2322_error_t
Error type.
Definition: rs2322.h:155
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:138
rs2322_init
RS2322_RETVAL rs2322_init(rs2322_t *ctx, rs2322_cfg_t *cfg)
Initialization function.
rs2322_t::uart
uart_t uart
Definition: rs2322.h:117
RS2322_RETVAL
#define RS2322_RETVAL
Definition: rs2322.h:80
rs2322_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs2322.h:131
rs2322_cfg_t
Click configuration structure definition.
Definition: rs2322.h:128
rs2322_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs2322.h:144
rs2322_cfg_t::rts
pin_name_t rts
Definition: rs2322.h:140
rs2322_t::dcd
digital_out_t dcd
Definition: rs2322.h:106
rs2322_t::dtr
digital_in_t dtr
Definition: rs2322.h:112
rs2322_cfg_t::uart_blocking
bool uart_blocking
Definition: rs2322.h:145
rs2322_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs2322.h:148
rs2322_t::ri
digital_out_t ri
Definition: rs2322.h:108
rs2322_cfg_t::dtr
pin_name_t dtr
Definition: rs2322.h:136
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:139
rs2322_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs2322.h:147
rs2322_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs2322.h:132
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:137
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.