components/driver/i2s.c
/**
 * @brief   Set gpio pins for I2S
 *
 * @param   i2s_num     I2S device number
 * @param   pin         Pin configuration
 * @return
 *      - ESP_OK                Set pin success
 *      - ESP_ERR_INVALID_ARG   GPIO is not available
 */
@brief   Set gpio pins for I2S
@param   i2s_num     I2S device number
@param   pin         Pin configuration
@return
- ESP_OK                Set pin success
- ESP_ERR_INVALID_ARG   GPIO is not available
@brief Set gpio pins for I2S @param i2s_num I2S device number @param pin Pin configuration @return - ESP_OK Set pin success - ESP_ERR_INVALID_ARG GPIO is not available
esp_err_t i2s_set_pin(i2s_port_t i2s_num, const i2s_pin_config_t *pin)
{
    ESP_RETURN_ON_FALSE((i2s_num < I2S_NUM_MAX), ESP_ERR_INVALID_ARG, TAG, "i2s_num error");
    if (pin == NULL) {
#if SOC_I2S_SUPPORTS_DAC
        return i2s_set_dac_mode(I2S_DAC_CHANNEL_BOTH_EN);
#else
        return ESP_ERR_INVALID_ARG;
#endif
    }
    ESP_RETURN_ON_FALSE((pin->bck_io_num == -1 || GPIO_IS_VALID_GPIO(pin->bck_io_num)),
                        ESP_ERR_INVALID_ARG, TAG, "bck_io_num invalid");
    ESP_RETURN_ON_FALSE((pin->ws_io_num == -1 || GPIO_IS_VALID_GPIO(pin->ws_io_num)),
                        ESP_ERR_INVALID_ARG, TAG, "ws_io_num invalid");
    ESP_RETURN_ON_FALSE((pin->data_out_num == -1 || GPIO_IS_VALID_GPIO(pin->data_out_num)),
                        ESP_ERR_INVALID_ARG, TAG, "data_out_num invalid");
    ESP_RETURN_ON_FALSE((pin->data_in_num == -1 || GPIO_IS_VALID_GPIO(pin->data_in_num)),
                        ESP_ERR_INVALID_ARG, TAG, "data_in_num invalid");
    if (p_i2s[i2s_num]->hal_cfg.mode & I2S_MODE_SLAVE) {
        if (p_i2s[i2s_num]->hal_cfg.mode & I2S_MODE_RX) {
            gpio_matrix_in_check_and_set(pin->ws_io_num, i2s_periph_signal[i2s_num].s_rx_ws_sig, 0);
            gpio_matrix_in_check_and_set(pin->bck_io_num, i2s_periph_signal[i2s_num].s_rx_bck_sig, 0);
        } else {
            gpio_matrix_in_check_and_set(pin->ws_io_num, i2s_periph_signal[i2s_num].s_tx_ws_sig, 0);
            gpio_matrix_in_check_and_set(pin->bck_io_num, i2s_periph_signal[i2s_num].s_tx_bck_sig, 0);
        }
    } else {
        ESP_RETURN_ON_ERROR(i2s_check_set_mclk(i2s_num, pin->mck_io_num), TAG, "mclk config failed");
        if (p_i2s[i2s_num]->hal_cfg.mode & I2S_MODE_TX) {
            gpio_matrix_out_check_and_set(pin->ws_io_num, i2s_periph_signal[i2s_num].m_tx_ws_sig, 0, 0);
            gpio_matrix_out_check_and_set(pin->bck_io_num, i2s_periph_signal[i2s_num].m_tx_bck_sig, 0, 0);
        } else {
            gpio_matrix_out_check_and_set(pin->ws_io_num, i2s_periph_signal[i2s_num].m_rx_ws_sig, 0, 0);
            gpio_matrix_out_check_and_set(pin->bck_io_num, i2s_periph_signal[i2s_num].m_rx_bck_sig, 0, 0);
        }
    }
    gpio_matrix_out_check_and_set(pin->data_out_num, i2s_periph_signal[i2s_num].data_out_sig, 0, 0);
    gpio_matrix_in_check_and_set(pin->data_in_num, i2s_periph_signal[i2s_num].data_in_sig, 0);
    return ESP_OK;
}
esp_err_t i2s_set_pin ( i2s_port_t i2s_num , const i2s_pin_config_t * pin ) { ESP_RETURN_ON_FALSE ( ( i2s_num < I2S_NUM_MAX ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; if ( pin == NULL ) { #if SOC_I2S_SUPPORTS_DAC return i2s_set_dac_mode ( I2S_DAC_CHANNEL_BOTH_EN ) ; #else return ESP_ERR_INVALID_ARG ; #endif } ESP_RETURN_ON_FALSE ( ( pin -> bck_io_num == -1 || GPIO_IS_VALID_GPIO ( pin -> bck_io_num ) ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; ESP_RETURN_ON_FALSE ( ( pin -> ws_io_num == -1 || GPIO_IS_VALID_GPIO ( pin -> ws_io_num ) ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; ESP_RETURN_ON_FALSE ( ( pin -> data_out_num == -1 || GPIO_IS_VALID_GPIO ( pin -> data_out_num ) ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; ESP_RETURN_ON_FALSE ( ( pin -> data_in_num == -1 || GPIO_IS_VALID_GPIO ( pin -> data_in_num ) ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; if ( p_i2s [ i2s_num ] -> hal_cfg . mode & I2S_MODE_SLAVE ) { if ( p_i2s [ i2s_num ] -> hal_cfg . mode & I2S_MODE_RX ) { gpio_matrix_in_check_and_set ( pin -> ws_io_num , i2s_periph_signal [ i2s_num ] . s_rx_ws_sig , 0 ) ; gpio_matrix_in_check_and_set ( pin -> bck_io_num , i2s_periph_signal [ i2s_num ] . s_rx_bck_sig , 0 ) ; } else { gpio_matrix_in_check_and_set ( pin -> ws_io_num , i2s_periph_signal [ i2s_num ] . s_tx_ws_sig , 0 ) ; gpio_matrix_in_check_and_set ( pin -> bck_io_num , i2s_periph_signal [ i2s_num ] . s_tx_bck_sig , 0 ) ; } } else { ESP_RETURN_ON_ERROR ( i2s_check_set_mclk ( i2s_num , pin -> mck_io_num ) , TAG , " " ) ; if ( p_i2s [ i2s_num ] -> hal_cfg . mode & I2S_MODE_TX ) { gpio_matrix_out_check_and_set ( pin -> ws_io_num , i2s_periph_signal [ i2s_num ] . m_tx_ws_sig , 0 , 0 ) ; gpio_matrix_out_check_and_set ( pin -> bck_io_num , i2s_periph_signal [ i2s_num ] . m_tx_bck_sig , 0 , 0 ) ; } else { gpio_matrix_out_check_and_set ( pin -> ws_io_num , i2s_periph_signal [ i2s_num ] . m_rx_ws_sig , 0 , 0 ) ; gpio_matrix_out_check_and_set ( pin -> bck_io_num , i2s_periph_signal [ i2s_num ] . m_rx_bck_sig , 0 , 0 ) ; } } gpio_matrix_out_check_and_set ( pin -> data_out_num , i2s_periph_signal [ i2s_num ] . data_out_sig , 0 , 0 ) ; gpio_matrix_in_check_and_set ( pin -> data_in_num , i2s_periph_signal [ i2s_num ] . data_in_sig , 0 ) ; return ESP_OK ; }
@brief   Set gpio pins for I2S
 @param   i2s_num     I2S device number
 @param   pin         Pin configuration
 @return
      - ESP_OK                Set pin success
      - ESP_ERR_INVALID_ARG   GPIO is not available
@brief Set gpio pins for I2S @param i2s_num I2S device number @param pin Pin configuration @return - ESP_OK Set pin success - ESP_ERR_INVALID_ARG GPIO is not available
/* Check validity of selected pins */ /* For "tx + rx + slave" or "rx + slave" mode, we should select RX signal index for ws and bck */ /* For "tx + slave" mode, we should select TX signal index for ws and bck */ /* mclk only available in master mode */ /* For "tx + rx + master" or "tx + master" mode, we should select TX signal index for ws and bck */ /* For "rx + master" mode, we should select RX signal index for ws and bck */ /* Set data input/ouput GPIO */