瑞芯微-I2S|音频驱动调试基本命令和工具-基于rk3568-2

原创 一口Linux 2024-03-18 11:50

点击左上方蓝色“一口Linux”,选择“设为星标

第一时间看干货文章 

【干货】嵌入式驱动工程师学习路线
【干货】Linux嵌入式知识点-思维导图-免费获取
【就业】一个可以写到简历的基于Linux物联网综合项目
【就业】找工作简历模版



 1

一口君后面会陆续更新基于瑞芯微rk3568的I2S系列文章。

10篇有对语音感兴趣的朋友,可以收藏该专题

瑞芯微 | I2S-音频基础 -1

基于Linux嵌入式设备常用调试方法很多,本文一口君把调试语音用到的工具和方法给大家做一个简单的介绍。

1.  procfs、sysfs

Linux系统上的/proc目录是一种文件系统,即proc文件系统。与其它常见的文件系统不同的是,/proc是一种伪文件系统(也即虚拟文件系统),存储的是当前内核运行状态的一系列特殊文件,用户可以通过这些文件查看有关系统硬件及当前正在运行进程的信息,甚至可以通过更改其中某些文件来改变内核的运行状态。

基于/proc文件系统如上所述的特殊性,其内的文件也常被称作虚拟文件,并具有一些独特的特点。例如,其中有些文件虽然使用查看命令查看时会返回大量信息,但文件本身的大小却会显示为0字节。此外,这些特殊文件中大多数文件的时间及日期属性通常为当前系统时间和日期,这跟它们随时会被刷新(存储于RAM中)有关。

ALSA有自己的proc tree,在/proc/asound这个目录下可以找到许多关于snd card 的详细信息。

  • /proc/asound
rk3568_r:/ # ls /proc/asound -l
total 0
dr-xr-xr-x 5 root root 0 2024-02-19 22:27 card0
dr-xr-xr-x 4 root root 0 2024-02-19 22:27 card1
-r--r--r-- 1 root root 0 2024-02-19 22:27 cards
-r--r--r-- 1 root root 0 2024-02-19 22:27 devices
-r--r--r-- 1 root root 0 2024-02-19 22:27 hwdep
-r--r--r-- 1 root root 0 2024-02-19 22:27 pcm
lrwxrwxrwx 1 root root 5 2024-02-19 22:27 rockchiphdmi -> card1
lrwxrwxrwx 1 root root 5 2024-02-19 22:27 rockchiprk809co -> card0
-r--r--r-- 1 root root 0 2024-02-19 22:27 timers
-r--r--r-- 1 root root 0 2024-02-19 22:27 version

其中主要的节点如下:

  • cardx:表示注册的sound card;
  • cards:显示当前配置的Alsa Drivers,index,the id string,short and long descriptions;
  • version:显示版本字符串;
  • devices:列举本机设备映射;
  • pcm:列举当前可用的 pcm devides,格式如下:-:::
  • /proc/asound/cards

通过 proc fs 确认声卡注册成功

# cat /proc/asound/cards
0 [rockchiprk809co]: rockchip_rk809- - rockchip,rk809-codec
rockchip,rk809-codec
7 [Loopback ]: Loopback - Loopback
Loopback 1
  • /proc/asound/devices

查看声卡下的功能设备

rk3568_r:/ #  cat /proc/asound/devices
  2: [ 0- 0]: digital audio playback
  3: [ 0- 0]: digital audio capture
  4: [ 0]   : control
  5: [ 1- 0]: digital audio playback
  6: [ 1]   : control
 33:        : timer

对于devices的print格式如下:

- Control设备: “minor: [card_id] : control”;
- PCM设备    : “minor: [card_id- device_id]: digital audio playback/capture”;
- timer设备  : “minor: : timer”;
  • /proc/asound/pcm

查看声卡采集、播放PCM信息

rk3568_r:/ # cat /proc/asound/pcm
cat /proc/asound/pcm
00-00: fe410000.i2s-rk817-hifi rk817-hifi-0 : fe410000.i2s-rk817-hifi rk817-hifi-0 : playback 1 : capture 1
01-00: rockchip,hdmi i2s-hifi-0 : rockchip,hdmi i2s-hifi-0 : playback 1
  • /proc/asound/version

查看ALSA驱动版本

rk3568_r:/ # cat /proc/asound/version
cat /proc/asound/version
Advanced Linux Sound Architecture Driver Version k4.19.232.
  • /proc/asound/card0/pcm0p/sub0/status

查看声卡0的信息

rk3568_r:/ # cat /proc/asound/card0/pcm0p/sub0/status
cat /proc/asound/card0/pcm0p/sub0/status
closed
rk3568_r:/sys/devices/platform/rk809-sound # ls
driver  driver_override  fe410000.i2s-rk817-hifi  modalias  of_node  power  sound  subsystem  uevent
kernel/Documentation/devicetree/bindings/sound/rockchip-i2s.txt  rockchip,i2s-tdm.txt

alsa_sound_init函数中会调用snd_info_init函数创建 /proc/asound目录,并将该entry保存在全局变量 snd_proc_root(即作为 sound proc root entry),代码如下

