ft 2.0.0.0
ft.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef FT_H
36#define FT_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// -------------------------------------------------------------- PUBLIC MACROS
66#define FT_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
77#define FT_OK 0
78#define FT_ERROR -1
85#define FT_DRV_HEADER_DATA 0x40
86#define FT_DRV_HEADER_LEN 5
87#define FT_DRV_DATA_CRC_LEN 2
94#define FT_DRV_NEW_DATA_AVAILABLE 1
95#define FT_DRV_CONFIRMED_PACKAGE 1
96#define FT_DRV_CHECK_HEADER_DATA_1 0
97#define FT_DRV_CHECK_HEADER_DATA_2 1
98#define FT_DRV_CHECK_LEN_DATA_LSB 2
99#define FT_DRV_CHECK_LEN_DATA_MSB 3
106#define FT_NEW_DATA_AVAILABLE 1
107#define FT_NEW_DATA_NOT_AVAILABLE 0
114#define FT_DRV_BUFFER_SIZE ( FT_MAX_DATA_BUFFER + FT_DRV_HEADER_LEN + FT_DRV_DATA_CRC_LEN )
115#define FT_MAX_DATA_BUFFER 256
118 // End group macro
119// --------------------------------------------------------------- PUBLIC TYPES
127typedef struct
128{
129 // Output pins
130 digital_out_t rst;
131 digital_out_t cs;
132
133 // Modules
134 uart_t uart;
135
136 uint8_t uart_rx_buffer[ FT_DRV_BUFFER_SIZE ];
137 uint8_t uart_tx_buffer[ FT_DRV_BUFFER_SIZE ];
138
139 // Response flags
142 uint8_t drv_rsp_buff[ FT_MAX_DATA_BUFFER ];
144 uint16_t drv_buff_cnt;
146
147} ft_t;
148
152typedef struct
153{
154 // Communication gpio pins
155 pin_name_t rx_pin;
156 pin_name_t tx_pin;
157
158 // Additional gpio pins
159 pin_name_t rst;
160 pin_name_t cs;
161
162 // static variable
163 uint32_t baud_rate; // Clock speed.
165 uart_data_bits_t data_bit; // Data bits.
166 uart_parity_t parity_bit; // Parity bit.
167 uart_stop_bits_t stop_bit; // Stop bits.
168
169} ft_cfg_t;
170
171// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
172
178#ifdef __cplusplus
179extern "C"{
180#endif
181
190void ft_cfg_setup ( ft_cfg_t *cfg );
191
200err_t ft_init ( ft_t *ctx, ft_cfg_t *cfg );
201
211void ft_generic_write ( ft_t *ctx, uint8_t *data_buf, uint16_t len );
212
224int32_t ft_generic_read ( ft_t *ctx, uint8_t *data_buf, uint16_t max_len );
225
234void ft_set_rst_pin ( ft_t *ctx, uint8_t state );
235
258void ft_send_package ( ft_t *ctx, uint8_t *data_buf, uint16_t len, uint8_t queue );
259
269uint8_t ft_get_data_status ( ft_t *ctx );
270
282uint16_t ft_get_data ( ft_t *ctx, uint8_t *data_buf );
283
294void ft_isr_parser ( ft_t *ctx, uint8_t rsp_data );
295
296#ifdef __cplusplus
297}
298#endif
299#endif // _FT_H_
300
301 // End public_function group
303
304// ------------------------------------------------------------------------- END
#define FT_DRV_BUFFER_SIZE
Definition ft.h:114
#define FT_MAX_DATA_BUFFER
Definition ft.h:115
void ft_isr_parser(ft_t *ctx, uint8_t rsp_data)
Collecting and preserving data received via uart interrupt routine.
uint8_t ft_get_data_status(ft_t *ctx)
Gets current status of data.
int32_t ft_generic_read(ft_t *ctx, uint8_t *data_buf, uint16_t max_len)
Generic read function.
void ft_cfg_setup(ft_cfg_t *cfg)
Config Object Initialization function.
err_t ft_init(ft_t *ctx, ft_cfg_t *cfg)
Initialization function.
void ft_generic_write(ft_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
void ft_set_rst_pin(ft_t *ctx, uint8_t state)
Set RST pin state.
uint16_t ft_get_data(ft_t *ctx, uint8_t *data_buf)
Gets new received data.
void ft_send_package(ft_t *ctx, uint8_t *data_buf, uint16_t len, uint8_t queue)
Sends full package to other module.
Click configuration structure definition.
Definition ft.h:153
uint32_t baud_rate
Definition ft.h:163
bool uart_blocking
Definition ft.h:164
uart_data_bits_t data_bit
Definition ft.h:165
pin_name_t tx_pin
Definition ft.h:156
pin_name_t rx_pin
Definition ft.h:155
uart_stop_bits_t stop_bit
Definition ft.h:167
uart_parity_t parity_bit
Definition ft.h:166
pin_name_t rst
Definition ft.h:159
pin_name_t cs
Definition ft.h:160
Click ctx object definition.
Definition ft.h:128
digital_out_t cs
Definition ft.h:131
uint16_t drv_rsp_lenght
Definition ft.h:145
uint16_t drv_buff_cnt
Definition ft.h:144
uint8_t drv_rsp_flag
Definition ft.h:143
uart_t uart
Definition ft.h:134
uint8_t drv_new_data
Definition ft.h:140
digital_out_t rst
Definition ft.h:130
uint8_t drv_start_package
Definition ft.h:141