ble3 2.0.0.0
ble3.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 BLE3_H
36#define BLE3_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
57// -------------------------------------------------------------- PUBLIC MACROS
67#define BLE3_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
69 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
70 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
71 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
79#define BLE3_RETVAL uint8_t
80
81#define BLE3_OK 0x00
82#define BLE3_INIT_ERROR 0xFF
89#define BLE3_PARSER_NO_ERROR 0x00
90#define BLE3_PARSER_ERROR_REF 0x01
91#define BLE3_PARSER_ERROR_CMD 0x02
92#define BLE3_PARSER_ERROR_DATA 0x04
99#define BLE3_STATUS_DEVICE_READY 1
100#define BLE3_STATUS_ACT_NETWORK_AND_BROKER 4
101#define BLE3_STATUS_ACT_NETWORK 2
102#define BLE3_STATUS_ACT_BROKER 3
103#define BLE3_STATUS_DEVICE_BUSY 0
110#define BLE3_MODULE_POWER_ON 1
111#define BLE3_MODULE_POWER_OFF 0
118#define BLE3_SINGLE_CMD_AT "AT"
119#define BLE3_SINGLE_CMD_AT_W "AT+W"
120#define BLE3_SINGLE_CMD_AT_R "AT+R"
121#define BLE3_SINGLE_CMD_ATE0 "ATE0"
122#define BLE3_SINGLE_CMD_ATE1 "ATE1"
123#define BLE3_SINGLE_CMD_AT_RST "AT+RST"
124#define BLE3_SINGLE_CMD_AT_CRST "AT+CRST"
125#define BLE3_SINGLE_CMD_AT_GMR "AT+GMR"
126#define BLE3_SINGLE_CMD_AT_GMSTA "AT+GMSTA"
127#define BLE3_SINGLE_CMD_AT_PUB "AT+PUB"
128
129#define BLE3_SINGLE_CMD_SET_AT_LRSP_1 "AT+LRSP=1"
130#define BLE3_SINGLE_CMD_SET_AT_LRSP_0 "AT+LRSP=0"
131#define BLE3_SINGLE_CMD_SET_AT_CEN_1 "AT+CEN=1"
132#define BLE3_SINGLE_CMD_SET_AT_CEN_0 "AT+CEN=0"
133#define BLE3_SINGLE_CMD_SET_AT_NWC_1 "AT+NWC=1"
134#define BLE3_SINGLE_CMD_SET_AT_NWC_0 "AT+NWC=0"
135#define BLE3_SINGLE_CMD_SET_AT_BRC_1 "AT+BRC=1"
136#define BLE3_SINGLE_CMD_SET_AT_BRC_0 "AT+BRC=0"
137#define BLE3_SINGLE_CMD_SET_AT_GPEN_0 "AT+GPEN=0"
138#define BLE3_SINGLE_CMD_SET_AT_GPEN_1 "AT+GPEN=1"
139
140#define BLE3_SINGLE_CMD_GET_AT_LRSP "AT+LRSP?"
141#define BLE3_SINGLE_CMD_GET_AT_CEN "AT+CEN?"
142#define BLE3_SINGLE_CMD_GET_AT_NWC "AT+NWC?"
143#define BLE3_SINGLE_CMD_GET_AT_BRC "AT+BRC?"
144#define BLE3_SINGLE_CMD_GET_AT_GPEN "AT+GPEN?"
145#define BLE3_SINGLE_CMD_GET_AT_NWCR "AT+NWCR?"
146#define BLE3_SINGLE_CMD_GET_AT_BRCR "AT+BRCR?"
147#define BLE3_SINGLE_CMD_GET_AT_DSET "AT+DSET?"
148
149#define BLE3_SINGLE_CMD_TEST_AT_LRSP "AT+LRSP=?"
150#define BLE3_SINGLE_CMD_TEST_AT_CEN "AT+CEN=?"
151#define BLE3_SINGLE_CMD_TEST_AT_NWC "AT+NWC=?"
152#define BLE3_SINGLE_CMD_TEST_AT_BRC "AT+BRC=?"
153#define BLE3_SINGLE_CMD_TEST_AT_GPEN "AT+GPEN=?"
154#define BLE3_SINGLE_CMD_TEST_AT_NWCR "AT+NWCR=?"
155#define BLE3_SINGLE_CMD_TEST_AT_BRCR "AT+BRCR=?"
156#define BLE3_SINGLE_CMD_TEST_AT_DSET "AT+DSET=?"
157
158#define BLE3_MULTI_CMD_AT_DSET "AT+DSET"
159#define BLE3_MULTI_CMD_AT_BRCR "AT+BRCR"
160#define BLE3_MULTI_CMD_AT_NWCR "AT+NWCR"
167#define DRV_RX_BUFFER_SIZE 100
168#define DRV_TX_BUFFER_SIZE 100
171 // End group macro
172// --------------------------------------------------------------- PUBLIC TYPES
180typedef struct
181{
182 // Output pins
183
184 digital_out_t rst;
185 digital_out_t rts;
186
187 // Input pins
188
189 digital_in_t cts;
190
191 // Modules
192
193 uart_t uart;
194
195 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
196 char uart_tx_buffer[ DRV_TX_BUFFER_SIZE ];
197
198} ble3_t;
199
203typedef struct
204{
205 // Communication gpio pins
206
207 pin_name_t rx_pin;
208 pin_name_t tx_pin;
209
210 // Additional gpio pins
211
212 pin_name_t rst;
213 pin_name_t cts;
214 pin_name_t rts;
215
216 // static variable
217
218 uint32_t baud_rate; // Clock speed.
220 uart_data_bits_t data_bit; // Data bits.
221 uart_parity_t parity_bit; // Parity bit.
222 uart_stop_bits_t stop_bit; // Stop bits.
223
224} ble3_cfg_t;
225
226 // End types group
227// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
228
234#ifdef __cplusplus
235extern "C"{
236#endif
237
247
257
264void ble3_generic_write ( ble3_t *ctx, char *data_buf, uint16_t len );
265
273int32_t ble3_generic_read ( ble3_t *ctx, char *data_buf, uint16_t max_len );
274
275
276#ifdef __cplusplus
277}
278#endif
279#endif // _BLE3_H_
280
281 // End public_function group
283
284// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition ble3.h:167
#define DRV_TX_BUFFER_SIZE
Definition ble3.h:168
#define BLE3_RETVAL
Definition ble3.h:79
int32_t ble3_generic_read(ble3_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
void ble3_generic_write(ble3_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void ble3_cfg_setup(ble3_cfg_t *cfg)
Config Object Initialization function.
BLE3_RETVAL ble3_init(ble3_t *ctx, ble3_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition ble3.h:204
pin_name_t rts
Definition ble3.h:214
uint32_t baud_rate
Definition ble3.h:218
pin_name_t cts
Definition ble3.h:213
bool uart_blocking
Definition ble3.h:219
uart_data_bits_t data_bit
Definition ble3.h:220
pin_name_t tx_pin
Definition ble3.h:208
pin_name_t rx_pin
Definition ble3.h:207
uart_stop_bits_t stop_bit
Definition ble3.h:222
uart_parity_t parity_bit
Definition ble3.h:221
pin_name_t rst
Definition ble3.h:212
Click ctx object definition.
Definition ble3.h:181
digital_out_t rts
Definition ble3.h:185
uart_t uart
Definition ble3.h:193
digital_in_t cts
Definition ble3.h:189
digital_out_t rst
Definition ble3.h:184