int __init snd_info_init(void)
{
    //1、创建 alsa proc root entry;
    snd_proc_root = snd_info_create_entry("asound"NULL);    
    if (!snd_proc_root)
        return -ENOMEM;
    snd_proc_root->mode = S_IFDIR | 0555;
    //2、创建 dir: /proc/asound
    snd_proc_root->p = proc_mkdir("asound"NULL);    
    if (!snd_proc_root->p)
        goto error;
#ifdef CONFIG_SND_OSSEMUL
    snd_oss_root = create_subdir(THIS_MODULE, "oss");
    if (!snd_oss_root)
        goto error;
#endif
#if IS_ENABLED(CONFIG_SND_SEQUENCER)
    snd_seq_root = create_subdir(THIS_MODULE, "seq");
    if (!snd_seq_root)
        goto error;
#endif
    if (snd_info_version_init() < 0 ||    //3、创建 file: /proc/asound/version
        snd_minor_info_init() < 0 ||    //4、创建 file: /proc/asound/devices
        snd_minor_info_oss_init() < 0 ||
        snd_card_info_init() < 0 ||        //5、创建 file: /proc/asound/cards
        snd_info_minor_register() < 0)
        goto error;
    return 0;

 error:
    snd_info_free_entry(snd_proc_root);
    return -ENOMEM;
}

查看时钟clk summary

查询音频时钟,确认时钟设置正确 示例:查询 i2s0 mclk 频率,以及其所在的 pll,结果:mclk 为 12288000 Hz,pll 源为 cpll

cat /sys/kernel/debug/clk/clk_summary | egrep "i2s0|pll"
pll_cpll 1 1 0 500000000
cpll 5 10 0 500000000
mclk_i2s0_rx_div 0 0 0 500000000
mclk_i2s0_rx_fracdiv 0 0 0 12288000
mclk_i2s0_rx_mux 0 0 0 12288000
mclk_i2s0_rx 0 0 0 12288000
mclk_i2s0_tx_div 1 1 0 500000000
mclk_i2s0_tx_fracdiv 1 1 0 12288000
mclk_i2s0_tx_mux 1 1 0 12288000
mclk_i2s0_tx 1 1 0 12288000
mclk_i2s0_tx_out2io 2 2 0 12288000

2.  寄存器

io命令

通过 io 命令 查看修改寄存器(适合 SOC 寄存器查询),配合芯片手册确认配置以及工作状态。

# cat /proc/iomem | grep i2s
ff800000-ff800fff : i2s@ff800000
# #
io -4 -l 0x40 0xff800000
ff800000: 7200000f 004e000f 10003f3f 00000010
ff800010: 000f0110 01f00000 00000000 00000003
ff800020: 00000000 00000000 00000000 0000001f
ff800030: 00003eff 00003eff 00000303 20150001

regmap

通过 regmap 节点查看寄存器(只读)。

rk3568_r:/ # cat /sys/kernel/debug/regmap/0-0020-rk817-codec/name
cat /sys/kernel/debug/regmap/0-0020-rk817-codec/name                            
rk808

## rk3568 i2s0控制器寄存器
rk3568_r: # cat /sys/kernel/debug/regmap/fe400000.i2s/registers
cat /sys/kernel/debug/regmap/fe400000.i2s/registers                                                                  
00: 7200000f
04: 01c8000f
08: 00001f1f
0c: XXXXXXXX
10: 000f0010
14: 01f00000
18: XXXXXXXX
1c: 00000000
20: XXXXXXXX
24: XXXXXXXX
2c: XXXXXXXX
30: 00003eff
34: 00003eff
38: 00000707


## codec es809寄存器

rk3568_r:/ # cat /sys/kernel/debug/regmap/0-0020-rk817-codec/registers
cat /sys/kernel/debug/regmap/0-0020-rk817-codec/registers    
00: 00
01: 00
02: 00
03: 00
04: 00
05: 00
06: 00
07: 00
08: 00
09: 00
0a: 00
0b: 00
0c: 00
0d: 00
0e: 00
0f: 00
10: 00
11: 00
12: 03
13: f4
14: 00
# ls /sys/kernel/debug/regmap/
0-0020-rk817-codec
ff800000.i2s
...
# cat /sys/kernel/debug/regmap/0-0020-rk817-codec/registers
12: 03
13: f4
14: 00
15: ff
16: 00
17: 40
18: 48
19: 00
1a: 00
1b: ff
1c: 00
1d: 00
1e: 02
1f: 00
...

注意: regmap 基于 cache 机制,如果通过 io 命令直接修改寄存器后, regmap 节点不会体现更新后的寄存器,除非驱动将寄存器类型设置为 volatile 或者将 regmap cache 关闭。

3. alsa-utils

瑞芯微的android版本的sdk中不支持aplay、arecord、amixer这组命令,下面是以复旦微厂家sdk举例。

官方sdk的buildroot目录下执行make menuconfig:

  │ Symbol: BR2_PACKAGE_ALSA_UTILS_APLAY [=y]            │  
  │ Type  : boolean                                      │  
  │ Prompt: aplay/arecord                                │  
  │   Location:                                          │  
  │     -> Target packages                               │  
  │       -> Audio and video applications                │  
  │ (1)     -> alsa-utils (BR2_PACKAGE_ALSA_UTILS [=y])  │  
  │   Defined at package/alsa-utils/Config.in:57         │  
  │   Depends on: BR2_PACKAGE_ALSA_UTILS [=y]            │  
  │   Selects: BR2_PACKAGE_ALSA_LIB_PCM [=y]



aplay

Usage: aplay [OPTION]... [FILE]...

-h, --help              help
    --version           print current version
-l, --list-devices      list all soundcards and digital audio devices
-L, --list-pcms         list device names
-D, --device=NAME       select PCM by name
-q, --quiet             quiet mode
-t, --file-type TYPE    file type (voc, wav, raw or au)
-c, --channels=#        channels
-f, --format=FORMAT     sample format (case insensitive)
-r, --rate=#            sample rate
-d, --duration=#        interrupt after # seconds
-M, --mmap              mmap stream
-N, --nonblock          nonblocking mode
-F, --period-time=#     distance between interrupts is # microseconds
-B, --buffer-time=#     buffer duration is # microseconds
    --period-size=#     distance between interrupts is # frames
    --buffer-size=#     buffer duration is # frames
