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 "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_uart.h"
38 
59 #define BLE12_CMD_AT "AT"
60 #define BLE12_CMD_SW_RESET "AT+RESET"
61 #define BLE12_CMD_GET_VERSION "AT+VERSION?"
62 #define BLE12_CMD_GET_RSSI "AT+RSSI?"
63 #define BLE12_CMD_SET_ADINTERVAL "AT+ADINTERVAL="
64 #define BLE12_CMD_GET_ADINTERVAL "AT+ADINTERVAL=?"
65 #define BLE12_CMD_SET_ADSTART "AT+ADSTART="
66 #define BLE12_CMD_GET_ADSTART "AT+ADSTART?"
67 #define BLE12_CMD_SET_ADVMANU "AT+ADVMANU="
68 #define BLE12_CMD_GET_ADVMANU "AT+ADVMANU?"
69 #define BLE12_CMD_SET_ADVRESP "AT+ADVRESP="
70 #define BLE12_CMD_GET_ADVRESP "AT+ADVRESP?"
71 #define BLE12_CMD_SET_SCANNER "AT+SCANNER="
72 #define BLE12_CMD_GET_SCANNER "AT+SCANNER?"
73 #define BLE12_CMD_SET_AUTOCON "AT+AUTOCON="
74 #define BLE12_CMD_GET_AUTOCON "AT+AUTOCON?"
75 #define BLE12_CMD_SET_DISCON "AT+DISCON=1"
76 #define BLE12_CMD_SET_FILTERA "AT+FILTERA="
77 #define BLE12_CMD_GET_FILTERA "AT+FILTERA?"
78 #define BLE12_CMD_SET_FILTERR "AT+FILTERR="
79 #define BLE12_CMD_GET_FILTERR "AT+FILTERR?"
80 #define BLE12_CMD_SET_MANUAID "AT+MANUAID="
81 #define BLE12_CMD_GET_MANUAID "AT+MANUAID?"
82 #define BLE12_CMD_SET_MANURID "AT+MANURID="
83 #define BLE12_CMD_GET_MANURID "AT+MANURID?"
84 #define BLE12_CMD_SET_DCDC "AT+DCDC="
85 #define BLE12_CMD_GET_DCDC "AT+DCDC?"
86 #define BLE12_CMD_SET_SAVE "AT+SAVE=1"
87 #define BLE12_CMD_SET_STOP "AT+STOP="
88 #define BLE12_CMD_SET_NAME "AT+NAME="
89 #define BLE12_CMD_GET_UART "AT+UART?"
90 #define BLE12_CMD_SET_UART "AT+UART="
91 #define BLE12_CMD_GET_ADDR "AT+ADDR?"
92 #define BLE12_CMD_GET_RX "AT+RX?"
93 #define BLE12_CMD_SET_DEFAULT "AT+DEFAULT"
94 #define BLE12_CMD_GET_RFPW "AT+RFPW?"
95 #define BLE12_CMD_SET_RFPW "AT+RFPW="
96 #define BLE12_CMD_SET_GPIO "AT+PIO="
97 #define BLE12_CMD_GET_GPIO "AT+PIO?"
98 #define BLE12_CMD_SET_GPIO_IO "AT+PIS="
99 #define BLE12_CMD_INIT_LED1 "AT+PIS=017,1"
100 #define BLE12_CMD_INIT_LED2 "AT+PIS=019,1"
101 
106 #define BLE12_EVT_CONNECTED "CONNECTED"
107 #define BLE12_EVT_DISCONNECTED "DISCONNECTED"
108 #define BLE12_EVT_SCAN_TIMEOUT "SCAN TIMEOUT"
109 
114 #define BLE12_LED_YELLOW 0x00
115 #define BLE12_LED_RED 0x01
116 #define BLE12_LED_ON 0x00
117 #define BLE12_LED_OFF 0x01
118 #define BLE12_OP_MODE_CMD 0x00
119 #define BLE12_OP_MODE_DATA 0x01
120 #define BLE12_SELECT_LED_YELLOW "017,"
121 #define BLE12_SELECT_LED_RED "019,"
122 #define BLE12_SET_LED_STATE_ON "0"
123 #define BLE12_SET_LED_STATE_OFF "1"
124 
130 #define DRV_BUFFER_SIZE 200
131  // ble12_cmd
133 
148 #define BLE12_MAP_MIKROBUS( cfg, mikrobus ) \
149  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
150  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
151  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
152  cfg.wkp = MIKROBUS( mikrobus, MIKROBUS_CS ); \
153  cfg.cmd = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
154  cfg.req = MIKROBUS( mikrobus, MIKROBUS_INT )
155  // ble12_map // ble12
158 
163 typedef struct
164 {
165  // Output pins
166  digital_out_t rst;
167  digital_out_t wkp;
168  digital_out_t cmd;
170  // Input pins
171  digital_in_t req;
173  // Modules
174  uart_t uart;
176  // Buffers
177  char uart_rx_buffer[ DRV_BUFFER_SIZE ];
178  char uart_tx_buffer[ DRV_BUFFER_SIZE ];
180 } ble12_t;
181 
186 typedef struct
187 {
188  // Communication gpio pins
189  pin_name_t rx_pin;
190  pin_name_t tx_pin;
192  // Additional gpio pins
193  pin_name_t rst;
194  pin_name_t wkp;
195  pin_name_t cmd;
196  pin_name_t req;
198  // Static variable
199  uint32_t baud_rate;
201  uart_data_bits_t data_bit;
202  uart_parity_t parity_bit;
203  uart_stop_bits_t stop_bit;
205 } ble12_cfg_t;
206 
211 typedef enum
212 {
213  BLE12_OK = 0,
214  BLE12_ERROR = -1
215 
217 
234 
249 err_t ble12_init ( ble12_t *ctx, ble12_cfg_t *cfg );
250 
264 err_t ble12_default_cfg ( ble12_t *ctx );
265 
279 err_t ble12_generic_write ( ble12_t *ctx, char *data_buf, uint16_t len );
280 
294 err_t ble12_generic_read ( ble12_t *ctx, char *data_buf, uint16_t max_len );
295 
307 
321 err_t ble12_send_cmd ( ble12_t *ctx, char *cmd );
322 
337 err_t ble12_send_data ( ble12_t *ctx, char *tx_data );
338 
352 err_t ble12_init_led ( ble12_t *ctx );
353 
373 err_t ble12_set_led_state ( ble12_t *ctx, uint8_t led, uint8_t state );
374 
388 err_t ble12_reset ( ble12_t *ctx );
389 
403 err_t ble12_get_version ( ble12_t *ctx );
404 
419 err_t ble12_set_device_name ( ble12_t *ctx, uint8_t *device_name );
420 
434 err_t ble12_save_config ( ble12_t *ctx );
435 
450 err_t ble12_set_adv_interval ( ble12_t *ctx, uint8_t *adv_interval );
451 
465 err_t ble12_disconnect ( ble12_t *ctx );
466 
480 err_t ble12_set_default ( ble12_t *ctx );
481 
495 err_t ble12_set_op_mode ( ble12_t *ctx, uint8_t op_mode );
496 
511 
512 #ifdef __cplusplus
513 }
514 #endif
515 #endif // BLE12_H
516  // ble12
518 
519 // ------------------------------------------------------------------------ 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:212
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:187
ble12_t::uart
uart_t uart
Definition: ble12.h:174
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:130
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:199
ble12_cfg_t::uart_blocking
bool uart_blocking
Definition: ble12.h:200
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:190
ble12_t::wkp
digital_out_t wkp
Definition: ble12.h:167
BLE12_ERROR
@ BLE12_ERROR
Definition: ble12.h:214
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:193
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:201
ble12_cfg_t::wkp
pin_name_t wkp
Definition: ble12.h:194
ble12_t::cmd
digital_out_t cmd
Definition: ble12.h:168
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:202
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:171
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:213
ble12_cfg_t::rx_pin
pin_name_t rx_pin
Definition: ble12.h:189
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:166
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:196
ble12_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: ble12.h:203
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:164
ble12_disconnect
err_t ble12_disconnect(ble12_t *ctx)
BLE 12 disconnect function.
ble12_cfg_t::cmd
pin_name_t cmd
Definition: ble12.h:195
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.