Skip to content

Commit

Permalink
Add conditional compilation for second I2C interface based on SOC_I2C…
Browse files Browse the repository at this point in the history
…_NUM (#10408)

The ESP32, ESP32-S and ESP32-H series have two I2C interfaces, while the ESP32-C series has only one.
  • Loading branch information
sivar2311 authored Oct 4, 2024
1 parent 733373a commit 5d873c0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ void TwoWire::onRequestService(uint8_t num, void *arg) {
#endif /* SOC_I2C_SUPPORT_SLAVE */

TwoWire Wire = TwoWire(0);
#if SOC_I2C_NUM > 1
TwoWire Wire1 = TwoWire(1);
#endif /* SOC_I2C_NUM */

#endif /* SOC_I2C_SUPPORTED */
2 changes: 2 additions & 0 deletions libraries/Wire/src/Wire.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ class TwoWire : public HardwareI2C {
};

extern TwoWire Wire;
#if SOC_I2C_NUM > 1
extern TwoWire Wire1;
#endif /* SOC_I2C_NUM */

#endif /* SOC_I2C_SUPPORTED */
#endif /* TwoWire_h */

4 comments on commit 5d873c0

@Jason2866
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

@sivar2311
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@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
Copy link
Member

@igrr igrr commented on 5d873c0 Oct 11, 2024

Choose a reason for hiding this comment

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

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
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

I created a new PR #10453

Please sign in to comment.