Skip to content

Commit c0ab63c

Browse files
committed
fix(i2s): fixed incorrect logic in slot reconfig
Closes #15256
1 parent 8095079 commit c0ab63c

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

components/esp_driver_i2s/i2s_pdm.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ static esp_err_t i2s_pdm_tx_set_slot(i2s_chan_handle_t handle, const i2s_pdm_tx_
126126
/* Update the mode info: slot configuration */
127127
i2s_pdm_tx_config_t *pdm_tx_cfg = (i2s_pdm_tx_config_t *)handle->mode_info;
128128
memcpy(&(pdm_tx_cfg->slot_cfg), slot_cfg, sizeof(i2s_pdm_tx_slot_config_t));
129+
/* Update the slot bit width to the actual slot bit width */
130+
pdm_tx_cfg->slot_cfg.slot_bit_width = (int)pdm_tx_cfg->slot_cfg.slot_bit_width < (int)pdm_tx_cfg->slot_cfg.data_bit_width ?
131+
pdm_tx_cfg->slot_cfg.data_bit_width : pdm_tx_cfg->slot_cfg.slot_bit_width;
129132

130133
portENTER_CRITICAL(&g_i2s.spinlock);
131134
/* Configure the hardware to apply PDM format */
@@ -311,7 +314,7 @@ esp_err_t i2s_channel_reconfig_pdm_tx_slot(i2s_chan_handle_t handle, const i2s_p
311314

312315
/* If the slot bit width changed, then need to update the clock */
313316
uint32_t slot_bits = slot_cfg->slot_bit_width == I2S_SLOT_BIT_WIDTH_AUTO ? slot_cfg->data_bit_width : slot_cfg->slot_bit_width;
314-
if (pdm_tx_cfg->slot_cfg.slot_bit_width == slot_bits) {
317+
if (pdm_tx_cfg->slot_cfg.slot_bit_width != slot_bits) {
315318
ESP_GOTO_ON_ERROR(i2s_pdm_tx_set_clock(handle, &pdm_tx_cfg->clk_cfg), err, TAG, "update clock failed");
316319
}
317320

@@ -438,6 +441,9 @@ static esp_err_t i2s_pdm_rx_set_slot(i2s_chan_handle_t handle, const i2s_pdm_rx_
438441
/* Update the mode info: slot configuration */
439442
i2s_pdm_rx_config_t *pdm_rx_cfg = (i2s_pdm_rx_config_t *)handle->mode_info;
440443
memcpy(&(pdm_rx_cfg->slot_cfg), slot_cfg, sizeof(i2s_pdm_rx_slot_config_t));
444+
/* Update the slot bit width to the actual slot bit width */
445+
pdm_rx_cfg->slot_cfg.slot_bit_width = (int)pdm_rx_cfg->slot_cfg.slot_bit_width < (int)pdm_rx_cfg->slot_cfg.data_bit_width ?
446+
pdm_rx_cfg->slot_cfg.data_bit_width : pdm_rx_cfg->slot_cfg.slot_bit_width;
441447

442448
portENTER_CRITICAL(&g_i2s.spinlock);
443449
/* Configure the hardware to apply PDM format */
@@ -624,7 +630,7 @@ esp_err_t i2s_channel_reconfig_pdm_rx_slot(i2s_chan_handle_t handle, const i2s_p
624630

625631
/* If the slot bit width changed, then need to update the clock */
626632
uint32_t slot_bits = slot_cfg->slot_bit_width == I2S_SLOT_BIT_WIDTH_AUTO ? slot_cfg->data_bit_width : slot_cfg->slot_bit_width;
627-
if (pdm_rx_cfg->slot_cfg.slot_bit_width == slot_bits) {
633+
if (pdm_rx_cfg->slot_cfg.slot_bit_width != slot_bits) {
628634
ESP_GOTO_ON_ERROR(i2s_pdm_rx_set_clock(handle, &pdm_rx_cfg->clk_cfg), err, TAG, "update clock failed");
629635
}
630636

components/esp_driver_i2s/i2s_std.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ static esp_err_t i2s_std_set_slot(i2s_chan_handle_t handle, const i2s_std_slot_c
136136
/* Update the mode info: slot configuration */
137137
i2s_std_config_t *std_cfg = (i2s_std_config_t *)(handle->mode_info);
138138
memcpy(&(std_cfg->slot_cfg), slot_cfg, sizeof(i2s_std_slot_config_t));
139+
/* Update the slot bit width to the actual slot bit width */
140+
std_cfg->slot_cfg.slot_bit_width = (int)std_cfg->slot_cfg.slot_bit_width < (int)std_cfg->slot_cfg.data_bit_width ?
141+
std_cfg->slot_cfg.data_bit_width : std_cfg->slot_cfg.slot_bit_width;
139142

140143
return ESP_OK;
141144
}
@@ -334,7 +337,7 @@ esp_err_t i2s_channel_reconfig_std_slot(i2s_chan_handle_t handle, const i2s_std_
334337

335338
/* If the slot bit width changed, then need to update the clock */
336339
uint32_t slot_bits = slot_cfg->slot_bit_width == I2S_SLOT_BIT_WIDTH_AUTO ? slot_cfg->data_bit_width : slot_cfg->slot_bit_width;
337-
if (std_cfg->slot_cfg.slot_bit_width == slot_bits) {
340+
if (std_cfg->slot_cfg.slot_bit_width != slot_bits) {
338341
ESP_GOTO_ON_ERROR(i2s_std_set_clock(handle, &std_cfg->clk_cfg), err, TAG, "update clock failed");
339342
}
340343

components/esp_driver_i2s/i2s_tdm.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ static esp_err_t i2s_tdm_set_clock(i2s_chan_handle_t handle, const i2s_tdm_clk_c
9494

9595
/* Update the mode info: clock configuration */
9696
memcpy(&(tdm_cfg->clk_cfg), clk_cfg, sizeof(i2s_tdm_clk_config_t));
97+
/* Update the slot bit width to the actual slot bit width */
98+
tdm_cfg->slot_cfg.slot_bit_width = (int)tdm_cfg->slot_cfg.slot_bit_width < (int)tdm_cfg->slot_cfg.data_bit_width ?
99+
tdm_cfg->slot_cfg.data_bit_width : tdm_cfg->slot_cfg.slot_bit_width;
97100

98101
return ret;
99102
}
@@ -343,7 +346,7 @@ esp_err_t i2s_channel_reconfig_tdm_slot(i2s_chan_handle_t handle, const i2s_tdm_
343346

344347
/* If the slot bit width changed, then need to update the clock */
345348
uint32_t slot_bits = slot_cfg->slot_bit_width == I2S_SLOT_BIT_WIDTH_AUTO ? slot_cfg->data_bit_width : slot_cfg->slot_bit_width;
346-
if (tdm_cfg->slot_cfg.slot_bit_width == slot_bits) {
349+
if (tdm_cfg->slot_cfg.slot_bit_width != slot_bits) {
347350
ESP_GOTO_ON_ERROR(i2s_tdm_set_clock(handle, &tdm_cfg->clk_cfg), err, TAG, "update clock failed");
348351
}
349352

0 commit comments

Comments
 (0)