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¶
Functions¶
-
int
bt_device_init(int mode, const char *name, int use_btcli)¶ Initialize Bluetooth hardware
- Return
For return value see bterr_e
- Parameters
mode: [in] Bluetooth controller mode see btmode_ename: [in] Name of device shown to other bluetooth device while searchinguse_btcli: [in] Bluetooth console select (1 to enable, 0 to disable). When enabled, /dev/bthost0 device file will not be available to the application.
-
int
bt_device_power(int on_off)¶ Turn on/off bluetooth hardware. Bluetooth is enabled by default when device is initialized.
- Return
For return value see bterr_e
- Parameters
on_off: [in] TRUE (1) to turn on or FLASE (0) to turn off
-
int
bt_device_reset(void)¶ Reset bluetooth hardware. Equivalent to turn off and then turn on.
- Return
For return value see bterr_e
-
int
bt_device_getinfo(struct btinfo_t *info)¶ Get Bluetooth controller information
- Return
For return value see bterr_e
- Parameters
info: [in,out] Pointer to structure to store information
-
int
bt_device_setname(const char *name)¶ Change display name of device
- Return
For return value see bterr_e
- Parameters
name: [in] Device name
-
int
bt_device_scan(unsigned int timeout)¶ Perform a bluetooth scan. This is a blocking function.
- Return
For return value see bterr_e
- Parameters
timeout: [in] Timeout value in seconds
-
int
bt_device_scancancel(void)¶ Cancel scan operation. calling this function will interrupt bt_device_scan()
- Return
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.
- Return
For return value see bterr_e
- Parameters
name: [in] Name of device to pair withpasscode: [in] Pair passcode/Pin. Can be NULL if auto-generated passcode is supported by device.
-
int
bt_device_unpair(const char *name)¶ Unpair a device
- Return
For return value see bterr_e
- Parameters
name: [in] Name of device to unpair
-
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
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
-
enum
bterr_e¶ Bluetooth error code
Values:
-
enumerator
BT_OK= 0¶ No error
-
enumerator
BT_ERR_ARG= -1¶ Invalid argument
-
enumerator
BT_ERR_OPFAIL= -2¶ Fail to perform operation
-
enumerator
BT_ERR_BUSY= -3¶ Hardware busy
-
enumerator
BT_ERR_NODEV= -4¶ No device found
-
enumerator
BT_ERR_SCAN= -5¶ BT Scan error
-
enumerator
BT_ERR_PAIR= -6¶ BT Pair error
-
enumerator
BT_ERR_TIMEOUT= -7¶ BT operation timeout
-
enumerator
BT_ERR_NOTSUPP= -8¶ BT operation not supported
-
enumerator
BT_ERR_NOMEM= -9¶ No memory
-
enumerator
