rs485isolator  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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define RS232ISOLATOR_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
57 
63 #define RS232ISOLATOR_RETVAL uint8_t
64 
65 #define RS232ISOLATOR_OK 0x00
66 #define RS232ISOLATOR_INIT_ERROR 0xFF
67 
73 #define DRV_RX_BUFFER_SIZE 500
74  // End group macro
77 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87  // Output pins
88 
89  digital_out_t cts;
90 
91  // Input pins
92 
93  digital_in_t rts;
94 
95  // Modules
96 
97  uart_t uart;
98 
99  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
100  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
101 
103 
107 typedef struct
108 {
109  // Communication gpio pins
110 
111  pin_name_t rx_pin;
112  pin_name_t tx_pin;
113 
114  // Additional gpio pins
115 
116  pin_name_t cts;
117  pin_name_t rts;
118 
119  // static variable
120 
121  uint32_t baud_rate; // Clock speed.
123  uart_data_bits_t data_bit; // Data bits.
124  uart_parity_t parity_bit; // Parity bit.
125  uart_stop_bits_t stop_bit; // Stop bits.
126 
128 
132 typedef uint8_t rs232isolator_error_t;
133  // End types group
135 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
136 
142 #ifdef __cplusplus
143 extern "C"{
144 #endif
145 
155 
164 
171 void rs232isolator_generic_write ( rs232isolator_t *ctx, char *data_buf, uint16_t len );
172 
180 int16_t rs232isolator_generic_read ( rs232isolator_t *ctx, char *data_buf, uint16_t max_len );
181 
190 void rs232_2_set_rts ( rs232isolator_t *ctx, uint8_t state );
191 
200 
207 void rs232isolator_send_command ( rs232isolator_t *ctx, char *command );
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 #endif // _RS232ISOLATOR_H_
213  // End public_function group
216 
217 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rs232isolator.h:73
rs232isolator_t::cts
digital_out_t cts
Definition: rs232isolator.h:89
RS232ISOLATOR_RETVAL
#define RS232ISOLATOR_RETVAL
Definition: rs232isolator.h:63
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:116
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:121
rs232isolator_cfg_t
Click configuration structure definition.
Definition: rs232isolator.h:108
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:125
rs232isolator_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs232isolator.h:111
rs232isolator_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs232isolator.h:112
rs232isolator_t::rts
digital_in_t rts
Definition: rs232isolator.h:93
rs232isolator_cfg_t::uart_blocking
bool uart_blocking
Definition: rs232isolator.h:122
rs232isolator_error_t
uint8_t rs232isolator_error_t
Error type.
Definition: rs232isolator.h:132
rs232isolator_cfg_t::rts
pin_name_t rts
Definition: rs232isolator.h:117
rs232isolator_t::uart
uart_t uart
Definition: rs232isolator.h:97
rs232isolator_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs232isolator.h:124
rs232isolator_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs232isolator.h:123
rs232isolator_t
Click ctx object definition.
Definition: rs232isolator.h:86