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 
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 BLUETOOTH_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 
77 #define BLUETOOTH_RETVAL uint8_t
78 
79 #define BLUETOOTH_INIT_OK 0x00
80 #define BLUETOOTH_INIT_ERROR 0xFF
81 
87 #define BLUETOOTH_CMD 0x01
88 #define BLUETOOTH_AOK 0x02
89 #define BLUETOOTH_CONN 0x03
90 #define BLUETOOTH_DONE 0x04
91 #define BLUETOOTH_ERR 0x00
92 #define BLUETOOTH_OK 0x01
93 
99 #define DRV_RX_BUFFER_SIZE 500
100  // End group macro
103 // --------------------------------------------------------------- PUBLIC TYPES
111 typedef struct
112 {
113  // Output pins
114 
115  digital_out_t rst;
116 
117  // Modules
118 
119  uart_t uart;
120 
121  char uart_rx_buffer[ DRV_RX_BUFFER_SIZE ];
122  char uart_tx_buffer[ DRV_RX_BUFFER_SIZE ];
123 
124 } bluetooth_t;
125 
129 typedef struct
130 {
131  // Communication gpio pins
132 
133  pin_name_t rx_pin;
134  pin_name_t tx_pin;
135 
136  // Additional gpio pins
137 
138  pin_name_t rst;
139 
140  // static variable
141 
142  uint32_t baud_rate; // Clock speed.
144  uart_data_bits_t data_bit; // Data bits.
145  uart_parity_t parity_bit; // Parity bit.
146  uart_stop_bits_t stop_bit; // Stop bits.
147 
149 
153 typedef uint8_t bluetooth_error_t;
154  // End types group
156 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
157 
163 #ifdef __cplusplus
164 extern "C"{
165 #endif
166 
176 
185 
192 void bluetooth_generic_write ( bluetooth_t *ctx, char *data_buf, uint16_t len );
193 
201 int32_t bluetooth_generic_read ( bluetooth_t *ctx, char *data_buf, uint16_t max_len );
202 
209 void bluetooth_write_command ( bluetooth_t *ctx, char *data_buf, uint16_t len );
210 
220 
231 
241 
251 
261 
271 void bluetooth_set_device_name ( bluetooth_t *ctx, uint8_t *name );
272 
297 void bluetooth_set_operating_mode ( bluetooth_t *ctx, uint8_t op_mode );
298 
308 
318 
335 void bluetooth_set_authentication ( bluetooth_t *ctx, uint8_t auth_value );
336 
355 void bluetooth_set_break ( bluetooth_t *ctx, uint8_t break_signal );
356 
369 BLUETOOTH_RETVAL bluetooth_set_cod ( bluetooth_t *ctx, uint8_t *msw, uint8_t *lsw );
370 
380 
390 void bluetooth_set_discoverability ( bluetooth_t *ctx, uint8_t *d_hex_value );
391 
401 void bluetooth_setConnectability ( bluetooth_t *ctx, uint8_t *c_hex_value );
402 
421 
433 void bluetooth_set_extended_status_string ( bluetooth_t *ctx, uint8_t *es_string );
434 
449 
472 
484 void bluetooth_set_remote_address ( bluetooth_t *ctx, uint8_t *r_addr );
485 
508 
518 
528 
538 
563 
573 
583 
593 void bluetooth_connect_to_remote_address ( bluetooth_t *ctx, uint8_t *r_addr );
594 
605 
615 
625 
635 
645 
655 
665 
675 
685 
704 
714 
715 #ifdef __cplusplus
716 }
717 #endif
718 #endif // _BLUETOOTH_H_
719  // End public_function group
722 
723 // ------------------------------------------------------------------------- END
DRV_RX_BUFFER_SIZE
#define DRV_RX_BUFFER_SIZE
Definition: bluetooth.h:99
bluetooth_enable
void bluetooth_enable(bluetooth_t *ctx)
Enable device function.
bluetooth_cfg_t
Click configuration structure definition.
Definition: bluetooth.h:130
bluetooth_setConnectability
void bluetooth_setConnectability(bluetooth_t *ctx, uint8_t *c_hex_value)
Set enable page scanning function.
bluetooth_set_device_name
void bluetooth_set_device_name(bluetooth_t *ctx, uint8_t *name)
Set the device name function.
bluetooth_get_firmware_version
void bluetooth_get_firmware_version(bluetooth_t *ctx)
Get firmware version function.
bluetooth_set_quiet_mode
BLUETOOTH_RETVAL bluetooth_set_quiet_mode(bluetooth_t *ctx, uint8_t q_mode)
Set quiet mode function.
bluetooth_enable_role_switch
void bluetooth_enable_role_switch(bluetooth_t *ctx)
Enables the role switch function.
bluetooth_t::rst
digital_out_t rst
Definition: bluetooth.h:115
bluetooth_get_signal_status
void bluetooth_get_signal_status(bluetooth_t *ctx)
Displays the remote side modem signal status function.
bluetooth_get_device_address
void bluetooth_get_device_address(bluetooth_t *ctx)
Get displays the device�s eBluetooth address function.
bluetooth_toggle_echo
void bluetooth_toggle_echo(bluetooth_t *ctx)
Toggles echo function.
bluetooth_get_extended_settings
void bluetooth_get_extended_settings(bluetooth_t *ctx)
Get displays the device�s extended settings function.
bluetooth_cfg_t::data_bit
uart_data_bits_t data_bit
Definition: bluetooth.h:144
bluetooth_error_t
uint8_t bluetooth_error_t
Error type.
Definition: bluetooth.h:153
bluetooth_set_baud_rate
BLUETOOTH_RETVAL bluetooth_set_baud_rate(bluetooth_t *ctx, uint32_t baud_rate)
Set the baud rate function.
bluetooth_init
BLUETOOTH_RETVAL bluetooth_init(bluetooth_t *ctx, bluetooth_cfg_t *cfg)
Initialization function.
bluetooth_cfg_t::rst
pin_name_t rst
Definition: bluetooth.h:138
bluetooth_cfg_t::rx_pin
pin_name_t rx_pin
Definition: bluetooth.h:133
bluetooth_set_extended_status_string
void bluetooth_set_extended_status_string(bluetooth_t *ctx, uint8_t *es_string)
Set extended status string function.
bluetooth_cfg_t::uart_blocking
bool uart_blocking
Definition: bluetooth.h:143
bluetooth_cfg_t::parity_bit
uart_parity_t parity_bit
Definition: bluetooth.h:145
bluetooth_generic_read
int32_t bluetooth_generic_read(bluetooth_t *ctx, char *data_buf, uint16_t max_len)
Generic read function.
bluetooth_exit_command_mode
void bluetooth_exit_command_mode(bluetooth_t *ctx)
Exit the command mode function.
bluetooth_disable_bonding
void bluetooth_disable_bonding(bluetooth_t *ctx)
Set bonding disable function.
bluetooth_t
Click ctx object definition.
Definition: bluetooth.h:112
bluetooth_scans_device
void bluetooth_scans_device(bluetooth_t *ctx)
Scans for Bluetooth devices in pairing mode function.
bluetooth_set_uart_parity
BLUETOOTH_RETVAL bluetooth_set_uart_parity(bluetooth_t *ctx, uint8_t character)
Set UART parity function.
bluetooth_set_factory_defaults
void bluetooth_set_factory_defaults(bluetooth_t *ctx)
Set factory defaults settings function.
bluetooth_set_authentication
void bluetooth_set_authentication(bluetooth_t *ctx, uint8_t auth_value)
Set the authentication function.
bluetooth_set_discoverability
void bluetooth_set_discoverability(bluetooth_t *ctx, uint8_t *d_hex_value)
Set enable an inquiry scan function.
bluetooth_enable_bonding
void bluetooth_enable_bonding(bluetooth_t *ctx)
Set bonding enable function.
bluetooth_get_help
void bluetooth_get_help(bluetooth_t *ctx)
Get displays a list of help command function.
bluetooth_get_basic_settings
void bluetooth_get_basic_settings(bluetooth_t *ctx)
Get displays basic settings function.
bluetooth_reboot
void bluetooth_reboot(bluetooth_t *ctx)
Reboot the module function.
bluetooth_disable_role_switch
void bluetooth_disable_role_switch(bluetooth_t *ctx)
Disables the role switch function.
BLUETOOTH_RETVAL
#define BLUETOOTH_RETVAL
Definition: bluetooth.h:77
bluetooth_enter_command_mode
void bluetooth_enter_command_mode(bluetooth_t *ctx)
Enter the command mode function.
bluetooth_connect_to_remote_address_fast_mode
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_write_command
void bluetooth_write_command(bluetooth_t *ctx, char *data_buf, uint16_t len)
Write command function.
bluetooth_cfg_t::tx_pin
pin_name_t tx_pin
Definition: bluetooth.h:134
bluetooth_set_remote_address
void bluetooth_set_remote_address(bluetooth_t *ctx, uint8_t *r_addr)
Set the remote Bluetooth address function.
bluetooth_set_special_config
BLUETOOTH_RETVAL bluetooth_set_special_config(bluetooth_t *ctx, uint16_t special_config)
Set special configuration settings function.
bluetooth_cfg_t::stop_bit
uart_stop_bits_t stop_bit
Definition: bluetooth.h:146
bluetooth_set_security_pin_code
BLUETOOTH_RETVAL bluetooth_set_security_pin_code(bluetooth_t *ctx, uint8_t *sp_code)
Set security pin code function.
bluetooth_cfg_setup
void bluetooth_cfg_setup(bluetooth_cfg_t *cfg)
Config Object Initialization function.
bluetooth_connect_to_remote_address
void bluetooth_connect_to_remote_address(bluetooth_t *ctx, uint8_t *r_addr)
Connect the device to a remote address function.
bluetooth_endspecial_config
void bluetooth_endspecial_config(bluetooth_t *ctx)
Ends configuration and puts the device into fast data mode function.
bluetooth_set_operating_mode
void bluetooth_set_operating_mode(bluetooth_t *ctx, uint8_t op_mode)
Set the operating mode function.
bluetooth_disable_7_bit_data_mode
void bluetooth_disable_7_bit_data_mode(bluetooth_t *ctx)
Disable 7-Bit data mode function.
bluetooth_generic_write
void bluetooth_generic_write(bluetooth_t *ctx, char *data_buf, uint16_t len)
Generic write function.
bluetooth_enable_7_bit_data_mode
void bluetooth_enable_7_bit_data_mode(bluetooth_t *ctx)
Enable 7-Bit data mode function.
bluetooth_set_cod
BLUETOOTH_RETVAL bluetooth_set_cod(bluetooth_t *ctx, uint8_t *msw, uint8_t *lsw)
Sets the class of device (COD) function.
bluetooth_hw_reset
void bluetooth_hw_reset(bluetooth_t *ctx)
Hardwere reset function.
bluetooth_cfg_t::baud_rate
uint32_t baud_rate
Definition: bluetooth.h:142
bluetooth_set_break
void bluetooth_set_break(bluetooth_t *ctx, uint8_t break_signal)
Set the break function.
bluetooth_t::uart
uart_t uart
Definition: bluetooth.h:119
bluetooth_set_undiscoverable
void bluetooth_set_undiscoverable(bluetooth_t *ctx)
Set undiscoverable mode function.
bluetooth_set_profile
BLUETOOTH_RETVAL bluetooth_set_profile(bluetooth_t *ctx, uint8_t profile)
Set the profile function.