-A, --avail-min=#       min available space for wakeup is # microseconds
-R, --start-delay=#     delay for automatic PCM start is # microseconds 
                        (relative to buffer size if <= 0)
-T, --stop-delay=#      delay for automatic PCM stop is # microseconds from xrun
-v, --verbose           show PCM structure and setup (accumulative)
-V, --vumeter=TYPE      enable VU meter (TYPE: mono or stereo)
-I, --separate-channels one file for each channel
-i, --interactive       allow interactive operation from stdin
-m, --chmap=ch1,ch2,..  Give the channel map to override or follow
    --disable-resample  disable automatic rate resample
    --disable-channels  disable automatic channel conversions
    --disable-format    disable automatic format conversions
    --disable-softvol   disable software volume control (softvol)
    --test-position     test ring buffer position
    --test-coef=#       test coefficient for ring buffer position (default 8)
                        expression for validation is: coef * (buffer_size / 2)
    --test-nowait       do not wait for ring buffer - eats whole CPU
    --max-file-time=#   start another output file when the old file has recorded
                        for this many seconds
    --process-id-file   write the process ID here
    --use-strftime      apply the strftime facility to the output file name
    --dump-hw-params    dump hw_params of the device
    --fatal-errors      treat all errors as fatal

示例:通过声卡0   播放   48k 采样率   2声道 16 位的静音数据

aplay -D hw:0,0 --period-size=1024 --buffer-size=4096 -r 48000 -c 2 -f s16_le
/dev/zero

arecord

Usage: arecord [OPTION]... [FILE]...

-h, --help              help
    --version           print current version
-l, --list-devices      list all soundcards and digital audio devices
-L, --list-pcms         list device names
-D, --device=NAME       select PCM by name
-q, --quiet             quiet mode
-t, --file-type TYPE    file type (voc, wav, raw or au)
-c, --channels=#        channels
-f, --format=FORMAT     sample format (case insensitive)
-r, --rate=#            sample rate
-d, --duration=#        interrupt after # seconds
-M, --mmap              mmap stream
-N, --nonblock          nonblocking mode
-F, --period-time=#     distance between interrupts is # microseconds
-B, --buffer-time=#     buffer duration is # microseconds
    --period-size=#     distance between interrupts is # frames
    --buffer-size=#     buffer duration is # frames
-A, --avail-min=#       min available space for wakeup is # microseconds
-R, --start-delay=#     delay for automatic PCM start is # microseconds 
                        (relative to buffer size if <= 0)
-T, --stop-delay=#      delay for automatic PCM stop is # microseconds from xrun
-v, --verbose           show PCM structure and setup (accumulative)
-V, --vumeter=TYPE      enable VU meter (TYPE: mono or stereo)
-I, --separate-channels one file for each channel
-i, --interactive       allow interactive operation from stdin
-m, --chmap=ch1,ch2,..  Give the channel map to override or follow
    --disable-resample  disable automatic rate resample
    --disable-channels  disable automatic channel conversions
    --disable-format    disable automatic format conversions
    --disable-softvol   disable software volume control (softvol)
    --test-position     test ring buffer position
    --test-coef=#       test coefficient for ring buffer position (default 8)
                        expression for validation is: coef * (buffer_size / 2)
    --test-nowait       do not wait for ring buffer - eats whole CPU
    --max-file-time=#   start another output file when the old file has recorded
                        for this many seconds
    --process-id-file   write the process ID here
    --use-strftime      apply the strftime facility to the output file name
    --dump-hw-params    dump hw_params of the device
    --fatal-errors      treat all errors as fatal

示例:通过声卡0 录制 16k 采样率 8声道 32 位 的音频数据

arecord -D hw:0,0 --period-size=1024 --buffer-size=4096 -r 16000 -c 8 -f s32_le
r.wav

aplay | arecord

两者通过管道可以方便的实现 loopback 功能,方便驱动调试和指标测试。示例:声卡0 录制 -> 声卡1 播放

# arecord -D hw:0,0 --period-size=1024 --buffer-size=4096 -r 48000 -c 2 -f s16_le
-t raw | aplay -D hw:1,0 --period-size=1024 --buffer-size=4096 -r 48000 -c 2 -f
s16_le -t raw

amixer

控制 codec 内部的通路开关,结合 codec 手册的音频拓扑图(比如 图 3-2 RK3308 codec)实现音频流的 路由,音量控制等

Usage: amixer  [command]

Available options:
  -h,--help       this help
  -c,--card N     select the card
  -D,--device N   select the device, default 'default'
  -d,--debug      debug mode
  -n,--nocheck    do not perform range checking
  -v,--version    print version of this program
  -q,--quiet      be quiet
  -i,--inactive   show also inactive controls
  -a,--abstract L select abstraction level (none or basic)
  -s,--stdin      Read and execute commands from stdin sequentially
  -R,--raw-volume Use the raw value (default)
  -M,--mapped-volume Use the mapped volume

Available commands:
  scontrols       show all mixer simple controls
  scontents   show contents of all mixer simple controls (default command)
  sset sID P      set contents for one mixer simple control
  sget sID        get contents for one mixer simple control
  controls        show all controls for given card
  contents        show contents of all controls for given card
  cset cID P      set control contents for one control
  cget cID        get control contents for one control

