rs485isolator  2.0.0.0
rs485isolator.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright (c) 2019, MikroElektronika - www.mikroe.com
4  * All rights reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef RS485ISOLATOR_H
36 #define RS485ISOLATOR_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_uart.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define RS485ISOLATOR_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
53  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
54  cfg.re = MIKROBUS( mikrobus, MIKROBUS_RST ); \
55  cfg.de = MIKROBUS( mikrobus, MIKROBUS_CS );
56 
62 #define RS485ISOLATOR_RETVAL uint8_t
63 
64 #define RS485ISOLATOR_OK 0x00
65 #define RS485ISOLATOR_INIT_ERROR 0xFF
66 
72 #define RS485ISOLATOR_RECEIVER_ENABLE 0
73 #define RS485ISOLATOR_RECEIVER_DISABLE 1
74 
80 #define RS485ISOLATOR_DRIVER_ENABLE 1
81 #define RS485ISOLATOR_DRIVER_DISABLE 0
82  // End group macro
85 // --------------------------------------------------------------- PUBLIC TYPES
91 typedef uart_data_t rs485isolator_data_t;
92 
96 typedef struct
97 {
98  // Output pins
99 
100  digital_out_t re;
101  digital_out_t de;
102 
103  // Modules
104 
105  uart_t uart;
106 
108 
112 typedef struct
113 {
114  // Communication gpio pins
115 
116  pin_name_t rx_pin;
117  pin_name_t tx_pin;
118 
119  // Additional gpio pins
120 
121  pin_name_t re;
122  pin_name_t de;
123 
124  // static variable
125 
126  hal_uart_baudrate_t baud_rate; // Clock speed.
127  hal_uart_data_bits_t data_bit; // Data bits.
128  hal_uart_parity_bit_t parity_bit; // Parity bit.
129  hal_uart_stop_bits_t stop_bit; // Stop bits.
130 
132  // End types group
134 
135 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
136 
142 #ifdef __cplusplus
143 extern "C"{
144 #endif
145 
155 
165 (
166  rs485isolator_t *ctx,
168 );
169 
180 (
181  rs485isolator_t *ctx,
182  rs485isolator_data_t *data_buf,
183  uart_length_t len
184 );
185 
195 
205 (
206  rs485isolator_t *ctx,
207  rs485isolator_data_t tx_data
208 );
209 
216 void rs485isolator_set_receiver_mode ( rs485isolator_t *ctx, uint8_t state );
217 
224 void rs485isolator_set_driver_mode ( rs485isolator_t *ctx, uint8_t state );
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 #endif // _RS485ISOLATOR_H_
230  // End public_function group
233 
234 // ------------------------------------------------------------------------- END
hal_uart_stop_bits_t stop_bit
Definition: rs485isolator.h:129
hal_uart_baudrate_t baud_rate
Definition: rs485isolator.h:126
void rs485isolator_set_driver_mode(rs485isolator_t *ctx, uint8_t state)
Set driver state.
pin_name_t rx_pin
Definition: rs485isolator.h:116
uart_t uart
Definition: rs485isolator.h:105
hal_uart_parity_bit_t parity_bit
Definition: rs485isolator.h:128
RS485ISOLATOR_RETVAL rs485isolator_init(rs485isolator_t *ctx, rs485isolator_cfg_t *cfg)
Initialization function.
digital_out_t de
Definition: rs485isolator.h:101
#define RS485ISOLATOR_RETVAL
Definition: rs485isolator.h:62
void rs485isolator_set_receiver_mode(rs485isolator_t *ctx, uint8_t state)
Set receiver state.
uart_data_t rs485isolator_data_t
Definition: rs485isolator.h:91
void rs485isolator_generic_single_write(rs485isolator_t *ctx, rs485isolator_data_t tx_data)
Generic single write function.
pin_name_t tx_pin
Definition: rs485isolator.h:117
digital_out_t re
Definition: rs485isolator.h:100
void rs485isolator_generic_multi_write(rs485isolator_t *ctx, rs485isolator_data_t *data_buf, uart_length_t len)
Generic multi write function.
pin_name_t de
Definition: rs485isolator.h:122
void rs485isolator_cfg_setup(rs485isolator_cfg_t *cfg)
Config Object Initialization function.
Click configuration structure definition.
Definition: rs485isolator.h:112
pin_name_t re
Definition: rs485isolator.h:121
hal_uart_data_bits_t data_bit
Definition: rs485isolator.h:127
Click ctx object definition.
Definition: rs485isolator.h:96
rs485isolator_data_t rs485isolator_generic_single_read(rs485isolator_t *ctx)
Generic single read function.