ble12 2.0.0.0
ble12.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 BLE12_H
29#define BLE12_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 BLE12_CMD_AT "AT"
74#define BLE12_CMD_SW_RESET "AT+RESET"
75#define BLE12_CMD_GET_VERSION "AT+VERSION?"
76#define BLE12_CMD_GET_RSSI "AT+RSSI?"
77#define BLE12_CMD_SET_ADINTERVAL "AT+ADINTERVAL="
78#define BLE12_CMD_GET_ADINTERVAL "AT+ADINTERVAL=?"
79#define BLE12_CMD_SET_ADSTART "AT+ADSTART="
80#define BLE12_CMD_GET_ADSTART "AT+ADSTART?"
81#define BLE12_CMD_SET_ADVMANU "AT+ADVMANU="
82#define BLE12_CMD_GET_ADVMANU "AT+ADVMANU?"
83#define BLE12_CMD_SET_ADVRESP "AT+ADVRESP="
84#define BLE12_CMD_GET_ADVRESP "AT+ADVRESP?"
85#define BLE12_CMD_SET_SCANNER "AT+SCANNER="
86#define BLE12_CMD_GET_SCANNER "AT+SCANNER?"
87#define BLE12_CMD_SET_AUTOCON "AT+AUTOCON="
88#define BLE12_CMD_GET_AUTOCON "AT+AUTOCON?"
89#define BLE12_CMD_SET_DISCON "AT+DISCON=1"
90#define BLE12_CMD_SET_FILTERA "AT+FILTERA="
91#define BLE12_CMD_GET_FILTERA "AT+FILTERA?"
92#define BLE12_CMD_SET_FILTERR "AT+FILTERR="
93#define BLE12_CMD_GET_FILTERR "AT+FILTERR?"
94#define BLE12_CMD_SET_MANUAID "AT+MANUAID="
95#define BLE12_CMD_GET_MANUAID "AT+MANUAID?"
96#define BLE12_CMD_SET_MANURID "AT+MANURID="
97#define BLE12_CMD_GET_MANURID "AT+MANURID?"
98#define BLE12_CMD_SET_DCDC "AT+DCDC="
99#define BLE12_CMD_GET_DCDC "AT+DCDC?"
100#define BLE12_CMD_SET_SAVE "AT+SAVE=1"
101#define BLE12_CMD_SET_STOP "AT+STOP="
102#define BLE12_CMD_SET_NAME "AT+NAME="
103#define BLE12_CMD_GET_UART "AT+UART?"
104#define BLE12_CMD_SET_UART "AT+UART="
105#define BLE12_CMD_GET_ADDR "AT+ADDR?"
106#define BLE12_CMD_GET_RX "AT+RX?"
107#define BLE12_CMD_SET_DEFAULT "AT+DEFAULT"
108#define BLE12_CMD_GET_RFPW "AT+RFPW?"
109#define BLE12_CMD_SET_RFPW "AT+RFPW="
110#define BLE12_CMD_SET_GPIO "AT+PIO="
111#define BLE12_CMD_GET_GPIO "AT+PIO?"
112#define BLE12_CMD_SET_GPIO_IO "AT+PIS="
113#define BLE12_CMD_INIT_LED1 "AT+PIS=017,1"
114#define BLE12_CMD_INIT_LED2 "AT+PIS=019,1"
115
120#define BLE12_EVT_CONNECTED "CONNECTED"
121#define BLE12_EVT_DISCONNECTED "DISCONNECTED"
122#define BLE12_EVT_SCAN_TIMEOUT "SCAN TIMEOUT"
123
128#define BLE12_LED_YELLOW 0x00
129#define BLE12_LED_RED 0x01
130#define BLE12_LED_ON 0x00
131#define BLE12_LED_OFF 0x01
132#define BLE12_OP_MODE_CMD 0x00
133#define BLE12_OP_MODE_DATA 0x01
134#define BLE12_SELECT_LED_YELLOW "017,"
135#define BLE12_SELECT_LED_RED "019,"
136#define BLE12_SET_LED_STATE_ON "0"
137#define BLE12_SET_LED_STATE_OFF "1"
138
144#define DRV_BUFFER_SIZE 200
145
146 // ble12_cmd
147
162#define BLE12_MAP_MIKROBUS( cfg, mikrobus ) \
163 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
164 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
165 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
166 cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_CS ); \
167 cfg.cmd = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
168 cfg.req = MIKROBUS( mikrobus, MIKROBUS_INT )
169
170 // ble12_map
171 // ble12
172
177typedef struct
178{
179 // Output pins
180 digital_out_t rst;
181 digital_out_t wkp;
182 digital_out_t cmd;
184 // Input pins
185 digital_in_t req;
187 // Modules
188 uart_t uart;
190 // Buffers
191 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
192 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
194} ble12_t;
195
200typedef struct
201{
202 // Communication gpio pins
203 pin_name_t rx_pin;
204 pin_name_t tx_pin;
206 // Additional gpio pins
207 pin_name_t rst;
208 pin_name_t wkp;
209 pin_name_t cmd;
210 pin_name_t req;
212 // Static variable
213 uint32_t baud_rate;
215 uart_data_bits_t data_bit;
216 uart_parity_t parity_bit;
217 uart_stop_bits_t stop_bit;
220
225typedef enum
226{
228 BLE12_ERROR = -1
229
231
248
263err_t ble12_init ( ble12_t *ctx, ble12_cfg_t *cfg );
264
279
293err_t ble12_generic_write ( ble12_t *ctx, char *data_buf, uint16_t len );
294
308err_t ble12_generic_read ( ble12_t *ctx, char *data_buf, uint16_t max_len );
309
321
335err_t ble12_send_cmd ( ble12_t *ctx, char *cmd );
336
351err_t ble12_send_data ( ble12_t *ctx, char *tx_data );
352
366err_t ble12_init_led ( ble12_t *ctx );
367
387err_t ble12_set_led_state ( ble12_t *ctx, uint8_t led, uint8_t state );
388
402err_t ble12_reset ( ble12_t *ctx );
403
418
433err_t ble12_set_device_name ( ble12_t *ctx, uint8_t *device_name );
434
449
464err_t ble12_set_adv_interval ( ble12_t *ctx, uint8_t *adv_interval );
465
480
495
510err_t ble12_set_op_mode ( ble12_t *ctx, uint8_t op_mode );
511
526
527#ifdef __cplusplus
528}
529#endif
530#endif // BLE12_H
531
532 // ble12
533
534// ------------------------------------------------------------------------ END
ble12_return_value_t
BLE 12 Click return value data.
Definition ble12.h:226
@ BLE12_ERROR
Definition ble12.h:228
@ BLE12_OK
Definition ble12.h:227
#define DRV_BUFFER_SIZE
BLE 12 driver buffer size.
Definition ble12.h:144
err_t ble12_default_cfg(ble12_t *ctx)
BLE 12 default configuration function.
err_t ble12_set_adv_interval(ble12_t *ctx, uint8_t *adv_interval)
BLE 12 set adv interval function.
err_t ble12_set_default(ble12_t *ctx)
BLE 12 set default function.
err_t ble12_save_config(ble12_t *ctx)
BLE 12 save config function.
err_t ble12_generic_read(ble12_t *ctx, char *data_buf, uint16_t max_len)
BLE 12 data reading function.
err_t ble12_get_version(ble12_t *ctx)
BLE 12 get version function.
err_t ble12_set_device_name(ble12_t *ctx, uint8_t *device_name)
BLE 12 set device name function.
err_t ble12_send_data(ble12_t *ctx, char *tx_data)
BLE 12 send data function.
err_t ble12_reset(ble12_t *ctx)
BLE 12 reset function.
err_t ble12_set_op_mode(ble12_t *ctx, uint8_t op_mode)
BLE 12 set operating mode function.
err_t ble12_init(ble12_t *ctx, ble12_cfg_t *cfg)
BLE 12 initialization function.
err_t ble12_init_led(ble12_t *ctx)
BLE 12 LED initialization function.
void ble12_cfg_setup(ble12_cfg_t *cfg)
BLE 12 configuration object setup function.
err_t ble12_event_startup(ble12_t *ctx)
BLE 12 event start-up function.
err_t ble12_send_cmd(ble12_t *ctx, char *cmd)
BLE 12 sends the command function.
err_t ble12_wake_up_device(ble12_t *ctx)
BLE 12 wake up the device function.
err_t ble12_disconnect(ble12_t *ctx)
BLE 12 disconnect function.
err_t ble12_generic_write(ble12_t *ctx, char *data_buf, uint16_t len)
BLE 12 data writing function.
err_t ble12_set_led_state(ble12_t *ctx, uint8_t led, uint8_t state)
BLE 12 set LED state function.
BLE 12 Click configuration object.
Definition ble12.h:201
uint32_t baud_rate
Definition ble12.h:213
pin_name_t wkp
Definition ble12.h:208
bool uart_blocking
Definition ble12.h:214
pin_name_t cmd
Definition ble12.h:209
pin_name_t req
Definition ble12.h:210
uart_data_bits_t data_bit
Definition ble12.h:215
pin_name_t tx_pin
Definition ble12.h:204
pin_name_t rx_pin
Definition ble12.h:203
uart_stop_bits_t stop_bit
Definition ble12.h:217
uart_parity_t parity_bit
Definition ble12.h:216
pin_name_t rst
Definition ble12.h:207
BLE 12 Click context object.
Definition ble12.h:178
digital_out_t cmd
Definition ble12.h:182
uart_t uart
Definition ble12.h:188
digital_in_t req
Definition ble12.h:185
digital_out_t wkp
Definition ble12.h:181
digital_out_t rst
Definition ble12.h:180