示例:查询声卡 controls,将播放通路切换到 SPK

# amixer -c 0 contents
numid=1,iface=MIXER,name='Playback Path'
type=ENUMERATED,access=rw------,values=1,items=11
; Item #0 'OFF'
; Item #1 'RCV'
; Item #2 'SPK'
; Item #3 'HP'
; Item #4 'HP_NO_MIC'
; Item #5 'BT'
; Item #6 'SPK_HP'
; Item #7 'RING_SPK'
; Item #8 'RING_HP'
; Item #9 'RING_HP_NO_MIC'
; Item #10 'RING_SPK_HP'
: values=0
...
# # amixer -c 0 cset numid=1 2
numid=1,iface=MIXER,name='Playback Path'
type=ENUMERATED,access=rw------,values=1,items=11
; Item #0 'OFF'
; Item #1 'RCV'
; Item #2 'SPK'
; Item #3 'HP'
; Item #4 'HP_NO_MIC'
; Item #5 'BT'
; Item #6 'SPK_HP'
; Item #7 'RING_SPK'
; Item #8 'RING_HP'
; Item #9 'RING_HP_NO_MIC'
; Item #10 'RING_SPK_HP'
: values=2

alsaloop

支持 任意声卡间的路由 支持 自适应时钟同步 自持 自适应重采样 支持 mixer controls 重定向

Usage: alsaloop [OPTION]...

-h,--help      help
-g,--config    configuration file (one line = one job specified)
-d,--daemonize daemonize the main process and use syslog for errors
-P,--pdevice   playback device
-C,--cdevice   capture device
-X,--pctl      playback ctl device
-Y,--cctl      capture ctl device
-l,--latency   requested latency in frames
-t,--tlatency  requested latency in usec (1/1000000sec)
-f,--format    sample format
-c,--channels  channels
-r,--rate      rate
-n,--resample  resample in alsa-lib
-A,--samplerate use converter (0=sincbest,1=sincmedium,2=sincfastest,
                               3=zerohold,4=linear)
-B,--buffer    buffer size in frames
-E,--period    period size in frames
-s,--seconds   duration of loop in seconds
-b,--nblock    non-block mode (very early process wakeup)
-S,--sync      sync mode(0=none,1=simple,2=captshift,3=playshift,4=samplerate,
                         5=auto)
-a,--slave     stream parameters slave mode (0=auto, 1=on, 2=off)
-T,--thread    thread number (-1 = create unique)
-m,--mixer redirect mixer, argument is:
      SRC_SLAVE_ID(PLAYBACK)[@DST_SLAVE_ID(CAPTURE)]
-O,--ossmixer rescan and redirect oss mixer, argument is:
      ALSA_ID@OSS_ID  (for example: "Master@VOLUME")
-e,--effect    apply an effect (bandpass filter sweep)
-v,--verbose   verbose mode (more -v means more verbose)
-w,--workaround use workaround (serialopen)
-U,--xrun      xrun profiling
-W,--wake      process wake timeout in ms
-z,--syslog    use syslog for errors

示例:声卡0录制的音频通过声卡1播放,同步模式采用 策略1(增加或减少采样点)

alsaloop -C hw:0,0 -P hw:1,0 -t 10000 -A 3 -S 1 -b -v

es8388播放和录音举例

/**************************************
 * 波形测试, RAW数据
 **************************************/

aplay -D hw:0,0 -f S24_LE -r 44100 -c 2 -t raw /bin/busybox & arecord -D hw:0,1 -f S24_LE -r 44100 -c 2 -d 5  record.wav
抓包, 上传record.wav到电脑,可以听见杂波

aplay -D hw:0,0 -f S24_LE -r 44100 -c 2 -t raw test.pcm & arecord -D hw:0,1 -f S24_LE -r 44100 -c 2 -d 5  record.wav
抓包, 上传record.wav到电脑,可以听见疯狂小鸟

aplay -D hw:0,0 -fS24_LE -r 44100 -c 2 -t raw /all_0x00.bin &
arecord -r 44100 -f S24_LE -c 2 -d 30 -D hw:0,1 record.wav
aplay -D hw:0,0 -fS24_LE -r 44100 -c 2 -t raw /all_0xff.bin &
arecord -r 44100 -f S24_LE -c 2 -d 30 -D hw:0,1 record.wav


aplay /test.wav &
arecord -r 44100 -f S24_LE -c 2 -d 30 -D hw:0,1 record.wav
抓包, 上传record.wav, 听见疯狂小鸟


/**************************************
 * 设置
 **************************************/

# 查看功能
amixer scontrols

# 耳机测试
amixer sset 'Headphone Playback ZC' on # 打开耳机播放 ZC
amixer sset 'Right Output Mixer PCM' on # 打开右声道
amixer sset 'Left Output Mixer PCM' on # 打开左声道
amixer sset Headphone 105,105 # 设置耳机音量
amixer sset Playback 230,230 # 设置播放音量
# 播放
aplay /opt/hardwareTest/wav/test.wav # <---------------------------------------------------

