ble10 2.0.0.0
ble10.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 BLE10_H
29#define BLE10_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_analog_in.h"
52#include "drv_uart.h"
53
74#define BLE10_CMD_AT "AT" // Attention
75#define BLE10_CMD_ATRST "ATRST" // Software Reset
76#define BLE10_CMD_ATFRST "ATFRST" // Factory Reset
77#define BLE10_CMD_ATSN "ATSN" // Set Device Name
78#define BLE10_CMD_ATP "ATP" // List Pairings
79#define BLE10_CMD_ATCP "ATCP" // Clear Pairings
80#define BLE10_CMD_ATDI "ATDI" // Discover Nearby Devices
81#define BLE10_CMD_ATT "ATT" // Get temperature
82
88#define DRV_BUFFER_SIZE 500
89
90 // ble10_cmd
91
106#define BLE10_MAP_MIKROBUS( cfg, mikrobus ) \
107 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
108 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
109 cfg.ain = MIKROBUS( mikrobus, MIKROBUS_AN ); \
110 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
111 cfg.pio3 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
112 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT ); \
113 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS );
114
115 // ble10_map
116 // ble10
117
122typedef struct
123{
124 // Output pins
125 digital_out_t rst;
126 digital_out_t cts;
128 // Input pins
129 digital_in_t rts;
130 digital_in_t pio3;
132 // Modules
133 uart_t uart;
134 analog_in_t adc;
136 // Buffers
137 char uart_rx_buffer[ DRV_BUFFER_SIZE ];
138 char uart_tx_buffer[ DRV_BUFFER_SIZE ];
140} ble10_t;
141
146typedef struct
147{
148 // Communication gpio pins
149 pin_name_t rx_pin;
150 pin_name_t tx_pin;
151 pin_name_t ain;
153 // Additional gpio pins
154 pin_name_t rst;
155 pin_name_t cts;
156 pin_name_t rts;
157 pin_name_t pio3;
159 // Static variable
160 uint32_t baud_rate;
162 uart_data_bits_t data_bit;
163 uart_parity_t parity_bit;
164 uart_stop_bits_t stop_bit;
166 analog_in_resolution_t resolution;
167 float vref;
170
175typedef enum
176{
178 BLE10_ERROR = -1
179
181
198
213err_t ble10_init ( ble10_t *ctx, ble10_cfg_t *cfg );
214
226
240err_t ble10_generic_write ( ble10_t *ctx, char *data_buf, uint16_t len );
241
255err_t ble10_generic_read ( ble10_t *ctx, char *data_buf, uint16_t max_len );
256
265uint8_t ble10_get_rts_pin ( ble10_t *ctx );
266
276
286void ble10_set_cts_pin ( ble10_t *ctx, uint8_t state );
287
297void ble10_set_rst_pin ( ble10_t *ctx, uint8_t state );
298
308
320err_t ble10_sw_reset ( ble10_t *ctx );
321
334
347err_t ble10_send_cmd ( ble10_t *ctx, char *at_cmd_buf );
348
362err_t ble10_send_cmd_with_parameter ( ble10_t *ctx, char *at_cmd_buf, char *param_buf );
363
376err_t ble10_send_cmd_check ( ble10_t *ctx, char *at_cmd_buf );
377
390
403
416err_t ble10_set_device_name ( ble10_t *ctx, char *dev_name );
417
430
444
457err_t ble10_read_an_pin_value ( ble10_t *ctx, uint16_t *data_out );
458
473err_t ble10_read_an_pin_voltage ( ble10_t *ctx, float *data_out );
474
475#ifdef __cplusplus
476}
477#endif
478#endif // BLE10_H
479
480 // ble10
481
482// ------------------------------------------------------------------------ END
ble10_return_value_t
BLE 10 Click return value data.
Definition ble10.h:176
@ BLE10_ERROR
Definition ble10.h:178
@ BLE10_OK
Definition ble10.h:177
#define DRV_BUFFER_SIZE
BLE 10 driver buffer size.
Definition ble10.h:88
err_t ble10_get_temperature(ble10_t *ctx)
BLE 10 get temperature function.
err_t ble10_generic_write(ble10_t *ctx, char *data_buf, uint16_t len)
BLE 10 data writing function.
err_t ble10_discover_nearby_devices(ble10_t *ctx)
BLE 10 discover nearby devices function.
void ble10_cfg_setup(ble10_cfg_t *cfg)
BLE 10 configuration object setup function.
err_t ble10_send_cmd_with_parameter(ble10_t *ctx, char *at_cmd_buf, char *param_buf)
BLE 10 send command with parameter function.
err_t ble10_remove_pairings(ble10_t *ctx)
BLE 10 remove pairings function.
err_t ble10_set_device_name(ble10_t *ctx, char *dev_name)
BLE 10 set local device name function.
void ble10_set_rst_pin(ble10_t *ctx, uint8_t state)
BLE 10 set reset pin function.
void ble10_hw_reset(ble10_t *ctx)
BLE 10 hw reset function.
void ble10_set_cts_pin(ble10_t *ctx, uint8_t state)
BLE 10 set clear to send pin function.
err_t ble10_send_cmd_check(ble10_t *ctx, char *at_cmd_buf)
BLE 10 send command check function.
err_t ble10_sw_reset(ble10_t *ctx)
BLE 10 software reset function.
void ble10_default_cfg(ble10_t *ctx)
BLE 10 default configuration function.
uint8_t ble10_get_pio3_pin(ble10_t *ctx)
BLE 10 get PIO3 pin function.
err_t ble10_generic_read(ble10_t *ctx, char *data_buf, uint16_t max_len)
BLE 10 data reading function.
err_t ble10_read_an_pin_voltage(ble10_t *ctx, float *data_out)
BLE 10 read AIN pin voltage level function.
err_t ble10_send_cmd(ble10_t *ctx, char *at_cmd_buf)
BLE 10 send command function.
err_t ble10_factory_reset(ble10_t *ctx)
BLE 10 factory reset function.
err_t ble10_list_pairings(ble10_t *ctx)
BLE 10 list current pairings function.
uint8_t ble10_get_rts_pin(ble10_t *ctx)
BLE 10 get ready to send pin function.
err_t ble10_read_an_pin_value(ble10_t *ctx, uint16_t *data_out)
BLE 10 read AIN pin value function.
err_t ble10_init(ble10_t *ctx, ble10_cfg_t *cfg)
BLE 10 initialization function.
BLE 10 Click configuration object.
Definition ble10.h:147
pin_name_t rts
Definition ble10.h:156
uint32_t baud_rate
Definition ble10.h:160
analog_in_resolution_t resolution
Definition ble10.h:166
float vref
Definition ble10.h:167
pin_name_t cts
Definition ble10.h:155
pin_name_t ain
Definition ble10.h:151
bool uart_blocking
Definition ble10.h:161
pin_name_t pio3
Definition ble10.h:157
uart_data_bits_t data_bit
Definition ble10.h:162
pin_name_t tx_pin
Definition ble10.h:150
pin_name_t rx_pin
Definition ble10.h:149
uart_stop_bits_t stop_bit
Definition ble10.h:164
uart_parity_t parity_bit
Definition ble10.h:163
pin_name_t rst
Definition ble10.h:154
BLE 10 Click context object.
Definition ble10.h:123
digital_in_t pio3
Definition ble10.h:130
uart_t uart
Definition ble10.h:133
digital_in_t rts
Definition ble10.h:129
digital_out_t rst
Definition ble10.h:125
digital_out_t cts
Definition ble10.h:126
analog_in_t adc
Definition ble10.h:134