蓝牙音频应用开发和驱动移植


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


9、流程图

在这里插入图片描述

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值