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 );
76#define TRF_RETVAL uint8_t
77
78#define TRF_OK 0x00
79#define TRF_INIT_ERROR 0xFF
86#define DRV_RX_BUFFER_SIZE 500
89 // End group macro
90// --------------------------------------------------------------- PUBLIC TYPES
99typedef 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
114typedef 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
131 // End types group
132// ------------------------------------------------------------------ CONSTANTS
140 // End constants group
141// ------------------------------------------------------------------ VARIABLES
148 // End variable group
149// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
150
156#ifdef __cplusplus
157extern "C"{
158#endif
159
169
178
188void trf_generic_multi_write ( trf_t *ctx, char *data_buf, uint8_t len );
189
199void trf_generic_multi_read ( trf_t *ctx, char *data_buf, uint8_t len );
200
201
211
220void trf_generic_single_write ( trf_t *ctx, char tx_data );
221
229uint8_t byte_ready();
230
231#ifdef __cplusplus
232}
233#endif
234#endif // _TRF_H_
235
236 // End public_function group
238
239// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition trf.h:86
#define TRF_RETVAL
Definition trf.h:76
void trf_generic_single_write(trf_t *ctx, char tx_data)
Generic single write function.
void trf_generic_multi_write(trf_t *ctx, char *data_buf, uint8_t len)
Generic multi write function.
TRF_RETVAL trf_init(trf_t *ctx, trf_cfg_t *cfg)
Initialization function.
void trf_generic_multi_read(trf_t *ctx, char *data_buf, uint8_t len)
Generic multi read function.
char trf_generic_single_read(trf_t *ctx)
Generic single read function.
void trf_cfg_setup(trf_cfg_t *cfg)
Config Object Initialization function.
uint8_t byte_ready()
Check for new byte received.
Click configuration structure definition.
Definition trf.h:115
uint32_t baud_rate
Definition trf.h:123
bool uart_blocking
Definition trf.h:124
uart_data_bits_t data_bit
Definition trf.h:125
pin_name_t tx_pin
Definition trf.h:119
pin_name_t rx_pin
Definition trf.h:118
uart_stop_bits_t stop_bit
Definition trf.h:127
uart_parity_t parity_bit
Definition trf.h:126
Click ctx object definition.
Definition trf.h:100
uart_t uart
Definition trf.h:104