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 );
62#define TRF_RETVAL uint8_t
63
64#define TRF_OK 0x00
65#define TRF_INIT_ERROR 0xFF
72#define DRV_RX_BUFFER_SIZE 500 // End group macro
76// --------------------------------------------------------------- PUBLIC TYPES
85typedef 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
100typedef 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
143extern "C"{
144#endif
145
155
164
174void trf_generic_multi_write ( trf_t *ctx, char *data_buf, uint8_t len );
175
185void trf_generic_multi_read ( trf_t *ctx, char *data_buf, uint8_t len );
186
187
197
206void trf_generic_single_write ( trf_t *ctx, char tx_data );
207
215uint8_t byte_ready();
216
217#ifdef __cplusplus
218}
219#endif
220#endif // _TRF_H_
221 // End public_function group
224
225// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition: trf.h:72
#define TRF_RETVAL
Definition: trf.h:62
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:101
uint32_t baud_rate
Definition: trf.h:109
bool uart_blocking
Definition: trf.h:110
uart_data_bits_t data_bit
Definition: trf.h:111
pin_name_t tx_pin
Definition: trf.h:105
pin_name_t rx_pin
Definition: trf.h:104
uart_stop_bits_t stop_bit
Definition: trf.h:113
uart_parity_t parity_bit
Definition: trf.h:112
Click ctx object definition.
Definition: trf.h:86
uart_t uart
Definition: trf.h:90