Now, I will output some data from I2S data line.
For simple, we do not enable any interrupt, and do not use DMA. Just put some data out.
We fill the register with a test data, for example 0x12345678.(This output is just noise, real sound data should be get from your wav file.)
Then enable I2S by the following command
Prepare LRCLK and BCLK.
./mems 0x60 0x00400098
./mems 0xa00 0x81004040
./mems 0xa24 0x0E
./mems 0xa20 0x800000aa
Put some DATA into I2S data wire.
./mems 0xa10 0x12345678
Watch the output from Logic Analyzer.
Looks like everything is alright.
Next, we should setup the I2C, to make WM8960G play the noise. 🙂
First make sure you have i2c-tools, we need command “i2cset”
WM8960G i2c interface is not standard i2c(if there is any standard 🙂 ) For most i2c chip, it is address(7bit) + write/read(1bit) + register address(8bit) + register data(8bit), so command “i2cdump” will work on such chip. Unfortunately, WM8960G is not such chip :P. Its I2C format is address(7bit) + write(1bit, write only) + register address(7bit) + register data(9bit), so we must calculate such register before we use it.
Once you setup this, WM8960 is ready to work. Check WM8960G datasheet for more details about the values.
i2cset -y 0 0x1a 0x1e 0x00
i2cset -y 0 0x1a 0x0e 0x02
i2cset -y 0 0x1a 0x08 0x05
i2cset -y 0 0x1a 0x68 0x07
i2cset -y 0 0x1a 0x6a 0x86
i2cset -y 0 0x1a 0x6c 0xc2
i2cset -y 0 0x1a 0x6e 0x26
i2cset -y 0 0x1a 0x32 0xc0
i2cset -y 0 0x1a 0x35 0xe1
i2cset -y 0 0x1a 0x5e 0x0c
i2cset -y 0 0x1a 0x45 0x00
i2cset -y 0 0x1a 0x4b 0x00
i2cset -y 0 0x1a 0x0a 0x00
i2cset -y 0 0x1a 0x05 0xf8
i2cset -y 0 0x1a 0x07 0xf8
Once you put data into register 0xa10, the headphone(left headphone connect to HP_L and GND, right headphone connect to HP_R and GND) will output some noise. The sound might be loud, be careful 🙂
If you write a simple app make it read from wav file and keep filling the register 0xa10, there will be some “music” out.
The “music” will not at good quality, due to the FIFO in RT5350 might overflow or underflow.
We must use DMA to make the music be played smoothly, but that is much much harder:
1. DMA have to enable DMA-I2S hardware interrupt, but that interrupt(id:7?) is already taken by openwrt, directly request interrupt will fail.
2. Interrupt must be used in kernel mode, so mems/memv will not work anymore, we can not peacefully play the code in user mode, but must write some “dangerous” code in kernel mode. 🙂
Next blog will be hard for new learner. Need strong linux kernel develop knowledge.