trf  2.0.0.0
trf.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 TRF_H
36 #define TRF_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 TRF_MAP_MIKROBUS( cfg, mikrobus ) \
64  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
65  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
66 
72 #define TRF_RETVAL uint8_t
73 
74 #define TRF_OK 0x00
75 #define TRF_INIT_ERROR 0xFF
76 
82 #define DRV_RX_BUFFER_SIZE 500
83  // End group macro
86 // --------------------------------------------------------------- PUBLIC TYPES
95 typedef struct
96 {
97 
98  // Modules
99 
100  uart_t uart;
101 
102  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
103  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
104 
105 } trf_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  // static variable
118 
119  uint32_t baud_rate; // Clock speed.
121  uart_data_bits_t data_bit; // Data bits.
122  uart_parity_t parity_bit; // Parity bit.
123  uart_stop_bits_t stop_bit; // Stop bits.
124 
125 } trf_cfg_t;
126  // End types group
128 // ------------------------------------------------------------------ CONSTANTS // End constants group
137 // ------------------------------------------------------------------ VARIABLES // End variable group
145 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
146 
152 #ifdef __cplusplus
153 extern "C"{
154 #endif
155 
164 void trf_cfg_setup ( trf_cfg_t *cfg );
165 
174 
184 void trf_generic_multi_write ( trf_t *ctx, char *data_buf, uint8_t len );
185 
195 void trf_generic_multi_read ( trf_t *ctx, char *data_buf, uint8_t len );
196 
197 
207 
216 void trf_generic_single_write ( trf_t *ctx, char tx_data );
217 
225 uint8_t byte_ready();
226 
227 #ifdef __cplusplus
228 }
229 #endif
230 #endif // _TRF_H_
231  // End public_function group
234 
235 // ------------------------------------------------------------------------- END
trf_cfg_t
Click configuration structure definition.
Definition: trf.h:111
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: trf.h:82
trf_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: trf.h:121
byte_ready
uint8_t byte_ready()
Check for new byte received.
trf_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: trf.h:122
trf_cfg_t::uart_blocking
bool uart_blocking
Definition: trf.h:120
trf_init
TRF_RETVAL trf_init(trf_t *ctx, trf_cfg_t *cfg)
Initialization function.
trf_t::uart
uart_t uart
Definition: trf.h:100
TRF_RETVAL
#define TRF_RETVAL
Definition: trf.h:72
trf_cfg_setup
void trf_cfg_setup(trf_cfg_t *cfg)
Config Object Initialization function.
trf_t
Click ctx object definition.
Definition: trf.h:96
trf_generic_single_write
void trf_generic_single_write(trf_t *ctx, char tx_data)
Generic single write function.
trf_cfg_t::tx_pin
pin_name_t tx_pin
Definition: trf.h:115
trf_generic_single_read
char trf_generic_single_read(trf_t *ctx)
Generic single read function.
trf_generic_multi_read
void trf_generic_multi_read(trf_t *ctx, char *data_buf, uint8_t len)
Generic multi read function.
trf_generic_multi_write
void trf_generic_multi_write(trf_t *ctx, char *data_buf, uint8_t len)
Generic multi write function.
trf_cfg_t::baud_rate
uint32_t baud_rate
Definition: trf.h:119
trf_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: trf.h:123
trf_cfg_t::rx_pin
pin_name_t rx_pin
Definition: trf.h:114