rs4858  2.1.0.0
rs4858.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef RS4858_H
29 #define RS4858_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
70 #define RS4858_TX_DRV_BUFFER_SIZE 100
71 #define RS4858_RX_DRV_BUFFER_SIZE 300
72  // rs4858_cmd
74 
89 #define RS4858_MAP_MIKROBUS( cfg, mikrobus ) \
90  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
91  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
92  cfg.en = MIKROBUS( mikrobus, MIKROBUS_RST )
93  // rs4858_map // rs4858
96 
101 typedef struct
102 {
103  // Output pins
104  digital_out_t en;
106  // Modules
107  uart_t uart;
109  // Buffers
110  uint8_t uart_rx_buffer[ RS4858_RX_DRV_BUFFER_SIZE ];
111  uint8_t uart_tx_buffer[ RS4858_TX_DRV_BUFFER_SIZE ];
113 } rs4858_t;
114 
119 typedef struct
120 {
121  // Communication gpio pins
122  pin_name_t rx_pin;
123  pin_name_t tx_pin;
125  // Additional gpio pins
126  pin_name_t en;
128  // Static variable
129  uint32_t baud_rate;
131  uart_data_bits_t data_bit;
132  uart_parity_t parity_bit;
133  uart_stop_bits_t stop_bit;
135 } rs4858_cfg_t;
136 
141 typedef enum
142 {
144  RS4858_ERROR = -1
145 
147 
164 
178 err_t rs4858_init ( rs4858_t *ctx, rs4858_cfg_t *cfg );
179 
191 
204 err_t rs4858_generic_write ( rs4858_t *ctx, uint8_t *data_in, uint16_t len );
205 
218 err_t rs4858_generic_read ( rs4858_t *ctx, uint8_t *data_out, uint16_t len );
219 
230 
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // RS4858_H
246  // rs4858
248 
249 // ------------------------------------------------------------------------ END
rs4858_cfg_setup
void rs4858_cfg_setup(rs4858_cfg_t *cfg)
RS485 8 configuration object setup function.
RS4858_RX_DRV_BUFFER_SIZE
#define RS4858_RX_DRV_BUFFER_SIZE
Definition: rs4858.h:71
rs4858_init
err_t rs4858_init(rs4858_t *ctx, rs4858_cfg_t *cfg)
RS485 8 initialization function.
rs4858_return_value_t
rs4858_return_value_t
RS485 8 Click return value data.
Definition: rs4858.h:142
rs4858_generic_write
err_t rs4858_generic_write(rs4858_t *ctx, uint8_t *data_in, uint16_t len)
RS485 8 data writing function.
rs4858_enable_device
void rs4858_enable_device(rs4858_t *ctx)
RS485 8 enable the device function.
rs4858_disable_device
void rs4858_disable_device(rs4858_t *ctx)
RS485 8 disable the device function.
RS4858_ERROR
@ RS4858_ERROR
Definition: rs4858.h:144
rs4858_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs4858.h:122
rs4858_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: rs4858.h:132
rs4858_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: rs4858.h:133
rs4858_t::en
digital_out_t en
Definition: rs4858.h:104
RS4858_OK
@ RS4858_OK
Definition: rs4858.h:143
rs4858_cfg_t::uart_blocking
bool uart_blocking
Definition: rs4858.h:130
rs4858_t::uart
uart_t uart
Definition: rs4858.h:107
rs4858_cfg_t::en
pin_name_t en
Definition: rs4858.h:126
rs4858_cfg_t::baud_rate
uint32_t baud_rate
Definition: rs4858.h:129
rs4858_generic_read
err_t rs4858_generic_read(rs4858_t *ctx, uint8_t *data_out, uint16_t len)
RS485 8 data reading function.
RS4858_TX_DRV_BUFFER_SIZE
#define RS4858_TX_DRV_BUFFER_SIZE
RS485 8 driver buffer size.
Definition: rs4858.h:70
rs4858_cfg_t
RS485 8 Click configuration object.
Definition: rs4858.h:120
rs4858_t
RS485 8 Click context object.
Definition: rs4858.h:102
rs4858_default_cfg
void rs4858_default_cfg(rs4858_t *ctx)
RS485 8 default configuration function.
rs4858_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs4858.h:123
rs4858_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: rs4858.h:131