btez  2.0.0.0
btez.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 BTEZ_H
36 #define BTEZ_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_uart.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define BTEZ_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
64  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
65  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
66  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
67  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
68 
74 #define BTEZ_RETVAL uint8_t
75 
76 #define BTEZ_OK 0x00
77 #define BTEZ_INIT_ERROR 0xFF
78 
84 #define DRV_RX_BUFFER_SIZE 500
85 #define DRV_TX_BUFFER_SIZE 200
86  // End group macro
89 // --------------------------------------------------------------- PUBLIC TYPES
97 typedef struct
98 {
99  // Output pins
100 
101  digital_out_t rst;
102  digital_out_t cts;
103 
104  // Input pins
105 
106  digital_in_t rts;
107 
108  // Modules
109 
110  uart_t uart;
111 
112  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
113  char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
114 
115 } btez_t;
116 
120 typedef struct
121 {
122  // Communication gpio pins
123 
124  pin_name_t rx_pin;
125  pin_name_t tx_pin;
126 
127  // Additional gpio pins
128 
129  pin_name_t rst;
130  pin_name_t cts;
131  pin_name_t rts;
132 
133  // static variable
134 
135  uint32_t baud_rate; // Clock speed.
137  uart_data_bits_t data_bit; // Data bits.
138  uart_parity_t parity_bit; // Parity bit.
139  uart_stop_bits_t stop_bit; // Stop bits.
140 
141 } btez_cfg_t;
142 
146 typedef uint8_t btez_error_t;
147  // End types group
149 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
150 
156 #ifdef __cplusplus
157 extern "C"{
158 #endif
159 
169 
179 
185 void btez_module_reset ( btez_t *ctx );
186 
194 void btez_generic_write ( btez_t *ctx, char *data_buf, uint16_t len );
195 
204 int32_t btez_generic_read ( btez_t *ctx, char *data_buf, uint16_t max_len );
205 
212 void btez_send_command ( btez_t *ctx, char *command );
213 
214 #ifdef __cplusplus
215 }
216 #endif
217 #endif // _BTEZ_H_
218  // End public_function group
221 
222 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: btez.h:84
btez_t::rst
digital_out_t rst
Definition: btez.h:101
btez_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: btez.h:139
btez_cfg_t
Click configuration structure definition.
Definition: btez.h:121
btez_cfg_t::tx_pin
pin_name_t tx_pin
Definition: btez.h:125
btez_cfg_t::cts
pin_name_t cts
Definition: btez.h:130
btez_cfg_t::rx_pin
pin_name_t rx_pin
Definition: btez.h:124
btez_cfg_t::baud_rate
uint32_t baud_rate
Definition: btez.h:135
btez_send_command
void btez_send_command(btez_t *ctx, char *command)
Send command function.
btez_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: btez.h:138
BTEZ_RETVAL
#define BTEZ_RETVAL
Definition: btez.h:74
btez_t::rts
digital_in_t rts
Definition: btez.h:106
btez_module_reset
void btez_module_reset(btez_t *ctx)
Reset module.
btez_error_t
uint8_t btez_error_t
Error type.
Definition: btez.h:146
btez_t
Click ctx object definition.
Definition: btez.h:98
btez_t::cts
digital_out_t cts
Definition: btez.h:102
btez_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: btez.h:137
btez_cfg_t::rts
pin_name_t rts
Definition: btez.h:131
btez_cfg_setup
void btez_cfg_setup(btez_cfg_t *cfg)
Config Object Initialization function.
btez_init
BTEZ_RETVAL btez_init(btez_t *ctx, btez_cfg_t *cfg)
Initialization function.
btez_t::uart
uart_t uart
Definition: btez.h:110
DRV_TX_BUFFER_SIZE
#define DRV_TX_BUFFER_SIZE
Definition: btez.h:85
btez_generic_write
void btez_generic_write(btez_t *ctx, char *data_buf, uint16_t len)
Generic write function.
btez_generic_read
int32_t btez_generic_read(btez_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
btez_cfg_t::uart_blocking
bool uart_blocking
Definition: btez.h:136
btez_cfg_t::rst
pin_name_t rst
Definition: btez.h:129