BillBob728
Posts: 2
Joined: Mon Oct 06, 2014 4:53 am

Using a I2S amp and a I2S microphone together.

Wed Jul 26, 2017 5:46 am

I am trying to use an amp and microphone with a raspberry pi zero. I am able to only get one or the other working depending on which one I setup first. I think that it is because they both use dtoverlay but I am not sure. How can I switch between the two at run time so that I can be using either the amp or the microphone? Thanks.

Amp: https://learn.adafruit.com/adafruit-max ... p/overview
Mic: https://learn.adafruit.com/adafruit-i2s ... t/overview

yodakohl
Posts: 18
Joined: Sun Sep 27, 2015 6:43 pm
Location: Austria
Contact: Website

Re: Using a I2S amp and a I2S microphone together.

Thu Jul 27, 2017 2:32 pm

You can use the driver from google: dtoverlay=googlevoicehat-soundcard

HiassofT
Posts: 220
Joined: Fri Jun 30, 2017 10:07 pm
Location: Salzburg, Austria
Contact: Website

Re: Using a I2S amp and a I2S microphone together.

Fri Jul 28, 2017 9:40 am

You can do that by using the simple-audio-card driver and a dts file. Here's an example dts file that uses the generic spdif receiver and transmitter codecs:

Code: Select all

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2708";

    fragment@0 {
        target-path = "/";
        __overlay__ {
            dual_soundcard: dual-soundcard {
                compatible = "simple-audio-card";
                simple-audio-card,name = "Dual";

                status="okay";

                capture_link: simple-audio-card,dai-link@0 {
                    format = "i2s";

                    r_cpu_dai: cpu {
                        sound-dai = <&i2s>;
/* TDM slot configuration needs PR1982
   https://github.com/raspberrypi/linux/pull/1982
                        dai-tdm-slot-num = <2>;
                        dai-tdm-slot-width = <32>;
*/
                    };

                    r_codec_dai: codec {
                        sound-dai = <&codec_in>;
                    };
                };

                playback_link: simple-audio-card,dai-link@1 {
                    format = "i2s";

                    p_cpu_dai: cpu {
                        sound-dai = <&i2s>;
/* TDM slot configuration needs PR1982
   https://github.com/raspberrypi/linux/pull/1982
                        dai-tdm-slot-num = <2>;
                        dai-tdm-slot-width = <32>;
*/
                    };

                    p_codec_dai: codec {
                        sound-dai = <&codec_out>;
                    };
                };

            };
        };
        };

    fragment@1 {
        target-path = "/";
        __overlay__ {
            codec_out: spdif-transmitter {
                #address-cells = <0>;
                #size-cells = <0>;
                #sound-dai-cells = <0>;
                compatible = "linux,spdif-dit";
                status = "okay";
            };
            codec_in: spdif-receiver {
                #address-cells = <0>;
                #size-cells = <0>;
                #sound-dai-cells = <0>;
                compatible = "linux,spdif-dir";
                status = "okay";
            };
        };
    };

    fragment@2 {
        target = <&i2s>;
        __overlay__ {
            #sound-dai-cells = <0>;
            status = "okay";
            };
    };

};
This overlay creates a soundcard with 2 devices, hwX,0 for playback and hwX,1 for recording:

Code: Select all

root@rpi3:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Dual [Dual], device 0: bcm2835-i2s-dit-hifi dit-hifi-0 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
root@rpi3:~# arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Dual [Dual], device 1: bcm2835-i2s-dir-hifi dir-hifi-1 []
  Subdevices: 1/1
  Subdevice #0: subdevice #0
If your codec(s) need real drivers to work (eg to configure them via I2S/SPI), just instantiate them as usual and reference them from in sound-dai nodes.

With PR1982 (it's just been merged, but will take a few days until it's included in rpi-update kernels) you also have the possibility to configure fixed bclk rates, eg when your codec always needs 32 bits per sample, and use DSP A/B and left/right justified modes in addition to I2S.

so long,

Hias

jnickel
Posts: 1
Joined: Wed Feb 20, 2019 4:34 pm

Re: Using a I2S amp and a I2S microphone together.

Wed Feb 20, 2019 4:43 pm

I was able to get the amplifier and microphone working simultaneously by making one adjustment to the source code for the microphone device (my_loader.ko).

I think, not an expert on linux device drivers, that the id number of the amplifier and the microphone were conflicting and whichever loaded first was used and the other ignored. Once I changed the id from 0 to 1, they could both load and the error message no longer appeared.

This is the change that I made to get both working simultaneously.

Code: Select all

== OLD CODE ===
 static struct platform_device snd_rpi_simple_card_device = {
.name = "asoc-simple-card", //module alias
.id = 0,
.num_resources = 0,
.dev = { .release = &device_release_callback,
.platform_data = &snd_rpi_simple_card_info, // *HACK ALERT*
},
== MODIFIED CODE ===
.name = "asoc-simple-card", //module alias
.id = 1,
.num_resources = 0,
.dev = {
.release = &device_release_callback,
.platform_data = &snd_rpi_simple_card_info, // *HACK ALERT*
},

Return to “Interfacing (DSI, CSI, I2C, etc.)”