ble6 2.0.0.0
ble6.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 BLE6_H
29#define BLE6_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
73#define BLE6_MODULE_POWER_OFF 0x00
74#define BLE6_MODULE_POWER_ON 0x01
75
81#define BLE6_DRV_BUFFER_SIZE 256
82
83 // ble6_cmd
84
99#define BLE6_MAP_MIKROBUS( cfg, mikrobus ) \
100 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
101 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
102 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
103 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
104 cfg.bl = MIKROBUS( mikrobus, MIKROBUS_PWM )
105
106 // ble6_map
107 // ble6
108
113typedef struct
114{
115 // Output pins
116 digital_out_t rst;
117 digital_out_t bl;
119 // Input pins
120 digital_in_t an;
122 // Modules
123 uart_t uart;
125 // Buffers
126 uint8_t uart_rx_buffer[ BLE6_DRV_BUFFER_SIZE ];
127 uint8_t uart_tx_buffer[ BLE6_DRV_BUFFER_SIZE ];
129} ble6_t;
130
135typedef struct
136{
137 // Communication gpio pins
138 pin_name_t rx_pin;
139 pin_name_t tx_pin;
141 // Additional gpio pins
142 pin_name_t an;
143 pin_name_t rst;
144 pin_name_t bl;
146 // Static variable
147 uint32_t baud_rate;
149 uart_data_bits_t data_bit;
150 uart_parity_t parity_bit;
151 uart_stop_bits_t stop_bit;
153} ble6_cfg_t;
154
159typedef struct
160{
161 uint8_t event_code;
162 uint8_t length;
163 uint8_t num_hci_cmd;
164 uint16_t cmd_opcode;
165 uint8_t status;
166 uint8_t payload[ BLE6_DRV_BUFFER_SIZE ];
167
168} ble6_rsp_t;
169
174typedef struct
175{
177 uint8_t le_length;
179 uint8_t le_status;
180 uint16_t le_conn_hdl;
181 uint8_t le_role;
183 uint8_t le_peer_addr[ 6 ];
188
190
195typedef struct
196{
197 uint8_t event_code;
198 uint8_t length;
199 uint16_t e_code;
200 uint16_t conn_hdl;
201 uint16_t attr_hdl;
202 uint16_t offset;
204 uint8_t attr_data[ 255 ];
205
207
212typedef enum
213{
215 BLE6_ERROR = -1
216
218
229typedef void ( *ble6_handler_t )( uint8_t *message_buf, uint32_t message_len );
230
235typedef void ( *ble6_hdl_t )( uint8_t* );
236
247
261err_t ble6_init ( ble6_t *ctx, ble6_cfg_t *cfg );
262
275err_t ble6_generic_write ( ble6_t *ctx, char *data_buf, uint16_t len );
276
289err_t ble6_generic_read ( ble6_t *ctx, char *data_buf, uint16_t max_len );
290
301int8_t ble6_strncmp ( uint8_t *string1, uint8_t *string2, uint8_t len );
302
310uint8_t ble6_byte_ready ( ble6_t *ctx );
311
323void ble6_power_on ( ble6_t *ctx, uint8_t en_pwr );
324
336void ble6_send_command ( ble6_t *ctx, uint8_t *tx_data, uint8_t n_bytes );
337
344void ble6_set_response_handler ( void ( *handler )( uint8_t* ), ble6_hdl_t driver_hdl );
345
353void ble6_set_handlers ( ble6_handler_t event_handler, ble6_handler_t eve_hdlr );
354
363void ble6_parser_rsp ( ble6_t *ctx, ble6_rsp_t *response );
364
365#ifdef __cplusplus
366}
367#endif
368#endif // BLE6_H
369
370 // ble6
371
372// ------------------------------------------------------------------------ END
ble6_return_value_t
BLE 6 Click return value data.
Definition ble6.h:213
@ BLE6_ERROR
Definition ble6.h:215
@ BLE6_OK
Definition ble6.h:214
#define BLE6_DRV_BUFFER_SIZE
BLE 6 driver buffer size.
Definition ble6.h:81
void ble6_parser_rsp(ble6_t *ctx, ble6_rsp_t *response)
Response parser function.
void(* ble6_hdl_t)(uint8_t *)
BLE 6 Click driver handler.
Definition ble6.h:235
void ble6_power_on(ble6_t *ctx, uint8_t en_pwr)
Set Power On function.
void ble6_cfg_setup(ble6_cfg_t *cfg)
BLE 6 configuration object setup function.
void ble6_set_handlers(ble6_handler_t event_handler, ble6_handler_t eve_hdlr)
Set handlers function.
int8_t ble6_strncmp(uint8_t *string1, uint8_t *string2, uint8_t len)
Lexicographically compares function.
void ble6_send_command(ble6_t *ctx, uint8_t *tx_data, uint8_t n_bytes)
Send command function.
err_t ble6_generic_write(ble6_t *ctx, char *data_buf, uint16_t len)
BLE 6 data writing function.
void ble6_set_response_handler(void(*handler)(uint8_t *), ble6_hdl_t driver_hdl)
Set response handlers function.
err_t ble6_generic_read(ble6_t *ctx, char *data_buf, uint16_t max_len)
BLE 6 data reading function.
err_t ble6_init(ble6_t *ctx, ble6_cfg_t *cfg)
BLE 6 initialization function.
void(* ble6_handler_t)(uint8_t *message_buf, uint32_t message_len)
BLE 6 Click driver handler.
Definition ble6.h:229
uint8_t ble6_byte_ready(ble6_t *ctx)
Check for new byte received.
BLE 6 Click configuration object.
Definition ble6.h:136
uint32_t baud_rate
Definition ble6.h:147
bool uart_blocking
Definition ble6.h:148
pin_name_t bl
Definition ble6.h:144
uart_data_bits_t data_bit
Definition ble6.h:149
pin_name_t tx_pin
Definition ble6.h:139
pin_name_t rx_pin
Definition ble6.h:138
uart_stop_bits_t stop_bit
Definition ble6.h:151
uart_parity_t parity_bit
Definition ble6.h:150
pin_name_t rst
Definition ble6.h:143
pin_name_t an
Definition ble6.h:142
Driver Response Le Meta Event.
Definition ble6.h:175
uint16_t le_conn_interval
Definition ble6.h:184
uint8_t le_length
Definition ble6.h:177
uint16_t le_conn_hdl
Definition ble6.h:180
uint8_t le_role
Definition ble6.h:181
uint16_t le_sup_timeout
Definition ble6.h:186
uint8_t le_subevent_code
Definition ble6.h:178
uint8_t le_event_code
Definition ble6.h:176
uint8_t le_status
Definition ble6.h:179
uint16_t le_conn_latency
Definition ble6.h:185
uint8_t le_peer_addr_type
Definition ble6.h:182
uint8_t le_master_clk_accuracy
Definition ble6.h:187
Driver Default Response type.
Definition ble6.h:160
uint16_t cmd_opcode
Definition ble6.h:164
uint8_t num_hci_cmd
Definition ble6.h:163
uint8_t length
Definition ble6.h:162
uint8_t status
Definition ble6.h:165
uint8_t event_code
Definition ble6.h:161
Driver Response type.
Definition ble6.h:196
uint16_t attr_hdl
Definition ble6.h:201
uint8_t length
Definition ble6.h:198
uint16_t offset
Definition ble6.h:202
uint16_t e_code
Definition ble6.h:199
uint16_t attr_data_len
Definition ble6.h:203
uint16_t conn_hdl
Definition ble6.h:200
uint8_t event_code
Definition ble6.h:197
BLE 6 Click context object.
Definition ble6.h:114
digital_out_t bl
Definition ble6.h:117
uart_t uart
Definition ble6.h:123
digital_in_t an
Definition ble6.h:120
digital_out_t rst
Definition ble6.h:116