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 
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 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define RS485ISOLATOR2_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70  cfg.re = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71  cfg.de = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72  cfg.inr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73  cfg. ind = MIKROBUS( mikrobus, MIKROBUS_INT )
74 
80 #define RS485ISOLATOR2_RETVAL uint8_t
81 
82 #define RS485ISOLATOR2_OK 0x00
83 #define RS485ISOLATOR2_INIT_ERROR 0xFF
84 
90 #define DRV_RX_BUFFER_SIZE 500
91 
93 #define RS485ISOLATOR2_ENABLE_RE 0x00
94 #define RS485ISOLATOR2_DISABLE_RE 0x01
95 
96 // Driver Output Enable
97 
98 #define RS485ISOLATOR2_ENABLE_DE 0x01
99 #define RS485ISOLATOR2_DISABLE_DE 0x00
100 
101 // Receiver Inversion Enable
102 
103 #define RS485ISOLATOR2_ENABLE_INR 0x01
104 #define RS485ISOLATOR2_DISABLE_INR 0x00
105 
106 // Driver Inversion Enable
107 
108 #define RS485ISOLATOR2_ENABLE_IND 0x01
109 #define RS485ISOLATOR2_DISABLE_IND 0x00
110  // End group macro
112 // --------------------------------------------------------------- PUBLIC TYPES
120 typedef struct
121 {
122  // Output pins
123 
124  digital_out_t re;
125  digital_out_t de;
126  digital_out_t inr;
127  digital_out_t ind;
128 
129  // Modules
130 
131  uart_t uart;
132 
133  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
134  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
135 
137 
141 typedef struct
142 {
143  // Communication gpio pins
144 
145  pin_name_t rx_pin;
146  pin_name_t tx_pin;
147 
148  // Additional gpio pins
149 
150  pin_name_t re;
151  pin_name_t de;
152  pin_name_t inr;
153  pin_name_t ind;
154 
155  // static variable
156 
157  uint32_t baud_rate; // Clock speed.
159  uart_data_bits_t data_bit; // Data bits.
160  uart_parity_t parity_bit; // Parity bit.
161  uart_stop_bits_t stop_bit; // Stop bits.
162 
164 
168 typedef uint8_t rs485isolator2_error_t;
169  // End types group
171 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
172 
178 #ifdef __cplusplus
179 extern "C"{
180 #endif
181 
191 
200 
206 void rs485isolator2_set_de_pin ( rs485isolator2_t *ctx, uint8_t state );
207 
213 void rs485isolator2_set_re_pin ( rs485isolator2_t *ctx, uint8_t state );
214 
220 void rs485isolator2_set_ind_pin ( rs485isolator2_t *ctx, uint8_t state );
221 
227 void rs485isolator2_set_inr_pin ( rs485isolator2_t *ctx, uint8_t state );
228 
235 void rs485isolator2_generic_write ( rs485isolator2_t *ctx, char *data_buf, uint16_t len );
236 
244 int32_t rs485isolator2_generic_read ( rs485isolator2_t *ctx, char *data_buf, uint16_t max_len );
245 
252 
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 #endif // _RS485ISOLATOR2_H_
258  // End public_function group
261 
262 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: rs485isolator2.h:90
rs485isolator2_cfg_t
Click configuration structure definition.
Definition: rs485isolator2.h:142
RS485ISOLATOR2_RETVAL
#define RS485ISOLATOR2_RETVAL
Definition: rs485isolator2.h:80
rs485isolator2_cfg_t::re
pin_name_t re
Definition: rs485isolator2.h:150
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:168
rs485isolator2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs485isolator2.h:161
rs485isolator2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs485isolator2.h:160
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:152
rs485isolator2_t::ind
digital_out_t ind
Definition: rs485isolator2.h:127
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:153
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:157
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:151
rs485isolator2_cfg_setup
void rs485isolator2_cfg_setup(rs485isolator2_cfg_t *cfg)
Config Object Initialization function.
rs485isolator2_t::uart
uart_t uart
Definition: rs485isolator2.h:131
rs485isolator2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs485isolator2.h:145
rs485isolator2_cfg_t::uart_blocking
bool uart_blocking
Definition: rs485isolator2.h:158
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:124
rs485isolator2_t::inr
digital_out_t inr
Definition: rs485isolator2.h:126
rs485isolator2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs485isolator2.h:159
rs485isolator2_t
Click ctx object definition.
Definition: rs485isolator2.h:121
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:146
rs485isolator2_t::de
digital_out_t de
Definition: rs485isolator2.h:125
rs485isolator2_send_bit_by_bit
void rs485isolator2_send_bit_by_bit(rs485isolator2_t *ctx, char *command)
Bit by bit write function.