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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 
43 // -------------------------------------------------------------- PUBLIC MACROS
53 #define TRF_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
56 
62 #define TRF_RETVAL uint8_t
63 
64 #define TRF_OK 0x00
65 #define TRF_INIT_ERROR 0xFF
66 
72 #define DRV_RX_BUFFER_SIZE 500
73  // End group macro
76 // --------------------------------------------------------------- PUBLIC TYPES
85 typedef struct
86 {
87 
88  // Modules
89 
90  uart_t uart;
91 
92  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
93  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
94 
95 } trf_t;
96 
100 typedef struct
101 {
102  // Communication gpio pins
103 
104  pin_name_t rx_pin;
105  pin_name_t tx_pin;
106 
107  // static variable
108 
109  uint32_t baud_rate; // Clock speed.
111  uart_data_bits_t data_bit; // Data bits.
112  uart_parity_t parity_bit; // Parity bit.
113  uart_stop_bits_t stop_bit; // Stop bits.
114 
115 } trf_cfg_t;
116  // End types group
118 // ------------------------------------------------------------------ CONSTANTS // End constants group
127 // ------------------------------------------------------------------ VARIABLES // End variable group
135 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
136 
142 #ifdef __cplusplus
143 extern "C"{
144 #endif
145 
154 void trf_cfg_setup ( trf_cfg_t *cfg );
155 
164 
174 void trf_generic_multi_write ( trf_t *ctx, char *data_buf, uint8_t len );
175 
185 void trf_generic_multi_read ( trf_t *ctx, char *data_buf, uint8_t len );
186 
187 
197 
206 void trf_generic_single_write ( trf_t *ctx, char tx_data );
207 
215 uint8_t byte_ready();
216 
217 #ifdef __cplusplus
218 }
219 #endif
220 #endif // _TRF_H_
221  // End public_function group
224 
225 // ------------------------------------------------------------------------- END
trf_cfg_t
Click configuration structure definition.
Definition: trf.h:101
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: trf.h:72
trf_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: trf.h:111
byte_ready
uint8_t byte_ready()
Check for new byte received.
trf_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: trf.h:112
trf_cfg_t::uart_blocking
bool uart_blocking
Definition: trf.h:110
trf_init
TRF_RETVAL trf_init(trf_t *ctx, trf_cfg_t *cfg)
Initialization function.
trf_t::uart
uart_t uart
Definition: trf.h:90
TRF_RETVAL
#define TRF_RETVAL
Definition: trf.h:62
trf_cfg_setup
void trf_cfg_setup(trf_cfg_t *cfg)
Config Object Initialization function.
trf_t
Click ctx object definition.
Definition: trf.h:86
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:105
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:109
trf_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: trf.h:113
trf_cfg_t::rx_pin
pin_name_t rx_pin
Definition: trf.h:104