esp-idf-lib icon indicating copy to clipboard operation
esp-idf-lib copied to clipboard

Add support for new I2C driver used in IDF 5.4

Open elijahnyp opened this issue 1 year ago • 5 comments

The issue

with the upcoming release of 5.4 (currently in beta), there is a new I2C driver. The new driver will not co-exist with the old driver (i2c.h vs i2c_master.h). Some libraries, like the esp32-camera library, support and use the new driver when compiled with version 5.4 of the IDF. Without updating to support the new driver, the esp-idf-lib drivers are incapable of co-existing with drivers that do use the new setup.

Which SDK are you using?

esp-idf

Which version of SDK are you using?

v5.4

Which build target have you used?

  • [X] esp32
  • [ ] esp32s2
  • [ ] esp32s3
  • [ ] esp32c2
  • [ ] esp8266
  • [ ] other

Component causing the issue

i2cdev

Anything in the logs that might be useful for us?

No response

Additional information or context

The issue occurs at runtime due to changes in i2c.c in idf 5.4. If the new driver is linked in, at runtime the old i2c driver aborts execution.

/**
 * @brief This function will be called during start up, to check that this legacy i2c driver is not running along with the new I2C driver
 */
__attribute__((constructor))
static void check_i2c_driver_conflict(void)
{
    // This function was declared as weak here. The new I2C driver has the implementation.
    // So if the new I2C driver is not linked in, then `i2c_acquire_bus_handle()` should be NULL at runtime.
    extern __attribute__((weak)) esp_err_t i2c_acquire_bus_handle(int port_num, void *i2c_new_bus, int mode);
    if ((void *)i2c_acquire_bus_handle != NULL) {
        ESP_EARLY_LOGE(I2C_TAG, "CONFLICT! driver_ng is not allowed to be used with this old driver");
        abort();
    }
    ESP_EARLY_LOGW(I2C_TAG, "This driver is an old driver, please migrate your application code to adapt `driver/i2c_master.h`");
}

Confirmation

  • [X] This report is not a question nor a request for drivers.

elijahnyp avatar Nov 17 '24 21:11 elijahnyp

Hi @UncleRus Is there any update for transition to a new driver version? https://github.com/UncleRus/esp-idf-lib/issues/626#issuecomment-2114567234

AxelLin avatar Dec 11 '24 03:12 AxelLin

Hi @UncleRus Any update? FYI, the IDF-5.4 is already released.

AxelLin avatar Jan 07 '25 04:01 AxelLin

same issue here

Graziele-Rodrigues avatar Jan 30 '25 11:01 Graziele-Rodrigues

Hi @trombik Any update for this issue?

AxelLin avatar May 06 '25 06:05 AxelLin

@AxelLin @Graziele-Rodrigues @elijahnyp I've created this i2cdev prototype that's been giving me promising results so far #707. @trombik Waiting for a feedback.

quinkq avatar Jun 12 '25 18:06 quinkq