Custom Board i2s_stream configuration - Cannot pass in custom gpio

CyborgZA
Posts: 1
Joined: Tue Jan 25, 2022 10:42 pm

Custom Board i2s_stream configuration - Cannot pass in custom gpio

Postby CyborgZA » Sun Jun 09, 2024 6:44 pm

Hi I am trying to initialize the i2c_stream by passing in my custom gpio configuration from the main code file. I have created an init function to set up the i2s config:

The problem I have is that the stream initialization fails: see LOG output:
W (1277) i2s_platform: i2s controller 0 has been occupied by i2s_driver
E (1287) i2s_common: i2s_new_channel(813): no available channel found
E (1297) i2s_std: i2s_channel_init_std_mode(202): input parameter 'handle' is NU
E (1297) I2S_STREAM_IDF5.x: I2S stream init failed


See my code below:

Code: Select all

	// Create custom i2s config
	i2s_std_config_t s1_std_cfg;
	s1_std_cfg = (i2s_std_config_t) {
        .clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(44100),
        .slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO),
        .gpio_cfg = {
                    .mclk = I2S_GPIO_UNUSED,    	// Custom gpio pin
                    .bclk =  S1_I2S_BCK_IO,			// Custom gpio pin
                    .ws = S1_I2S_WS_IO,			// Custom gpio pin
                    .dout = S1_I2S_DO_IO,			// Custom gpio pin
                    .din = I2S_GPIO_UNUSED,
                    .invert_flags = {
                        .mclk_inv = false,
                        .bclk_inv = false,
                        .ws_inv = false,
                    }
        },
    };
        // Create i2s stream to write data to DAC
     audio_element_handle_t i2s_stream_writer;
     i2s_stream_cfg_t i2s_stream_cfg = I2S_STREAM_CFG_DEFAULT();
     i2s_stream_cfg.std_cfg = s1_std_cfg;      //Here i pass in my custom i2s config before initializing the stream
     i2s_stream_cfg.type = AUDIO_STREAM_WRITER;
     i2s_stream_writer = i2s_stream_init(&i2s_stream_cfg);



it seems that this approach is not going to work as the adf explicitly gets the gpio from the "board_pins_config.h" from inside the i2s_steam code files.
In the i2s_streamidf5.c file, the function i2s_driver_startup(..) calls the function get_i2s_pins(..) which overrides what I am trying to insert. I have commented it out but still have issues with the i2s stream initialization. not sure if it is because the adf use different i2s headers?

Is there a way I can make this work without making changes to the adf code files?

migmel
Posts: 22
Joined: Wed Oct 25, 2023 9:01 am

Re: Custom Board i2s_stream configuration - Cannot pass in custom gpio

Postby migmel » Thu Jun 27, 2024 12:06 am

When you use ADF, many processes happen in the background. For example, when you call the
audio_board_init() function, codecs, adc, I2S, and i2C are initialized. So you cannot have your
custom i2s configuration using the same i2s instance that ADF is using(Problem is, ADF mostly uses
all the MCU resources).
Otherwise you will get the annoying messages:
"W (1277) i2s_platform: i2s controller 0 has been occupied by i2s_driver" and
"E (1287) i2s_common: i2s_new_channel(813): no available channel found"
So, if you actually need to use ADF, you must adapt your code to what is available, because adapting
ADF to your code will be painful and a lot of changes need to be done to the library, some of which
are not even possible because they are hidden in a static library.
Probably you will need to make small modifications to the library.
There is not other way to do it IMHO.

tank104
Posts: 6
Joined: Mon May 06, 2024 9:45 pm

Re: Custom Board i2s_stream configuration - Cannot pass in custom gpio

Postby tank104 » Tue Oct 15, 2024 6:04 pm

Did you find a solution for this?
I am having the same problem.

It seems like there should be a solution, since ESP32 apparently allows you to use any GPIO pin for I2S.

enGaryN
Posts: 3
Joined: Mon Apr 29, 2024 6:05 pm

Re: Custom Board i2s_stream configuration - Cannot pass in custom gpio

Postby enGaryN » Wed Oct 16, 2024 3:50 am

tank104 wrote:
Tue Oct 15, 2024 6:04 pm
Did you find a solution for this?
I am having the same problem.

It seems like there should be a solution, since ESP32 apparently allows you to use any GPIO pin for I2S.
You have to create custom board with your pins etc. configuration and select it in Configuration

Who is online

Users browsing this forum: No registered users and 26 guests