components/driver/i2s.c
/**
 * @brief   I2S check the validity of configuration
 *
 * @param   i2s_num     I2S device number
 * @param   cfg         I2S HAL configuration
 * @return
 *      - ESP_OK                I2S configuration is valid
 *      - ESP_ERR_INVALID_ARG   I2S configuration is invalid
 */
@brief   I2S check the validity of configuration
@param   i2s_num     I2S device number
@param   cfg         I2S HAL configuration
@return
- ESP_OK                I2S configuration is valid
- ESP_ERR_INVALID_ARG   I2S configuration is invalid
@brief I2S check the validity of configuration @param i2s_num I2S device number @param cfg I2S HAL configuration @return - ESP_OK I2S configuration is valid - ESP_ERR_INVALID_ARG I2S configuration is invalid
static esp_err_t i2s_check_cfg_validity(i2s_port_t i2s_num, i2s_hal_config_t *cfg)
{
#if SOC_I2S_SUPPORTS_PDM_TX || SOC_I2S_SUPPORTS_PDM_RX
    if (cfg->mode & I2S_MODE_PDM) {
        ESP_RETURN_ON_FALSE(i2s_num == I2S_NUM_0, ESP_ERR_INVALID_ARG, TAG, "I2S PDM mode only support on I2S0");
#if !SOC_I2S_SUPPORTS_PDM_TX
        ESP_RETURN_ON_FALSE(!(cfg->mode & I2S_MODE_TX), ESP_ERR_INVALID_ARG, TAG, "PDM does not support TX on this chip");
#endif 
#if !SOC_I2S_SUPPORTS_PDM_RX
        ESP_RETURN_ON_FALSE(!(cfg->mode & I2S_MODE_RX), ESP_ERR_INVALID_ARG, TAG, "PDM does not support RX on this chip");
#endif 
    }
#else
    ESP_RETURN_ON_FALSE(!(cfg->mode & I2S_MODE_PDM), ESP_ERR_INVALID_ARG, TAG, "I2S PDM mode not supported on current chip");
#endif  || SOC_I2S_SUPPORTS_PDM_RX
#if SOC_I2S_SUPPORTS_ADC || SOC_I2S_SUPPORTS_DAC
    if (cfg->mode & (I2S_MODE_ADC_BUILT_IN | I2S_MODE_DAC_BUILT_IN)) {
        ESP_RETURN_ON_FALSE(i2s_num == I2S_NUM_0, ESP_ERR_INVALID_ARG, TAG, "I2S built-in ADC/DAC only support on I2S0");
    }
#else
    ESP_RETURN_ON_FALSE((cfg->mode & I2S_MODE_TX) || (cfg->mode & I2S_MODE_RX), ESP_ERR_INVALID_ARG, TAG, "I2S no TX/RX mode selected");
    ESP_RETURN_ON_FALSE(cfg->comm_fmt && (cfg->comm_fmt < I2S_COMM_FORMAT_STAND_MAX), ESP_ERR_INVALID_ARG, TAG, "invalid communication formats");
#endif 
    return ESP_OK;
}
static esp_err_t i2s_check_cfg_validity ( i2s_port_t i2s_num , i2s_hal_config_t * cfg ) { #if SOC_I2S_SUPPORTS_PDM_TX || SOC_I2S_SUPPORTS_PDM_RX if ( cfg -> mode & I2S_MODE_PDM ) { ESP_RETURN_ON_FALSE ( i2s_num == I2S_NUM_0 , ESP_ERR_INVALID_ARG , TAG , " " ) ; #if ! SOC_I2S_SUPPORTS_PDM_TX ESP_RETURN_ON_FALSE ( ! ( cfg -> mode & I2S_MODE_TX ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; #endif #if ! SOC_I2S_SUPPORTS_PDM_RX ESP_RETURN_ON_FALSE ( ! ( cfg -> mode & I2S_MODE_RX ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; #endif } #else ESP_RETURN_ON_FALSE ( ! ( cfg -> mode & I2S_MODE_PDM ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; #endif #if SOC_I2S_SUPPORTS_ADC || SOC_I2S_SUPPORTS_DAC if ( cfg -> mode & ( I2S_MODE_ADC_BUILT_IN | I2S_MODE_DAC_BUILT_IN ) ) { ESP_RETURN_ON_FALSE ( i2s_num == I2S_NUM_0 , ESP_ERR_INVALID_ARG , TAG , " " ) ; } #else ESP_RETURN_ON_FALSE ( ( cfg -> mode & I2S_MODE_TX ) || ( cfg -> mode & I2S_MODE_RX ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; ESP_RETURN_ON_FALSE ( cfg -> comm_fmt && ( cfg -> comm_fmt < I2S_COMM_FORMAT_STAND_MAX ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; #endif return ESP_OK ; }
@brief   I2S check the validity of configuration
 @param   i2s_num     I2S device number
 @param   cfg         I2S HAL configuration
 @return
      - ESP_OK                I2S configuration is valid
      - ESP_ERR_INVALID_ARG   I2S configuration is invalid
@brief I2S check the validity of configuration @param i2s_num I2S device number @param cfg I2S HAL configuration @return - ESP_OK I2S configuration is valid - ESP_ERR_INVALID_ARG I2S configuration is invalid
/* Check PDM mode */ // SOC_I2S_SUPPORTS_PDM_TX // SOC_I2S_SUPPORTS_PDM_RX // SOC_I2S_SUPPORTS_PDM_TX || SOC_I2S_SUPPORTS_PDM_RX /* Check built-in ADC/DAC mode */ /* Check the transmit/receive mode */ /* Check communication format */ // SOC_I2S_SUPPORTS_ADC || SOC_I2S_SUPPORTS_DAC