rs4852  2.0.0.0
rs4852.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 RS4852_H
36 #define RS4852_H
37 
38 #include "drv_digital_out.h"
39 #include "drv_uart.h"
40 
41 // -------------------------------------------------------------- PUBLIC MACROS
51 #define RS4852_MAP_MIKROBUS( cfg, mikrobus ) \
52  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
53  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
54  cfg.oe = MIKROBUS( mikrobus, MIKROBUS_CS ); \
55  cfg.re = MIKROBUS( mikrobus, MIKROBUS_PWM );
56 
62 #define RS4852_RETVAL uint8_t
63 
64 #define RS4852_OK 0x00
65 #define RS4852_INIT_ERROR 0xFF
66 
72 #define RS4852_RX_DISABLE 0x01
73 #define RS4852_RX_ENABLE 0x00
74 
75 #define RS4852_TX_DISABLE 0x00
76 #define RS4852_TX_ENABLE 0x01
77 
78 #define RS4852_RX_PIN 0x00
79 #define RS4852_TX_PIN 0x01
80  // End group macro
83 // --------------------------------------------------------------- PUBLIC TYPES
89 typedef uart_data_t rs4852_data_t;
90 
94 typedef struct
95 {
96  // Output pins
97 
98  digital_out_t oe;
99  digital_out_t re;
100 
101  // Modules
102 
103  uart_t uart;
104 
105 } rs4852_t;
106 
110 typedef struct
111 {
112  // Communication gpio pins
113 
114  pin_name_t rx_pin;
115  pin_name_t tx_pin;
116 
117  // Additional gpio pins
118 
119  pin_name_t oe;
120  pin_name_t re;
121 
122  // static variable
123 
124  hal_uart_baudrate_t baud_rate; // Clock speed.
125  hal_uart_data_bits_t data_bit; // Data bits.
126  hal_uart_parity_bit_t parity_bit; // Parity bit.
127  hal_uart_stop_bits_t stop_bit; // Stop bits.
128 
129 } rs4852_cfg_t;
130  // End types group
132 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
133 
139 #ifdef __cplusplus
140 extern "C"{
141 #endif
142 
151 void rs4852_cfg_setup ( rs4852_cfg_t *cfg );
152 
161 
169 void rs4852_default_cfg ( rs4852_t *ctx );
170 
180 void rs4852_generic_multi_write ( rs4852_t *ctx, rs4852_data_t *data_buf, uart_length_t len );
181 
191 void rs4852_generic_multi_read ( rs4852_t *ctx, rs4852_data_t *data_buf, uart_length_t len );
192 
202 
211 void rs4852_generic_single_write ( rs4852_t *ctx, rs4852_data_t tx_data );
212 
223 void rs4852_power_mode ( rs4852_t *ctx, uint8_t pin, uint8_t state );
224 
225 #ifdef __cplusplus
226 }
227 #endif
228 #endif // _RS4852_H_
229  // End public_function group
232 
233 // ------------------------------------------------------------------------- END
rs4852_generic_single_read
rs4852_data_t rs4852_generic_single_read(rs4852_t *ctx)
Generic single read function.
rs4852_data_t
uart_data_t rs4852_data_t
Definition: rs4852.h:89
rs4852_init
RS4852_RETVAL rs4852_init(rs4852_t *ctx, rs4852_cfg_t *cfg)
Initialization function.
rs4852_cfg_t::rx_pin
pin_name_t rx_pin
Definition: rs4852.h:114
rs4852_generic_multi_write
void rs4852_generic_multi_write(rs4852_t *ctx, rs4852_data_t *data_buf, uart_length_t len)
Generic multi write function.
rs4852_power_mode
void rs4852_power_mode(rs4852_t *ctx, uint8_t pin, uint8_t state)
Power mode controle pins.
rs4852_default_cfg
void rs4852_default_cfg(rs4852_t *ctx)
Click Default Configuration function.
rs4852_generic_single_write
void rs4852_generic_single_write(rs4852_t *ctx, rs4852_data_t tx_data)
Generic single write function.
rs4852_t::uart
uart_t uart
Definition: rs4852.h:103
rs4852_cfg_t::stop_bit
hal_uart_stop_bits_t stop_bit
Definition: rs4852.h:127
rs4852_cfg_t::data_bit
hal_uart_data_bits_t data_bit
Definition: rs4852.h:125
rs4852_generic_multi_read
void rs4852_generic_multi_read(rs4852_t *ctx, rs4852_data_t *data_buf, uart_length_t len)
Generic multi read function.
rs4852_t::re
digital_out_t re
Definition: rs4852.h:99
rs4852_cfg_t::re
pin_name_t re
Definition: rs4852.h:120
RS4852_RETVAL
#define RS4852_RETVAL
Definition: rs4852.h:62
rs4852_t::oe
digital_out_t oe
Definition: rs4852.h:98
rs4852_cfg_t
Click configuration structure definition.
Definition: rs4852.h:110
rs4852_cfg_t::oe
pin_name_t oe
Definition: rs4852.h:119
rs4852_cfg_t::baud_rate
hal_uart_baudrate_t baud_rate
Definition: rs4852.h:124
rs4852_cfg_t::tx_pin
pin_name_t tx_pin
Definition: rs4852.h:115
rs4852_cfg_setup
void rs4852_cfg_setup(rs4852_cfg_t *cfg)
Config Object Initialization function.
rs4852_cfg_t::parity_bit
hal_uart_parity_bit_t parity_bit
Definition: rs4852.h:126
rs4852_t
Click ctx object definition.
Definition: rs4852.h:94