components/driver/i2s.c
/**
 * @brief   I2S DMA interrupt initialization
 * @note    I2S will use GDMA if chip supports, and the interrupt is triggered by GDMA.
 *
 * @param   i2s_num     I2S device number
 * @return
 *      - ESP_OK                    I2S DMA interrupt initialize success
 *      - ESP_ERR_NOT_FOUND         GDMA channel not found
 *      - ESP_ERR_INVALID_ARG       Invalid arguments
 *      - ESP_ERR_INVALID_STATE     GDMA state error
 */
@brief   I2S DMA interrupt initialization
@note    I2S will use GDMA if chip supports, and the interrupt is triggered by GDMA.

@param   i2s_num     I2S device number
@return
- ESP_OK                    I2S DMA interrupt initialize success
- ESP_ERR_NOT_FOUND         GDMA channel not found
- ESP_ERR_INVALID_ARG       Invalid arguments
- ESP_ERR_INVALID_STATE     GDMA state error
@brief I2S DMA interrupt initialization @note I2S will use GDMA if chip supports and the interrupt is triggered by GDMA . @param i2s_num I2S device number @return - ESP_OK I2S DMA interrupt initialize success - ESP_ERR_NOT_FOUND GDMA channel not found - ESP_ERR_INVALID_ARG Invalid arguments - ESP_ERR_INVALID_STATE GDMA state error
static esp_err_t i2s_dma_intr_init(i2s_port_t i2s_num, int intr_flag)
{
#if SOC_GDMA_SUPPORTED
    gdma_trigger_t trig = {.periph = GDMA_TRIG_PERIPH_I2S};
    switch (i2s_num) {
#if SOC_I2S_NUM > 1
    case I2S_NUM_1:
        trig.instance_id = SOC_GDMA_TRIG_PERIPH_I2S1;
        break;
#endif
    default:
        trig.instance_id = SOC_GDMA_TRIG_PERIPH_I2S0;
        break;
    }
    gdma_channel_alloc_config_t dma_cfg = {};
    if ( p_i2s[i2s_num]->hal_cfg.mode & I2S_MODE_TX) {
        dma_cfg.direction = GDMA_CHANNEL_DIRECTION_TX;
        ESP_RETURN_ON_ERROR(gdma_new_channel(&dma_cfg, &p_i2s[i2s_num]->tx_dma_chan), TAG, "Register tx dma channel error");
        ESP_RETURN_ON_ERROR(gdma_connect(p_i2s[i2s_num]->tx_dma_chan, trig), TAG, "Connect tx dma channel error");
        gdma_tx_event_callbacks_t cb = {.on_trans_eof = i2s_dma_tx_callback};
        gdma_register_tx_event_callbacks(p_i2s[i2s_num]->tx_dma_chan, &cb, p_i2s[i2s_num]);
    }
    if ( p_i2s[i2s_num]->hal_cfg.mode & I2S_MODE_RX) {
        dma_cfg.direction = GDMA_CHANNEL_DIRECTION_RX;
        ESP_RETURN_ON_ERROR(gdma_new_channel(&dma_cfg, &p_i2s[i2s_num]->rx_dma_chan), TAG, "Register rx dma channel error");
        ESP_RETURN_ON_ERROR(gdma_connect(p_i2s[i2s_num]->rx_dma_chan, trig), TAG, "Connect rx dma channel error");
        gdma_rx_event_callbacks_t cb = {.on_recv_eof = i2s_dma_rx_callback};
        gdma_register_rx_event_callbacks(p_i2s[i2s_num]->rx_dma_chan, &cb, p_i2s[i2s_num]);
    }
#else
    ESP_RETURN_ON_ERROR(esp_intr_alloc(i2s_periph_signal[i2s_num].irq, intr_flag, i2s_intr_handler_default, p_i2s[i2s_num], &p_i2s[i2s_num]->i2s_isr_handle), TAG, "Register I2S Interrupt error");
#endif 
    return ESP_OK;
}
static esp_err_t i2s_dma_intr_init ( i2s_port_t i2s_num , int intr_flag ) { #if SOC_GDMA_SUPPORTED gdma_trigger_t trig = { . periph = GDMA_TRIG_PERIPH_I2S } ; switch ( i2s_num ) { #if SOC_I2S_NUM > 1 case I2S_NUM_1 : trig . instance_id = SOC_GDMA_TRIG_PERIPH_I2S1 ; break ; #endif default : trig . instance_id = SOC_GDMA_TRIG_PERIPH_I2S0 ; break ; } gdma_channel_alloc_config_t dma_cfg = { } ; if ( p_i2s [ i2s_num ] -> hal_cfg . mode & I2S_MODE_TX ) { dma_cfg . direction = GDMA_CHANNEL_DIRECTION_TX ; ESP_RETURN_ON_ERROR ( gdma_new_channel ( & dma_cfg , & p_i2s [ i2s_num ] -> tx_dma_chan ) , TAG , " " ) ; ESP_RETURN_ON_ERROR ( gdma_connect ( p_i2s [ i2s_num ] -> tx_dma_chan , trig ) , TAG , " " ) ; gdma_tx_event_callbacks_t cb = { . on_trans_eof = i2s_dma_tx_callback } ; gdma_register_tx_event_callbacks ( p_i2s [ i2s_num ] -> tx_dma_chan , & cb , p_i2s [ i2s_num ] ) ; } if ( p_i2s [ i2s_num ] -> hal_cfg . mode & I2S_MODE_RX ) { dma_cfg . direction = GDMA_CHANNEL_DIRECTION_RX ; ESP_RETURN_ON_ERROR ( gdma_new_channel ( & dma_cfg , & p_i2s [ i2s_num ] -> rx_dma_chan ) , TAG , " " ) ; ESP_RETURN_ON_ERROR ( gdma_connect ( p_i2s [ i2s_num ] -> rx_dma_chan , trig ) , TAG , " " ) ; gdma_rx_event_callbacks_t cb = { . on_recv_eof = i2s_dma_rx_callback } ; gdma_register_rx_event_callbacks ( p_i2s [ i2s_num ] -> rx_dma_chan , & cb , p_i2s [ i2s_num ] ) ; } #else ESP_RETURN_ON_ERROR ( esp_intr_alloc ( i2s_periph_signal [ i2s_num ] . irq , intr_flag , i2s_intr_handler_default , p_i2s [ i2s_num ] , & p_i2s [ i2s_num ] -> i2s_isr_handle ) , TAG , " " ) ; #endif return ESP_OK ; }
@brief   I2S DMA interrupt initialization
 @note    I2S will use GDMA if chip supports, and the interrupt is triggered by GDMA.
@brief I2S DMA interrupt initialization @note I2S will use GDMA if chip supports and the interrupt is triggered by GDMA .
/* Set GDMA trigger module */ /* Set GDMA config */ /* Register a new GDMA tx channel */ /* Set callback function for GDMA, the interrupt is triggered by GDMA, then the GDMA ISR will call the  callback function */ /* Register a new GDMA rx channel */ /* Set callback function for GDMA, the interrupt is triggered by GDMA, then the GDMA ISR will call the  callback function */ /* Initial I2S module interrupt */ // SOC_GDMA_SUPPORTED