Let's configure I2S sound card and try to output some audio there.
I'm doing this on top of latest at the moment Armbian, calls itself 'Armbian 20.08.17 Buster with Linux 5.8.16-sunxi'. It's installation is covered here.
1. Get this repo
$ git clone -b H3 https://github.com/anabolyc/pcm5102a-for-armbian-orangepi-zero
$ cd pcm5102a-for-armbian-orangepi-zero
We need to add device tree overlay. It will tell linux kernel to use I2S pins not just as regular GPIOs, but as audio output device.
$ sudo armbian-add-overlay i2s-sound.dts
It will compile and add our overlay file to /boot/overlay-user folder and add user_overlays=i2s-sound recored to /boot/armbianEnv.txt file. So after reboot kernel will try to apply aout overlay. But we should not reboot just yet, since we referenced kernel module (i2s driver) that not exists yet.
Let's build it first. Since we're about to build kernel module, we need kernel headers.
$ sudo apt install build-essential linux-headers-current-sunxi
You should be able to see kernel headers present now
$ ls -al /lib/modules/$(uname -r)/build
lrwxrwxrwx 1 root root 35 Oct 20 20:15 /lib/modules/5.8.16-sunxi/build -> /usr/src/linux-headers-5.8.16-sunxi
Now lets build
$ make all make -C /lib/modules/5.8.16-sunxi/build M=/home/dronische/dev/pcm5102a-for-armbian-orangepi-zero modules make[1]: Entering directory '/usr/src/linux-headers-5.8.16-sunxi' CC [M] /home/dronische/dev/pcm5102a-for-armbian-orangepi-zero/pcm5102a.o MODPOST /home/dronische/dev/pcm5102a-for-armbian-orangepi-zero/Module.symvers CC [M] /home/dronische/dev/pcm5102a-for-armbian-orangepi-zero/pcm5102a.mod.o LD [M] /home/dronische/dev/pcm5102a-for-armbian-orangepi-zero/pcm5102a.ko make[1]: Leaving directory '/usr/src/linux-headers-5.8.16-sunxi'
If it shows success we're ready to copy kompiled module to system
$ sudo make install
sudo cp pcm5102a.ko /lib/modules/5.8.16-sunxi
sudo depmod -a
Now we ready to reboot
Let's check if kernel module loaded
$ lsmod | grep snd_soc_pcm5102 snd_soc_pcm5102a 16384 1
Let's check if card is listed
$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: I2Smaster [I2S-master], device 0: 1c22000.i2s-pcm5102a-hifi pcm5102a-hifi-0 [1c22000.i2s-pcm5102a-hifi pcm5102a-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: sun8ih3hdmi [sun8i-h3-hdmi], device 0: 1c22800.i2s-i2s-hifi i2s-hifi-0 [1c22800.i2s-i2s-hifi i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
Looks good, but we don't relly now yet if card is working, since system will output pins with data whether someone listening on the other end or not. Let's produce some sound to see if it's actually working
speaker-test -t sine -f 2500 -c 2
This works, let's do some real audio then
$ sudo apt install mpg123
...
$ mpg123 http://live.btvradio.bg/z-rock.mp3
Not sure if you hear it, bit it sounds great ;)
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.