Bluetooth¶
MT2503 chipset supports BT3.0 with EDR can work in BT host and client mode.
Currently only SPP profile is supported by SDK.
System create device file /dev/bthost0 for host mode of operation. This file can be used to perform standard IO operations (open, close, read, write etc.). SDK also provide api to enable console over bluetooth, If console is enabled then host operation file will not be available for application.
For client mode of operation device files are created under /dev/btclient/ after Bluetooth device search is performed. Application can initiate pairing and standard io operation can then be performed via system calls.
API Reference¶
Header File¶
Source: include/hw/bluetooth.h
#include <hw/bluetooth.h>
Functions¶
-
int bt_device_init(int mode, const char *name, int use_btcli)¶
Initialize Bluetooth hardware
- Parameters
mode – [in] Bluetooth controller mode see btmode_e
name – [in] Name of device shown to other bluetooth device while searching
use_btcli – [in] Bluetooth console select (1 to enable, 0 to disable). When enabled, /dev/bthost0 device file will not be available to the application.
- Returns
For return value see bterr_e
-
int bt_device_power(int on_off)¶
Turn on/off bluetooth hardware. Bluetooth is enabled by default when device is initialized.
- Parameters
on_off – [in] TRUE (1) to turn on or FALSE (0) to turn off
- Returns
For return value see bterr_e
-
int bt_device_reset(void)¶
Reset bluetooth hardware. Equivalent to turn off and then turn on.
- Returns
For return value see bterr_e
-
int bt_device_getinfo(struct btinfo_t *info)¶
Get Bluetooth controller information
- Parameters
info – [in,out] Pointer to structure to store information
- Returns
For return value see bterr_e
-
int bt_device_setname(const char *name)¶
Change display name of device
- Parameters
name – [in] Device name
- Returns
For return value see bterr_e
-
int bt_device_scan(unsigned int timeout)¶
Perform a bluetooth scan. This is a blocking function.
- Parameters
timeout – [in] Timeout value in seconds
- Returns
For return value see bterr_e
-
int bt_device_scancancel(void)¶
Cancel scan operation. calling this function will interrupt bt_device_scan()
- Returns
For return value see bterr_e
-
int bt_device_getcount(int type)¶
Get device list count
-
int bt_device_getdevinfo(int idx, int type, struct btdevinfo_t *out_devinfo)¶
Get bluetooth device information. This function can be called to get list of devices after a scan is performed or to get list of paired devices.
-
int bt_device_pair(const char *name, const char *passcode)¶
Pair a device.
- Parameters
name – [in] Name of device to pair with
passcode – [in] Pair passcode/Pin. Can be NULL if auto-generated passcode is supported by device.
- Returns
For return value see bterr_e
-
int bt_device_unpair(const char *name)¶
Unpair a device
- Parameters
name – [in] Name of device to unpair
- Returns
For return value see bterr_e
-
void bt_print_devlist(int disp_type)¶
Helper function to display device list
- Parameters
disp_type – [in] Display list type devtype_e
-
int bt_manager_init(void)¶
Install “BTMAN” command to manage Bluetooth controller from command line interface.
Command Format: BTMAN [OP] [ARG]
OP - Operation to perform ARG - Argument, depends on operation
Available operation:
Power - Power on/off BT. ARG = 0/1
Scan - Scan BT devices. ARG = Timeout (optional, default 10s)
List - List all BT devices (Paired and Searched).
Pair - Pair a BT device. ARG = [DEV NAME],[PASSKEY (optional)]
Unpair - Unpair a BT device. ARG = DEV NAME (All devices are unpaired if no argument given)
If no operation is specified, Command will print BT controller related information
Structures¶
-
struct btdevinfo_t¶
Bluetooth device information structure
-
struct btinfo_t¶
Bluetooth Controller information structure
Public Members
-
struct btdevinfo_t dev¶
BT contoller device info
-
int power¶
Controller power on/off status
-
int visible¶
Controller visibility status
-
struct btdevinfo_t dev¶
Macros¶
-
BTDEV_NAME_LEN_MAX¶
Note
Bluetooth is not available on MT2625 (NB-IoT) Platform. Maximum length for BT device name
Enumerations¶
-
enum btmode_e¶
Bluetooth Operation mode
Values:
-
enumerator BT_CLASSIC¶
BT+EDR Classic mode
-
enumerator BT_LE¶
Bluetooth Low Energy
-
enumerator BT_CLASSIC¶
-
enum bterr_e¶
Bluetooth error code
Values:
-
enumerator BT_OK¶
No error
-
enumerator BT_ERR_ARG¶
Invalid argument
-
enumerator BT_ERR_OPFAIL¶
Fail to perform operation
-
enumerator BT_ERR_BUSY¶
Hardware busy
-
enumerator BT_ERR_NODEV¶
No device found
-
enumerator BT_ERR_SCAN¶
BT Scan error
-
enumerator BT_ERR_PAIR¶
BT Pair error
-
enumerator BT_ERR_TIMEOUT¶
BT operation timeout
-
enumerator BT_ERR_NOTSUPP¶
BT operation not supported
-
enumerator BT_ERR_NOMEM¶
No memory
-
enumerator BT_OK¶
