rockchip移植ap6256蓝牙

rockchip 平台

蓝牙AP6256移植文档
(1)硬件设备树配置 主要配置声卡 还有上电管脚等
wireless-bluetooth {
compatible = “bluetooth-platdata”;
uart_rts_gpios = <&gpio2 RK_PA3 GPIO_ACTIVE_LOW>;
pinctrl-names = “default”, “rts_gpio”;
pinctrl-0 = <&uart0_rts>;
pinctrl-1 = <&uart0_rts_gpio>;
BT,power_gpio = <&gpio2 RK_PA6 GPIO_ACTIVE_HIGH>;
BT,wake_host_irq = <&gpio2 RK_PB0 GPIO_ACTIVE_HIGH>;
status = “okay”;
};
&uart0 {
pinctrl-names = “default”;
pinctrl-0 = <&uart0_xfer &uart0_cts>;
status = “okay”;
};

bt-sound {
           status = "okay";
            compatible = "simple-audio-card";
            simple-audio-card,format = "dsp_b";
            simple-audio-card,bitclock-inversion = <1>;
            simple-audio-card,mclk-fs = <256>;
            simple-audio-card,name = "rockchip,bt";
            simple-audio-card,cpu {
                    sound-dai = <&i2s_8ch_0>;
            };
            simple-audio-card,codec {
                    sound-dai = <&bt_sco>;
            };
    };

    bt_sco: bt-sco {
            compatible = "delta,dfbmcs320";
            #sound-dai-cells = <0>;
    };
&i2s_8ch_0 {
status = "okay";
assigned-clocks = <&cru SCLK_I2S0_8CH_RX>;
assigned-clock-parents = <&cru SCLK_I2S0_8CH_TX_MUX>;
rockchip,clk-trcm = <1>; // 1 - only tx_lrck/bclk is used   这里用的tx  rx的话可以改为2
#sound-dai-cells = <0>;

};
主要配置上电管脚, uart管脚 和pcm声卡

(2)配置好编译 然后启动系统

启动后 硬件量 ap6256的3.3V 内部晶振 37.4M
还有32.768k时钟 (不产生可以无法下载固件)
32.768根据电路中是如何设置
比如 电路中来自rtc
那么在设备树中增加
&pinctrl {
pinctrl-names = “default”;
pinctrl-0 = <&rtc_32k>;
可产生32.768k的时钟

通过
echo 0 > /sys/class/rfkill/rfkill0/state
sleep 3
echo 1 > /sys/class/rfkill/rfkill0/state
sleep 3
来量蓝牙的上电管脚 1.8V 电压

这个时候 正常情况下

echo 1 > /sys/class/rfkill/rfkill0/state

[ 65.431510] [BT_RFKILL]: rfkill_rk_set_power: set bt wake_host pin output high!
[ 65.494167] [BT_RFKILL]: rfkill_rk_set_power: set bt wake_host pin input!
[ 65.494384] [BT_RFKILL]: ENABLE UART_RTS
[ 65.595263] [BT_RFKILL]: DISABLE UART_RTS
[ 65.595284] [BT_# RFKILL]: bt turn on power

蓝牙正常上电

(3)蓝牙操作 需要移植bluez 和bluealsa
a.下载固件
brcm_patchram_plus1 --enable_hci --no2bytes --use_baudrate_for_download --tosleep 200000 --baudrate 1500000 --patchram /system/etc/BCM4345C5.hcd /dev/ttyS0 -d &
需要注意的是 --baudrate 1500000 可能出问题 可以使用115200 或者 3000000 出现问题大多是固件地址 或者波特率不对
b.正常下载后
while [ -z “hciconfig -a | grep hci0” ]; do
echo “waiting for hci0 init”
sleep 2
done
通过该命令可等待 hci0 创建好

然后 hciconfig hci0 up

在通过hciconfig -a 可看到hci0创建好

hciconfig -a

hci0: Type: Primary Bus: UART
BD Address: C0:84:7D:AE:20:33 ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN ISCAN
RX bytes:806 acl:0 sco:0 events:52 errors:0
TX bytes:1855 acl:0 sco:0 commands:52 errors:0
Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3
Link policy: RSWITCH SNIFF
Link mode: SLAVE ACCEPT
Name: ‘rk12345’
Class: 0x200000
Service Classes: Audio
Device Class: Miscellaneous,
HCI Version: 5.0 (0x9) Revision: 0x50
LMP Version: 5.0 (0x9) Subversion: 0x6606
Manufacturer: Broadcom Corporation (15)

为了使对方可以搜索到和可连接 可通过下列命令

bluetoothd -n & bluez协议栈
如果出现
bluetoothd[294]: Bluetooth daemon 5.50
D-Bus setup failed: Failed to connect to socket /var/run/dbus/system_bus_socket: No such file or directory
bluetoothd[294]: Unable to get on D-Bus

需要打开dbus
例如:

start_system_dbus

creating system bus

sleep 3

hciconfig hci0 piscan
hciconfig hci0 class 0x240404
hciconfig hci0 name ‘test12345’

bluealsa -p hfp-hf & hfp协议支持

3.这个时候对方就可以手机直接连接设备 并且进行打电话测试
上行测试
arecord -Dhw:1,0 -r 8000 -f S16_LE -c 2 |aplay -D hw:0,0 -r 8000 -c 2 -f S16_LE 将麦克风采集的数据送到蓝牙 然后到对端听筒中

你可能感兴趣的:(蓝牙)