Skip to content

Commit 9d33cd4

Browse files
committed
feat(i2s): add bclk_div config for std mode
1 parent 7dd1f9e commit 9d33cd4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

components/esp_driver_i2s/i2s_std.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ static esp_err_t i2s_std_calculate_clock(i2s_chan_handle_t handle, const i2s_std
4343
ESP_LOGW(TAG, "the current mclk multiple cannot perform integer division (slot_num: %"PRIu32", slot_bits: %"PRIu32")", handle->total_slot, slot_bits);
4444
}
4545
} else {
46-
/* For slave mode, mclk >= bclk * 8, so fix bclk_div to 2 first */
47-
clk_info->bclk_div = 8;
46+
if (clk_cfg->bclk_div < 8) {
47+
ESP_LOGW(TAG, "the current bclk division is too small, adjust the bclk division to 8");
48+
clk_info->bclk_div = 8;
49+
} else {
50+
clk_info->bclk_div = clk_cfg->bclk_div;
51+
}
4852
clk_info->bclk = rate * handle->total_slot * slot_bits;
4953
clk_info->mclk = clk_info->bclk * clk_info->bclk_div;
5054
}

components/esp_driver_i2s/include/driver/i2s_std.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ extern "C" {
204204
.sample_rate_hz = rate, \
205205
.clk_src = I2S_CLK_SRC_DEFAULT, \
206206
.mclk_multiple = I2S_MCLK_MULTIPLE_256, \
207+
.bclk_div = 8, \
207208
}
208209
#else
209210
/**
@@ -217,6 +218,7 @@ extern "C" {
217218
.clk_src = I2S_CLK_SRC_DEFAULT, \
218219
.ext_clk_freq_hz = 0, \
219220
.mclk_multiple = I2S_MCLK_MULTIPLE_256, \
221+
.bclk_div = 8, \
220222
}
221223
#endif
222224

@@ -265,6 +267,7 @@ typedef struct {
265267
* but please set this field a multiple of `3` (like 384) when using 24-bit data width,
266268
* otherwise the sample rate might be inaccurate
267269
*/
270+
uint32_t bclk_div; /*!< The division from MCLK to BCLK, only take effect for slave role, it shouldn't be smaller than 8. Increase this field when data sent by slave lag behind */
268271
} i2s_std_clk_config_t;
269272

270273
/**

0 commit comments

Comments
 (0)