Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 5d873c0

Browse files
authoredOct 4, 2024··
Add conditional compilation for second I2C interface based on SOC_I2C_NUM (#10408)
The ESP32, ESP32-S and ESP32-H series have two I2C interfaces, while the ESP32-C series has only one.
1 parent 733373a commit 5d873c0

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed
 

‎libraries/Wire/src/Wire.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,8 @@ void TwoWire::onRequestService(uint8_t num, void *arg) {
646646
#endif /* SOC_I2C_SUPPORT_SLAVE */
647647

648648
TwoWire Wire = TwoWire(0);
649+
#if SOC_I2C_NUM > 1
649650
TwoWire Wire1 = TwoWire(1);
651+
#endif /* SOC_I2C_NUM */
650652

651653
#endif /* SOC_I2C_SUPPORTED */

‎libraries/Wire/src/Wire.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ class TwoWire : public HardwareI2C {
144144
};
145145

146146
extern TwoWire Wire;
147+
#if SOC_I2C_NUM > 1
147148
extern TwoWire Wire1;
149+
#endif /* SOC_I2C_NUM */
148150

149151
#endif /* SOC_I2C_SUPPORTED */
150152
#endif /* TwoWire_h */

4 commit comments

Comments
 (4)

Jason2866 commented on Oct 10, 2024

@Jason2866
Collaborator

@sivar2311 @me-no-dev This merge from branch master needs to be changed to SOC_HP_I2C_NUM

sivar2311 commented on Oct 11, 2024

@sivar2311
ContributorAuthor

@Jason2866 Thanks!
But why is SOC_HP_I2C_NUM correct and SOC_I2C_NUM is not?

Unfortunately their meaning is neither mentioned in the documentation nor in the source code.

igrr commented on Oct 11, 2024

@igrr
Member

SOC_HP_I2C_NUM is the number of I2C controllers in the digital domain. SOC_I2C_NUM is the total number of I2C controllers, including the ones in LP domain. In recent IDF versions, LP I2C controllers can be also accessed using the same I2C master driver as the ones in the digital domain.

See ESP32-C6 soc_caps for an example: https://github.com/espressif/esp-idf/blob/6e5a178b3120dced7fa5c29c655cc22ea182df3d/components/soc/esp32c6/include/soc/soc_caps.h#L240-L241

sivar2311 commented on Oct 12, 2024

@sivar2311
ContributorAuthor

Thanks for your eagle eyes @Jason2866 and for clearification @igrr !

I created a new PR #10453

Please sign in to comment.