Skip to content

feat(i2c): Add support for new APIs (required for ESP-IDF >= v5.5) #458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 13, 2025

Conversation

finger563
Copy link
Contributor

@finger563 finger563 commented Jun 13, 2025

Description

  • Add kconfig to i2c component to select legacy or new api
  • Add i2c master/slave components which mirror new APIs
  • Add new menu components
  • Update example to test new APIs
  • Update docs

Motivation and Context

As of ESP-IDF >= 5.5, the legacy API (which was previously the only I2C API espp supported) will be removed. This PR allows users to migrate to the new APIs if they wish. The default is still the legacy API.

How has this been tested?

  • Build and run i2c/example configured to use the new APIs and test the various master and master_device functions using the CLI.

Screenshots (if appropriate, e.g. schematic, board, console logs, lab pictures):

No-CLI testing:

CleanShot 2025-06-13 at 09 51 08

Bus menu testing:

CleanShot 2025-06-13 at 13 17 25

CleanShot 2025-06-13 at 13 17 36

CleanShot 2025-06-13 at 13 17 48

CleanShot 2025-06-13 at 13 18 06

CleanShot 2025-06-13 at 13 19 21

Device menu testing:

CleanShot 2025-06-13 at 13 19 38

CleanShot 2025-06-13 at 13 19 58

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Hardware (schematic, board, system design) change
  • Software change

Checklist:

  • My change requires a change to the documentation.
  • I have added / updated the documentation related to this change via either README or WIKI

Software

  • I have added tests to cover my changes.
  • I have updated the .github/workflows/build.yml file to add my new test to the automated cloud build github action.
  • All new and existing tests passed.
  • My code follows the code style of this project.

@finger563 finger563 requested a review from Copilot June 13, 2025 18:48
@finger563 finger563 self-assigned this Jun 13, 2025
@finger563 finger563 added enhancement New feature or request i2c labels Jun 13, 2025
Copy link

github-actions bot commented Jun 13, 2025

✅Static analysis result - no issues found! ✅

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds support for selecting between the legacy and new ESP-IDF I2C APIs (required for ESP-IDF ≥ 5.5), implements new C++ wrappers for master and slave I2C buses/devices, and updates documentation, examples, and build files accordingly.

  • Introduce Kconfig choice to toggle legacy vs. new I2C API
  • Add i2c_master/i2c_slave components and CLI menus for new APIs
  • Update docs (.rst, Doxyfile) and example app to demonstrate both APIs

Reviewed Changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
doc/en/i2c.rst Add sections for legacy/new API selection and details
doc/Doxyfile Include new headers for documentation generation
components/i2c/include/i2c_format_helpers.hpp Preprocessor guards for legacy vs. new API includes
components/i2c/include/i2c_slave_menu.hpp New CLI menu implementation for I2C slave device
components/i2c/example/main/i2c_example.cpp Example updated to conditionally show legacy or new API flows
components/i2c/Kconfig Add choice for I2C API selection
components/i2c/CMakeLists.txt Register source directories
Comments suppressed due to low confidence (4)

components/i2c/include/i2c_format_helpers.hpp:7

  • The preprocessor directive should be #elif, not #elseif, to correctly guard the new API include path.
#elseif defined(CONFIG_I2C_USE_NEW_API)

components/i2c/include/i2c_slave_menu.hpp:65

  • The format specifier {::#02x} is invalid; it should be {: #02x} or {:#02x} to format bytes in hexadecimal.
out << fmt::format("Read {} bytes from slave: {::#02x}\n", len, data);

components/i2c/include/i2c_slave_menu.hpp:78

  • Same invalid format specifier {::#02x} here; use {:#02x} to correctly format the data bytes.
out << fmt::format("Wrote {} bytes to slave: {::#02x}\n", data.size(), data);

components/i2c/example/main/i2c_example.cpp:159

  • The placeholder {::#02x} is incorrect—should be {:#02x} when formatting the vector of addresses in hexadecimal.
logger.info("Found devices at addresses: {::#02x}", found_addresses);

@finger563 finger563 merged commit 818ec15 into main Jun 13, 2025
83 checks passed
@finger563 finger563 deleted the feat/new-i2c-apis branch June 13, 2025 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request i2c
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant