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
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_analog_in.h"
48 #include "drv_uart.h"
49 
70 #define BLUETOOTH2_ESCAPE_SEQUENCE "+++"
71 #define BLUETOOTH2_FACTORY_RESET "SET RESET"
72 #define BLUETOOTH2_LIST_PAIRINGS "SET BT PAIR"
73 #define BLUETOOTH2_REMOVE_PAIRINGS "SET BT PAIR *"
74 #define BLUETOOTH2_SW_RESET "RESET"
75 #define BLUETOOTH2_SET_DEVICE_NAME "SET BT NAME "
76 #define BLUETOOTH2_FIND_OTHER_DEVICES "INQUIRY "
77 #define BLUETOOTH2_PAIR "PAIR "
78 #define BLUETOOTH2_SET_CONTROL_CONFIG "SET CONTROL CONFIG "
79 #define BLUETOOTH2_ENABLE_OK_WITH_DEFAULT_VALUES "0040 1100"
80 #define BLUETOOTH2_DEV_ADDRESS_FORMAT "xx:xx:xx:xx:xx:xx"
81 
87 #define DRV_BUFFER_SIZE 200
88  // bluetooth2_set
90 
105 #define BLUETOOTH2_MAP_MIKROBUS( cfg, mikrobus ) \
106  cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
107  cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
108  cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
109  cfg.aio = MIKROBUS( mikrobus, MIKROBUS_AN ); \
110  cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
111  cfg.io7 = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
112  cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT )
113  // bluetooth2_map // bluetooth2
120 typedef struct bluetooth2_s
121 {
122  digital_out_t rst;
123  digital_out_t io7;
124  digital_out_t cts;
125  digital_in_t rts;
127  uart_t uart;
128  analog_in_t adc;
134 
139 typedef struct
140 {
141  pin_name_t rx_pin;
142  pin_name_t tx_pin;
143  pin_name_t cts;
144  pin_name_t aio;
145  pin_name_t rst;
146  pin_name_t io7;
147  pin_name_t rts;
149  analog_in_resolution_t resolution;
150  float vref;
152  uint32_t baud_rate;
154  uart_data_bits_t data_bit;
155  uart_parity_t parity_bit;
156  uart_stop_bits_t stop_bit;
159 
164 typedef enum
165 {
167  BLUETOOTH2_ERROR = -1
168 
170 
187 
203 
215 
229 err_t bluetooth2_generic_write ( bluetooth2_t *ctx, char *data_buf, uint16_t len );
230 
244 err_t bluetooth2_generic_read ( bluetooth2_t *ctx, char *data_buf, uint16_t max_len );
245 
258 err_t bluetooth2_read_an_pin_value ( bluetooth2_t *ctx, uint16_t *data_out );
259 
274 err_t bluetooth2_read_an_pin_voltage ( bluetooth2_t *ctx, float *data_out );
275 
285 void bluetooth2_set_cts_pin ( bluetooth2_t *ctx, uint8_t state );
286 
296 void bluetooth2_set_rst_pin ( bluetooth2_t *ctx, uint8_t state );
297 
307 void bluetooth2_set_io7_pin ( bluetooth2_t *ctx, uint8_t state );
308 
318 
331 err_t bluetooth2_write_command ( bluetooth2_t *ctx, char *data_buf );
332 
342 
356 
369 
382 
395 
408 
421 err_t bluetooth2_set_device_name ( bluetooth2_t *ctx, char *dev_name );
422 
437 err_t bluetooth2_find_other_devices ( bluetooth2_t *ctx, uint8_t timeout );
438 
452 err_t bluetooth2_pair ( bluetooth2_t *ctx, uint8_t *dev_addr );
453 
467 
468 #ifdef __cplusplus
469 }
470 #endif
471 #endif // BLUETOOTH2_H
472  // bluetooth2
474 
475 // ------------------------------------------------------------------------ END
bluetooth2_enable_ok_response
err_t bluetooth2_enable_ok_response(bluetooth2_t *ctx)
Bluetooth2 enable OK response function.
bluetooth2_write_command
err_t bluetooth2_write_command(bluetooth2_t *ctx, char *data_buf)
Bluetooth2 write command function.
bluetooth2_s::uart
uart_t uart
Definition: bluetooth2.h:127
bluetooth2_cfg_t::resolution
analog_in_resolution_t resolution
Definition: bluetooth2.h:149
bluetooth2_cfg_t::aio
pin_name_t aio
Definition: bluetooth2.h:144
bluetooth2_cfg_t::uart_blocking
bool uart_blocking
Definition: bluetooth2.h:153
bluetooth2_cfg_t::baud_rate
uint32_t baud_rate
Definition: bluetooth2.h:152
bluetooth2_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: bluetooth2.h:155
BLUETOOTH2_OK
@ BLUETOOTH2_OK
Definition: bluetooth2.h:166
bluetooth2_list_pairings
err_t bluetooth2_list_pairings(bluetooth2_t *ctx)
Bluetooth2 list current pairings function.
bluetooth2_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: bluetooth2.h:156
bluetooth2_s
Bluetooth2 Click context object.
Definition: bluetooth2.h:121
bluetooth2_s::cts
digital_out_t cts
Definition: bluetooth2.h:124
bluetooth2_cfg_t::rx_pin
pin_name_t rx_pin
Definition: bluetooth2.h:141
bluetooth2_s::uart_tx_buffer
char uart_tx_buffer[DRV_BUFFER_SIZE]
Definition: bluetooth2.h:131
bluetooth2_read_an_pin_voltage
err_t bluetooth2_read_an_pin_voltage(bluetooth2_t *ctx, float *data_out)
Bluetooth2 read AN pin voltage level function.
DRV_BUFFER_SIZE
#define DRV_BUFFER_SIZE
Bluetooth2 driver buffer size.
Definition: bluetooth2.h:87
bluetooth2_cfg_t::cts
pin_name_t cts
Definition: bluetooth2.h:143
bluetooth2_init
err_t bluetooth2_init(bluetooth2_t *ctx, bluetooth2_cfg_t *cfg)
Bluetooth2 initialization function.
bluetooth2_sw_reset
err_t bluetooth2_sw_reset(bluetooth2_t *ctx)
Bluetooth2 sw reset function.
bluetooth2_get_rts_pin
uint8_t bluetooth2_get_rts_pin(bluetooth2_t *ctx)
Bluetooth2 get request to send pin function.
bluetooth2_cfg_t::rts
pin_name_t rts
Definition: bluetooth2.h:147
bluetooth2_factory_reset
err_t bluetooth2_factory_reset(bluetooth2_t *ctx)
Bluetooth2 factory reset function.
bluetooth2_cfg_t::tx_pin
pin_name_t tx_pin
Definition: bluetooth2.h:142
bluetooth2_cfg_setup
void bluetooth2_cfg_setup(bluetooth2_cfg_t *cfg)
Bluetooth2 configuration object setup function.
bluetooth2_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: bluetooth2.h:154
bluetooth2_set_cts_pin
void bluetooth2_set_cts_pin(bluetooth2_t *ctx, uint8_t state)
Bluetooth2 set clear to send pin function.
bluetooth2_remove_pairings
err_t bluetooth2_remove_pairings(bluetooth2_t *ctx)
Bluetooth2 remove pairings function.
bluetooth2_set_io7_pin
void bluetooth2_set_io7_pin(bluetooth2_t *ctx, uint8_t state)
Bluetooth2 set PIO7 pin function.
bluetooth2_find_other_devices
err_t bluetooth2_find_other_devices(bluetooth2_t *ctx, uint8_t timeout)
Bluetooth2 find other devices function.
bluetooth2_s::adc
analog_in_t adc
Definition: bluetooth2.h:128
bluetooth2_hw_reset
void bluetooth2_hw_reset(bluetooth2_t *ctx)
Bluetooth2 hw reset function.
bluetooth2_s::uart_rx_buffer
char uart_rx_buffer[DRV_BUFFER_SIZE]
Definition: bluetooth2.h:130
bluetooth2_cfg_t::io7
pin_name_t io7
Definition: bluetooth2.h:146
bluetooth2_t
struct bluetooth2_s bluetooth2_t
Bluetooth2 Click context object.
BLUETOOTH2_ERROR
@ BLUETOOTH2_ERROR
Definition: bluetooth2.h:167
bluetooth2_s::io7
digital_out_t io7
Definition: bluetooth2.h:123
bluetooth2_cfg_t::rst
pin_name_t rst
Definition: bluetooth2.h:145
bluetooth2_cfg_t
Bluetooth2 Click configuration object.
Definition: bluetooth2.h:140
bluetooth2_return_value_t
bluetooth2_return_value_t
Bluetooth2 Click return value data.
Definition: bluetooth2.h:165
bluetooth2_toggle_mode
err_t bluetooth2_toggle_mode(bluetooth2_t *ctx)
Bluetooth2 toggle mode function.
bluetooth2_s::rts
digital_in_t rts
Definition: bluetooth2.h:125
bluetooth2_cfg_t::vref
float vref
Definition: bluetooth2.h:150
bluetooth2_read_an_pin_value
err_t bluetooth2_read_an_pin_value(bluetooth2_t *ctx, uint16_t *data_out)
Bluetooth2 read AN pin value function.
bluetooth2_pair
err_t bluetooth2_pair(bluetooth2_t *ctx, uint8_t *dev_addr)
Bluetooth2 set local device name function.
bluetooth2_set_device_name
err_t bluetooth2_set_device_name(bluetooth2_t *ctx, char *dev_name)
Bluetooth2 set local device name function.
bluetooth2_default_cfg
void bluetooth2_default_cfg(bluetooth2_t *ctx)
Bluetooth2 default configuration function.
bluetooth2_set_rst_pin
void bluetooth2_set_rst_pin(bluetooth2_t *ctx, uint8_t state)
Bluetooth2 set reset pin function.
bluetooth2_generic_read
err_t bluetooth2_generic_read(bluetooth2_t *ctx, char *data_buf, uint16_t max_len)
Bluetooth2 data reading function.
bluetooth2_s::rst
digital_out_t rst
Definition: bluetooth2.h:122
bluetooth2_generic_write
err_t bluetooth2_generic_write(bluetooth2_t *ctx, char *data_buf, uint16_t len)
Bluetooth2 data writing function.