components/driver/i2s.c
/**
 * @brief   I2S set GPIO for mclk
 *
 * @param   i2s_num     I2S device number
 * @param   gpio_num    GPIO number for mclk
 * @return
 *      - ESP_OK                Check or set success
 *      - ESP_ERR_INVALID_ARG   GPIO is not available
 */
@brief   I2S set GPIO for mclk
@param   i2s_num     I2S device number
@param   gpio_num    GPIO number for mclk
@return
- ESP_OK                Check or set success
- ESP_ERR_INVALID_ARG   GPIO is not available
@brief I2S set GPIO for mclk @param i2s_num I2S device number @param gpio_num GPIO number for mclk @return - ESP_OK Check or set success - ESP_ERR_INVALID_ARG GPIO is not available
static esp_err_t i2s_check_set_mclk(i2s_port_t i2s_num, gpio_num_t gpio_num)
{
    if (gpio_num == -1) {
        return ESP_OK;
    }
#if CONFIG_IDF_TARGET_ESP32
    ESP_RETURN_ON_FALSE((gpio_num == GPIO_NUM_0 || gpio_num == GPIO_NUM_1 || gpio_num == GPIO_NUM_3),
                        ESP_ERR_INVALID_ARG, TAG,
                        "ESP32 only support to set GPIO0/GPIO1/GPIO3 as mclk signal, error GPIO number:%d", gpio_num);
    bool is_i2s0 = i2s_num == I2S_NUM_0;
    if (gpio_num == GPIO_NUM_0) {
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0_CLK_OUT1);
        WRITE_PERI_REG(PIN_CTRL, is_i2s0 ? 0xFFF0 : 0xFFFF);
    } else if (gpio_num == GPIO_NUM_1) {
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD_CLK_OUT3);
        WRITE_PERI_REG(PIN_CTRL, is_i2s0 ? 0xF0F0 : 0xF0FF);
    } else {
        PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_U0RXD_CLK_OUT2);
        WRITE_PERI_REG(PIN_CTRL, is_i2s0 ? 0xFF00 : 0xFF0F);
    }
#else
    ESP_RETURN_ON_FALSE(GPIO_IS_VALID_GPIO(gpio_num), ESP_ERR_INVALID_ARG, TAG, "mck_io_num invalid");
    gpio_matrix_out_check_and_set(gpio_num, i2s_periph_signal[i2s_num].mck_out_sig, 0, 0);
#endif
    ESP_LOGI(TAG, "I2S%d, MCLK output by GPIO%d", i2s_num, gpio_num);
    return ESP_OK;
}
static esp_err_t i2s_check_set_mclk ( i2s_port_t i2s_num , gpio_num_t gpio_num ) { if ( gpio_num == -1 ) { return ESP_OK ; } #if CONFIG_IDF_TARGET_ESP32 ESP_RETURN_ON_FALSE ( ( gpio_num == GPIO_NUM_0 || gpio_num == GPIO_NUM_1 || gpio_num == GPIO_NUM_3 ) , ESP_ERR_INVALID_ARG , TAG , " " , gpio_num ) ; bool is_i2s0 = i2s_num == I2S_NUM_0 ; if ( gpio_num == GPIO_NUM_0 ) { PIN_FUNC_SELECT ( PERIPHS_IO_MUX_GPIO0_U , FUNC_GPIO0_CLK_OUT1 ) ; WRITE_PERI_REG ( PIN_CTRL , is_i2s0 ? 0xFFF0 : 0xFFFF ) ; } else if ( gpio_num == GPIO_NUM_1 ) { PIN_FUNC_SELECT ( PERIPHS_IO_MUX_U0TXD_U , FUNC_U0TXD_CLK_OUT3 ) ; WRITE_PERI_REG ( PIN_CTRL , is_i2s0 ? 0xF0F0 : 0xF0FF ) ; } else { PIN_FUNC_SELECT ( PERIPHS_IO_MUX_U0RXD_U , FUNC_U0RXD_CLK_OUT2 ) ; WRITE_PERI_REG ( PIN_CTRL , is_i2s0 ? 0xFF00 : 0xFF0F ) ; } #else ESP_RETURN_ON_FALSE ( GPIO_IS_VALID_GPIO ( gpio_num ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; gpio_matrix_out_check_and_set ( gpio_num , i2s_periph_signal [ i2s_num ] . mck_out_sig , 0 , 0 ) ; #endif ESP_LOGI ( TAG , " " , i2s_num , gpio_num ) ; return ESP_OK ; }
@brief   I2S set GPIO for mclk
 @param   i2s_num     I2S device number
 @param   gpio_num    GPIO number for mclk
 @return
      - ESP_OK                Check or set success
      - ESP_ERR_INVALID_ARG   GPIO is not available
@brief I2S set GPIO for mclk @param i2s_num I2S device number @param gpio_num GPIO number for mclk @return - ESP_OK Check or set success - ESP_ERR_INVALID_ARG GPIO is not available