Merge branch 'fix/i2c_bus_handle_check' into 'master'

fix(i2c): Add bus handle check so that it will not be panic when there is no free bus

Closes IDFGH-13993 and IDFGH-13963

See merge request espressif/esp-idf!34695
pull/14315/merge
C.S.M 2024-11-07 12:21:33 +08:00
commit 269322191a
3 zmienionych plików z 8 dodań i 4 usunięć

Wyświetl plik

@ -784,8 +784,12 @@ static esp_err_t i2c_master_bus_destroy(i2c_master_bus_handle_t bus_handle)
{
ESP_RETURN_ON_FALSE(bus_handle, ESP_ERR_INVALID_ARG, TAG, "no memory for i2c master bus");
i2c_master_bus_handle_t i2c_master = bus_handle;
esp_err_t err = ESP_OK;
if (i2c_master->base) {
i2c_common_deinit_pins(i2c_master->base);
if (i2c_release_bus_handle(i2c_master->base) == ESP_OK) {
err = i2c_release_bus_handle(i2c_master->base);
}
if (err == ESP_OK) {
if (i2c_master) {
if (i2c_master->bus_lock_mux) {
vSemaphoreDeleteWithCaps(i2c_master->bus_lock_mux);

Wyświetl plik

@ -393,7 +393,7 @@ Please note that no STOP condition bit is inserted between the write and read op
};
i2c_master_dev_handle_t dev_handle;
ESP_ERROR_CHECK(i2c_master_bus_add_device(I2C_PORT_NUM_0, &dev_cfg, &dev_handle));
ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
uint8_t buf[20] = {0x20};
uint8_t buffer[2];
ESP_ERROR_CHECK(i2c_master_transmit_receive(dev_handle, buf, sizeof(buf), buffer, 2, -1));

Wyświetl plik

@ -393,7 +393,7 @@ I2C 主机写入后读取
};
i2c_master_dev_handle_t dev_handle;
ESP_ERROR_CHECK(i2c_master_bus_add_device(I2C_PORT_NUM_0, &dev_cfg, &dev_handle));
ESP_ERROR_CHECK(i2c_master_bus_add_device(bus_handle, &dev_cfg, &dev_handle));
uint8_t buf[20] = {0x20};
uint8_t buffer[2];
ESP_ERROR_CHECK(i2c_master_transmit_receive(dev_handle, buf, sizeof(buf), buffer, 2, -1));