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
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 
69 #define BLE12_CMD_AT "AT"
70 #define BLE12_CMD_SW_RESET "AT+RESET"
71 #define BLE12_CMD_GET_VERSION "AT+VERSION?"
72 #define BLE12_CMD_GET_RSSI "AT+RSSI?"
73 #define BLE12_CMD_SET_ADINTERVAL "AT+ADINTERVAL="
74 #define BLE12_CMD_GET_ADINTERVAL "AT+ADINTERVAL=?"
75 #define BLE12_CMD_SET_ADSTART "AT+ADSTART="
76 #define BLE12_CMD_GET_ADSTART "AT+ADSTART?"
77 #define BLE12_CMD_SET_ADVMANU "AT+ADVMANU="
78 #define BLE12_CMD_GET_ADVMANU "AT+ADVMANU?"
79 #define BLE12_CMD_SET_ADVRESP "AT+ADVRESP="
80 #define BLE12_CMD_GET_ADVRESP "AT+ADVRESP?"
81 #define BLE12_CMD_SET_SCANNER "AT+SCANNER="
82 #define BLE12_CMD_GET_SCANNER "AT+SCANNER?"
83 #define BLE12_CMD_SET_AUTOCON "AT+AUTOCON="
84 #define BLE12_CMD_GET_AUTOCON "AT+AUTOCON?"
85 #define BLE12_CMD_SET_DISCON "AT+DISCON=1"
86 #define BLE12_CMD_SET_FILTERA "AT+FILTERA="
87 #define BLE12_CMD_GET_FILTERA "AT+FILTERA?"
88 #define BLE12_CMD_SET_FILTERR "AT+FILTERR="
89 #define BLE12_CMD_GET_FILTERR "AT+FILTERR?"
90 #define BLE12_CMD_SET_MANUAID "AT+MANUAID="
91 #define BLE12_CMD_GET_MANUAID "AT+MANUAID?"
92 #define BLE12_CMD_SET_MANURID "AT+MANURID="
93 #define BLE12_CMD_GET_MANURID "AT+MANURID?"
94 #define BLE12_CMD_SET_DCDC "AT+DCDC="
95 #define BLE12_CMD_GET_DCDC "AT+DCDC?"
96 #define BLE12_CMD_SET_SAVE "AT+SAVE=1"
97 #define BLE12_CMD_SET_STOP "AT+STOP="
98 #define BLE12_CMD_SET_NAME "AT+NAME="
99 #define BLE12_CMD_GET_UART "AT+UART?"
100 #define BLE12_CMD_SET_UART "AT+UART="
101 #define BLE12_CMD_GET_ADDR "AT+ADDR?"
102 #define BLE12_CMD_GET_RX "AT+RX?"
103 #define BLE12_CMD_SET_DEFAULT "AT+DEFAULT"
104 #define BLE12_CMD_GET_RFPW "AT+RFPW?"
105 #define BLE12_CMD_SET_RFPW "AT+RFPW="
106 #define BLE12_CMD_SET_GPIO "AT+PIO="
107 #define BLE12_CMD_GET_GPIO "AT+PIO?"
108 #define BLE12_CMD_SET_GPIO_IO "AT+PIS="
109 #define BLE12_CMD_INIT_LED1 "AT+PIS=017,1"
110 #define BLE12_CMD_INIT_LED2 "AT+PIS=019,1"
111 
116 #define BLE12_EVT_CONNECTED "CONNECTED"
117 #define BLE12_EVT_DISCONNECTED "DISCONNECTED"
118 #define BLE12_EVT_SCAN_TIMEOUT "SCAN TIMEOUT"
119 
124 #define BLE12_LED_YELLOW 0x00
125 #define BLE12_LED_RED 0x01
126 #define BLE12_LED_ON 0x00
127 #define BLE12_LED_OFF 0x01
128 #define BLE12_OP_MODE_CMD 0x00
129 #define BLE12_OP_MODE_DATA 0x01
130 #define BLE12_SELECT_LED_YELLOW "017,"
131 #define BLE12_SELECT_LED_RED "019,"
132 #define BLE12_SET_LED_STATE_ON "0"
133 #define BLE12_SET_LED_STATE_OFF "1"
134 
140 #define DRV_BUFFER_SIZE 200
141  // ble12_cmd
143 
158 #define BLE12_MAP_MIKROBUS( cfg, mikrobus ) \
159  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
160  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
161  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
162  cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_CS ); \
163  cfg.cmd = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
164  cfg.req = MIKROBUS( mikrobus, MIKROBUS_INT )
165  // ble12_map // ble12
168 
173 typedef struct
174 {
175  // Output pins
176  digital_out_t rst;
177  digital_out_t wkp;
178  digital_out_t cmd;
180  // Input pins
181  digital_in_t req;
183  // Modules
184  uart_t uart;
186  // Buffers
187  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
188  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
190 } ble12_t;
191 
196 typedef struct
197 {
198  // Communication gpio pins
199  pin_name_t rx_pin;
200  pin_name_t tx_pin;
202  // Additional gpio pins
203  pin_name_t rst;
204  pin_name_t wkp;
205  pin_name_t cmd;
206  pin_name_t req;
208  // Static variable
209  uint32_t baud_rate;
211  uart_data_bits_t data_bit;
212  uart_parity_t parity_bit;
213  uart_stop_bits_t stop_bit;
215 } ble12_cfg_t;
216 
221 typedef enum
222 {
223  BLE12_OK = 0,
224  BLE12_ERROR = -1
225 
227 
244 
259 err_t ble12_init ( ble12_t *ctx, ble12_cfg_t *cfg );
260 
274 err_t ble12_default_cfg ( ble12_t *ctx );
275 
289 err_t ble12_generic_write ( ble12_t *ctx, char *data_buf, uint16_t len );
290 
304 err_t ble12_generic_read ( ble12_t *ctx, char *data_buf, uint16_t max_len );
305 
317 
331 err_t ble12_send_cmd ( ble12_t *ctx, char *cmd );
332 
347 err_t ble12_send_data ( ble12_t *ctx, char *tx_data );
348 
362 err_t ble12_init_led ( ble12_t *ctx );
363 
383 err_t ble12_set_led_state ( ble12_t *ctx, uint8_t led, uint8_t state );
384 
398 err_t ble12_reset ( ble12_t *ctx );
399 
413 err_t ble12_get_version ( ble12_t *ctx );
414 
429 err_t ble12_set_device_name ( ble12_t *ctx, uint8_t *device_name );
430 
444 err_t ble12_save_config ( ble12_t *ctx );
445 
460 err_t ble12_set_adv_interval ( ble12_t *ctx, uint8_t *adv_interval );
461 
475 err_t ble12_disconnect ( ble12_t *ctx );
476 
490 err_t ble12_set_default ( ble12_t *ctx );
491 
506 err_t ble12_set_op_mode ( ble12_t *ctx, uint8_t op_mode );
507 
522 
523 #ifdef __cplusplus
524 }
525 #endif
526 #endif // BLE12_H
527  // ble12
529 
530 // ------------------------------------------------------------------------ END
ble12_reset
err_t ble12_reset(ble12_t *ctx)
BLE 12 reset function.
ble12_return_value_t
ble12_return_value_t
BLE 12 Click return value data.
Definition: ble12.h:222
ble12_init_led
err_t ble12_init_led(ble12_t *ctx)
BLE 12 LED initialization function.
ble12_cfg_t
BLE 12 Click configuration object.
Definition: ble12.h:197
ble12_t::uart
uart_t uart
Definition: ble12.h:184
ble12_generic_read
err_t ble12_generic_read(ble12_t *ctx, char *data_buf, uint16_t max_len)
BLE 12 data reading function.
ble12_get_version
err_t ble12_get_version(ble12_t *ctx)
BLE 12 get version function.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
BLE 12 driver buffer size.
Definition: ble12.h:140
ble12_default_cfg
err_t ble12_default_cfg(ble12_t *ctx)
BLE 12 default configuration function.
ble12_cfg_t::baud_rate
uint32_t baud_rate
Definition: ble12.h:209
ble12_cfg_t::uart_blocking
bool uart_blocking
Definition: ble12.h:210
ble12_init
err_t ble12_init(ble12_t *ctx, ble12_cfg_t *cfg)
BLE 12 initialization function.
ble12_cfg_t::tx_pin
pin_name_t tx_pin
Definition: ble12.h:200
ble12_t::wkp
digital_out_t wkp
Definition: ble12.h:177
BLE12_ERROR
@ BLE12_ERROR
Definition: ble12.h:224
ble12_set_led_state
err_t ble12_set_led_state(ble12_t *ctx, uint8_t led, uint8_t state)
BLE 12 set LED state function.
ble12_cfg_t::rst
pin_name_t rst
Definition: ble12.h:203
ble12_set_device_name
err_t ble12_set_device_name(ble12_t *ctx, uint8_t *device_name)
BLE 12 set device name function.
ble12_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: ble12.h:211
ble12_cfg_t::wkp
pin_name_t wkp
Definition: ble12.h:204
ble12_t::cmd
digital_out_t cmd
Definition: ble12.h:178
ble12_send_data
err_t ble12_send_data(ble12_t *ctx, char *tx_data)
BLE 12 send data function.
ble12_set_default
err_t ble12_set_default(ble12_t *ctx)
BLE 12 set default function.
ble12_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: ble12.h:212
ble12_set_op_mode
err_t ble12_set_op_mode(ble12_t *ctx, uint8_t op_mode)
BLE 12 set operating mode function.
ble12_t::req
digital_in_t req
Definition: ble12.h:181
ble12_wake_up_device
err_t ble12_wake_up_device(ble12_t *ctx)
BLE 12 wake up the device function.
ble12_cfg_setup
void ble12_cfg_setup(ble12_cfg_t *cfg)
BLE 12 configuration object setup function.
BLE12_OK
@ BLE12_OK
Definition: ble12.h:223
ble12_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ble12.h:199
ble12_send_cmd
err_t ble12_send_cmd(ble12_t *ctx, char *cmd)
BLE 12 sends the command function.
ble12_t::rst
digital_out_t rst
Definition: ble12.h:176
ble12_set_adv_interval
err_t ble12_set_adv_interval(ble12_t *ctx, uint8_t *adv_interval)
BLE 12 set adv interval function.
ble12_cfg_t::req
pin_name_t req
Definition: ble12.h:206
ble12_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ble12.h:213
ble12_event_startup
err_t ble12_event_startup(ble12_t *ctx)
BLE 12 event start-up function.
ble12_t
BLE 12 Click context object.
Definition: ble12.h:174
ble12_disconnect
err_t ble12_disconnect(ble12_t *ctx)
BLE 12 disconnect function.
ble12_cfg_t::cmd
pin_name_t cmd
Definition: ble12.h:205
ble12_generic_write
err_t ble12_generic_write(ble12_t *ctx, char *data_buf, uint16_t len)
BLE 12 data writing function.
ble12_save_config
err_t ble12_save_config(ble12_t *ctx)
BLE 12 save config function.