From 67e4f97ab436125c489d70590ffb451d2012f5b2 Mon Sep 17 00:00:00 2001 From: sivar2311 Date: Wed, 2 Oct 2024 17:36:46 +0200 Subject: [PATCH] Add conditional compilation for second I2C interface based on SOC_I2C_NUM The ESP32, ESP32-S and ESP32-H series have two I2C interfaces, while the ESP32-C series has only one. --- libraries/Wire/src/Wire.cpp | 2 ++ libraries/Wire/src/Wire.h | 2 ++ 2 files changed, 4 insertions(+) diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index 047795f949a..8ac0c25595d 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -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 */ diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index fcf94313d52..cf720d48234 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -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 */