fix(i2c): Enhance lp clock source and avoid deadlock,

Closes https://github.com/espressif/esp-idf/issues/14908,
Closes https://github.com/espressif/esp-idf/issues/14906
This commit is contained in:
C.S.M
2024-11-21 11:23:15 +08:00
parent cfea4f7c98
commit d4f3c9c0d5
4 changed files with 67 additions and 1 deletions

View File

@@ -932,6 +932,19 @@ esp_err_t i2c_new_master_bus(const i2c_master_bus_config_t *bus_config, i2c_mast
}
#if SOC_LP_I2C_SUPPORTED
else {
soc_periph_lp_i2c_clk_src_t clk_srcs[] = SOC_LP_I2C_CLKS;
bool lp_clock_match = false;
for (int i = 0; i < sizeof(clk_srcs) / sizeof(clk_srcs[0]); i++) {
if ((int)clk_srcs[i] == (int)i2c_master->base->clk_src) {
/* Clock source matches. Override the source clock type with the user configured value */
lp_clock_match = true;
break;
}
}
ESP_GOTO_ON_FALSE(lp_clock_match, ESP_ERR_NOT_SUPPORTED, err, TAG, "the clock source does not support lp i2c, please check");
LP_I2C_SRC_CLK_ATOMIC() {
lp_i2c_ll_set_source_clk(hal->dev, i2c_master->base->clk_src);
}