components/driver/i2s.c
/**
 * @brief   Set PDM mode down-sample rate
 *          In PDM RX mode, there would be 2 rounds of downsample process in hardware.
 *          In the first downsample process, the sampling number can be 16 or 8.
 *          In the second downsample process, the sampling number is fixed as 8.
 *          So the clock frequency in PDM RX mode would be (fpcm * 64) or (fpcm * 128) accordingly.
 * @note    After calling this function, it would call i2s_set_clk inside to update the clock frequency.
 *          Please call this function after I2S driver has been initialized.
 *
 * @param   i2s_num I2S device number
 * @param   downsample i2s RX down sample rate for PDM mode.
 * @return
 *     - ESP_OK Success
 *     - ESP_ERR_INVALID_ARG Parameter error
 *     - ESP_ERR_NO_MEM      Out of memory
 */
@brief   Set PDM mode down-sample rate
In PDM RX mode, there would be 2 rounds of downsample process in hardware.
In the first downsample process, the sampling number can be 16 or 8.
In the second downsample process, the sampling number is fixed as 8.
So the clock frequency in PDM RX mode would be (fpcm * 64) or (fpcm * 128) accordingly.
@note    After calling this function, it would call i2s_set_clk inside to update the clock frequency.
Please call this function after I2S driver has been initialized.

@param   i2s_num I2S device number
@param   downsample i2s RX down sample rate for PDM mode.
@return
- ESP_OK Success
- ESP_ERR_INVALID_ARG Parameter error
- ESP_ERR_NO_MEM      Out of memory
@brief Set PDM mode down - sample rate In PDM RX mode there would be 2 rounds of downsample process in hardware . In the first downsample process the sampling number can be 16 or 8 . In the second downsample process the sampling number is fixed as 8 . So the clock frequency in PDM RX mode would be ( fpcm * 64 ) or ( fpcm * 128 ) accordingly . @note After calling this function it would call i2s_set_clk inside to update the clock frequency . Please call this function after I2S driver has been initialized . @param i2s_num I2S device number @param downsample i2s RX down sample rate for PDM mode . @return - ESP_OK Success - ESP_ERR_INVALID_ARG Parameter error - ESP_ERR_NO_MEM Out of memory
esp_err_t i2s_set_pdm_rx_down_sample(i2s_port_t i2s_num, i2s_pdm_dsr_t downsample)
{
    ESP_RETURN_ON_FALSE(p_i2s[i2s_num], ESP_FAIL, TAG, "i2s has not installed yet");
    ESP_RETURN_ON_FALSE((p_i2s[i2s_num]->hal_cfg.mode & I2S_MODE_PDM), ESP_ERR_INVALID_ARG, TAG, "i2s mode is not PDM mode");
    i2s_stop(i2s_num);
    i2s_hal_set_rx_pdm_dsr(&(p_i2s[i2s_num]->hal), downsample);
    return i2s_set_clk(i2s_num, p_i2s[i2s_num]->hal_cfg.sample_rate, p_i2s[i2s_num]->hal_cfg.sample_bits, p_i2s[i2s_num]->hal_cfg.active_chan);
}
esp_err_t i2s_set_pdm_rx_down_sample ( i2s_port_t i2s_num , i2s_pdm_dsr_t downsample ) { ESP_RETURN_ON_FALSE ( p_i2s [ i2s_num ] , ESP_FAIL , TAG , " " ) ; ESP_RETURN_ON_FALSE ( ( p_i2s [ i2s_num ] -> hal_cfg . mode & I2S_MODE_PDM ) , ESP_ERR_INVALID_ARG , TAG , " " ) ; i2s_stop ( i2s_num ) ; i2s_hal_set_rx_pdm_dsr ( & ( p_i2s [ i2s_num ] -> hal ) , downsample ) ; return i2s_set_clk ( i2s_num , p_i2s [ i2s_num ] -> hal_cfg . sample_rate , p_i2s [ i2s_num ] -> hal_cfg . sample_bits , p_i2s [ i2s_num ] -> hal_cfg . active_chan ) ; }
@brief   Set PDM mode down-sample rate
          In PDM RX mode, there would be 2 rounds of downsample process in hardware.
@brief Set PDM mode down - sample rate In PDM RX mode there would be 2 rounds of downsample process in hardware .
// i2s will start in 'i2s_set_clk'