ble4 2.0.0.0
ble4.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 BLE4_H
36#define BLE4_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 BLE4_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
68 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
69 cfg.dtr = MIKROBUS( mikrobus, MIKROBUS_AN ); \
70 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.dsr = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
73 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
80#define BLE4_RETVAL uint8_t
81
82#define BLE4_OK 0x00
83#define BLE4_INIT_ERROR 0xFF
90#define BLE4_END_BUFF 0
97#define BLE4_RSP_READY 1
98#define BLE4_RSP_NOT_READY 0
105#define BLE4_ECHO_ON 1
106#define BLE4_ECHO_OFF 0
113#define BLE4_COMMAND_MODE 0
114#define BLE4_DATA_MODE 1
115#define BLE4_EXT_DATA_MODE 2
116#define BLE4_PPP_MODE 3
123#define BLE4_DISABLED_ROLE 0
124#define BLE4_CENTRAL_ROLE 1
125#define BLE4_PERIPHERAL_ROLE 2
126#define BLE4_SIMULTANEOUS_ROLE 3
133#define BLE4_SEC_DISABLED 1
134#define BLE4_SEC_JUST_WORKS 2
135#define BLE4_SEC_DISPLAY_ONLY 3
136#define BLE4_SEC_DISPLAY_YES_NO 4
137#define BLE4_SEC_KEYBOARD_ONLY 5
138#define BLE4_SEC_OUT_OF_BAND 6
145#define BLE4_GAP_NON_PAIRING_MODE 1
146#define BLE4_GAP_PAIRING_MODE 2
153#define BLE4_GAP_NON_CONNECTABLE_MODE 1
154#define BLE4_GAP_CONNECTABLE_MODE 2
161#define BLE4_GAP_NON_DISCOVERABLE_MODE 1
162#define BLE4_GAP_LIMITED_DISCOVERABLE_MODE 2
163#define BLE4_GAP_GENERAL_DISCOVERABLE_MODE 3
170#define DRV_RX_BUFFER_SIZE 100
171#define DRV_TX_BUFFER_SIZE 100
174 // End group macro
175// --------------------------------------------------------------- PUBLIC TYPES
184typedef struct
185{
186 // Output pins
187
188 digital_out_t rst;
189 digital_out_t cts;
190 digital_out_t dsr;
191
192 // Input pins
193
194 digital_in_t dtr;
195 digital_in_t rts;
196
197 // Modules
198
199 uart_t uart;
200
201 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
202 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
203
204 uint8_t rsp_rdy;
206
207} ble4_t;
208
212typedef struct
213{
214 // Communication gpio pins
215
216 pin_name_t rx_pin;
217 pin_name_t tx_pin;
218
219 // Additional gpio pins
220
221 pin_name_t dtr;
222 pin_name_t rst;
223 pin_name_t cts;
224 pin_name_t dsr;
225 pin_name_t rts;
226
227 // static variable
228
229 uint32_t baud_rate; // Clock speed.
231 uart_data_bits_t data_bit; // Data bits.
232 uart_parity_t parity_bit; // Parity bit.
233 uart_stop_bits_t stop_bit; // Stop bits.
234
235} ble4_cfg_t;
236
237 // End types group
238// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
239
245#ifdef __cplusplus
246extern "C"{
247#endif
248
258
268
276void ble4_reset ( ble4_t *ctx );
277
284void ble4_generic_write ( ble4_t *ctx, char *data_buf, uint16_t len );
285
293int32_t ble4_generic_read ( ble4_t *ctx, char *data_buf, uint16_t max_len );
294
305
318void ble4_send_command ( ble4_t *ctx, char * command, uint8_t term_char );
319
330
341
348
360void ble4_set_start_mode_cmd ( ble4_t *ctx, uint8_t start_mode );
361
370
384void ble4_enter_mode_cmd ( ble4_t *ctx, uint8_t mode );
385
395void ble4_set_echo_cmd ( ble4_t *ctx, uint8_t echo_en );
396
405
418void ble4_set_local_name_cmd ( ble4_t *ctx, char *local_name );
419
428
445void ble4_set_low_energy_role_cmd ( ble4_t *ctx, uint8_t le_role );
446
455
467
483
495
518void ble4_set_sec_mode_cmd ( ble4_t *ctx, uint8_t sec_mode );
519
528
537void ble4_pairing_en_cmd ( ble4_t *ctx, uint8_t pairing_mode );
538
547
556void ble4_connectability_en_cmd ( ble4_t *ctx, uint8_t conn_mode );
557
566
582void ble4_discoverability_en_cmd ( ble4_t *ctx, uint8_t discover_mode );
583
592
600void ble4_get_info ( ble4_t *ctx );
601
614uint8_t ble4_sps_central_pairing ( ble4_t *ctx, uint8_t *local_addr );
615
627
640void ble4_set_cts_pin ( ble4_t *ctx, uint8_t state );
641
653void ble4_set_dsr_pin ( ble4_t *ctx, uint8_t state );
654
667uint8_t ble4_get_dtr_pin ( ble4_t *ctx );
668
680uint8_t ble4_get_rts_pin ( ble4_t *ctx );
681
682#ifdef __cplusplus
683}
684#endif
685#endif // _BLE4_H_
686
687 // End public_function group
689
690// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition ble4.h:170
#define DRV_TX_BUFFER_SIZE
Definition ble4.h:171
#define BLE4_RETVAL
Definition ble4.h:80
void ble4_generic_write(ble4_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void ble4_check_pairing_cmd(ble4_t *ctx)
Get Pairing Mode command.
void ble4_send_command(ble4_t *ctx, char *command, uint8_t term_char)
Transmit function.
void ble4_set_local_name_cmd(ble4_t *ctx, char *local_name)
Local Name Setting command.
void ble4_connectability_en_cmd(ble4_t *ctx, uint8_t conn_mode)
Connectability Mode Setting command.
void ble4_set_echo_cmd(ble4_t *ctx, uint8_t echo_en)
Echo On/Off command.
void ble4_set_default_cmd(ble4_t *ctx)
Default Configuration command.
int32_t ble4_generic_read(ble4_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
BLE4_RETVAL ble4_init(ble4_t *ctx, ble4_cfg_t *cfg)
Initialization function.
void ble4_set_low_energy_role_cmd(ble4_t *ctx, uint8_t le_role)
Bluetooth Low Energy Role Setting command.
void ble4_set_sec_mode_cmd(ble4_t *ctx, uint8_t sec_mode)
Security Mode Setting command.
void ble4_check_connectability_cmd(ble4_t *ctx)
Get Connectability Mode command.
void ble4_get_sec_mode_cmd(ble4_t *ctx)
Get Security Mode command.
void ble4_fact_rst_cmd(ble4_t *ctx)
Factory Reset command.
void ble4_get_low_energy_role_cmd(ble4_t *ctx)
Get Bluetooth Low Energy Role command.
void ble4_check_discoverability_cmd(ble4_t *ctx)
Get Discoverability Mode command.
void ble4_get_local_addr_cmd(ble4_t *ctx)
Get Local Address command.
void ble4_set_cts_pin(ble4_t *ctx, uint8_t state)
CTS Pin Setting function.
void ble4_set_start_mode_cmd(ble4_t *ctx, uint8_t start_mode)
Module Start Mode Setting command.
uint8_t ble4_response_ready(ble4_t *ctx)
Response Ready function.
void ble4_pairing_en_cmd(ble4_t *ctx, uint8_t pairing_mode)
Pairing Mode Setting command.
uint8_t ble4_sps_central_pairing(ble4_t *ctx, uint8_t *local_addr)
SPS Pairing As Central Device command.
void ble4_get_start_mode_cmd(ble4_t *ctx)
Get Module Start Mode command.
void ble4_get_info(ble4_t *ctx)
Get Info command.
uint8_t ble4_get_dtr_pin(ble4_t *ctx)
Check DTR Pin function.
void ble4_get_echo_cmd(ble4_t *ctx)
Get Echo Setting command.
void ble4_get_local_name_cmd(ble4_t *ctx)
Get Local Name command.
void ble4_cfg_setup(ble4_cfg_t *cfg)
Config Object Initialization function.
void ble4_discoverability_en_cmd(ble4_t *ctx, uint8_t discover_mode)
Discoverability Mode Setting command.
void ble4_sps_peripheral_pairing(ble4_t *ctx)
SPS Pairing As Peripheral Device command.
void ble4_reset(ble4_t *ctx)
Reset function.
void ble4_get_list_peers_cmd(ble4_t *ctx)
Get Peer List command.
void ble4_enter_mode_cmd(ble4_t *ctx, uint8_t mode)
Enter Data Mode command.
uint8_t ble4_get_rts_pin(ble4_t *ctx)
Check RTS Pin function.
void ble4_get_server_cnfg_cmd(ble4_t *ctx)
Get Server Configuration command.
void ble4_set_dsr_pin(ble4_t *ctx, uint8_t state)
Set DSR Pin function.
void ble4_store_cnfg_cmd(ble4_t *ctx)
Store Current Configuration command.
Click configuration structure definition.
Definition ble4.h:213
pin_name_t dtr
Definition ble4.h:221
pin_name_t rts
Definition ble4.h:225
uint32_t baud_rate
Definition ble4.h:229
pin_name_t cts
Definition ble4.h:223
bool uart_blocking
Definition ble4.h:230
uart_data_bits_t data_bit
Definition ble4.h:231
pin_name_t tx_pin
Definition ble4.h:217
pin_name_t rx_pin
Definition ble4.h:216
uart_stop_bits_t stop_bit
Definition ble4.h:233
pin_name_t dsr
Definition ble4.h:224
uart_parity_t parity_bit
Definition ble4.h:232
pin_name_t rst
Definition ble4.h:222
Click ctx object definition.
Definition ble4.h:185
digital_out_t dsr
Definition ble4.h:190
uint8_t termination_char
Definition ble4.h:205
uart_t uart
Definition ble4.h:199
uint8_t rsp_rdy
Definition ble4.h:204
digital_in_t rts
Definition ble4.h:195
digital_out_t rst
Definition ble4.h:188
digital_out_t cts
Definition ble4.h:189
digital_in_t dtr
Definition ble4.h:194