rs232isolator  2.0.0.0
rs232isolator.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 RS232ISOLATOR_H
36 #define RS232ISOLATOR_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define RS232ISOLATOR_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
66  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
67 
73 #define RS232ISOLATOR_RETVAL uint8_t
74 
75 #define RS232ISOLATOR_OK 0x00
76 #define RS232ISOLATOR_INIT_ERROR 0xFF
77 
83 #define DRV_RX_BUFFER_SIZE 500
84  // End group macro
87 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef struct
96 {
97  // Output pins
98 
99  digital_out_t cts;
100 
101  // Input pins
102 
103  digital_in_t rts;
104 
105  // Modules
106 
107  uart_t uart;
108 
109  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
110  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
111 
113 
117 typedef struct
118 {
119  // Communication gpio pins
120 
121  pin_name_t rx_pin;
122  pin_name_t tx_pin;
123 
124  // Additional gpio pins
125 
126  pin_name_t cts;
127  pin_name_t rts;
128 
129  // static variable
130 
131  uint32_t baud_rate; // Clock speed.
133  uart_data_bits_t data_bit; // Data bits.
134  uart_parity_t parity_bit; // Parity bit.
135  uart_stop_bits_t stop_bit; // Stop bits.
136 
138 
142 typedef uint8_t rs232isolator_error_t;
143  // End types group
145 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
146 
152 #ifdef __cplusplus
153 extern "C"{
154 #endif
155 
165 
174 
181 void rs232isolator_generic_write ( rs232isolator_t *ctx, char *data_buf, uint16_t len );
182 
190 int16_t rs232isolator_generic_read ( rs232isolator_t *ctx, char *data_buf, uint16_t max_len );
191 
200 void rs232_2_set_rts ( rs232isolator_t *ctx, uint8_t state );
201 
210 
217 void rs232isolator_send_command ( rs232isolator_t *ctx, char *command );
218 
219 #ifdef __cplusplus
220 }
221 #endif
222 #endif // _RS232ISOLATOR_H_
223  // End public_function group
226 
227 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rs232isolator.h:83
rs232isolator_t::cts
digital_out_t cts
Definition: rs232isolator.h:99
RS232ISOLATOR_RETVAL
#define RS232ISOLATOR_RETVAL
Definition: rs232isolator.h:73
rs232_2_get_cts
uint8_t rs232_2_get_cts(rs232isolator_t *ctx)
Read CTS state.
rs232_2_set_rts
void rs232_2_set_rts(rs232isolator_t *ctx, uint8_t state)
Function settings RTS state.
rs232isolator_send_command
void rs232isolator_send_command(rs232isolator_t *ctx, char *command)
Function for send command.
rs232isolator_cfg_t::cts
pin_name_t cts
Definition: rs232isolator.h:126
rs232isolator_cfg_setup
void rs232isolator_cfg_setup(rs232isolator_cfg_t *cfg)
Config Object Initialization function.
rs232isolator_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs232isolator.h:131
rs232isolator_cfg_t
Click configuration structure definition.
Definition: rs232isolator.h:118
rs232isolator_generic_write
void rs232isolator_generic_write(rs232isolator_t *ctx, char *data_buf, uint16_t len)
Generic write function.
rs232isolator_init
RS232ISOLATOR_RETVAL rs232isolator_init(rs232isolator_t *ctx, rs232isolator_cfg_t *cfg)
Initialization function.
rs232isolator_generic_read
int16_t rs232isolator_generic_read(rs232isolator_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
rs232isolator_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs232isolator.h:135
rs232isolator_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs232isolator.h:121
rs232isolator_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs232isolator.h:122
rs232isolator_t::rts
digital_in_t rts
Definition: rs232isolator.h:103
rs232isolator_cfg_t::uart_blocking
bool uart_blocking
Definition: rs232isolator.h:132
rs232isolator_error_t
uint8_t rs232isolator_error_t
Error type.
Definition: rs232isolator.h:142
rs232isolator_cfg_t::rts
pin_name_t rts
Definition: rs232isolator.h:127
rs232isolator_t::uart
uart_t uart
Definition: rs232isolator.h:107
rs232isolator_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs232isolator.h:134
rs232isolator_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs232isolator.h:133
rs232isolator_t
Click ctx object definition.
Definition: rs232isolator.h:96