ftdi  2.1.0.0
ftdi.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef FTDI_H
29 #define FTDI_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_uart.h"
48 
70 #define FTDI_TX_DRV_BUFFER_SIZE 100
71 #define FTDI_RX_DRV_BUFFER_SIZE 300
72  // ftdi_cmd
74 
89 #define FTDI_MAP_MIKROBUS( cfg, mikrobus ) \
90  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
91  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX );
92  // ftdi_map // ftdi
95 
100 typedef struct
101 {
102  // Modules
103  uart_t uart;
105  // Buffers
106  uint8_t uart_rx_buffer[ FTDI_RX_DRV_BUFFER_SIZE ];
107  uint8_t uart_tx_buffer[ FTDI_TX_DRV_BUFFER_SIZE ];
109 } ftdi_t;
110 
115 typedef struct
116 {
117  // Communication gpio pins
118  pin_name_t rx_pin;
119  pin_name_t tx_pin;
121  // Static variable
122  uint32_t baud_rate;
124  uart_data_bits_t data_bit;
125  uart_parity_t parity_bit;
126  uart_stop_bits_t stop_bit;
128 } ftdi_cfg_t;
129 
134 typedef enum
135 {
136  FTDI_OK = 0,
137  FTDI_ERROR = -1
138 
140 
157 
171 err_t ftdi_init ( ftdi_t *ctx, ftdi_cfg_t *cfg );
172 
185 err_t ftdi_generic_write ( ftdi_t *ctx, uint8_t *data_in, uint16_t len );
186 
199 err_t ftdi_generic_read ( ftdi_t *ctx, uint8_t *data_out, uint16_t len );
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 #endif // FTDI_H
205  // ftdi
207 
208 // ------------------------------------------------------------------------ END
ftdi_cfg_t::baud_rate
uint32_t baud_rate
Definition: ftdi.h:122
ftdi_t::uart
uart_t uart
Definition: ftdi.h:103
ftdi_generic_read
err_t ftdi_generic_read(ftdi_t *ctx, uint8_t *data_out, uint16_t len)
FTDI data reading function.
ftdi_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ftdi.h:118
FTDI_TX_DRV_BUFFER_SIZE
#define FTDI_TX_DRV_BUFFER_SIZE
FTDI driver buffer size.
Definition: ftdi.h:70
ftdi_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ftdi.h:119
ftdi_generic_write
err_t ftdi_generic_write(ftdi_t *ctx, uint8_t *data_in, uint16_t len)
FTDI data writing function.
ftdi_init
err_t ftdi_init(ftdi_t *ctx, ftdi_cfg_t *cfg)
FTDI initialization function.
ftdi_t
FTDI Click context object.
Definition: ftdi.h:101
ftdi_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ftdi.h:125
ftdi_return_value_t
ftdi_return_value_t
FTDI Click return value data.
Definition: ftdi.h:135
FTDI_RX_DRV_BUFFER_SIZE
#define FTDI_RX_DRV_BUFFER_SIZE
Definition: ftdi.h:71
ftdi_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ftdi.h:126
ftdi_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ftdi.h:124
ftdi_cfg_t
FTDI Click configuration object.
Definition: ftdi.h:116
FTDI_ERROR
@ FTDI_ERROR
Definition: ftdi.h:137
FTDI_OK
@ FTDI_OK
Definition: ftdi.h:136
ftdi_cfg_setup
void ftdi_cfg_setup(ftdi_cfg_t *cfg)
FTDI configuration object setup function.
ftdi_cfg_t::uart_blocking
bool uart_blocking
Definition: ftdi.h:123