Fix LP_I2C_NUM_0 support: use LP_I2C_SCLK_DEFAULT clock source#13
Open
lptr wants to merge 1 commit into
Open
Conversation
i2c_setup_port always passed I2C_CLK_SRC_DEFAULT to i2c_new_master_bus, which returns ESP_ERR_NOT_SUPPORTED for LP_I2C_NUM_0. LP I2C requires LP_I2C_SCLK_DEFAULT instead. clk_source and lp_source_clk are union members in i2c_master_bus_config_t sharing the same memory, but LP_I2C_SCLK_DEFAULT is not a valid i2c_clock_source_t value so the driver rejects the HP default when given an LP port number. Fix: set clk_source = LP_I2C_SCLK_DEFAULT when dev->port == LP_I2C_NUM_0, guarded by SOC_LP_I2C_SUPPORTED so it compiles cleanly on chips without an LP I2C peripheral. All HP bus behaviour is unchanged. Fixes: esp-idf-lib#12
This was referenced May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12.
i2c_setup_porthardcoded.clk_source = I2C_CLK_SRC_DEFAULTin thei2c_master_bus_config_tinitializer. ForLP_I2C_NUM_0this is the wrongvalue:
clk_sourceandlp_source_clkare union members in the struct, andLP_I2C_SCLK_DEFAULTis not a validi2c_clock_source_t— passingI2C_CLK_SRC_DEFAULTfor an LP port causesi2c_new_master_busto returnESP_ERR_NOT_SUPPORTED.The fix detects the LP port and sets
LP_I2C_SCLK_DEFAULT, guarded by#if SOC_LP_I2C_SUPPORTEDso it is a no-op on chips without LP_I2C.Testing
Validated on ESP32-C6 (the only current ESP-IDF target with
SOC_LP_I2C_SUPPORTED):a firmware project using i2cdev devices (
INA219,BQ27220) onLP_I2C_NUM_0(GPIO6/GPIO7) now initialises correctly. Previously the first i2cdev transaction
on the LP port returned
ESP_ERR_NOT_SUPPORTED.HP I2C behaviour on ESP32-C6 and ESP32-S3 is unchanged — the
elsebranchkeeps
I2C_CLK_SRC_DEFAULTfor all HP ports, and the#if SOC_LP_I2C_SUPPORTEDguard means the new code is not compiled on chips without LP_I2C.
Notes
.clk_source = LP_I2C_SCLK_DEFAULT(not the
.lp_source_clkfield name) — both field names work because they areunion members, but the value is what matters.
for context on why we ended up pinning the fork as a submodule while waiting for
this PR to land.