# MIC测试
#设置声卡输入捕获音量大小
amixer sset Capture 56,56
amixer sset 'ADC PCM' 200,200
#音频输入,关闭所有右声道
amixer sset 'Right Input Mixer Boost' off
amixer sset 'Right Boost Mixer RINPUT1' off
amixer sset 'Right Input Boost Mixer RINPUT1' 0
amixer sset 'Right Boost Mixer RINPUT2' off
amixer sset 'Right Input Boost Mixer RINPUT2' 0
amixer sset 'Right Boost Mixer RINPUT3' off
amixer sset 'Right Input Boost Mixer RINPUT3' 0
#音频输入,打开左声道 1 和 2,关闭 3
amixer sset 'Left Input Mixer Boost' on
amixer sset 'Left Boost Mixer LINPUT1' on
amixer sset 'Left Input Boost Mixer LINPUT1' 5
amixer sset 'Left Boost Mixer LINPUT2' on
amixer sset 'Left Input Boost Mixer LINPUT2' 3
amixer sset 'Left Boost Mixer LINPUT3' off
amixer sset 'Left Input Boost Mixer LINPUT3' 0
# 录音
arecord -r 44100 -f S24_LE -c 2 -d 10 -D hw:0,1 record.wav # <---------------------------------------------------

# Line IN 测试
#设置声卡输入捕获音量大小
amixer sset Capture 56,56
amixer sset 'ADC PCM' 200,200
#音频输入,打开左声道 3,,关闭 1 和 2
amixer sset 'Left Input Mixer Boost' on
amixer sset 'Left Boost Mixer LINPUT1' off
amixer sset 'Left Input Boost Mixer LINPUT1' 0
amixer sset 'Left Boost Mixer LINPUT2' off
amixer sset 'Left Input Boost Mixer LINPUT2' 0
amixer sset 'Left Boost Mixer LINPUT3' on
amixer sset 'Left Input Boost Mixer LINPUT3' 5
#音频输入,打开右声道 2,关闭 1 和 3
amixer sset 'Right Input Mixer Boost' on
amixer sset 'Right Boost Mixer RINPUT1' off
amixer sset 'Right Input Boost Mixer RINPUT1' 0
amixer sset 'Right Boost Mixer RINPUT2' on
amixer sset 'Right Input Boost Mixer RINPUT2' 5
amixer sset 'Right Boost Mixer RINPUT3' off
amixer sset 'Right Input Boost Mixer RINPUT3' 0

4. tiny-alsa

RK Android SDK 标配 tiny-alsa 工具。

Linux ALSA 在内核层提供了 alsa-driver,在应用层提供了 alsa-lib,应用程序只需要调用 alsa-lib 提供的 API 即可完成对底层硬件的操作。

但由于 ALSA 架构太过于庞大,对于嵌入式设备而言很多功能用不到,且会增加功耗,所以 Android 采用了精简后的 tinyalsa

Android 中使用 tinyalsa 控制管理所有模式的音频通路,也可以使用 tinyalsa 提供的工具进行查看、调试。

Tinyalsa 源码位于 android 源码目录下 external/tinyalsa,可以使用 mmm 命令编译,

mmm external/tinyalsa

编译 tinyalsa 后会生成四个小工具:

  • tinymix
  • tinyplay
  • inycap
  • inypcminfo

1) tinypcminfo

tinypcminfo 用于查看 pcm 通道的相关信息,如 PCM 采样率,Channels,采样点数等信息。

Usage: tinypcminfo [-D card] [-d device]

示例:

rk3568_r:/ # tinypcminfo -D 0
Info for card 0, device 0:

PCM out:
     Access:   0x000009
  Format[0]:   0x000444
  Format[1]:   00000000
Format Name:   S16_LE, S24_LE, S32_LE
  Subformat:   0x000001
       Rate:   min=8000Hz      max=96000Hz
   Channels:   min=2           max=8
Sample bits:   min=16          max=32
Period size:   min=8           max=65536
Period count:   min=2           max=16384

PCM in:
     Access:   0x000009
  Format[0]:   0x000444
  Format[1]:   00000000
Format Name:   S16_LE, S24_LE, S32_LE
  Subformat:   0x000001
       Rate:   min=8000Hz      max=96000Hz
   Channels:   min=2           max=8
Sample bits:   min=16          max=32
Period size:   min=8           max=65536
Period count:   min=2           max=16384

2) tinyplay

tinyplay 是一个简易的音乐播放器,一般用于播放测试。可以直接进行播放 wav 格式文件,在播放前需要先使用 tinymix 进行相关控件的设置。

Usage: tinyplay file.wav [-D card] [-d device] [-p period_size] [-n n_periods]

示例:播放src_test_xiaoniao.wav、1khz_44100_16bit.wav 音频文件

rk3568_r:/sdcard # tinyplay src_test_xiaoniao.wav
Playing sample: 2 ch, 44100 hz, 16 bit 1764000 bytes

rk3568_r:/sdcard # tinyplay 1khz_44100_16bit.wav
Playing sample: 2 ch, 44100 hz, 16 bit 15876000 bytes

3) tinycap

tinycap 是一个简易的录音软件,一般用于录音测试。

使用之前也需要先设置录音相关的控件,设置好控件后,执行 tinycap xxx.wav 即可将音频录制到 xxx.wav 中。

Usage: tinycap file.wav [-D card] [-d device] [-c channels] [-r rate] [-b bits]
[-p period_size] [-n n_periods]

示例:44.1k 采样率录制音频

# tinycap /sdcard/rec.wav -D 0 -d 0 –c 2 –r 44100 –b 16 –p 1024 –n 3

rk3568_r:/sdcard # tinycap /sdcard/rec.wav -D 0
Capturing sample: 2 ch, 44100 hz, 16 bit

4) tinymix

控制 codec 内部的通路开关, 音量控制等。效果等同于 amixer

1)tinymix 可以查看系统的音频控件,可直接执行 tinymix 进行查看;2)tinymix 可以手动设置控件的值,控件可通过 tinymix 查看,或者通过 mixer_paths.xml 查看。

usage: tinymix [-D card]

