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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_uart.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define FT_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
54  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
55  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
56  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS )
57 
63 #define FT_OK 0
64 #define FT_ERROR -1
65 
71 #define FT_DRV_HEADER_DATA 0x40
72 #define FT_DRV_HEADER_LEN 5
73 #define FT_DRV_DATA_CRC_LEN 2
74 
80 #define FT_DRV_NEW_DATA_AVAILABLE 1
81 #define FT_DRV_CONFIRMED_PACKAGE 1
82 #define FT_DRV_CHECK_HEADER_DATA_1 0
83 #define FT_DRV_CHECK_HEADER_DATA_2 1
84 #define FT_DRV_CHECK_LEN_DATA_LSB 2
85 #define FT_DRV_CHECK_LEN_DATA_MSB 3
86 
92 #define FT_NEW_DATA_AVAILABLE 1
93 #define FT_NEW_DATA_NOT_AVAILABLE 0
94 
100 #define FT_DRV_BUFFER_SIZE ( FT_MAX_DATA_BUFFER + FT_DRV_HEADER_LEN + FT_DRV_DATA_CRC_LEN )
101 #define FT_MAX_DATA_BUFFER 256
102  // End group macro
105 // --------------------------------------------------------------- PUBLIC TYPES
113 typedef struct
114 {
115  // Output pins
116  digital_out_t rst;
117  digital_out_t cs;
118 
119  // Modules
120  uart_t uart;
121 
122  uint8_t uart_rx_buffer[ FT_DRV_BUFFER_SIZE ];
123  uint8_t uart_tx_buffer[ FT_DRV_BUFFER_SIZE ];
124 
125  // Response flags
126  uint8_t drv_new_data;
128  uint8_t drv_rsp_buff[ FT_MAX_DATA_BUFFER ];
129  uint8_t drv_rsp_flag;
130  uint16_t drv_buff_cnt;
131  uint16_t drv_rsp_lenght;
132 
133 } ft_t;
134 
138 typedef struct
139 {
140  // Communication gpio pins
141  pin_name_t rx_pin;
142  pin_name_t tx_pin;
143 
144  // Additional gpio pins
145  pin_name_t rst;
146  pin_name_t cs;
147 
148  // static variable
149  uint32_t baud_rate; // Clock speed.
151  uart_data_bits_t data_bit; // Data bits.
152  uart_parity_t parity_bit; // Parity bit.
153  uart_stop_bits_t stop_bit; // Stop bits.
154 
155 } ft_cfg_t;
156 
157 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158 
164 #ifdef __cplusplus
165 extern "C"{
166 #endif
167 
176 void ft_cfg_setup ( ft_cfg_t *cfg );
177 
186 err_t ft_init ( ft_t *ctx, ft_cfg_t *cfg );
187 
197 void ft_generic_write ( ft_t *ctx, uint8_t *data_buf, uint16_t len );
198 
210 int32_t ft_generic_read ( ft_t *ctx, uint8_t *data_buf, uint16_t max_len );
211 
220 void ft_set_rst_pin ( ft_t *ctx, uint8_t state );
221 
244 void ft_send_package ( ft_t *ctx, uint8_t *data_buf, uint16_t len, uint8_t queue );
245 
255 uint8_t ft_get_data_status ( ft_t *ctx );
256 
268 uint16_t ft_get_data ( ft_t *ctx, uint8_t *data_buf );
269 
280 void ft_isr_parser ( ft_t *ctx, uint8_t rsp_data );
281 
282 #ifdef __cplusplus
283 }
284 #endif
285 #endif // _FT_H_
286  // End public_function group
289 
290 // ------------------------------------------------------------------------- END
ft_t::uart
uart_t uart
Definition: ft.h:120
ft_generic_write
void ft_generic_write(ft_t *ctx, uint8_t *data_buf, uint16_t len)
Generic write function.
ft_init
err_t ft_init(ft_t *ctx, ft_cfg_t *cfg)
Initialization function.
ft_t::drv_buff_cnt
uint16_t drv_buff_cnt
Definition: ft.h:130
FT_DRV_BUFFER_SIZE
#define FT_DRV_BUFFER_SIZE
Definition: ft.h:100
ft_t
Click ctx object definition.
Definition: ft.h:114
ft_cfg_t
Click configuration structure definition.
Definition: ft.h:139
ft_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ft.h:152
ft_t::cs
digital_out_t cs
Definition: ft.h:117
ft_t::rst
digital_out_t rst
Definition: ft.h:116
ft_generic_read
int32_t ft_generic_read(ft_t *ctx, uint8_t *data_buf, uint16_t max_len)
Generic read function.
ft_cfg_t::cs
pin_name_t cs
Definition: ft.h:146
ft_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ft.h:142
FT_MAX_DATA_BUFFER
#define FT_MAX_DATA_BUFFER
Definition: ft.h:101
ft_cfg_t::uart_blocking
bool uart_blocking
Definition: ft.h:150
ft_t::drv_start_package
uint8_t drv_start_package
Definition: ft.h:127
ft_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ft.h:151
ft_send_package
void ft_send_package(ft_t *ctx, uint8_t *data_buf, uint16_t len, uint8_t queue)
Sends full package to other module.
ft_t::drv_rsp_lenght
uint16_t drv_rsp_lenght
Definition: ft.h:131
ft_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ft.h:153
ft_get_data
uint16_t ft_get_data(ft_t *ctx, uint8_t *data_buf)
Gets new received data.
ft_isr_parser
void ft_isr_parser(ft_t *ctx, uint8_t rsp_data)
Collecting and preserving data received via uart interrupt routine.
ft_get_data_status
uint8_t ft_get_data_status(ft_t *ctx)
Gets current status of data.
ft_cfg_t::rst
pin_name_t rst
Definition: ft.h:145
ft_set_rst_pin
void ft_set_rst_pin(ft_t *ctx, uint8_t state)
Set RST pin state.
ft_t::drv_new_data
uint8_t drv_new_data
Definition: ft.h:126
ft_cfg_t::baud_rate
uint32_t baud_rate
Definition: ft.h:149
ft_t::drv_rsp_flag
uint8_t drv_rsp_flag
Definition: ft.h:129
ft_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ft.h:141
ft_cfg_setup
void ft_cfg_setup(ft_cfg_t *cfg)
Config Object Initialization function.