本文詳細(xì)記錄在NXP I.MX6ULL+Linux平臺(tái)下進(jìn)行WM8960音頻芯片移植的過程,其他平臺(tái)操作方法類似,希望為大家提供幫助。
1.環(huán)境準(zhǔn)備
平臺(tái): HD6ULL-IOT開發(fā)板
要求:外接一個(gè)WM8960模塊。要求能正常播放音頻文件。
2.原理圖及相關(guān)資料
將模塊飛線到底板J17上,接法如下;且模塊1腳接了J17的1腳(3.3V);然后模塊的3腳(GND)接的J17的29腳地。
WM8960資料:
https://www.waveshare.net/wiki/WM8960_Audio_Board
3.內(nèi)核以及設(shè)備樹調(diào)試
內(nèi)核需要勾選WM8960相關(guān)配置,可以make menuconfig后/搜索8960然后勾上就行。
設(shè)備樹注意三點(diǎn):
①. 客戶飛線WM8960是掛載到i2c1上的。
sound { compatible = "fsl,imx6ul-evk-wm8960", "fsl,imx-audio-wm8960"; model = "wm8960-audio"; cpu-dai = <&sai2>; audio-codec = <&codec>; asrc-controller = <&asrc>; codec-master; gpr = <&gpr>; /*not support * hp-det = ; * hp-det-pin: JD1 JD2 or JD3 * hp-det-polarity = 0: hp detect high for headphone * hp-det-polarity = 1: hp detect high for speaker hp-det = <3 0>; hp-det-gpios = <&gpio5 4 0>; mic-det-gpios = <&gpio5 4 0>; */ audio-routing = "Headphone Jack", "HP_L", "Headphone Jack", "HP_R", "Ext Spk", "SPK_LP", "Ext Spk", "SPK_LN", "Ext Spk", "SPK_RP", "Ext Spk", "SPK_RN", "LINPUT2", "Mic Jack", "LINPUT3", "Mic Jack", "RINPUT1", "Main MIC", "RINPUT2", "Main MIC", "Mic Jack", "MICB", "Main MIC", "MICB", "CPU-Playback", "ASRC-Playback", "Playback", "CPU-Playback", "ASRC-Capture", "CPU-Capture", "CPU-Capture", "Capture"; }; }; &sai2 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_sai2>; assigned-clocks = <&clks IMX6UL_CLK_SAI2_SEL>, <&clks IMX6UL_CLK_SAI2>; assigned-clock-parents = <&clks IMX6UL_CLK_PLL4_AUDIO_DIV>; assigned-clock-rates = <0>, <12288000>; status = "okay"; }; pinctrl_sai2: sai2grp { fsl,pins = < MX6UL_PAD_JTAG_TDI__SAI2_TX_BCLK0x17088 MX6UL_PAD_JTAG_TDO__SAI2_TX_SYNC0x17088 MX6UL_PAD_JTAG_TRST_B__SAI2_TX_DATA0x11088 MX6UL_PAD_JTAG_TCK__SAI2_RX_DATA0x11088 MX6UL_PAD_JTAG_TMS__SAI2_MCLK0x17088 MX6UL_PAD_SNVS_TAMPER4__GPIO5_IO040x17059 >; }; &i2c1 { clock-frequency = <100000>; pinctrl-names = "default"; pinctrl-0 = <&pinctrl_i2c1>; status = "okay"; codec: wm8960@1a { compatible = "wlf,wm8960"; reg = <0x1a>; clocks = <&clks IMX6UL_CLK_SAI2>; clock-names = "mclk"; wlf,shared-lrclk; }; }; pinctrl_i2c1: i2c1grp { fsl,pins = < MX6UL_PAD_CSI_PIXCLK__I2C1_SCL 0x4001b8b0 MX6UL_PAD_CSI_MCLK__I2C1_SDA 0x4001b8b0 >; };
②. 時(shí)鐘線(SCL)和數(shù)據(jù)線(SDA)是飛線到J17的3,4腳(UART6_TXD,UART6_RXD),對(duì)應(yīng)的CSI_MCLK與CSI_PIXCLK,我們需要將其復(fù)用成I2C1_SCL,I2C1_SDA功能。(需要查詢對(duì)應(yīng)的引腳功能列表和datasheet)
pinctrl_i2c1: i2c1grp { fsl,pins = < MX6UL_PAD_CSI_PIXCLK__I2C1_SCL 0x4001b8b0 MX6UL_PAD_CSI_MCLK__I2C1_SDA 0x4001b8b0 >; };
③. 由于底板上有一個(gè)耳機(jī)接口是從核心板直接引出的,我們需要禁掉他。
sound-mqs { compatible = "fsl,imx-audio-mqs"; model = "mqs-audio"; cpu-dai = <&sai1>; asrc-controller = <&asrc>; audio-codec = <&mqs>; status = "disabled"; }; &sai1 { assigned-clocks = <&clks IMX6UL_CLK_SAI1_SEL>, <&clks IMX6UL_CLK_SAI1>; assigned-clock-parents = <&clks IMX6UL_CLK_PLL4_AUDIO_DIV>; assigned-clock-rates = <0>, <24576000>; status = "disabled"; }; &mqs { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_mqs>; clocks = <&clks IMX6UL_CLK_SAI1>; clock-names = "mclk"; status = "disabled"; };
重新編譯后替換設(shè)備樹,然后cd /home/audio ./aplay 1.wav。插上耳機(jī)或者揚(yáng)聲器即有聲音。
在調(diào)試過程中,可通過i2cdetect -y -a 0(此處wm8960掛載在i2c1)檢查音頻設(shè)備是否掛載到i2c1上,或者dmesg | grep wm8960檢查驅(qū)動(dòng)是否加載成功。
4.錄音測(cè)試
首先需要有arecord這個(gè)工具;
源碼下載網(wǎng)址:https://www.alsa-project.org/wiki/Download#alsa-lib
編譯參考網(wǎng)址:https://blog.csdn.net/gjy938815/article/details/11809269
編譯好后:alsa-utils-1.2.9\aplay 這個(gè)目錄下會(huì)生成aplay(145M),然后改名為arecord即可。
錄音播放測(cè)試:
將arecord拷貝到U盤內(nèi),依次執(zhí)行以下指令: cp /mnt/sda1/arecord /home/demo/ chmod a+x /home/demo/arecord cd /home/audio/ ./amixer cset numid=1 60 錄音功能需設(shè)置錄音控件的參數(shù) ./amixer cset numid=36 240 錄音功能需設(shè)置錄音控件的參數(shù) ./amixer cset numid=41 1 將麥克風(fēng)輸出信號(hào)同時(shí)記錄在左右聲道 cd /home/demo 執(zhí)行下面這個(gè)指令時(shí)需要對(duì)著WM8960說話,會(huì)錄音到/tmp/t.wav文件中。 錄音時(shí)間為10s ./arecord -f cd -d 10 /tmp/t.wav 播放錄音文件 (最好用耳機(jī)聽聲音) cd /home/audio/ ./aplay /tmp/t.wav
5.音量調(diào)節(jié)
控制耳機(jī)音量大小: numid=11,iface=MIXER,name='Headphone Playback Volume' ./amixer cset numid=11 80 (范圍0~127, 80合適) 控制喇叭音量大小: numid=13,iface=MIXER,name='Speaker Playback Volume' 這個(gè)配置 ./amixer cset numid=13 100 (范圍0~127,但一般100聲音就合適了) 錄音時(shí)配置: numid=36,iface=MIXER,name='ADC PCM Capture Volume' ./amixer cset numid=36 190 (錄音范圍0~255,一般190左右合適,值過大雜聲會(huì)有點(diǎn)大) numid=1,iface=MIXER,name='Capture Volume' (設(shè)置捕獲的音量) ./amixer cset numid=1 30 (范圍0~63 ,可以選擇30)
至此,我們完成移植、測(cè)試的全部工作。如您在開發(fā)過程中遇到問題,歡迎技術(shù)交流。
?
-
芯片
+關(guān)注
關(guān)注
455文章
50714瀏覽量
423136 -
NXP
+關(guān)注
關(guān)注
60文章
1278瀏覽量
184035 -
Linux
+關(guān)注
關(guān)注
87文章
11292瀏覽量
209323 -
音頻芯片
+關(guān)注
關(guān)注
3文章
130瀏覽量
17939 -
IMX6ULL
+關(guān)注
關(guān)注
3文章
16瀏覽量
4042
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論