WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: I2S driver (C)  (Read 4831 times)

Offline masterglob

  • Newbie
  • *
  • Posts: 11
I2S driver (C)
« on: October 13, 2019, 12:26:03 PM »
Hi all,

I am new to Raspberry (3B) & tinyCore (9.x). I want to compile C/C++ application using I2C, I2S, wifi and other GPIOs. I have GCC and wifi extension  installed OK.

I already installed WiringPi (and WinringPiI2C) extension (I tested them OK with a I2C LCD display and LED/Buttons).

I would like to port a code I had on a Wemos D1 MINI using I2S interface to sound out a PCM5102 from a C application.

I found somewhere that I2S pins are:
- BCK on PIN12 = WiringPi1 = GPIO18
- LRCK on PIN 35 = WiringPi23 =GPIO19
- DATAo n PIN 40 = WiringPi29 = GPIO21

But I cannot find the I2S interface in WiringPi or anywhere... All topics deal with installation of players that seem to support I2S (which I do not want).
Where can I find the I2S Developper extension (All interfaces I need are: i2s_begin, i2s_set_rate, i2s_write_sample, i2s_get_real_rate, i2s_is_full  and  i2s_is_empty).
I do not either see any I2S-like name under "/dev"...

moreover, how would I need to set up my config.txt. The only "documented" items are (Though, I don't know what to do with them):
- dtparam=i2c=on,spi=on,i2s=on
- dtoverlay=i2s-mmap   (+i2s-gpio28-31 that I don't seem to need)
- dtparam=audio=on (?)

Thanks for help!
« Last Edit: October 13, 2019, 12:35:26 PM by masterglob »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: I2S driver (C)
« Reply #1 on: October 13, 2019, 03:26:56 PM »
Hi masterglob
You might need to install  compiletc.tcz  so you have a proper toolchain for compiling.

Offline masterglob

  • Newbie
  • *
  • Posts: 11
Re: I2S driver (C)
« Reply #2 on: October 14, 2019, 08:13:13 AM »
Hi,
Thanks for response. I already have a C compiling environment. Do you think the I2S include files will come with "compiletc.tcz"?  I can post later the list of all installed extension in my TC.

Offline masterglob

  • Newbie
  • *
  • Posts: 11
Re: I2S driver (C)
« Reply #3 on: October 14, 2019, 03:33:31 PM »
I added in my /opt/bootlocal.sh:
Code: [Select]
/sbin/modprobe snd_soc_pcm5102a

Code: [Select]
tc@wtplayer:~$ lsmod
Module                  Size  Used by    Not tainted
snd_soc_pcm5102a        2277  0
i2c_dev                 7287  0
brcmfmac              211043  0
brcmutil                9223  1 brcmfmac
cfg80211              548840  1 brcmfmac
rfkill                 21321  1 cfg80211
snd_soc_bcm2835_i2s     6347  0
snd_soc_core          177338  2 snd_soc_pcm5102a,snd_soc_bcm2835_i2s
snd_pcm_dmaengine       6034  1 snd_soc_core
snd_compress            9996  1 snd_soc_core
snd_bcm2835            23123  0
snd_pcm                97468  3 snd_soc_core,snd_pcm_dmaengine,snd_bcm2835
snd_timer              23881  1 snd_pcm
snd                    70476  5 snd_soc_core,snd_compress,snd_bcm2835,snd_pcm,snd_timer
squashfs               34499 65
zram                   23021  1
zsmalloc               18832  1 zram
i2c_bcm2835             6293  0
spi_bcm2835             7468  0
bcm2835_gpiomem         3783  0
uio_pdrv_genirq         3788  0
uio                    10425  1 uio_pdrv_genirq

Code: [Select]
tc@wtplayer:~$ aplay -l
tc@wtplayer:~$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
  Subdevices: 8/8
  Subdevice #0: subdevice #0
  Subdevice #1: subdevice #1
  Subdevice #2: subdevice #2
  Subdevice #3: subdevice #3
  Subdevice #4: subdevice #4
  Subdevice #5: subdevice #5
  Subdevice #6: subdevice #6
  Subdevice #7: subdevice #7
card 0: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
  Subdevices: 1/1
  Subdevice #0: subdevice #0


Code: [Select]
tc@wtplayer:~$ cat /proc/asound/cards
 0 [ALSA           ]: bcm2835 - bcm2835 ALSA
                      bcm2835 ALSA


Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: I2S driver (C)
« Reply #4 on: October 14, 2019, 04:10:54 PM »
Hi masterglob
... I need are: i2s_begin, i2s_set_rate, i2s_write_sample, i2s_get_real_rate, i2s_is_full  and  i2s_is_empty). ...
Those function names appear to be unique to Arduino.

Maybe Googling for:
Code: [Select]
raspberry pi alsa i2s developmentwill provide some better answers.

Offline masterglob

  • Newbie
  • *
  • Posts: 11
Re: I2S driver (C)
« Reply #5 on: October 14, 2019, 06:18:50 PM »
I already read many of these topics, however, one is interseting:

https://github.com/taylorxv/raspberry-pi-i2s-driver

However, I am stuck in step "Install Scripts" (
Quote
The next step requires that you have the kernel source...
)
The makefile calls
 
Code: [Select]
make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) modules
but I do not have any "build" folder in "/lib/modules/4.9.22-piCore-v7". And I do not understand how I should install it. It is not a TCZ? Is there any relation with http://www.tinycorelinux.net/9.x/armv7/releases/RPi/src/kernel/ ? (But once again I don't know where to unzip those files)

