文章目录
一、关系图
二、驱动文件
1、移植蓝牙驱动文件到内核
将bluetooth_uart_driver文件夹内的 .h
和 .c
文件都拷贝至 < kernel >/drivers/bluetooth
目录
相同文件替换就好
2、修改内核菜单
Kconfig
config BT_HCIUART_RTL3WIRE
bool "Realtek Three wire UART (H5) protocol support"
depends on BT_HCIUART
help
Realtek Three wire UART (H5) transport layer makes it possible
to use Realtek Bluetooth controller with Three wire UART.
Say Y here to compile support for Realtek Three wire UART.
Makefile
hci_uart-y += rtk_coex.o
hci_uart-$(CONFIG_BT_HCIUART_RTL3WIRE) += hci_rtk_h5.o
3、内核配置修改
三、工具编译
tar :
-J,–xz :xz
-j ,–bzip2 :bzip2 格式
-z,–gzip :gzip 格式
Bluez
依赖库:
- GCC compiler (编译器)
- GLib library (C库)
- D-Bus library (通信库)
- udev library (optional) (设备管理库)
- readline (command line clients) (命令行库)
配置选项:
–disable-cups : 关闭蓝牙打印机系统
–enable-testing : 测试工具
–enable-experimental:实验工具
–enable-deprecated : 弃用工具
make clean:删除目标文件
GLib
源码:https://gitlab.gnome.org/GNOME/glib/
GLib : 低级核心库,构成了GTK和GNOME等项目的基础。为C语言提供数据结构处理、可移植性包装器,以及诸如事件循环、线程、动态加载和对象系统等运行时功能的接口。
D-Bus
D-Bus : 用于进程间通信和协调的简单系统
官网:https://www.freedesktop.org/wiki/Software/dbus/
源码 : https://dbus.freedesktop.org/releases/dbus/
Requisite:
- Gettext (语言库): https://www.gnu.org/software/gettext/
- expat (XML解析器库) : https://github.com/libexpat/libexpat/releases
Optional:
- libselinux (for SELinux integration)
- doxygen (for API documentation)
- xmlto or meinproc4 (for Spec & other XML documentation)
Gettext
./configure --host=arm-linux-gnueabihf --prefix=/tmp --disable-c++
expat
./configure --host=arm-linux-gnueabihf --prefix=/tmp
udev
readline
源码:https://tiswww.case.edu/php/chet/readline/rltop.html
四、工具作用
1、bluetoothd
蓝牙守护进程
bluetoothd --debug=error -C &
2、bluetoothctl
蓝牙命令控制工具
常用命令:
show: 自身蓝牙情况
power on :上电
scan on: 开启蓝牙扫描
scan off:关闭蓝牙扫描
connect : 连接蓝牙设备
quit : 退出
3、bluealsa
蓝牙音频协议工具
支持三个profile:a2dp、hfp、hsp
问题:
bluealsa: Couldn’t acquire D-Bus name: org.bluealsa
解决方法:
vi /etc/dbus-1/system.d/bluetooth.conf 添加两句话
4、bluealsa-aplay
用于开启蓝牙通信链路
五、蓝牙开启
1、准备工具
Bluez文件、工具:
1、蓝牙固件放到/lib/firmware/rtlbt/下
2、bluetoothctl、hciconfig、hcitool、hcidump、bluetoothd
3、移植 < bluez > /src/bluetooth.conf到/etc/dbus-1/system.d/
打包移植
打包命令:
tar -cf xxx.tar directory
解包命令:
tar -xf xxx.tar
Bluez-alsa文件、工具:
1、库文件:
libbluetooth.so*
libsbc.so*
libspandsp.so*
libSegFault.so
libtiff.so*
2、bluetooth.conf添加bluealsa信息
2、启动命令
蓝牙uart串口通信,h5协议是三根线(TX、RX、GND)
1、初始化
./rtk_hciattach -n -s 115200 ttySAC5 rtk_h5 &
2、开启守护
./bluetoothd --debug=error -C &
3、开启hci
./hciconfig
./hciconfig hci0 up
4、添加profile
./bluealsa -p hfp-hf &
5、使能配对
./hciconfig hci0 piscan
3、如何实现无交互连接
使用bluez-tools即可实现无交互连接
https://github.com/khvzak/bluez-tools
命令: bt-agent --capability=NoInputNoOutput &
4、音频链路启动
在HFP协议中,链路的开启与关闭 必须由网关角色(AG)控制,从设备(HF)不能控制链路的开关
命令: bluealsa-aplay --profile-sco xx:xx:xx:xx:xx:xx(填写具体的蓝牙设备地址) &(开启HFP协议的SCO通道)
5、log生成
开启HCI和bluetood守护进程后,输入: hcidump -w xxx.cfa &
生成log文本,cfa文件用ComProbe Protocol Analysis System查看蓝牙操作的细节
六、编译注意事项
bluez
configure配置的时候,–sysconfdir和–localstatedir两个参数很重要,需要设置
–sysconfdir : 用于放置bluetoothd的配置文件(main.conf)
–localstatedir : 存放蓝牙连接设备信息
七、出现的问题
1、configure: error: sndfile library is required
原因:sbc缺乏sndfile库
2、/bin/bash: autogen: 未找到命令
解决办法:sudo apt install autogen
3、glib.h:没有那个文件或目录
因为依赖库是glib-2.0,而glib-2.0生成的链接头文件目录名为glib-2.0并不是glib