diff --git a/components/driver/i2s/i2s_pdm.c b/components/driver/i2s/i2s_pdm.c index 3ec4356213..856cf43a1f 100644 --- a/components/driver/i2s/i2s_pdm.c +++ b/components/driver/i2s/i2s_pdm.c @@ -103,10 +103,14 @@ static esp_err_t i2s_pdm_tx_set_slot(i2s_chan_handle_t handle, const i2s_pdm_tx_ /* Share bck and ws signal in full-duplex mode */ i2s_ll_share_bck_ws(handle->controller->hal.dev, handle->controller->full_duplex); + /* Update the mode info: slot configuration */ + i2s_pdm_tx_config_t *pdm_tx_cfg = (i2s_pdm_tx_config_t *)handle->mode_info; + memcpy(&(pdm_tx_cfg->slot_cfg), slot_cfg, sizeof(i2s_pdm_tx_slot_config_t)); + portENTER_CRITICAL(&g_i2s.spinlock); /* Configure the hardware to apply PDM format */ bool is_slave = handle->role == I2S_ROLE_SLAVE; - i2s_hal_slot_config_t *slot_hal_cfg = (i2s_hal_slot_config_t *)slot_cfg; + i2s_hal_slot_config_t *slot_hal_cfg = (i2s_hal_slot_config_t *)(&(pdm_tx_cfg->slot_cfg)); #if SOC_I2S_HW_VERSION_2 /* Times 10 to transform the float type to integer because we should avoid float type in hal */ slot_hal_cfg->pdm_tx.hp_cut_off_freq_hzx10 = (uint32_t)(slot_cfg->hp_cut_off_freq_hz * 10); @@ -114,10 +118,6 @@ static esp_err_t i2s_pdm_tx_set_slot(i2s_chan_handle_t handle, const i2s_pdm_tx_ i2s_hal_pdm_set_tx_slot(&(handle->controller->hal), is_slave, slot_hal_cfg); portEXIT_CRITICAL(&g_i2s.spinlock); - /* Update the mode info: slot configuration */ - i2s_pdm_tx_config_t *pdm_tx_cfg = (i2s_pdm_tx_config_t *)handle->mode_info; - memcpy(&(pdm_tx_cfg->slot_cfg), slot_cfg, sizeof(i2s_pdm_tx_slot_config_t)); - return ESP_OK; } @@ -389,16 +389,21 @@ static esp_err_t i2s_pdm_rx_set_slot(i2s_chan_handle_t handle, const i2s_pdm_rx_ /* Share bck and ws signal in full-duplex mode */ i2s_ll_share_bck_ws(handle->controller->hal.dev, handle->controller->full_duplex); - portENTER_CRITICAL(&g_i2s.spinlock); - /* Configure the hardware to apply PDM format */ - bool is_slave = (handle->role == I2S_ROLE_SLAVE) | handle->controller->full_duplex; - i2s_hal_pdm_set_rx_slot(&(handle->controller->hal), is_slave, (i2s_hal_slot_config_t *)slot_cfg); - portEXIT_CRITICAL(&g_i2s.spinlock); - /* Update the mode info: slot configuration */ i2s_pdm_rx_config_t *pdm_rx_cfg = (i2s_pdm_rx_config_t *)handle->mode_info; memcpy(&(pdm_rx_cfg->slot_cfg), slot_cfg, sizeof(i2s_pdm_rx_slot_config_t)); + portENTER_CRITICAL(&g_i2s.spinlock); + /* Configure the hardware to apply PDM format */ + bool is_slave = (handle->role == I2S_ROLE_SLAVE) | handle->controller->full_duplex; + i2s_hal_slot_config_t *slot_hal_cfg = (i2s_hal_slot_config_t *)(&(pdm_rx_cfg->slot_cfg)); +#if SOC_I2S_SUPPORTS_PDM_RX_HP_FILTER + /* Times 10 to transform the float type to integer because we should avoid float type in hal */ + slot_hal_cfg->pdm_rx.hp_cut_off_freq_hzx10 = (uint32_t)(slot_cfg->hp_cut_off_freq_hz * 10); +#endif + i2s_hal_pdm_set_rx_slot(&(handle->controller->hal), is_slave, slot_hal_cfg); + portEXIT_CRITICAL(&g_i2s.spinlock); + return ESP_OK; } diff --git a/components/hal/i2s_hal.c b/components/hal/i2s_hal.c index ae00f259ee..56e7e225d5 100644 --- a/components/hal/i2s_hal.c +++ b/components/hal/i2s_hal.c @@ -255,7 +255,7 @@ void i2s_hal_pdm_set_rx_slot(i2s_hal_context_t *hal, bool is_slave, const i2s_ha #if SOC_I2S_SUPPORTS_PDM_RX_HP_FILTER uint32_t param0; uint32_t param5; - s_i2s_hal_get_cut_off_coef(slot_cfg->pdm_rx.hp_cut_off_freq_hz, ¶m0, ¶m5); + s_i2s_hal_get_cut_off_coef(slot_cfg->pdm_rx.hp_cut_off_freq_hzx10, ¶m0, ¶m5); i2s_ll_rx_enable_pdm_hp_filter(hal->dev, slot_cfg->pdm_rx.hp_en); i2s_ll_rx_set_pdm_hp_filter_param0(hal->dev, param0); i2s_ll_rx_set_pdm_hp_filter_param5(hal->dev, param5); diff --git a/components/hal/include/hal/i2s_hal.h b/components/hal/include/hal/i2s_hal.h index 02e3256949..2be2180b9d 100644 --- a/components/hal/include/hal/i2s_hal.h +++ b/components/hal/include/hal/i2s_hal.h @@ -94,7 +94,7 @@ typedef struct { i2s_pdm_slot_mask_t slot_mask; /*!< Choose the slots to activate */ #if SOC_I2S_SUPPORTS_PDM_RX_HP_FILTER bool hp_en; /*!< High pass filter enable */ - float hp_cut_off_freq_hz; /*!< High pass filter cut-off frequency, range 23.3Hz ~ 185Hz, see cut-off frequency sheet above */ + uint32_t hp_cut_off_freq_hzx10; /*!< High pass filter cut-off frequency times 10, range 23.3Hz ~ 185Hz, see cut-off frequency sheet above */ uint32_t amplify_num; /*!< The amplification number of the final conversion result */ #endif // SOC_I2S_SUPPORTS_PDM_RX_HP_FILTER