文章目录
1、蓝牙音频
bluealsa
源码:
https://github.com/arkq/bluez-alsa
音频编码图:
A2DP Profile 强制要求最低支持SBC编码
HFP强制要求支持CVSD编码
依赖库
zlib
./configure --prefix=/tmp
Makefile修改:
CC=arm-linux-gnueabihf-gcc
LDSHARED=arm-linux-gnueabihf-gcc -shared -Wl,-soname,libz.so.1,–version-script,zlib.map
CPP=arm-linux-gnueabihf-gcc -E
AR=arm-linux-gnueabihf-ar
RANLIB=arm-linux-gnueabihf-ranlib
libffi
./configure --host=arm-linux-gnueabihf --prefix=/tmp
glib
https://download.gnome.org/sources/glib/
依赖zlib和libffi
./configure
–host=arm-linux-gnueabihf
–prefix=/tmp CFLAGS=-I/tmp/include
PKG_CONFIG_PATH=/tmp/lib/pkgconfig
glib_cv_stack_grows=no
glib_cv_uscore=yes
ac_cv_func_posix_getpwuid_r=yes
ac_cv_func_posix_getgrgid_r=yes
expat
./configure --host=arm-linux-gnueabihf --prefix=/tmp
dbus
依赖expat
./configure --host=arm-linux-gnueabihf --prefix= --sysconfdir=/etc CFLAGS=-I/tmp/include LDFLAGS=-L/tmp/lib PKG_CONFIG_PATH=/tmp/lib/pkgconfig --with-dbus-user=root
libical
export CC=arm-linux-gnueabihf-gcc
export CXX=arm-linux-gnueabihf-g++
cmake -DCMAKE_INSTALL_PREFIX=/tmp
ncurses
./configure --host=arm-linux-gnueabihf --prefix=/tmp CXX=arm-linux-gnueabihf-g++
readline
./configure --host=arm-linux-gnueabihf --prefix=/tmp LDFLAGS=-L/tmp/lib LIBS=-lncurses bash_cv_wcwidth_broken=yes
bluez
./configure
–host=arm-linux-gnueabihf
–prefix=/tmp
PKG_CONFIG_PATH=/tmp/lib/pkgconfig
CFLAGS=-I/tmp/include
LDFLAGS=-L/tmp/lib
LIBS=-lncurses
–disable-systemd
–disable-udev
–disable-cups
–disable-obex
–enable-library
–enable-experimental
–enable-tools
–enable-debug
–enable-test
alsa-lib
注意事项:
blue-alsa如果是旧版,alsa-lib是过于新的话会出现问题,注意版本之间配合
源码:
https://www.alsa-project.org/files/pub/lib/
编译:
./configure --host=arm-linux-gnueabihf --prefix=/tmp
sndfile (sbc依赖库)
源码:
https://github.com/libsndfile/libsndfile/tree/master
编译:
./configure --host=arm-linux-gnueabihf --prefix=/tmp
sbc
源码:
git clone git://git.kernel.org/pub/scm/bluetooth/sbc.git
编译:
./configure --host=arm-linux-gnueabihf --prefix=/tmp PKG_CONFIG_PATH=/tmp/lib/pkgconfig CFLAGS=-I/tmp/include LDFLAGS=-L/tmp/lib LIBS=-lsndfile
工具:
autoreconf工具 : 根据configure.ac 文件自动化构建系统的更新和重新生成 (对于个人来说就是生成了configure文件)
2、工具
1、dbus-daemon
dbus-daemon --system
最基础的守护进程
2、bluealsa
增加本地蓝牙协议工具
3、sdptool
用于查询设备支持的蓝牙协议情况
sdptool browse local
:本地查询
sdptool browse <address>
:查询远端设备
4、bluealsa-aplay
用于开启蓝牙通信链路
3、profile增加
bluealsa支持三个profile:a2dp、hfp、hsp
手机 : hfp-ag(hands-free audio gateway)
蓝牙耳机、音箱: hfp-hf
问题
./bluealsa: Couldn’t acquire D-Bus name: org.bluealsa
解决方法:
vi /etc/dbus-1/system.d/bluetooth.conf 添加两句话
4、蓝牙
蓝牙uart串口通信,h5协议是三根线(TX、RX、GND)
启动命令
1、初始化
./rtk_hciattach -n -s 115200 ttySAC5 rtk_h5 &
2、开启守护
./bluetoothd -n -d -C &
3、开启hci
./hciconfig
./hciconfig hci0 up
4、添加profile
./bluealsa -p hfp-hf &
5、使能配对
./hciconfig hci0 piscan
如何实现无交互连接
使用bluez-tools即可实现无交互连接
https://github.com/khvzak/bluez-tools
命令: bt-agent --capability=NoInputNoOutput &
音频链路启动
在HFP协议中,链路的开启与关闭 必须由网关角色(AG)控制,从设备(HF)不能控制链路的开关
命令: bluealsa-aplay --profile-sco xx:xx:xx:xx:xx:xx(填写具体的蓝牙设备地址) &(开启HFP协议的SCO通道)
5、移植
一、内核修改
二、移植蓝牙文件到内核
将bluetooth_uart_driver文件夹内的 .h
和 .c
文件都拷贝至 < kernel >/drivers/bluetooth
目录
相同文件替换就好
三、修改菜单
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
四、内核开启H5
五、打包蓝牙协议栈bluez传输到板子
1、蓝牙固件放到/lib/firmware/rtlbt/下
2、bluetoothctl、hciconfig、hcitool、hcidump、bluetoothd
3、移植 < bluez > /src/bluetooth.conf到/etc/dbus-1/system.d/
为了方便,将需要的程序打包成一个tar压缩文件,tftp获取压缩包后解压即可一次性获得所需要的程序
打包命令:
tar -cf xxx.tar directory
解包命令:
tar -xf xxx.tar
六、bluealsa移植
1、移植库文件:
libbluetooth.so*
libsbc.so*
libspandsp.so*
libSegFault.so
libtiff.so*
2、bluetooth.conf添加bluealsa信息
6、编译选项
bluez
configure配置的时候,–sysconfdir和–localstatedir两个参数很重要,需要设置
–sysconfdir : 用于放置bluetoothd的配置文件(main.conf)
–localstatedir : 存放蓝牙连接设备信息
7、log查询
开启HCI和bluetood守护进程后,输入: hcidump -w xxx.cfa &
获取log命令文本,cfa文件用ComProbe Protocol Analysis System查看蓝牙操作的细节
8、出现的问题
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