-
Notifications
You must be signed in to change notification settings - Fork 478
feat: migrate i2cdev to new ESP-IDF I2C master driver API #707
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
feat: migrate i2cdev to new ESP-IDF I2C master driver API #707
Conversation
7235547 to
c5c8580
Compare
- Replace legacy command-based I2C with handle-based master API - Add device handle tracking and automatic resource cleanup - Enhance addressing support (7-bit/10-bit) and error handling - Implement smart retry logic with exponential backoff - Add buffer overflow protection and memory optimization - Maintain backward compatibility via i2cdev_legacy.c bridge - Preserve existing sensor driver API compatibility potentialy fixes UncleRus#667 UncleRus#713 #741
c5c8580 to
8faefbe
Compare
|
Hi @quinkq I just tested it with both idf-5.2 and idf-5.4 branchs. Thanks, |
…nfig - Fix "bus not ready" probe failures on ESP-IDF 5.3+ - Add CONFIG_I2CDEV_AUTO_ENABLE_PULLUPS option - Improve probe function consistency across ESP-IDF versions
|
Hi @AxelLin |
|
Hi @quinkq Thank you for the fix. Regards, |
|
@quinkq Thanks for the proposal. I will certainly have a close look. |
|
Also, please have a look at my proposal and have your voice heard. |
|
Hi @trombik |
|
@AxelLin Sorry for my inactivity. I'll take a look and merge it ASAP. |
|
Just a brief comment about the PR: I can see how you devoted your time and you I appreciate it. |
|
@AxelLin Merged, thanks! |
|
Forgot to mention @quinkq. Thank you, too. |
Summary
Migrate i2cdev to new ESP-IDF I2C master driver API (v5.3+)
Changes Made
Compatibility
i2cdev_legacy.cTesting
Modern I2cdev Workflow
Initialization Phase
i2cdev_init()→ Creates port mutexes for all I2C portssensor_init_desc()→i2c_dev_create_mutex()→ Creates device mutex + registers device + sets defaults (7-bit addressing)First I2C Operation (Lazy Setup)
Call Stack Order:
i2c_dev_read_reg() └── i2c_do_operation_with_retry() ─── Entry point with retry logic └── i2c_setup_device() ────────── Called on each retry attempt └── i2c_setup_port() ──────── Called if device setup needed └── Create bus/validate pinsWhen
i2c_dev_read_reg()ori2c_dev_write_reg()is called for the first time:Logical Flow:
i2c_setup_port()- Bus management (called by setup_device)i2c_setup_device()- Device registration (called by retry function)i2c_setup_port()to ensure port is readyi2c_do_operation_with_retry()- Entry pointi2c_setup_device()before each attemptDirect ESP-IDF calls - Actual I2C operation
i2c_master_transmit(),i2c_master_receive(), ori2c_master_transmit_receive()Subsequent Operations
Cleanup Phase
i2c_dev_delete_mutex()→ Remove device from bus, decrement ref counti2cdev_done()→ Final cleanup of all remaining resourcesFIXES #667