Skip to content

esp32/machine_i2c: Set default for new I2C driver at esp-idf >= v5.5.2.#19256

Open
robert-hh wants to merge 2 commits into
micropython:masterfrom
robert-hh:esp32_i2c_len0
Open

esp32/machine_i2c: Set default for new I2C driver at esp-idf >= v5.5.2.#19256
robert-hh wants to merge 2 commits into
micropython:masterfrom
robert-hh:esp32_i2c_len0

Conversation

@robert-hh
Copy link
Copy Markdown
Contributor

Summary

With v5.5.2 and up the the additional bus probing is not needed any more. It was needed because transfers to a non-existing address caused an error message to be printed instead of just returning an error code. With esp-idf v5.5.2 it returns just an error code. For 0-length writes as being used by i2c.scan(), an additional code path using i2c_master_execute_defined_operations() is needed to avoid an error message.
By default the new I2C driver is enabled for esp-idf version >= 5.5.2.

There is a slight inconsistency: reading 0 bytes from a non-existing address return an empty bytes object and does not raise an error. Writing 0 bytes to a non-existing address returns an error. That case is used by i2c.scan().

Testing

Tested with a Generic ESP32 and esp-idf v5.5.1, v5.5.2 and v5.5.4. Tested as well using the new driver with v5.5.1.
Tested V5.5.2 with Generic ESP32, ESP32S2, ESP32S3, ESP32C2, ESP32C3, ESP32C5, ESP32C6, ESP32P4. Driving an external device as I2C controller.

Trade-offs and Alternatives

There is still a problem with I2CTarget mode. But that exists back to v5.4.2 and did not get worse with v5.5.2 and v5.5.4

Generative AI

I did not use generative AI tools when creating this PR.

@robert-hh
Copy link
Copy Markdown
Contributor Author

@dpgeorge The code path for the new I2C driver still contains code to support esp-idf versions < 5.5.2. For code clarity, that can be removed and a Pre-Compiler check added that flags an error is the esp-idf version is < v5.5.2. Likewise the old driver path could get a check for esp-idf < v6.0.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 21, 2026

Code size report:

Reference:  docs/library/rp2.DMA: Correct and add pack_ctrl defaults. [8f3a416]
Comparison: esp32/machine_i2c.c: Restrict new I2C driver to esp-idf version >=5.5.2. [merge of 0dffd4a]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32: +6228 +0.356% ESP32_GENERIC[incl +2408(data) +32(bss)]
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

robert-hh added 2 commits May 24, 2026 10:57
By default the new I2C driver is enabled for esp-idf version >= 5.5.2.

With v5.5.2 and up the the additional bus probing is not needed any
more. It was needed because transfers to a non-existing address caused
an error message to be printed instead of just returning an error code.
With esp-idf v5.5.2 it returns just an error code.
For 0-length writes as being used by i2c.scan(), an additional code path
using i2c_master_execute_defined_operations() is needed to avoid an
error message.

Tested with a Generic ESP32 and esp-idf v5.5.1, v5.5.2 and v5.5.4.
Tested as well using the new driver with v5.5.1.
Tested V5.5.2 with Generic ESP32, ESP32S2, ESP32S3, ESP32C2, ESP32C3,
ESP32C5, ESP32C6, ESP32P4. Driving an external device as I2C controller.

There is a slight inconsistency: reading 0 bytes from a non-existing
address return an empty bytes object and does not raise an error.
Writing 0 bytes to a non-existing address returns an error. That case
is used by i2c.scan().

Signed-off-by: robert-hh <robert@hammelrath.com>
If the new driver is enabled for versions previous to v5.5.2, an error
is raised and compilation aborted.

Signed-off-by: robert-hh <robert@hammelrath.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants