milkv6. internal codec — mic

Article directory

  • 1. Hardware
  • 2. dts
  • 3. Configuration pin board_init
    • pin
  • 4. Makefile
  • 5. config
  • 6. Add tinyalsa
  • 7. Test results
    • 7.1 View recording device information
    • 7.2 Record audio
    • 7.3 Get the recorded device on PC
    • 7.4 Use audacity to view waveforms

1. Hardware


i2s0 – adc
i2s1–pdm
i2s3 — dace spk_en is doubtful

i2s2 – external decoder

pdm does not need to be used because the di/do of i2s1 is used to connect LEDs.
Note: Here, the signal of i2s1 and the speaker output of the internal codec multiplex a pin, and the result is given to LED.

The model number of the mic is 4015. You can search it directly on Taobao. When inserting it, align it with the ring on the board. If it is aligned, it will be positive or negative.

2.dts

duo_buildroot_sdk\duo-buildroot-sdk\build\boards\default\dts\cv180x\cv180x_base.dtsi

adc: adc@0300A100 {<!-- -->
compatible = "cvitek,cv182xaadc";
reg = <0x0 0x0300A100 0x0 0x100>;
clocks = < & amp;i2s_mclk 0>;
clock-names = "i2sclk";
clk_source = <0x04130000>; /* MCLK source is I2S3 */
};

dac: dac@0300A000 {<!-- -->
compatible = "cvitek,cv182xadac";
reg = <0x0 0x0300A000 0x0 0x100>;
clocks = < & amp;i2s_mclk 0>;
clock-names = "i2sclk";
};

pdm: pdm@0x041D0C00 {<!-- -->
compatible = "cvitek,cv1835pdm";
reg = <0x0 0x041D0C00 0x0 0x100>;
clocks = < & amp;i2s_mclk 0>;
clock-names = "i2sclk";
};

sound_adc {<!-- -->
compatible = "cvitek,cv182xa-adc";
cvi,model = "CV182XA";
cvi,card_name = "cv182xa_adc";
};

sound_dac {<!-- -->
compatible = "cvitek,cv182xa-dac";
cvi,model = "CV182XA";
cvi,card_name = "cv182xa_dac";
};

sound_PDM {<!-- -->
compatible = "cvitek,cv182x-pdm";
cvi,model = "CV182X";
cvi,card_name = "cv182x_internal_PDM";
};

cvi-pdm uses Cv1835_cv1835pdm.c
The dai_link of 182x is still an old interface and cannot be compiled.

//cv182x_cv182xpdm.c
static struct snd_soc_dai_link cv182x_pdm_dai = {<!-- -->
.name = "cv182x-i2s-pdm",
.stream_name = "cv182x-pdm",
.cpu_dai_name = "4110000.i2s",
.codec_dai_name = "cv1835pdm",
.platform_name = "4110000.i2s",
.codec_name = "41d0c00.pdm",
.ops = &cv182x_pdm_ops,
.init = cv182x_pdm_codec_init,
.dai_fmt = SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_IB_NF
| SND_SOC_DAIFMT_CBM_CFM,
};

i2s is closed by default and needs to be opened in the following file.

duo_buildroot_sdk\duo-buildroot-sdk\build\boards\default\dts\cv180x\cv180x_asic_qfn.dtsi

 /*
/delete-node/ i2s@04100000;
/delete-node/i2s@04130000;
/delete-node/i2s@04110000;
/delete-node/i2s@04120000;
*/

3. Configuration pin board_init

PINMUX_CONFIG(SPK_EN, SPK_EN);
PINMUX_CONFIG(PAD_AUD_AINL_MIC, PAD_AUD_AINL_MIC);


I have doubts. If spk_en is just a switch, where should out be? Is it LED?

pin

duo_buildroot_sdk\duo-buildroot-sdk\u-boot-2021.10\board\cvitek\cv180x
Here is the register information of the board and the interface in board_init.

#define SPK_EN__XGPIOA_15 3