For information:
Code: [Select]
tc@wtplayer:~/_dev/i2s/i2s_driver_src$  tce-load -wi linux-4.9.y_api_headers
linux-4.9.y_api_headers is already installed!
 
« Last Edit: October 14, 2019, 06:26:39 PM by masterglob »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1267
Re: I2S driver (C)
« Reply #6 on: October 14, 2019, 10:08:24 PM »
There is not currently an i2s development package on tc.

But since all of the current rpi alsa/i2s based soundcards are done with kernel drivers.   I would suggest you start there.   Yes, all the files you need to build an out of tree driver are here http://www.tinycorelinux.net/9.x/armv7/releases/RPi/src/kernel/


« Last Edit: October 14, 2019, 10:12:45 PM by Paul_123 »

Offline masterglob

  • Newbie
  • *
  • Posts: 11
Re: I2S driver (C)
« Reply #7 on: October 16, 2019, 07:18:05 AM »
I see.
Thank Paul for help, but I guess that will be too complicated for me, because I never built kernel modules and have no knowledge on how to do it... The 'starting point' is really too obscure for me.
I may try to port the source code in a simple user application, but I am not sure this will be so easy and stable  (including possible timing precisions issue when not in kernel, or GPIO conflicts..)

I will try to determine what seems simplest. In the meantime, if you have any suggestions? that will be helpful.

Regards,




Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14849
Re: I2S driver (C)
« Reply #8 on: October 16, 2019, 07:46:24 AM »
Preparing the kernel source is not difficult - you can use this (from CorePure64) as an analogy:

Code: [Select]
tce-load -i compiletc perl5 bash ncursesw-dev bc glibc_apps

[configure kernel]
make mrproper
copy .config
make oldconfig

make prepare
make modules_prepare

cp Module.symvers
make SUBDIRS=scripts/mod

cd /lib/modules/4.19.10-tinycore64
sudo ln -s /usr/src/linux-4.19.10 build

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1267
Re: I2S driver (C)
« Reply #9 on: October 16, 2019, 11:30:13 AM »
Not sure what exactly you are trying to do, but it sounds like you are writing audio.   Why not just use an exiting driver that uses i2s/pcm5102a codec  (dtoverlay=hifiberry-dac)

Then just write data using alsa.

Offline masterglob

  • Newbie
  • *
  • Posts: 11
Re: I2S driver (C)
« Reply #10 on: October 16, 2019, 12:27:15 PM »
Quote
Not sure what exactly you are trying to do, but it sounds like you are writing audio.   Why not just use an exiting driver that uses i2s/pcm5102a codec  (dtoverlay=hifiberry-dac)

Yes, I want to play audio but not directly audio files. I want to send 2 different stereo streams on Jack & SPI. The two audio streams are a mix of some audio tracks in an audio file  and somedynamically generated sound...

It is not that I though ALSA does not make it possible to do this (I have nt been looking into what  we can do with it or how). The thing is that I just wanted to use my simple existing mockup code from my WEMOS...

[Edit after quick google research]
Probably ALSA is the good solution. I will study that...
« Last Edit: October 16, 2019, 12:37:11 PM by masterglob »

Offline masterglob

  • Newbie
  • *
  • Posts: 11
[SOLVED] Re: I2S driver (C)
« Reply #11 on: October 18, 2019, 05:39:48 AM »
Thank you both! :D

The easy answer was to use alsa... I did not need to build any kernel module.

Sorry again for "noob" question... I failed to find he entry point by myself :'(