最近,因新增需求需要在现有产品上增加UAC的功能,查阅并学习相关知识后,在rk3588 SOC硬件平台搭载android13系统平台上成功配置了uac及uac&adb的复合设备。基于开源共享精神希望给大家提供些参考。
1.技术可行性预研
(1)我首先预览rockchip发布的文档包,遍历了系统及usb相关的文档,其中Rockchip_Developer_Guide_USB_Gadget_UAC_CN.pdf文档中已经明确了RK3588内核中已经对RK3588 && Linux-5.10做了相关技术支持。
但是阅读android初始化配置文件,并没有相关uac的系统配置内容;内核中也无uac相关配置项。看到了usb配置文件及内核中对audio_source的支持,试验生效audio_source后,可以在/dev/snd/下生成对应的pcm设备;但使用inypcminfo指令来查询设备属性时系统崩溃,直接往对应的pcm设备推数据亦然。
(2)询问rockchip FAE关于rk3588关于uac技术支持现状,被告知需要自行支持,可行。
2.UAC及UAC,ADB符合设备系统配置
(1)内核增加uac配置
--- a/kernel-5.10/arch/arm64/configs/rockchip_defconfig
+++ b/kernel-5.10/arch/arm64/configs/rockchip_defconfig
@@ -837,6 +837,9 @@ CONFIG_USB_CONFIGFS_MASS_STORAGE=yCONFIG_USB_CONFIGFS_F_FS=yCONFIG_USB_CONFIGFS_F_ACC=yCONFIG_USB_CONFIGFS_F_AUDIO_SRC=y
+CONFIG_USB_CONFIGFS_F_UAC1=y
+CONFIG_USB_CONFIGFS_F_UAC1_LEGACY=y
+CONFIG_USB_CONFIGFS_F_UAC2=yCONFIG_USB_CONFIGFS_F_MIDI=yCONFIG_USB_CONFIGFS_F_UVC=yCONFIG_TYPEC_TCPM=y
(2)配置文件增加uac,及uac,adb符合设备配置
a).init.usb.configfs.rc文件增加内容
--- a/system/core/rootdir/init.usb.configfs.rc
+++ b/system/core/rootdir/init.usb.configfs.rc
@@ -106,6 +106,22 @@ on property:sys.usb.ffs.ready=1 && property:sys.usb.config=accessory,audio_sourcwrite /config/usb_gadget/g1/UDC ${sys.usb.controller}setprop sys.usb.state ${sys.usb.config}+on property:sys.usb.config=uac && property:sys.usb.configfs=1
+ write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "uac2"
+ symlink /config/usb_gadget/g1/functions/uac2.gs0 /config/usb_gadget/g1/configs/b.1/f1
+ write /config/usb_gadget/g1/UDC ${sys.usb.controller}
+ setprop sys.usb.state ${sys.usb.config}
+
+on property:sys.usb.config=uac,adb && property:sys.usb.configfs=1
+ start adbd
+
+on property:sys.usb.ffs.ready=1 && property:sys.usb.config=uac,adb && property:sys.usb.configfs=1
+ write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "uac_adb"
+ symlink /config/usb_gadget/g1/functions/uac2.gs0 /config/usb_gadget/g1/configs/b.1/f1
+ symlink /config/usb_gadget/g1/functions/ffs.adb /config/usb_gadget/g1/configs/b.1/f2
+ write /config/usb_gadget/g1/UDC ${sys.usb.controller}
+ setprop sys.usb.state ${sys.usb.config}
+on property:sys.usb.config=midi && property:sys.usb.configfs=1write /config/usb_gadget/g1/configs/b.1/strings/0x409/configuration "midi"symlink /config/usb_gadget/g1/functions/midi.gs5 /config/usb_gadget/g1/configs/b.1/f1
b).init.usb.rc文件增加内容
--- a/system/core/rootdir/init.usb.rc
+++ b/system/core/rootdir/init.usb.rc
@@ -103,6 +103,24 @@ on property:sys.usb.config=accessory,audio_source,adb && property:sys.usb.configstart adbdsetprop sys.usb.state ${sys.usb.config}+# UAC2 USB audio Class accessory configuration
+on property:sys.usb.config=uac && property:sys.usb.configfs=0
+ write /sys/class/android_usb/android0/enable 0
+ write /sys/class/android_usb/android0/idVendor 2207
+ write /sys/class/android_usb/android0/idProduct 0019
+ write /sys/class/android_usb/android0/functions ${sys.usb.config}
+ write /sys/class/android_usb/android0/enable 1
+ setprop sys.usb.state ${sys.usb.config}
+
+# UAC2 && adb Class accessory configuration
+on property:sys.usb.config=uac,adb && property:sys.usb.configfs=0
+ write /sys/class/android_usb/android0/enable 0
+ write /sys/class/android_usb/android0/idVendor 2207
+ write /sys/class/android_usb/android0/idProduct 001a
+ write /sys/class/android_usb/android0/functions ${sys.usb.config}
+ write /sys/class/android_usb/android0/enable 1
+ setprop sys.usb.state ${sys.usb.config}
+# Used to set USB configuration at boot and to switch the configuration# when changing the default configurationon boot && property:persist.sys.usb.config=*
c).init.rk30board.usb.rc文件增加内容
--- a/device/rockchip/common/rootdir/init.rk30board.usb.rc
+++ b/device/rockchip/common/rootdir/init.rk30board.usb.rc
@@ -82,6 +82,17 @@ on early-boot/config/usb_gadget/g1/functions/uvc.gs6/streaming/class/hs/hsymlink /config/usb_gadget/g1/functions/uvc.gs6/streaming/header/h \/config/usb_gadget/g1/functions/uvc.gs6/streaming/class/ss/h
+
+ #uac function description
+ mkdir /config/usb_gadget/g1/functions/uac2.gs0
+ write /config/usb_gadget/g1/functions/uac2.gs0/p_chmask 3
+ write /config/usb_gadget/g1/functions/uac2.gs0/p_ssize 2
+ write /config/usb_gadget/g1/functions/uac2.gs0/p_srate "48000"
+ write /config/usb_gadget/g1/functions/uac2.gs0/c_chmask 3
+ write /config/usb_gadget/g1/functions/uac2.gs0/c_ssize 2
+ write /config/usb_gadget/g1/functions/uac2.gs0/c_srate "48000"
+ write /config/usb_gadget/g1/functions/uac2.gs0/c_feature_unit 1
+ mkdir /config/usb_gadget/g1/configs/b.1 0770 shell shellmkdir /config/usb_gadget/g1/configs/b.1/strings/0x409 0770 shell shellwrite /config/usb_gadget/g1/os_desc/b_vendor_code 0x1
@@ -118,6 +129,7 @@ on early-bootchown system system /config/usb_gadget/g1/functions/rndis.gs4chown system system /config/usb_gadget/g1/functions/midi.gs5chown system system /config/usb_gadget/g1/functions/uvc.gs6
+ chown system system /config/usb_gadget/g1/functions/uac2.gs0chown system system /config/usb_gadget/g1/functions/ncm.gs7setprop sys.usb.mtp.device_type 3
@@ -175,6 +187,12 @@ on property:sys.usb.config=uvc && property:sys.usb.configfs=1on property:sys.usb.config=uvc,adb && property:sys.usb.configfs=1write /config/usb_gadget/g1/idProduct 0x0015
+
+on property:sys.usb.config=uac && property:sys.usb.configfs=1
+ write /config/usb_gadget/g1/idProduct 0x0019
+
+on property:sys.usb.config=uac,adb && property:sys.usb.configfs=1
+ write /config/usb_gadget/g1/idProduct 0x001aon property:sys.usb.config=accessory && property:sys.usb.configfs=1write /config/usb_gadget/g1/idVendor 0x18d1
sdk文件 | 对应rk3588调试板文件路径 |
system/core/rootdir/init.usb.rc | /system/etc/init/hw/init.usb.rc |
system/core/rootdir/init.usb.configfs.rc | /system/etc/init/hw/init.usb.configfs.rc |
device/rockchip/common/rootdir/init.rk30board.usb.rc | /vendor/etc/init/hw/init.rk30board.usb.rc |
3.编译后测试
(1)rk3588生效UAC设备
通过setprop指令生效uac或 uac,adb设备,需要先置none清空原配置再生效uac
只生效uac:
setprop sys.usb.config none;setprop sys.usb.config uac
生效uac,adb的复合设备:
setprop sys.usb.config none;setprop sys.usb.config uac,adb
(2)查看声卡信息及配置内容
(3)PC上查看uac识别情况
(4)音频测试,在PC上录音
在rk3588上推wav数据给PCM设备(playback),既可在PC上使用录音机app进行收音测试。
rk3588_t:/data/yueyc # tinyplay /data/yueyc/ihatetoloveyou48k.wav -D 7 -d 0
Playing sample: 2 ch, 48000 hz, 16 bit 47607428 bytes
(5)音频测试,在PC上放音
在pc上选择好,音频输出设备为rk3588 声卡
在rk3588抓取数据如下:
rk3588_t:/data/yueyc # tinycap ./capture.pcm -D 7 -d 0 -c 2 -r 48000 -b 16
Capturing sample: 2 ch, 48000 hz, 16 bit
^CCaptured 1724416 frames
rk3588_t:/data/yueyc #
附加说明
MP3格式转wav指令
#将不同采样率MP3转为所需采样率MP3
ffmpeg -i xxx.mp3 -ac 2 -ar 48000 -y xxx48k.mp3
#将mp3转为相同采样率的wav音频格式指令
ffmpeg -i xxx48k.mp3 xxx48k.wav