esp-adf icon indicating copy to clipboard operation
esp-adf copied to clipboard

How can I reuse the i2s_chan_handle_t rx_handle elsewhere after initializing it using i2s_stream_init from audio_stream? (AUD-6460)

Open skipify opened this issue 6 months ago • 3 comments

After using i2s_stream_init, I found that the I2S driver gets installed and stored in the static variable static struct i2s_key_slot_s i2s_key_slot[SOC_I2S_NUM];. At this point, if I want to reuse the I2S driver elsewhere—for example, when using audio_codec_new_i2s_data, which requires passing the following structure:

typedef struct {
    uint8_t port;      /*!< I2S port, this port needs to be pre-installed by other modules */
    void   *rx_handle; /*!< I2S RX handle, required in IDF 5.x */
    void   *tx_handle; /*!< I2S TX handle, required in IDF 5.x */
} audio_codec_i2s_cfg_t;

—I can directly retrieve the corresponding handle.

I’m thinking of adding the following functions to i2s_stream:

i2s_chan_handle_t i2s_stream_get_rx_handle(int port) {
    return i2s_key_slot[port].rx_handle;
}

i2s_chan_handle_t i2s_stream_get_tx_handle(int port) {
    return i2s_key_slot[port].tx_handle;
}

Are there any other ways to initialize audio_codec_new_i2s_data? I would appreciate your guidance.

skipify avatar Jun 20 '25 03:06 skipify

After initializing the I2S stream, if you need to reuse the same I2S interface (e.g., with audio_codec_new_i2s_data), you can simply pass the handles through the audio_codec_i2s_cfg_t structure. If you choose to access the handles directly (e.g., via static variable indexing), consider adding locks to prevent data corruption.

520lbl avatar Jun 25 '25 07:06 520lbl

After initializing the I2S stream, if you need to reuse the same I2S interface (e.g., with audio_codec_new_i2s_data), you can simply pass the handles through the audio_codec_i2s_cfg_t structure. If you choose to access the handles directly (e.g., via static variable indexing), consider adding locks to prevent data corruption.

@520lbl Thank you very much for your reply. However, after initializing with i2s_stream, how can I retrieve the handle? I couldn’t find a method to get the handle within i2s_stream.

skipify avatar Jun 25 '25 08:06 skipify

To reuse the I2S interface, configure the audio_codec_i2s_cfg_t structure with the same i2s_port value as your i2s_stream initialization.

520lbl avatar Jul 07 '25 10:07 520lbl