#definePAD_AUD_AINL_MIC__XGPIOC_23 3
#definePAD_AUD_AINL_MIC__IIS1_BCLK 4
#define PAD_AUD_AINL_MIC__IIS2_BCLK 5
#definePAD_AUD_AINR_MIC__XGPIOC_22 3
#definePAD_AUD_AINR_MIC__IIS1_DO 4
#define PAD_AUD_AINR_MIC__IIS2_DI 5
#definePAD_AUD_AINR_MIC__IIS1_DI 6
#definePAD_AUD_AOUTL__XGPIOC_25 3
#definePAD_AUD_AOUTL__IIS1_LRCK 4
#define PAD_AUD_AOUTL__IIS2_LRCK 5
#definePAD_AUD_AOUTR__XGPIOC_24 3
#definePAD_AUD_AOUTR__IIS1_DI 4
#definePAD_AUD_AOUTR__IIS2_DO 5
#definePAD_AUD_AOUTR__IIS1_DO 6

4.makefile

Combined with the compatible in the above dts, match the corresponding driver in the code.

obj-$(CONFIG_SND_SOC_CV182XA_CV182XAADC) + = cv181x_cv181xadc.o
obj-$(CONFIG_SND_SOC_CV182XA_CV182XADAC) + = cv181x_cv181xdac.o

ifeq ($(CONFIG_SND_SOC_CV182XAADC),m)
obj-$(CONFIG_SND_SOC_CV182XAADC) + = cv182xa_ai.o
cv182xa_ai-objs + = cv181xadc.o
else
obj-$(CONFIG_SND_SOC_CV182XAADC) + = cv181xadc.o
endif

ifeq ($(CONFIG_SND_SOC_CV182XADAC),m)
obj-$(CONFIG_SND_SOC_CV182XADAC) + = cv182xa_ao.o
cv182xa_ao-objs + = cv181xdac.o
else
obj-$(CONFIG_SND_SOC_CV182XADAC) + = cv181xdac.o
endif

5.config

Open config
duo_buildroot_sdk\duo-buildroot-sdk\build\boards\cv180x\cv1800b_milkv_duo_sd\linux\cvitek_cv1800b_milkv_duo_sd_defconfig

#PDM
CONFIG_SND_SOC_CV1835PDM=y
CONFIG_SND_SOC_CV1835_CV1835PDM=y

#ADC
CONFIG_SND_SOC_CV182XAADC=y
CONFIG_SND_SOC_CV182XA_CV182XAADC=y

#DAC
CONFIG_SND_SOC_CV182XADAC=y
CONFIG_SND_SOC_CV182XA_CV182XADAC=y

Open i2s0/1/3

6. Add tinyalsa

Please refer to my other post for this, so I won’t go into details here.

7. Test results

7.1 View recording device information

[root@milkv]~# cat /proc/asound/devices
  0:[0]:control
 16: [ 0- 0]: digital audio playback
 32: [1]: control
 33: : timer
 56: [1-0]: digital audio capture
 64: [2]: control
 80: [2- 0]: digital audio playback

As shown in the figure, three pcm devices are currently supported, among which card1 device0 is the recording device, which also comes with its own mic.

7.2 Record audio

Execute the following command
tinycap: tinyalsa’s tool for recording audio
-D: card1, see the sound card information in /proc/asound/cards for details
-d: Device under the sound card, check /proc/asound/device.
-t: recording duration 5 seconds
-c: record mono, the default is dual channel

[root@milkv]~# tinycap a.wav -D 1 -d 0 -t 5 -c 1
Capturing sample: 1 ch, 48000 hz, 16 bit
Captured 241664 frames

7.3 Get the recorded device on PC

In the cmd window of the Windows computer, enter the command

/root/a.wav: Audio path for recording and storage
./: The folder path where the current cmd window is located

scp [email protected]:/root/a.wav ./

7.4 Use audacity to view waveforms

As shown in the picture, the high amplitude is the sound of me banging the table.


As shown in the picture below, this is my speaking voice, but it is obvious that the pickup is very small. Although it is posted on the device, this can be made larger by changing the gain value through tinymix.
The noise floor is very large. If you want to hear the human voice clearly, the noise floor will also be amplified simultaneously. If you need to identify it, you need to add noise reduction processing.

At this point, the recording function of the duo’s own development board is OK.