Skip to content

Commit

Permalink
[I2C] Fix compilation for ESP8266
Browse files Browse the repository at this point in the history
  • Loading branch information
tonhuisman committed Jan 31, 2025
1 parent 114161a commit 1eb141c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Custom-sample.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@
#endif
#ifdef ESP32
#define DEFAULT_PIN_I2C_SDA -1 // Undefined
#define DEFAULT_PIN_I2C2_SDA -1 // Undefined
#define DEFAULT_PIN_I2C3_SDA -1 // Undefined
#endif
#ifdef ESP8266
#define DEFAULT_PIN_I2C_SCL 5
#endif
#ifdef ESP32
#define DEFAULT_PIN_I2C_SCL -1 // Undefined
#endif
#define DEFAULT_PIN_I2C2_SDA -1 // Undefined
#define DEFAULT_PIN_I2C3_SDA -1 // Undefined
#define DEFAULT_PIN_I2C3_SCL -1 // Undefined
#define DEFAULT_PIN_I2C3_SCL -1 // Undefined
#endif
#define DEFAULT_I2C_CLOCK_SPEED 400000 // Use 100 kHz if working with old I2C chips
#define FEATURE_I2C_DEVICE_SCAN 1

Expand Down
4 changes: 0 additions & 4 deletions src/src/CustomBuild/ESPEasyDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,12 @@
#define DEFAULT_PIN_I2C_SDA -1 // Undefined
#endif
#endif
#ifdef ESP32
#ifndef DEFAULT_PIN_I2C2_SDA
#define DEFAULT_PIN_I2C2_SDA -1 // Undefined
#endif
#ifndef DEFAULT_PIN_I2C3_SDA
#define DEFAULT_PIN_I2C3_SDA -1 // Undefined
#endif
#endif
#ifndef DEFAULT_PIN_I2C_SCL
#ifdef ESP8266
#define DEFAULT_PIN_I2C_SCL 5
Expand All @@ -236,14 +234,12 @@
#define DEFAULT_PIN_I2C_SCL -1 // Undefined
#endif
#endif
#ifdef ESP32
#ifndef DEFAULT_PIN_I2C2_SCL
#define DEFAULT_PIN_I2C2_SCL -1 // Undefined
#endif
#ifndef DEFAULT_PIN_I2C3_SCL
#define DEFAULT_PIN_I2C3_SCL -1 // Undefined
#endif
#endif
#ifndef DEFAULT_I2C_CLOCK_SPEED
#define DEFAULT_I2C_CLOCK_SPEED 400000 // Use 100 kHz if working with old I2C chips
#endif
Expand Down
7 changes: 6 additions & 1 deletion src/src/DataStructs_templ/SettingsStruct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,12 @@ bool SettingsStruct_tmpl<N_TASKS>::isSPI_valid() const {
template<unsigned int N_TASKS>
bool SettingsStruct_tmpl<N_TASKS>::isI2C_pin(int8_t pin) const {
if (pin < 0) { return false; }
for (uint8_t i2cBus = 0; i2cBus < getI2CBusCount(); ++i2cBus) {
#if !FEATURE_I2C_MULTIPLE
const uint8_t i2cBus = 0;
#else // if !FEATURE_I2C_MULTIPLE
for (uint8_t i2cBus = 0; i2cBus < getI2CBusCount(); ++i2cBus)
#endif // if !FEATURE_I2C_MULTIPLE
{
if ((getI2CSdaPin(i2cBus) == pin) || (getI2CSclPin(i2cBus) == pin)) {
return true;
}
Expand Down

0 comments on commit 1eb141c

Please sign in to comment.