I2S, HIFI Audio Pi Hats

Hi guys (Raxda and users),

Just got my RockPi4 up and running. I want to use it for Hifi DSP applications. I’m using the Ubuntu server image and installed ALSA and ALSA utils.

aplay -l gives me:
**** List of PLAYBACK Hardware Devices ****
card 0: rockchipes8316c [rockchip,es8316-codec], device 0: ff880000.i2s-ES8316 HiFi ES8316 HiFi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: HDMICODEC [HDMI-CODEC], device 0: ff8a0000.i2s-i2s-hifi i2s-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0

The first seems to be the onboard stereo CODEC. But I want to use my own Pi HAT with a much higher quality DAC on it. I’ve probed the I2S pins but they seem to be flatlines. So… the I2S pins on the 40 pin PI header are connected to I2S1? And the ESP CODEC is connected to I2S0?

See page 59 of the RK 3399 CODEC:
http://opensource.rock-chips.com/images/6/60/Rockchip_RK3399_Datasheet_V1.6-20170301.pdf

Cheers,

Pieter

I can see in:

…that I2S0 is indeed hardwired to the ESP CODEC by Raxda, and the RK3399 datasheet claims I2S2 is hardwired to HDMI.

Now… how to add support for a HIFI HAT? Just add the device tree config in this big .dts file? Is there a way to easily recompile the RockPi4 kernel? @jack

Rock Pi 4 is a lost opportunity regarding audio. The internal STEREO codec is hardwired to multichannel I2S0 which leaves only the STEREO I2S1 for the external header. So no multichannel audio I/O is available via I2S, forget that board. On Nano PI M4 for an example all I2S0 pins have been routed to separate GPIO1 header.

See the rockpi4b DTS for connections made on board:

@mhelin Yes, aware of that. But for me personally, stereo would be fine. So, I’m keeping my thumbs crossed. Do you have any boards (faster than pi3) that can do multichannel?

I just love it when people with little to no understanding of audio start barfing out their “knowledge”.

An i2s bus is made up out of 3 or more wires.
bit clock,
frame clock,
data1

dataN

Each data wire, according to i2s protocol specification, is capable of carrying 2 channels.
The two channels are distinguished based on state of the frame clock signal.
Clock goes up: channel 0 transmits.
Clock goes down: channel 1 transmits.

And this is where your knowledge ends.

Here is some new knowledge for you;
A 48 kHz signal, with a 16 bit sample size, and 2 channels, requires 48000 * 16 * 2 = 1.536 MHz bit clock, in the least.

So what happens if you crank the clock speed up to, say, 6 MHz?
I’ll tell you what happens: you still have your 2 channel audio, but it is in a 128 bit window, leaving 96 bits of empty space.

So think about what you can do with that, with just a little bit of modification to the protocol…

  1. Instead of the frame clock changing state at the start of each channel’s sample, just pulse the frame clock for 1 bit at the very beginning of a cycle.
  2. Now just line up 8 channels worth of data and dump it out on the line.

How do you know when one channel ends and the next begins?

  • the first channel begins with the frame clock pulse.
  • each subsequent channel begins 8 bits after the beginning of the previous channel.

This is called “TDM”, and in this mode of operation, most codec’s can handle 8 channels.

And yes, this hardware DOES support it.

@superduper This board does not support 8 channel audio I/O, check the RK3399 datasheet and schematics. I2S1 is the only I2S bus connected to the pin header. It might be possible to pinmux different signals to those pins (maybe from I2S0), don’t know.

This is what datasheet tells:

  • I2S0/I2S2 support up to 8 channels TX and 8 channels RX. I2S1 supports up to 2
    channels TX and 2 channels RX
  • I2S2 is connected to HDMI and DisplayPort internally. I2S0 and I2S1 are exposed
    for peripherals.

There is no mention on TDM support, yes I know what it means.
http://opensource.rock-chips.com/images/6/60/Rockchip_RK3399_Datasheet_V1.6-20170301.pdf

So if the chip really supports TDM over I2S1 the why do they keep it secret, why don’t they tell it.

Anyway, Nano Pi M4 (SBC) has a separate header for all I2S0 signals.

Edit:
Found another datasheet:
http://opensource.rock-chips.com/images/e/ee/Rockchip_RK3399TRM_V1.4_Part1-20170408.pdf

It documents various PCM modes which look like TDM. Anyway, none of them supports 8 channel audio input (which is my main interest). The 8 channel modes have their uses though.

Like the OP I’m interested in getting I2S1 working with stereo configuration.

So how can it be achieved?

I see that there’s hifiberry dts files.
Means stereo is supported. But Hifiberry also enable I2C pin, which isn’t necessary for connecting a DAC thru I2S. So instead of derailing this thread with multichannel, maybe a little help in how to enable the I2S1 of the header pins?

Depends on the model you are using but there will likely be an overlay in the wiki for that board.

The pinout isn’t always the same but the I2S modules are really just 3 pins (plus vcc & gnd) and not complex, often a bit more flexible due to heatsinks and often, cost less whilst still the same components.

Both use the hifiberry drivers on the pi https://learn.adafruit.com/adafruit-i2s-stereo-decoder-uda1334a/raspberry-pi-usage haven’t tried on a Radxa board but presume the same.

Often you don’t have to but one of these on in between the power lines will clean the dc power also.

Hi, can’t find overlay for a rock pi 4a i2s connection. Is there any ?

Here is overlay for another product

Any ideas what should be changed ?

Thanks!