rs485isolator2  2.0.0.0
rs485isolator2.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 RS485ISOLATOR2_H
36 #define RS485ISOLATOR2_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 
53 // -------------------------------------------------------------- PUBLIC MACROS
63 #define RS485ISOLATOR2_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
66  cfg.re = MIKROBUS( mikrobus, MIKROBUS_RST ); \
67  cfg.de = MIKROBUS( mikrobus, MIKROBUS_CS ); \
68  cfg.inr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
69  cfg. ind = MIKROBUS( mikrobus, MIKROBUS_INT )
70 
76 #define RS485ISOLATOR2_RETVAL uint8_t
77 
78 #define RS485ISOLATOR2_OK 0x00
79 #define RS485ISOLATOR2_INIT_ERROR 0xFF
80 
86 #define DRV_RX_BUFFER_SIZE 500
87 
89 #define RS485ISOLATOR2_ENABLE_RE 0x00
90 #define RS485ISOLATOR2_DISABLE_RE 0x01
91 
92 // Driver Output Enable
93 
94 #define RS485ISOLATOR2_ENABLE_DE 0x01
95 #define RS485ISOLATOR2_DISABLE_DE 0x00
96 
97 // Receiver Inversion Enable
98 
99 #define RS485ISOLATOR2_ENABLE_INR 0x01
100 #define RS485ISOLATOR2_DISABLE_INR 0x00
101 
102 // Driver Inversion Enable
103 
104 #define RS485ISOLATOR2_ENABLE_IND 0x01
105 #define RS485ISOLATOR2_DISABLE_IND 0x00
106  // End group macro
108 // --------------------------------------------------------------- PUBLIC TYPES
116 typedef struct
117 {
118  // Output pins
119 
120  digital_out_t re;
121  digital_out_t de;
122  digital_out_t inr;
123  digital_out_t ind;
124 
125  // Modules
126 
127  uart_t uart;
128 
129  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
130  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
131 
133 
137 typedef struct
138 {
139  // Communication gpio pins
140 
141  pin_name_t rx_pin;
142  pin_name_t tx_pin;
143 
144  // Additional gpio pins
145 
146  pin_name_t re;
147  pin_name_t de;
148  pin_name_t inr;
149  pin_name_t ind;
150 
151  // static variable
152 
153  uint32_t baud_rate; // Clock speed.
155  uart_data_bits_t data_bit; // Data bits.
156  uart_parity_t parity_bit; // Parity bit.
157  uart_stop_bits_t stop_bit; // Stop bits.
158 
160 
164 typedef uint8_t rs485isolator2_error_t;
165  // End types group
167 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
168 
174 #ifdef __cplusplus
175 extern "C"{
176 #endif
177 
187 
196 
202 void rs485isolator2_set_de_pin ( rs485isolator2_t *ctx, uint8_t state );
203 
209 void rs485isolator2_set_re_pin ( rs485isolator2_t *ctx, uint8_t state );
210 
216 void rs485isolator2_set_ind_pin ( rs485isolator2_t *ctx, uint8_t state );
217 
223 void rs485isolator2_set_inr_pin ( rs485isolator2_t *ctx, uint8_t state );
224 
231 void rs485isolator2_generic_write ( rs485isolator2_t *ctx, char *data_buf, uint16_t len );
232 
240 int32_t rs485isolator2_generic_read ( rs485isolator2_t *ctx, char *data_buf, uint16_t max_len );
241 
248 
249 
250 #ifdef __cplusplus
251 }
252 #endif
253 #endif // _RS485ISOLATOR2_H_
254  // End public_function group
257 
258 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rs485isolator2.h:86
rs485isolator2_cfg_t
Click configuration structure definition.
Definition: rs485isolator2.h:138
RS485ISOLATOR2_RETVAL
#define RS485ISOLATOR2_RETVAL
Definition: rs485isolator2.h:76
rs485isolator2_cfg_t::re
pin_name_t re
Definition: rs485isolator2.h:146
rs485isolator2_init
RS485ISOLATOR2_RETVAL rs485isolator2_init(rs485isolator2_t *ctx, rs485isolator2_cfg_t *cfg)
Initialization function.
rs485isolator2_error_t
uint8_t rs485isolator2_error_t
Error type.
Definition: rs485isolator2.h:164
rs485isolator2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs485isolator2.h:157
rs485isolator2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs485isolator2.h:156
rs485isolator2_generic_write
void rs485isolator2_generic_write(rs485isolator2_t *ctx, char *data_buf, uint16_t len)
Generic write function.
rs485isolator2_cfg_t::inr
pin_name_t inr
Definition: rs485isolator2.h:148
rs485isolator2_t::ind
digital_out_t ind
Definition: rs485isolator2.h:123
rs485isolator2_set_de_pin
void rs485isolator2_set_de_pin(rs485isolator2_t *ctx, uint8_t state)
Set DE ( cs ) pin state.
rs485isolator2_cfg_t::ind
pin_name_t ind
Definition: rs485isolator2.h:149
rs485isolator2_set_re_pin
void rs485isolator2_set_re_pin(rs485isolator2_t *ctx, uint8_t state)
Set RE ( reset ) pin state.
rs485isolator2_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs485isolator2.h:153
rs485isolator2_set_ind_pin
void rs485isolator2_set_ind_pin(rs485isolator2_t *ctx, uint8_t state)
Get IND (int) pin state.
rs485isolator2_cfg_t::de
pin_name_t de
Definition: rs485isolator2.h:147
rs485isolator2_cfg_setup
void rs485isolator2_cfg_setup(rs485isolator2_cfg_t *cfg)
Config Object Initialization function.
rs485isolator2_t::uart
uart_t uart
Definition: rs485isolator2.h:127
rs485isolator2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs485isolator2.h:141
rs485isolator2_cfg_t::uart_blocking
bool uart_blocking
Definition: rs485isolator2.h:154
rs485isolator2_generic_read
int32_t rs485isolator2_generic_read(rs485isolator2_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
rs485isolator2_t::re
digital_out_t re
Definition: rs485isolator2.h:120
rs485isolator2_t::inr
digital_out_t inr
Definition: rs485isolator2.h:122
rs485isolator2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs485isolator2.h:155
rs485isolator2_t
Click ctx object definition.
Definition: rs485isolator2.h:117
rs485isolator2_set_inr_pin
void rs485isolator2_set_inr_pin(rs485isolator2_t *ctx, uint8_t state)
Set INR ( pwm ) pin state.
rs485isolator2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs485isolator2.h:142
rs485isolator2_t::de
digital_out_t de
Definition: rs485isolator2.h:121
rs485isolator2_send_bit_by_bit
void rs485isolator2_send_bit_by_bit(rs485isolator2_t *ctx, char *command)
Bit by bit write function.