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 
42 #ifdef PREINIT_SUPPORTED
43 #include "preinit.h"
44 #endif
45 
46 #ifdef MikroCCoreVersion
47  #if MikroCCoreVersion >= 1
48  #include "delays.h"
49  #endif
50 #endif
51 
52 #include "drv_digital_out.h"
53 #include "drv_digital_in.h"
54 #include "drv_uart.h"
55 
56 
57 // -------------------------------------------------------------- PUBLIC MACROS
67 #define TRF_MAP_MIKROBUS( cfg, mikrobus ) \
68  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
70 
76 #define TRF_RETVAL uint8_t
77 
78 #define TRF_OK 0x00
79 #define TRF_INIT_ERROR 0xFF
80 
86 #define DRV_RX_BUFFER_SIZE 500
87  // End group macro
90 // --------------------------------------------------------------- PUBLIC TYPES
99 typedef struct
100 {
101 
102  // Modules
103 
104  uart_t uart;
105 
106  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
107  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
108 
109 } trf_t;
110 
114 typedef struct
115 {
116  // Communication gpio pins
117 
118  pin_name_t rx_pin;
119  pin_name_t tx_pin;
120 
121  // static variable
122 
123  uint32_t baud_rate; // Clock speed.
125  uart_data_bits_t data_bit; // Data bits.
126  uart_parity_t parity_bit; // Parity bit.
127  uart_stop_bits_t stop_bit; // Stop bits.
128 
129 } trf_cfg_t;
130  // End types group
132 // ------------------------------------------------------------------ CONSTANTS // End constants group
141 // ------------------------------------------------------------------ VARIABLES // End variable group
149 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
150 
156 #ifdef __cplusplus
157 extern "C"{
158 #endif
159 
168 void trf_cfg_setup ( trf_cfg_t *cfg );
169 
178 
188 void trf_generic_multi_write ( trf_t *ctx, char *data_buf, uint8_t len );
189 
199 void trf_generic_multi_read ( trf_t *ctx, char *data_buf, uint8_t len );
200 
201 
211 
220 void trf_generic_single_write ( trf_t *ctx, char tx_data );
221 
229 uint8_t byte_ready();
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 #endif // _TRF_H_
235  // End public_function group
238 
239 // ------------------------------------------------------------------------- END
trf_cfg_t
Click configuration structure definition.
Definition: trf.h:115
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: trf.h:86
trf_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: trf.h:125
byte_ready
uint8_t byte_ready()
Check for new byte received.
trf_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: trf.h:126
trf_cfg_t::uart_blocking
bool uart_blocking
Definition: trf.h:124
trf_init
TRF_RETVAL trf_init(trf_t *ctx, trf_cfg_t *cfg)
Initialization function.
trf_t::uart
uart_t uart
Definition: trf.h:104
TRF_RETVAL
#define TRF_RETVAL
Definition: trf.h:76
trf_cfg_setup
void trf_cfg_setup(trf_cfg_t *cfg)
Config Object Initialization function.
trf_t
Click ctx object definition.
Definition: trf.h:100
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:119
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:123
trf_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: trf.h:127
trf_cfg_t::rx_pin
pin_name_t rx_pin
Definition: trf.h:118