I2C: Fix issue that pointer would be NULL if calls i2c_param first,

Closes https://github.com/espressif/esp-idf/issues/10163
This commit is contained in:
Cao Sen Miao 2023-01-04 12:12:47 +08:00
parent c948a70895
commit 467356cfcd
2 changed files with 5 additions and 2 deletions

View File

@ -756,6 +756,7 @@ esp_err_t i2c_param_config(i2c_port_t i2c_num, const i2c_config_t *i2c_conf)
return ret;
}
i2c_hw_enable(i2c_num);
i2c_hal_init(&i2c_context[i2c_num].hal, i2c_num);
I2C_ENTER_CRITICAL(&(i2c_context[i2c_num].spinlock));
i2c_ll_disable_intr_mask(i2c_context[i2c_num].hal.dev, I2C_LL_INTR_MASK);
i2c_ll_clear_intr_mask(i2c_context[i2c_num].hal.dev, I2C_LL_INTR_MASK);

View File

@ -51,8 +51,10 @@ void i2c_hal_master_init(i2c_hal_context_t *hal)
void i2c_hal_init(i2c_hal_context_t *hal, int i2c_port)
{
hal->dev = I2C_LL_GET_HW(i2c_port);
i2c_ll_enable_controller_clock(hal->dev, true);
if (hal->dev == NULL) {
hal->dev = I2C_LL_GET_HW(i2c_port);
i2c_ll_enable_controller_clock(hal->dev, true);
}
}
void i2c_hal_deinit(i2c_hal_context_t *hal)