rk3568_r:/sdcard # tinymix --help
tinymix [options] [control name/#] [value to set]
    options:
    --device|-D #>   - use the given card # instead of 0.
    --all-values|-a       - show all possible values/ranges for control.
    --tabs-only|-t        - separate all output columns/values with tabs.
    --value-only|-v       - show only the value for the selected control.

示例:

rk3568_r:/sdcard # tinymix
Mixer name: 'rockchip,rk809-codec'
Number of controls: 2
ctl     type    num     name                                     value

0       ENUM    1       Playback Path                            OFF
1       ENUM    1       Capture MIC Path                         MIC OFF


rk3568_r:/sdcard # tinymix -a
Mixer name: 'rockchip,rk809-codec'
Number of controls: 2
ctl     type    num     name                   value
        range/values
0       ENUM    1       Playback Path          >OFF RCV SPK HP HP_NO_MIC BT SPK_HP RING_SPK RING_HP RING_HP_NO_MIC RING_SPK_HP
1       ENUM    1       Capture MIC Path       >MIC OFF Main Mic Hands Free Mic BT Sco Mic

5. i2c工具链

i2c工具主要用于配置codec,本文使用的是es8388,配置该芯片可以通过i2c接口。

通过 i2c tool 查看修改 codec 寄存器(适合 i2c 类型的 codec 设备),配合 codec 手册确认配置以及工作 状态。

rk3568sdk集成i2c工具链,做了精简,与其他版本工具链使用略有差别。

安装命令

apt-get update
apt-get install i2c-tools

linux版本代码下载路径:

https://mirrors.edge.kernel.org/pub/software/utils/i2c-tools/

i2cdetect

rk3568_r:/ # i2cdetect --help
usage: i2cdetect [-ary] BUS [FIRST LAST]
usage: i2cdetect -F BUS
usage: i2cdetect -l

Detect i2c devices.

-a      All addresses (0x00-0x7f rather than 0x03-0x77)
-F      Show functionality
-l      List all buses
-r      Probe with SMBus Read Byte
-y      Answer "yes" to confirmation prompts (for script use)

查询 i2c0 总线上的设备

rk3568_r:/ # i2cdetect -y 0
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- UU -- -- --
20: UU -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

i2cdump

dump 设备的所有寄存器

rk3568_r:/ # i2cdump --help
usage: i2cdump [-fy] BUS CHIP

Dump i2c registers.

-f      Force access to busy devices
-y      Answer "yes" to confirmation prompts (for script use)

示例:查询 i2c0 总线下 rk817(设备地址:0x20)的寄存器,其中 0x12 ~ 0x4f 为 codec 寄存器。

rk3568_r:/ # i2cdump -f -y 0 0x20
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f    0123456789abcdef
00: 02 00 09 04 08 17 05 00 00 00 01 01 00 01 80 00    ?.?????...??.??.
10: 00 00 03 f4 00 00 00 06 c8 00 00 00 00 00 00 00    ..??...??.......
20: 00 00 00 ff ff 00 00 70 00 66 00 00 00 00 00 0f    ...??..p.f.....?
30: 06 03 03 00 a5 02 00 00 01 ff ff 00 00 e0 0f 09    ???.??..???..???
40: 69 7f 0c 58 2d 0c 95 01 00 00 00 0f 20 00 0f 00    i??X-???...? .?.
50: 8c 00 01 00 01 b0 44 10 00 60 00 00 00 00 00 00    ?.?.??D?.`......
60: 00 00 00 00 00 00 00 00 00 00 00 00 01 00 eb 00    ............?.?.
70: 00 00 00 00 ff ff ff ff 00 01 ff ff 00 00 00 00    ....????.???....
80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
90: 60 80 e9 7f cb df a6 80 e9 00 00 00 00 00 00 00    `????????.......
a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00    ................
b0: 00 0f 0f 0f 0f 04 a4 ff ff 00 64 1c 20 64 1a 20    .????????.d? d?
c0: 64 00 00 64 1a 20 6b ff ff ff ff ff 0c 0c 0c 0c    d..d? k?????????
d0: 0c 0c 6c 6c 6c 6c 6c 6c 30 30 30 30 30 30 09 31    ??llllll000000?1
e0: 00 00 00 55 a2 c8 c5 40 00 ff 22 03 0a 80 94 0e    ...U???@.?"?????
f0: c2 ac a0 40 18 40 00 86 00 fc 00 ff 00 ff 60 00    ???@?@.?.?.?.?`.

i2cget

查询单个寄存器值

Usage: i2cget [-f] [-y] I2CBUS CHIP-ADDRESS [DATA-ADDRESS [MODE]]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
MODE is one of:
b (read byte data, default)
w (read word data)
c (write byte/read byte)
Append p for SMBus PEC

rk3568_r:/ # i2cget --help
usage: i2cget [-fy] BUS CHIP ADDR

Read an i2c register.

-f      Force access to busy devices
-y      Answer "yes" to confirmation prompts (for script use)

示例:查询 rk817 的 0x12 寄存器

rk3568_r:/ # i2cget -f -y 0 0x20 0x12
0x03

i2cset

修改单个寄存器值

Usage: i2cset [-f] [-y] [-m MASK] [-r] I2CBUS CHIP-ADDRESS DATA-ADDRESS [VALUE]
... [MODE]
I2CBUS is an integer or an I2C bus name
ADDRESS is an integer (0x03 - 0x77)
MODE is one of:
c (byte, no value)
b (byte data, default)
w (word data)
i (I2C block data)
s (SMBus block data)
Append p for SMBus PEC


rk3568_r:/ # i2cset --help
usage: i2cset [-fy] BUS CHIP ADDR VALUE... MODE

Write an i2c register. MODE is b for byte, w for 16-bit word, i for I2C block.

-f      Force access to busy devices
-y      Answer "yes" to confirmation prompts (for script use)

示例:修改 rk817(0x20) 的 0x12 寄存器,将值改为0

 rk3568_r:/ # i2cset -fy 0 0x20 0x12 0 b
 rk3568_r:/ # i2cget -f -y 0 0x20 0x12
 0x00

i2ctransfer

i2c-tools-4.0及以后版本添加了i2ctransfer命令。

i2cget和i2cset可以读写的i2c设备的寄存器地址小于0xff,即寄存器是8位地址。

如果i2c设备寄存器是16位地址,可使用i2ctransfer命令,该命令同样可用在寄存器地址是8位的设备。

1、命令

"Usage: i2ctransfer [-f] [-y] [-v] [-V] [-a] I2CBUS DESC [DATA] [DESC [DATA]]...\n"
"  I2CBUS is an integer or an I2C bus name\n"
"  DESC describes the transfer in the form: {r|w}LENGTH[@address]\n"
"    1) read/write-flag 2) LENGTH (range 0-65535, or '?')\n"
"    3) I2C address (use last one if omitted)\n"
"  DATA are LENGTH bytes for a write message. They can be shortened by a suffix:\n"
"    = (keep value constant until LENGTH)\n"
"    + (increase value by 1 until LENGTH)\n"
"    - (decrease value by 1 until LENGTH)\n"
"    p (use pseudo random generator until LENGTH with value as seed)\n\n"
"Example (bus 0, read 8 byte at offset 0x64 from EEPROM at 0x50):\n"
"  # i2ctransfer 0 w1@0x50 0x64 r8\n"
"Example (same EEPROM, at offset 0x42 write 0xff 0xfe ... 0xf0):\n"
"  # i2ctransfer 0 w17@0x50 0x42 0xff-\n");

2、用法

## 从i2c 4号总线0x38设备的0x3a01寄存器开始读16个字节的数据,w2:表示寄存器0x3a01的长度为2个字节
i2ctransfer -y -f 4 w2@0x38 0x3a 0x01 r16
## 向i2c 4号总线0x38设备的0x3a01寄存器写0x10,w3:表示寄存器0x3a01和写入值0x10的长度为3字节
i2ctransfer -y -f 4 w3@0x38 0x3a 0x01 0x10

逻辑分析仪

调试过程中,有时候我们需要抓取控制器和codec之间语音信号,并转换成语音数据,

一口君使用的是Kingst的 LA系列逻辑分析仪。

这是一款非常简单容易上手的设备,

即使新手也很容易就能上手,

比示波器好用很多。后面会单独开一篇讲解该设备如何抓取波形并转换成语音数据。抓取波形页面

end



一口Linux 


关注,回复【1024】海量Linux资料赠送

精彩文章合集

文章推荐

【专辑】ARM
【专辑】粉丝问答
【专辑】所有原创
专辑linux入门
专辑计算机网络
专辑Linux驱动
【干货】嵌入式驱动工程师学习路线
【干货】Linux嵌入式所有知识点-思维导图


一口Linux 写点代码,写点人生!
评论 (0)
  • 这款无线入耳式蓝牙耳机是长这个样子的,如下图。侧面特写,如下图。充电接口来个特写,用的是卡座卡在PCB板子上的,上下夹紧PCB的正负极,如下图。撬开耳机喇叭盖子,如下图。精致的喇叭(HY),如下图。喇叭是由电学产生声学的,具体结构如下图。电池包(AFS 451012  21 12),用黄色耐高温胶带进行包裹(安规需求),加强隔离绝缘的,如下图。451012是电池包的型号,聚合物锂电池+3.7V 35mAh,详细如下图。电路板是怎么拿出来的呢,剪断喇叭和电池包的连接线,底部抽出PCB板子
    liweicheng 2025-05-06 22:58 485浏览
  • UNISOC Miracle Gaming奇迹手游引擎亮点:• 高帧稳帧:支持《王者荣耀》等主流手游90帧高画质模式,连续丢帧率最高降低85%;• 丝滑操控:游戏冷启动速度提升50%,《和平精英》开镜开枪操作延迟降低80%;• 极速网络:专属游戏网络引擎,使《王者荣耀》平均延迟降低80%;• 智感语音:与腾讯GVoice联合,弱网环境仍能保持清晰通话;• 超高画质:游戏画质增强、超级HDR画质、游戏超分技术,优化游戏视效。全球手游市场规模日益壮大,游戏玩家对极致体验的追求愈发苛刻。紫光展锐全新U
    紫光展锐 2025-05-07 17:07 266浏览
  • 飞凌嵌入式作为龙芯合作伙伴,隆重推出FET-2K0300i-S全国产自主可控工业级核心板!FET-2K0300i-S核心板基于龙芯2K0300i工业级处理器开发设计,集成1个64位LA264处理器,主频1GHz,提供高效的计算能力;支持硬件ECC;2K0300i还具备丰富的连接接口USB、SDIO、UART、SPI、CAN-FD、Ethernet、ADC等一应俱全,龙芯2K0300i支持四路CAN-FD接口,具备良好的可靠性、实时性和灵活性,可满足用户多路CAN需求。除性价比超高的国产处理器外,
    飞凌嵌入式 2025-05-07 11:54 61浏览
  • 后摄像头是长这个样子,如下图。5孔(D-,D+,5V,12V,GND),说的是连接线的个数,如下图。4LED,+12V驱动4颗LED灯珠,给摄像头补光用的,如下图。打开后盖,发现里面有透明白胶(防水)和白色硬胶(固定),用合适的工具,清理其中的胶状物。BOT层,AN3860,Panasonic Semiconductor (松下电器)制造的,Cylinder Motor Driver IC for Video Camera,如下图。TOP层,感光芯片和广角聚焦镜头组合,如下图。感光芯片,看着是玻
    liweicheng 2025-05-07 23:55 251浏览
  • 硅二极管温度传感器是一种基于硅半导体材料特性的测温装置,其核心原理是利用硅二极管的电学参数(如正向压降或电阻)随温度变化的特性实现温度检测。以下是其工作原理、技术特点及典型应用:一、工作原理1、‌PN结温度特性‌硅二极管由PN结构成,当温度变化时,其正向电压 VF与温度呈线性负相关关系。例如,温度每升高1℃,VF约下降2 mV。2、‌电压—温度关系‌通过jing确测量正向电压的微小变化,可推算出环境温度值。部分型号(如SI410)在宽温域内(如1.4 K至475 K)仍能保持高线性度。
    锦正茂科技 2025-05-09 13:52 87浏览
  • Matter协议是一个由Amazon Alexa、Apple HomeKit、Google Home和Samsung SmartThings等全球科技巨头与CSA联盟共同制定的开放性标准,它就像一份“共生契约”,能让原本相互独立的家居生态在应用层上握手共存,同时它并非另起炉灶,而是以IP(互联网协议)为基础框架,将不同通信协议下的家居设备统一到同一套“语义规则”之下。作为应用层上的互通标准,Matter协议正在重新定义智能家居行业的运行逻辑,它不仅能向下屏蔽家居设备制造商的生态和系统,让设备、平
    华普微HOPERF 2025-05-08 11:40 237浏览
  • 温度传感器的工作原理依据其类型可分为以下几种主要形式:一、热电阻温度传感器利用金属或半导体材料的电阻值随温度变化的特性实现测温:l ‌金属热电阻‌(如铂电阻 Pt100、Pt1000):高温下电阻值呈线性增长,稳定性高,适用于工业精密测温。l ‌热敏电阻‌(NTC/PTC):NTC 热敏电阻阻值随温度升高而下降,PTC 则相反;灵敏度高但线性范围较窄,常用于电子设备温控。二、热电偶传感器基于‌塞贝克效应‌(Seebeck effect):两种不同
    锦正茂科技 2025-05-09 13:31 84浏览
  • 随着智能驾驶时代到来,汽车正转变为移动计算平台。车载AI技术对存储器提出新挑战:既要高性能,又需低功耗和车规级可靠性。贞光科技代理的紫光国芯车规级LPDDR4存储器,以其卓越性能成为国产芯片产业链中的关键一环,为智能汽车提供坚实的"记忆力"支持。作为官方授权代理商,贞光科技通过专业技术团队和完善供应链,让这款国产存储器更好地服务国内汽车厂商。本文将探讨车载AI算力需求现状及贞光科技如何通过紫光国芯LPDDR4产品满足市场需求。 车载AI算力需求激增的背景与挑战智能驾驶推动算力需求爆发式
    贞光科技 2025-05-07 16:54 183浏览
  • 二位半 5线数码管的驱动方法这个2位半的7段数码管只用5个管脚驱动。如果用常规的7段+共阳/阴则需要用10个管脚。如果把每个段看成独立的灯。5个管脚来点亮,任选其中一个作为COM端时,另外4条线可以单独各控制一个灯。所以实际上最多能驱动5*4 = 20个段。但是这里会有一个小问题。如果想点亮B1,可以让第3条线(P3)置高,P4 置低,其它阳极连P3的灯对应阴极P2 P1都应置高,此时会发现C1也会点亮。实际操作时,可以把COM端线P3设置为PP输出,其它线为OD输出。就可以单独控制了。实际的驱
    southcreek 2025-05-07 15:06 369浏览
  • 文/郭楚妤编辑/cc孙聪颖‍相较于一众措辞谨慎、毫无掌舵者个人风格的上市公司财报,利亚德的财报显得尤为另类。利亚德光电集团成立于1995年,是一家以LED显示、液晶显示产品设计、生产、销售及服务为主业的高新技术企业。自2016年年报起,无论业绩优劣,董事长李军每年都会在财报末尾附上一首七言打油诗,抒发其对公司当年业绩的感悟。从“三年翻番顺大势”“智能显示我第一”“披荆斩棘幸从容”等词句中,不难窥见李军的雄心壮志。2012年,利亚德(300296.SZ)在深交所创业板上市。成立以来,该公司在细分领
    华尔街科技眼 2025-05-07 19:25 327浏览
  • 在过去的很长一段时间里,外卖市场呈现出美团和饿了么双寡头垄断的局面。美团凭借先发优势、强大的地推团队以及精细化的运营策略,在市场份额上长期占据领先地位。数据显示,截至2024年上半年,美团外卖以68.2%的市场份额领跑外卖行业,成为当之无愧的行业老大。其业务广泛覆盖,从一线城市的繁华商圈到二三线城市的大街小巷,几乎无处不在,为无数消费者提供便捷的外卖服务。饿了么作为阿里本地生活服务的重要一环,依托阿里强大的资金和技术支持,也在市场中站稳脚跟,以25.4%的份额位居第二。尽管市场份额上与美团有一定
    用户1742991715177 2025-05-06 19:43 56浏览
我要评论
0
0
点击右上角,分享到朋友圈 我知道啦
请使用浏览器分享功能 我知道啦