BT
介绍BT的移植和使用方法。
模块介绍
K1平台上主要通过外部BT模块来实现BT功能,支持UART,USB等接口的蓝牙模块。
功能介绍
BT框架图可以分为以下几个层次:
源码结构介绍
BT相关的源码可以分为以下几个部分:
- 蓝牙协议栈,以bluez协议栈为例,代码分为两部分,一部分在内核空间,一部分在用户空间。
- BT HCI驱动,主要实现HCI层。
- 平台相关部分,主要实现模组供电以及使能等相关接口,供rfkill驱动调用。
- 接口驱动,主要实现BT数据传输接口功能,如UART,USB等接口。
BLUEZ协议栈源码在以下目录:
drivers/net/bluetooth
|-- af_bluetooth.c
|-- af_bluetooth.o
|-- bnep #Bluetooth网络封装协议
│ |-- bnep.h
│ |-- core.c
│ |-- Kconfig
│ |-- Makefile
│ |-- netdev.c
│ |-- sock.c
|-- hci_codec.c
|-- hci_codec.h
|-- hci_conn.c
|-- hci_core.c #Hci core实现
|-- hci_debugfs.c
|-- hci_debugfs.h
|-- hci_event.c
|-- hci_request.c
|-- hci_request.h
|-- hci_sock.c
|-- hci_sync.c
|-- hci_sysfs.c
|-- hidp #Bluetooth hid实现
│ |-- core.c
│ |-- hidp.h
│ |-- Kconfig
│ |-- Makefile
│ |-- sock.c
|-- iso.c
|-- Kconfig
|-- l2cap_core.c #l2cap core实现
|-- l2cap_sock.c
|-- lib.c
|-- Makefile
|-- mgmt.c #mgmt蓝牙管理实现
|-- mgmt_config.c
|-- mgmt_config.h
|-- mgmt_util.c
|-- mgmt_util.h
|-- rfcomm #rfcomm协议
│ |-- core.c
│ |-- Kconfig
│ |-- Makefile
│ |-- sock.c
│ |-- tty.c
|-- sco.c
|-- selftest.c
|-- selftest.h
|-- smp.c
|-- smp.h
HCI驱动的源码在以下目录:
drivers/bluetooth
|-- btbcm.c #broadcom厂 商实现
|-- btrtl.c #realtek厂商实现
|-- btusb.c #hci uart实现
|-- hci_h4.c #hci h4实现
|-- hci_h5.c #hci h5实现
|-- hci_ldisc.c #蓝牙hci的线路规程
平台相关的源码:
drivers/soc/spacemit/spacemit-rf
|-- spacemit-pwrseq.c #WIFI和蓝牙等公共部分实现
|-- spacemit-wlan.c #WIFI供电,gpio以及时钟相关接口实现
|-- spacemit-bt.c #BT供电,gpio以及时钟相关接口实现
接口相关的源码参考各个接口驱动说明文档。
关键特性
平台uart接口特性
特性 | 特性说明 |
---|---|
支持4线流控 | 最高支持3.6Mbps |
支持DMA | 支持DMA传输模式 |
模组性能规格
模组型号 | 规格 |
---|---|
rtl8852bs | 支持Bluetooth 5.2 |
支持Bluetooth 2.0 UART HCI H4/H5 | |
aic8800d80 | 支持Bluetooth 5.3 |
支持Bluetooth 2.0 UART HCI H4 |
配置介绍
主要包括驱动使能配置和dts配置
CONFIG配置
协议栈配置
Networking support (NET [=y])
Bluetooth subsystem support (BT [=y])
Bluetooth Classic (BR/EDR) features (BT_BREDR [=y])
RFCOMM protocol support (BT_RFCOMM [=y])
RFCOMM TTY support (BT_RFCOMM_TTY [=y])
BNEP protocol support (BT_BNEP [=y])
HIDP protocol support (BT_HIDP [=y])
Bluetooth Low Energy (LE) features (BT_LE [=y])
Export Bluetooth internals in debugfs (BT_DEBUGFS [=y])
UART HCI配置
Networking support (NET [=y])
Bluetooth subsystem support (BT [=y])
Bluetooth device drivers
HCI UART driver (BT_HCIUART [=y])
UART (H4) protocol support (BT_HCIUART_H4 [=y])
Three-wire UART (H5) protocol support (BT_HCIUART_3WIRE [=y])
Realtek protocol support (BT_HCIUART_RTL [=y])
默认支持H4和H5,其中Realtek的蓝牙串口走的是H5协议。
USB HCI配置
Networking support (NET [=y])
Bluetooth subsystem support (BT [=y])
Bluetooth device drivers
HCI USB driver (BT_HCIBTUSB [=m])
Broadcom protocol support (BT_HCIBTUSB_BCM [=y])
Realtek protocol support (BT_HCIBTUSB_RTL [=y])
BT_HCIBTUSB_BCM和BT_HCIBTUSB_RTL分别对应Broadcom和Realtek的支持。
AVRCP配置
Device Drivers
Input device support
Generic input layer (needed for keyboard, mouse, ...) (INPUT [=y])
Miscellaneous devices (INPUT_MISC [=y])
User level driver support (INPUT_UINPUT [=y])
如果要把 AVRCP 的按键值等信息通过 input device 送给用户态程序,则需要打开INPUT_UINPUT。
HOGP配置
Device Drivers
HID bus support (HID_SUPPORT [=y])
HID bus core support (HID[=y])
User-space I/O driver support for HID subsystem (UHID [=y])
如果要把HoG的KEY_1, KEY_2, KEY_ESC等按键值通过input device送给用户态程序,则需要打开UHID。
平台配置
Device Drivers
SOC (System On Chip) specific Drivers
Spacemit rfkill driver (SPACEMIT_RFKILL [=y])
CONFIG_SPACEMIT_RFKILL 为BT模组提供平台相关支持,默认情况,此选项为Y