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
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 RS232ISOLATOR_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
70 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
77#define RS232ISOLATOR_RETVAL uint8_t
78
79#define RS232ISOLATOR_OK 0x00
80#define RS232ISOLATOR_INIT_ERROR 0xFF
87#define DRV_RX_BUFFER_SIZE 500
90 // End group macro
91// --------------------------------------------------------------- PUBLIC TYPES
99typedef struct
100{
101 // Output pins
102
103 digital_out_t cts;
104
105 // Input pins
106
107 digital_in_t rts;
108
109 // Modules
110
111 uart_t uart;
112
113 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
114 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
115
117
121typedef struct
122{
123 // Communication gpio pins
124
125 pin_name_t rx_pin;
126 pin_name_t tx_pin;
127
128 // Additional gpio pins
129
130 pin_name_t cts;
131 pin_name_t rts;
132
133 // static variable
134
135 uint32_t baud_rate; // Clock speed.
137 uart_data_bits_t data_bit; // Data bits.
138 uart_parity_t parity_bit; // Parity bit.
139 uart_stop_bits_t stop_bit; // Stop bits.
140
142
146typedef uint8_t rs232isolator_error_t;
147
148 // End types group
149// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
150
156#ifdef __cplusplus
157extern "C"{
158#endif
159
169
178
185void rs232isolator_generic_write ( rs232isolator_t *ctx, char *data_buf, uint16_t len );
186
194int16_t rs232isolator_generic_read ( rs232isolator_t *ctx, char *data_buf, uint16_t max_len );
195
204void rs232_2_set_rts ( rs232isolator_t *ctx, uint8_t state );
205
214
221void rs232isolator_send_command ( rs232isolator_t *ctx, char *command );
222
223#ifdef __cplusplus
224}
225#endif
226#endif // _RS232ISOLATOR_H_
227
228 // End public_function group
230
231// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition rs232isolator.h:87
#define RS232ISOLATOR_RETVAL
Definition rs232isolator.h:77
void rs232isolator_cfg_setup(rs232isolator_cfg_t *cfg)
Config Object Initialization function.
RS232ISOLATOR_RETVAL rs232isolator_init(rs232isolator_t *ctx, rs232isolator_cfg_t *cfg)
Initialization function.
int16_t rs232isolator_generic_read(rs232isolator_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void rs232isolator_generic_write(rs232isolator_t *ctx, char *data_buf, uint16_t len)
Generic write function.
uint8_t rs232_2_get_cts(rs232isolator_t *ctx)
Read CTS state.
void rs232_2_set_rts(rs232isolator_t *ctx, uint8_t state)
Function settings RTS state.
void rs232isolator_send_command(rs232isolator_t *ctx, char *command)
Function for send command.
uint8_t rs232isolator_error_t
Error type.
Definition rs232isolator.h:146
Click configuration structure definition.
Definition rs232isolator.h:122
pin_name_t rts
Definition rs232isolator.h:131
uint32_t baud_rate
Definition rs232isolator.h:135
pin_name_t cts
Definition rs232isolator.h:130
bool uart_blocking
Definition rs232isolator.h:136
uart_data_bits_t data_bit
Definition rs232isolator.h:137
pin_name_t tx_pin
Definition rs232isolator.h:126
pin_name_t rx_pin
Definition rs232isolator.h:125
uart_stop_bits_t stop_bit
Definition rs232isolator.h:139
uart_parity_t parity_bit
Definition rs232isolator.h:138
Click ctx object definition.
Definition rs232isolator.h:100
uart_t uart
Definition rs232isolator.h:111
digital_in_t rts
Definition rs232isolator.h:107
digital_out_t cts
Definition rs232isolator.h:103