rs485isolator 2.0.0.0
rs485isolator.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 RS485ISOLATOR_H
36#define RS485ISOLATOR_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 RS485ISOLATOR_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.re = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.de = MIKROBUS( mikrobus, MIKROBUS_CS )
77#define RS485ISOLATOR_OK 0
78#define RS485ISOLATOR_ERROR -1
85#define RS485ISOLATOR_RECEIVER_ENABLE 0
86#define RS485ISOLATOR_RECEIVER_DISABLE 1
93#define RS485ISOLATOR_DRIVER_ENABLE 1
94#define RS485ISOLATOR_DRIVER_DISABLE 0
101#define RS485ISOLATOR_DRV_RX_BUFFER_SIZE 200
102#define RS485ISOLATOR_DRV_TX_BUFFER_SIZE 200
105 // End group macro
106// --------------------------------------------------------------- PUBLIC TYPES
114typedef struct
115{
116 // Output pins
117 digital_out_t re;
118 digital_out_t de;
119
120 // Modules
121 uart_t uart;
122
123 uint8_t uart_rx_buffer[ RS485ISOLATOR_DRV_RX_BUFFER_SIZE ];
124 uint8_t uart_tx_buffer[ RS485ISOLATOR_DRV_TX_BUFFER_SIZE ];
125
127
131typedef struct
132{
133 // Communication gpio pins
134 pin_name_t rx_pin;
135 pin_name_t tx_pin;
136
137 // Additional gpio pins
138 pin_name_t re;
139 pin_name_t de;
140
141 // static variable
142 uint32_t baud_rate; // Clock speed.
144 uart_data_bits_t data_bit; // Data bits.
145 uart_parity_t parity_bit; // Parity bit.
146 uart_stop_bits_t stop_bit; // Stop bits.
147
149
150 // End types group
151// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
152
158#ifdef __cplusplus
159extern "C"{
160#endif
161
171
180
187void rs485isolator_generic_write ( rs485isolator_t *ctx, uint8_t *data_buf, uint16_t len );
188
196err_t rs485isolator_generic_read ( rs485isolator_t *ctx, uint8_t *data_buf, uint16_t max_len );
197
205
213
214#ifdef __cplusplus
215}
216#endif
217#endif // _RS485ISOLATOR_H_
218
219 // End public_function group
221
222// ------------------------------------------------------------------------- END
#define RS485ISOLATOR_DRV_RX_BUFFER_SIZE
Definition rs485isolator.h:101
#define RS485ISOLATOR_DRV_TX_BUFFER_SIZE
Definition rs485isolator.h:102
void rs485isolator_cfg_setup(rs485isolator_cfg_t *cfg)
Config Object Initialization function.
err_t rs485isolator_init(rs485isolator_t *ctx, rs485isolator_cfg_t *cfg)
Initialization function.
void rs485isolator_set_driver_mode(rs485isolator_t *ctx, uint8_t state)
Set driver state.
void rs485isolator_set_receiver_mode(rs485isolator_t *ctx, uint8_t state)
Set receiver state.
void rs485isolator_generic_write(rs485isolator_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
err_t rs485isolator_generic_read(rs485isolator_t *ctx, uint8_t *data_buf, uint16_t max_len)
Generic read function.
Click configuration structure definition.
Definition rs485isolator.h:132
uint32_t baud_rate
Definition rs485isolator.h:142
pin_name_t re
Definition rs485isolator.h:138
bool uart_blocking
Definition rs485isolator.h:143
uart_data_bits_t data_bit
Definition rs485isolator.h:144
pin_name_t tx_pin
Definition rs485isolator.h:135
pin_name_t de
Definition rs485isolator.h:139
pin_name_t rx_pin
Definition rs485isolator.h:134
uart_stop_bits_t stop_bit
Definition rs485isolator.h:146
uart_parity_t parity_bit
Definition rs485isolator.h:145
Click ctx object definition.
Definition rs485isolator.h:115
digital_out_t re
Definition rs485isolator.h:117
uart_t uart
Definition rs485isolator.h:121
digital_out_t de
Definition rs485isolator.h:118