rs4852 2.0.0.0
rs4852.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 RS4852_H
36#define RS4852_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_uart.h"
41
42// -------------------------------------------------------------- PUBLIC MACROS
52#define RS4852_MAP_MIKROBUS( cfg, mikrobus ) \
53 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55 cfg.de = MIKROBUS( mikrobus, MIKROBUS_CS ); \
56 cfg.re = MIKROBUS( mikrobus, MIKROBUS_PWM )
63#define RS4852_RETVAL uint8_t
64
65#define RS4852_OK 0x00
66#define RS4852_INIT_ERROR 0xFF
73#define DRV_RX_BUFFER_SIZE 500
80#define RS4852_ENABLE_DE 0x01
81#define RS4852_DISABLE_DE 0x00
88#define RS4852_ENABLE_RE 0x00
89#define RS4852_DISABLE_RE 0x01 // End group macro
93// --------------------------------------------------------------- PUBLIC TYPES
101typedef struct
102{
103 // Output pins
104
105 digital_out_t de;
106 digital_out_t re;
107
108 // Modules
109
110 uart_t uart;
111
112 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
113 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
114
115} rs4852_t;
116
120typedef struct
121{
122 // Communication gpio pins
123
124 pin_name_t rx_pin;
125 pin_name_t tx_pin;
126
127 // Additional gpio pins
128
129 pin_name_t de;
130 pin_name_t re;
131
132 // static variable
133
134 uint32_t baud_rate; // Clock speed.
136 uart_data_bits_t data_bit; // Data bits.
137 uart_parity_t parity_bit; // Parity bit.
138 uart_stop_bits_t stop_bit; // Stop bits.
139
141
145typedef uint8_t rs4852_error_t;
146 // End types group
148// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
149
155#ifdef __cplusplus
156extern "C"{
157#endif
158
168
177
184void rs4852_generic_write ( rs4852_t *ctx, char *data_buf, uint16_t len );
185
193int32_t rs4852_generic_read ( rs4852_t *ctx, char *data_buf, uint16_t max_len );
194
200void rs4852_set_de_pin ( rs4852_t *ctx, uint8_t state );
201
207void rs4852_set_re_pin ( rs4852_t *ctx, uint8_t state );
208
209#ifdef __cplusplus
210}
211#endif
212#endif // _RS4852_H_
213 // End public_function group
216
217// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition: rs4852.h:73
#define RS4852_RETVAL
Definition: rs4852.h:63
void rs4852_set_re_pin(rs4852_t *ctx, uint8_t state)
Set RE ( reset ) pin state.
void rs4852_set_de_pin(rs4852_t *ctx, uint8_t state)
Set DE ( cs ) pin state.
int32_t rs4852_generic_read(rs4852_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void rs4852_cfg_setup(rs4852_cfg_t *cfg)
Config Object Initialization function.
void rs4852_generic_write(rs4852_t *ctx, char *data_buf, uint16_t len)
Generic write function.
RS4852_RETVAL rs4852_init(rs4852_t *ctx, rs4852_cfg_t *cfg)
Initialization function.
uint8_t rs4852_error_t
Error type.
Definition: rs4852.h:145
Click configuration structure definition.
Definition: rs4852.h:121
uint32_t baud_rate
Definition: rs4852.h:134
pin_name_t re
Definition: rs4852.h:130
bool uart_blocking
Definition: rs4852.h:135
uart_data_bits_t data_bit
Definition: rs4852.h:136
pin_name_t tx_pin
Definition: rs4852.h:125
pin_name_t de
Definition: rs4852.h:129
pin_name_t rx_pin
Definition: rs4852.h:124
uart_stop_bits_t stop_bit
Definition: rs4852.h:138
uart_parity_t parity_bit
Definition: rs4852.h:137
Click ctx object definition.
Definition: rs4852.h:102
digital_out_t re
Definition: rs4852.h:106
uart_t uart
Definition: rs4852.h:110
digital_out_t de
Definition: rs4852.h:105