bluetooth 2.0.0.0
bluetooth.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 BLUETOOTH_H
36#define BLUETOOTH_H
37
38#include "drv_digital_out.h"
39#include "drv_digital_in.h"
40#include "drv_uart.h"
41
42
43// -------------------------------------------------------------- PUBLIC MACROS
53#define BLUETOOTH_MAP_MIKROBUS( cfg, mikrobus ) \
54 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
55 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
56 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST )
63#define BLUETOOTH_RETVAL uint8_t
64
65#define BLUETOOTH_INIT_OK 0x00
66#define BLUETOOTH_INIT_ERROR 0xFF
73#define BLUETOOTH_CMD 0x01
74#define BLUETOOTH_AOK 0x02
75#define BLUETOOTH_CONN 0x03
76#define BLUETOOTH_DONE 0x04
77#define BLUETOOTH_ERR 0x00
78#define BLUETOOTH_OK 0x01
85#define DRV_RX_BUFFER_SIZE 500 // End group macro
89// --------------------------------------------------------------- PUBLIC TYPES
97typedef struct
98{
99 // Output pins
100
101 digital_out_t rst;
102
103 // Modules
104
105 uart_t uart;
106
107 char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
108 char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
109
111
115typedef struct
116{
117 // Communication gpio pins
118
119 pin_name_t rx_pin;
120 pin_name_t tx_pin;
121
122 // Additional gpio pins
123
124 pin_name_t rst;
125
126 // static variable
127
128 uint32_t baud_rate; // Clock speed.
130 uart_data_bits_t data_bit; // Data bits.
131 uart_parity_t parity_bit; // Parity bit.
132 uart_stop_bits_t stop_bit; // Stop bits.
133
135
139typedef uint8_t bluetooth_error_t;
140 // End types group
142// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
143
149#ifdef __cplusplus
150extern "C"{
151#endif
152
162
171
178void bluetooth_generic_write ( bluetooth_t *ctx, char *data_buf, uint16_t len );
179
187int32_t bluetooth_generic_read ( bluetooth_t *ctx, char *data_buf, uint16_t max_len );
188
195void bluetooth_write_command ( bluetooth_t *ctx, char *data_buf, uint16_t len );
196
206
217
227
237
247
257void bluetooth_set_device_name ( bluetooth_t *ctx, uint8_t *name );
258
283void bluetooth_set_operating_mode ( bluetooth_t *ctx, uint8_t op_mode );
284
294
304
321void bluetooth_set_authentication ( bluetooth_t *ctx, uint8_t auth_value );
322
341void bluetooth_set_break ( bluetooth_t *ctx, uint8_t break_signal );
342
355BLUETOOTH_RETVAL bluetooth_set_cod ( bluetooth_t *ctx, uint8_t *msw, uint8_t *lsw );
356
366
376void bluetooth_set_discoverability ( bluetooth_t *ctx, uint8_t *d_hex_value );
377
387void bluetooth_setConnectability ( bluetooth_t *ctx, uint8_t *c_hex_value );
388
407
419void bluetooth_set_extended_status_string ( bluetooth_t *ctx, uint8_t *es_string );
420
435
458
470void bluetooth_set_remote_address ( bluetooth_t *ctx, uint8_t *r_addr );
471
494
504
514
524
549
559
569
580
591
601
611
621
631
641
651
661
671
690
700
701#ifdef __cplusplus
702}
703#endif
704#endif // _BLUETOOTH_H_
705 // End public_function group
708
709// ------------------------------------------------------------------------- END
#define DRV_RX_BUFFER_SIZE
Definition: bluetooth.h:85
#define BLUETOOTH_RETVAL
Definition: bluetooth.h:63
int32_t bluetooth_generic_read(bluetooth_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
BLUETOOTH_RETVAL bluetooth_set_cod(bluetooth_t *ctx, uint8_t *msw, uint8_t *lsw)
Sets the class of device (COD) function.
void bluetooth_disable_role_switch(bluetooth_t *ctx)
Disables the role switch function.
void bluetooth_connect_to_remote_address_fast_mode(bluetooth_t *ctx, uint8_t *r_addr)
Connect the device to a remote address fast mode function.
BLUETOOTH_RETVAL bluetooth_set_quiet_mode(bluetooth_t *ctx, uint8_t q_mode)
Set quiet mode function.
BLUETOOTH_RETVAL bluetooth_set_profile(bluetooth_t *ctx, uint8_t profile)
Set the profile function.
void bluetooth_reboot(bluetooth_t *ctx)
Reboot the module function.
void bluetooth_set_discoverability(bluetooth_t *ctx, uint8_t *d_hex_value)
Set enable an inquiry scan function.
void bluetooth_generic_write(bluetooth_t *ctx, char *data_buf, uint16_t len)
Generic write function.
void bluetooth_set_extended_status_string(bluetooth_t *ctx, uint8_t *es_string)
Set extended status string function.
BLUETOOTH_RETVAL bluetooth_set_uart_parity(bluetooth_t *ctx, uint8_t character)
Set UART parity function.
void bluetooth_hw_reset(bluetooth_t *ctx)
Hardwere reset function.
BLUETOOTH_RETVAL bluetooth_set_special_config(bluetooth_t *ctx, uint16_t special_config)
Set special configuration settings function.
void bluetooth_set_break(bluetooth_t *ctx, uint8_t break_signal)
Set the break function.
void bluetooth_enable_role_switch(bluetooth_t *ctx)
Enables the role switch function.
void bluetooth_set_authentication(bluetooth_t *ctx, uint8_t auth_value)
Set the authentication function.
void bluetooth_setConnectability(bluetooth_t *ctx, uint8_t *c_hex_value)
Set enable page scanning function.
void bluetooth_disable_7_bit_data_mode(bluetooth_t *ctx)
Disable 7-Bit data mode function.
void bluetooth_scans_device(bluetooth_t *ctx)
Scans for Bluetooth devices in pairing mode function.
void bluetooth_set_undiscoverable(bluetooth_t *ctx)
Set undiscoverable mode function.
void bluetooth_exit_command_mode(bluetooth_t *ctx)
Exit the command mode function.
void bluetooth_enable_bonding(bluetooth_t *ctx)
Set bonding enable function.
void bluetooth_toggle_echo(bluetooth_t *ctx)
Toggles echo function.
void bluetooth_get_extended_settings(bluetooth_t *ctx)
Get displays the device�s extended settings function.
void bluetooth_write_command(bluetooth_t *ctx, char *data_buf, uint16_t len)
Write command function.
void bluetooth_set_remote_address(bluetooth_t *ctx, uint8_t *r_addr)
Set the remote Bluetooth address function.
void bluetooth_get_firmware_version(bluetooth_t *ctx)
Get firmware version function.
void bluetooth_connect_to_remote_address(bluetooth_t *ctx, uint8_t *r_addr)
Connect the device to a remote address function.
void bluetooth_disable_bonding(bluetooth_t *ctx)
Set bonding disable function.
void bluetooth_endspecial_config(bluetooth_t *ctx)
Ends configuration and puts the device into fast data mode function.
void bluetooth_enable(bluetooth_t *ctx)
Enable device function.
void bluetooth_set_device_name(bluetooth_t *ctx, uint8_t *name)
Set the device name function.
void bluetooth_get_signal_status(bluetooth_t *ctx)
Displays the remote side modem signal status function.
void bluetooth_set_operating_mode(bluetooth_t *ctx, uint8_t op_mode)
Set the operating mode function.
BLUETOOTH_RETVAL bluetooth_set_security_pin_code(bluetooth_t *ctx, uint8_t *sp_code)
Set security pin code function.
void bluetooth_get_device_address(bluetooth_t *ctx)
Get displays the device�s eBluetooth address function.
void bluetooth_enable_7_bit_data_mode(bluetooth_t *ctx)
Enable 7-Bit data mode function.
void bluetooth_set_factory_defaults(bluetooth_t *ctx)
Set factory defaults settings function.
void bluetooth_cfg_setup(bluetooth_cfg_t *cfg)
Config Object Initialization function.
BLUETOOTH_RETVAL bluetooth_init(bluetooth_t *ctx, bluetooth_cfg_t *cfg)
Initialization function.
void bluetooth_get_basic_settings(bluetooth_t *ctx)
Get displays basic settings function.
void bluetooth_get_help(bluetooth_t *ctx)
Get displays a list of help command function.
void bluetooth_enter_command_mode(bluetooth_t *ctx)
Enter the command mode function.
BLUETOOTH_RETVAL bluetooth_set_baud_rate(bluetooth_t *ctx, uint32_t baud_rate)
Set the baud rate function.
uint8_t bluetooth_error_t
Error type.
Definition: bluetooth.h:139
Click configuration structure definition.
Definition: bluetooth.h:116
uint32_t baud_rate
Definition: bluetooth.h:128
bool uart_blocking
Definition: bluetooth.h:129
uart_data_bits_t data_bit
Definition: bluetooth.h:130
pin_name_t tx_pin
Definition: bluetooth.h:120
pin_name_t rx_pin
Definition: bluetooth.h:119
uart_stop_bits_t stop_bit
Definition: bluetooth.h:132
uart_parity_t parity_bit
Definition: bluetooth.h:131
pin_name_t rst
Definition: bluetooth.h:124
Click ctx object definition.
Definition: bluetooth.h:98
uart_t uart
Definition: bluetooth.h:105
digital_out_t rst
Definition: bluetooth.h:101