bluetooth2 2.0.0.0
bluetooth2.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 BLUETOOTH2_H
29#define BLUETOOTH2_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 BLUETOOTH2_ESCAPE_SEQUENCE "+++"
75#define BLUETOOTH2_FACTORY_RESET "SET RESET"
76#define BLUETOOTH2_LIST_PAIRINGS "SET BT PAIR"
77#define BLUETOOTH2_REMOVE_PAIRINGS "SET BT PAIR *"
78#define BLUETOOTH2_SW_RESET "RESET"
79#define BLUETOOTH2_SET_DEVICE_NAME "SET BT NAME "
80#define BLUETOOTH2_FIND_OTHER_DEVICES "INQUIRY "
81#define BLUETOOTH2_PAIR "PAIR "
82#define BLUETOOTH2_SET_CONTROL_CONFIG "SET CONTROL CONFIG "
83#define BLUETOOTH2_ENABLE_OK_WITH_DEFAULT_VALUES "0040 1100"
84#define BLUETOOTH2_DEV_ADDRESS_FORMAT "xx:xx:xx:xx:xx:xx"
85
91#define DRV_BUFFER_SIZE 200
92
93 // bluetooth2_set
94
109#define BLUETOOTH2_MAP_MIKROBUS( cfg, mikrobus ) \
110 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
111 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
112 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
113 cfg.aio = MIKROBUS( mikrobus, MIKROBUS_AN ); \
114 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
115 cfg.io7 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
116 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
117
118 // bluetooth2_map
119 // bluetooth2
124typedef struct bluetooth2_s
125{
126 digital_out_t rst;
127 digital_out_t io7;
128 digital_out_t cts;
129 digital_in_t rts;
131 uart_t uart;
132 analog_in_t adc;
138
143typedef struct
144{
145 pin_name_t rx_pin;
146 pin_name_t tx_pin;
147 pin_name_t cts;
148 pin_name_t aio;
149 pin_name_t rst;
150 pin_name_t io7;
151 pin_name_t rts;
153 analog_in_resolution_t resolution;
154 float vref;
156 uint32_t baud_rate;
158 uart_data_bits_t data_bit;
159 uart_parity_t parity_bit;
160 uart_stop_bits_t stop_bit;
163
174
191
207
219
233err_t bluetooth2_generic_write ( bluetooth2_t *ctx, char *data_buf, uint16_t len );
234
248err_t bluetooth2_generic_read ( bluetooth2_t *ctx, char *data_buf, uint16_t max_len );
249
262err_t bluetooth2_read_an_pin_value ( bluetooth2_t *ctx, uint16_t *data_out );
263
278err_t bluetooth2_read_an_pin_voltage ( bluetooth2_t *ctx, float *data_out );
279
289void bluetooth2_set_cts_pin ( bluetooth2_t *ctx, uint8_t state );
290
300void bluetooth2_set_rst_pin ( bluetooth2_t *ctx, uint8_t state );
301
311void bluetooth2_set_io7_pin ( bluetooth2_t *ctx, uint8_t state );
312
322
335err_t bluetooth2_write_command ( bluetooth2_t *ctx, char *data_buf );
336
346
360
373
386
399
412
425err_t bluetooth2_set_device_name ( bluetooth2_t *ctx, char *dev_name );
426
441err_t bluetooth2_find_other_devices ( bluetooth2_t *ctx, uint8_t timeout );
442
456err_t bluetooth2_pair ( bluetooth2_t *ctx, uint8_t *dev_addr );
457
471
472#ifdef __cplusplus
473}
474#endif
475#endif // BLUETOOTH2_H
476
477 // bluetooth2
478
479// ------------------------------------------------------------------------ END
bluetooth2_return_value_t
Bluetooth2 Click return value data.
Definition bluetooth2.h:169
@ BLUETOOTH2_ERROR
Definition bluetooth2.h:171
@ BLUETOOTH2_OK
Definition bluetooth2.h:170
struct bluetooth2_s bluetooth2_t
Bluetooth2 Click context object.
#define DRV_BUFFER_SIZE
Bluetooth2 driver buffer size.
Definition bluetooth2.h:91
err_t bluetooth2_find_other_devices(bluetooth2_t *ctx, uint8_t timeout)
Bluetooth2 find other devices function.
err_t bluetooth2_set_device_name(bluetooth2_t *ctx, char *dev_name)
Bluetooth2 set local device name function.
void bluetooth2_default_cfg(bluetooth2_t *ctx)
Bluetooth2 default configuration function.
err_t bluetooth2_remove_pairings(bluetooth2_t *ctx)
Bluetooth2 remove pairings function.
err_t bluetooth2_generic_read(bluetooth2_t *ctx, char *data_buf, uint16_t max_len)
Bluetooth2 data reading function.
err_t bluetooth2_sw_reset(bluetooth2_t *ctx)
Bluetooth2 sw reset function.
err_t bluetooth2_factory_reset(bluetooth2_t *ctx)
Bluetooth2 factory reset function.
err_t bluetooth2_init(bluetooth2_t *ctx, bluetooth2_cfg_t *cfg)
Bluetooth2 initialization function.
void bluetooth2_set_io7_pin(bluetooth2_t *ctx, uint8_t state)
Bluetooth2 set PIO7 pin function.
void bluetooth2_hw_reset(bluetooth2_t *ctx)
Bluetooth2 hw reset function.
void bluetooth2_set_rst_pin(bluetooth2_t *ctx, uint8_t state)
Bluetooth2 set reset pin function.
void bluetooth2_set_cts_pin(bluetooth2_t *ctx, uint8_t state)
Bluetooth2 set clear to send pin function.
err_t bluetooth2_generic_write(bluetooth2_t *ctx, char *data_buf, uint16_t len)
Bluetooth2 data writing function.
err_t bluetooth2_toggle_mode(bluetooth2_t *ctx)
Bluetooth2 toggle mode function.
err_t bluetooth2_pair(bluetooth2_t *ctx, uint8_t *dev_addr)
Bluetooth2 set local device name function.
err_t bluetooth2_write_command(bluetooth2_t *ctx, char *data_buf)
Bluetooth2 write command function.
err_t bluetooth2_list_pairings(bluetooth2_t *ctx)
Bluetooth2 list current pairings function.
err_t bluetooth2_read_an_pin_value(bluetooth2_t *ctx, uint16_t *data_out)
Bluetooth2 read AN pin value function.
void bluetooth2_cfg_setup(bluetooth2_cfg_t *cfg)
Bluetooth2 configuration object setup function.
uint8_t bluetooth2_get_rts_pin(bluetooth2_t *ctx)
Bluetooth2 get request to send pin function.
err_t bluetooth2_read_an_pin_voltage(bluetooth2_t *ctx, float *data_out)
Bluetooth2 read AN pin voltage level function.
err_t bluetooth2_enable_ok_response(bluetooth2_t *ctx)
Bluetooth2 enable OK response function.
Bluetooth2 Click configuration object.
Definition bluetooth2.h:144
pin_name_t rts
Definition bluetooth2.h:151
uint32_t baud_rate
Definition bluetooth2.h:156
pin_name_t aio
Definition bluetooth2.h:148
analog_in_resolution_t resolution
Definition bluetooth2.h:153
float vref
Definition bluetooth2.h:154
pin_name_t cts
Definition bluetooth2.h:147
pin_name_t io7
Definition bluetooth2.h:150
bool uart_blocking
Definition bluetooth2.h:157
uart_data_bits_t data_bit
Definition bluetooth2.h:158
pin_name_t tx_pin
Definition bluetooth2.h:146
pin_name_t rx_pin
Definition bluetooth2.h:145
uart_stop_bits_t stop_bit
Definition bluetooth2.h:160
uart_parity_t parity_bit
Definition bluetooth2.h:159
pin_name_t rst
Definition bluetooth2.h:149
Bluetooth2 Click context object.
Definition bluetooth2.h:125
char uart_tx_buffer[DRV_BUFFER_SIZE]
Definition bluetooth2.h:135
uart_t uart
Definition bluetooth2.h:131
digital_in_t rts
Definition bluetooth2.h:129
digital_out_t rst
Definition bluetooth2.h:126
digital_out_t cts
Definition bluetooth2.h:128
char uart_rx_buffer[DRV_BUFFER_SIZE]
Definition bluetooth2.h:134
digital_out_t io7
Definition bluetooth2.h:127
analog_in_t adc
Definition bluetooth2.h:132