VoCore: I2S Sound Card WM8960G 2

Its time to make I2S work.

I2S contains three wires for sound:
BCLK: bit clock, basic clock for the data.
LRCLK: left channel/right channel clock.
DATA: used to send data.

My target is to enable BCLK and LRCLK, in I2S master mode.

For simple, I did not have to write a driver but directly write to register by mmap /dev/mem.

Here is a small application to make it easy.
Source Code: mems.c, memv.c
mems is used to set register, memv is used to view register.
PS: I guess there already exists tons of such tools, but I am too lazy to search, just five minutes work. 😀

Compile the source code and upload them to VoCore.

First, we should set pinmux, to make the pinmux from GPIO mode to I2S + GPIO mode.
From RT5350 datasheet, its register is 0x0060.
use memv to get it current value:

memv 0x0060 4

result:

# ./memv 0x0060 4
offset: 0x10000060, size: 0x00000004
ADDR    : +0 +1 +2 +3 +4 +5 +6 +7  +8 +9 +A +B +C +D +E +F    0123456789ABCDEF
00000000: 9C 00 40 00                                         ..@.

so it is 0x0040009C = 0000 0000 0100 0000 0000 0000 1001 1100 in binary.
4:2 bit are 111, it means UARTF_SHARE_MODE is all GPIO.
check datasheet again, I2S + GPIO is 110, so we update it to 0000 0000 0100 0000 0000 0000 1001 1000 = 0x00400098

mems 0x0060 0x00400098

Note: change 4:2 but keep all other bits.

Then, setup I2S register, update PLL to make BCLK output correct clock.
Set LRCLK to 44100Hz, so BCLK = 44100Hz x 16bits x 2channels = 1411200Hz
From datasheet FreqOut = FreqIn *(1/2) *{1 / [DIVINT+DIVCOMP/(512)]}, FreqOut = 1.4112M, FreqIn = 40M.
So DIVINT = 0x0E, DIVCOMP = 0x58, and PLL clock bit enable.

mems 0x0a20 0x80000058
memv 0x0a24 0x0000000E

Final, enable I2S, view its output.

memv 0x0a00 0x81004040

The result looks pretty well 🙂
i2s
If you do not have a logic analyzer, a voltmeter is a simple replacement. If the I2S BCLK and LRCLK output is about 1.65V(3.3V/2), that means I2S circle in VoCore is working.

Next blog I will talk about how to output some real sound data through I2S.