rk3566+es7202 4mic矩阵+2回采调试记录

原理图:

三个es7202部分

rk3566的对应脚

看原理图,

rk3566 的pdm信号有四个输入:PDM_SDI0_M0、PDM_SDI1_M0、PDM_SDI2_M0、PDM_SDI3_M0

pdm有两个clk信号:PDM_CLK0_M0 PDM_CLK1_M0

我们有3个es7202,其中有4个mic,2条回采,用到SDI和CLK为DM_SDI1_M0、PDM_SDI2_M0、PDM_SDI3_M0、PDM_CLK1_M0,使用i2c4,供电3.3v

根据硬件信息修改dts:

    es7202-sound {
        compatible = "simple-audio-card";
        simple-audio-card,format = "pdm";
        simple-audio-card,name = "rockchip,es7202";
        simple-audio-card,mclk-fs = <256>;
        status = "okay";    
        simple-audio-card,cpu {
                    sound-dai = <&pdm>;
            };
        simple-audio-card,codec {
                    sound-dai = <&es7202>;
            };
    };

&i2c4 {
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&i2c4m0_xfer>;
    clock-frequency = <200000>;

    es7202: es7202@30 {
        status = "okay";
        #sound-dai-cells = <0>;
        compatible = "ES7202_PDM_ADC_1";
        reg = <0x30>;
    };

    es7202_31: es7202@31 {
        status = "okay";
        #sound-dai-cells = <0>;
        compatible = "ES7202_PDM_ADC_2";
        reg = <0x31>;
    };

    es7202_32: es7202@32 {
        status = "okay";
        #sound-dai-cells = <0>;
        compatible = "ES7202_PDM_ADC_3";
        reg = <0x32>;
    };
};

因为没有使用PDM_CLK0_M、PDM_SDI0_M0,改pdm部分

&pdm {
    status = "okay";
    #sound-dai-cells = <0>;
    rockchip,path-map = <1 2 3 0>;  //这里需要按照硬件改为对应的sdi口
    pinctrl-names = "default";
    pinctrl-0 = <&pdmm0_clk1
            &pdmm0_sdi1
            &pdmm0_sdi2
            &pdmm0_sdi3>;

修改驱动:

kernel/sound/soc/codecs/es7202.c

kernel/sound/soc/codecs/es7202.h

根据mic个数改:#define ES7202_CHANNELS_MAX     MIC_CHN_6

至此修改完成且录音正常,但我们还有录音声音太小的问题,看es7202芯片说明0x1d 0x1e是改增益的,把增益加到最大即设置为0x1c,在我们板子上加到最大仍然是录音声音太小,需要加入如下补丁使用数字增益:

hardware/rockchip/audio/tinyalsa_hal$ git diff audio_hw.c
diff --git a/tinyalsa_hal/audio_hw.c b/tinyalsa_hal/audio_hw.c
index fb1471e..3cd153c 100755
--- a/tinyalsa_hal/audio_hw.c
+++ b/tinyalsa_hal/audio_hw.c
@@ -2870,6 +2870,27 @@ static void in_apply_ramp(struct stream_in *in, int16_t *buffer, size_t frames)
     in->ramp_frames -= frames;
 }

+static void record_set_volume(void* buffer, size_t bytes, int gain)
+{
+    short *pcm_data = (short *)buffer;
+    int pcm_val;
+    int i;
+
+    for(i=0; i<(bytes/2); i++ ) {
+        pcm_val = pcm_data[i] * gain;
+        if (pcm_val < abs(32767) ) {
+            pcm_data[i] = gain * pcm_data[i];
+        }
+        else if (pcm_val > 32767) {
+            pcm_val = 32767;
+        }
+        else if (pcm_val < -32767) {
+            pcm_val = -32767
+        }
+        pcm_data[i] = pcm_val;
+    }
+}
+
 /**
  * @brief in_read
  *
@@ -2930,6 +2951,7 @@ static ssize_t in_read(struct audio_stream_in *stream, void* buffer,
         bytes = frames_rd * audio_stream_in_frame_size(stream);
     }

+    record_set_volume(buffer, bytes, 6);
     dump_in_data(buffer, bytes);
  • 15
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值