Skip to content

Commit 45f4bef

Browse files
authored
Fixes Arduino Wire::begin overload (#7000)
Makes Wire::begin() fully compatible with Arduino mainstream (Master/Slave)
1 parent aae4563 commit 45f4bef

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: cores/esp32/esp32-hal-i2c.c

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ esp_err_t i2cInit(uint8_t i2c_num, int8_t sda, int8_t scl, uint32_t frequency){
7272
} else if(frequency > 1000000UL){
7373
frequency = 1000000UL;
7474
}
75+
log_i("Initialising I2C Master: sda=%d scl=%d freq=%d", sda, scl, frequency);
7576

7677
i2c_config_t conf = { };
7778
conf.mode = I2C_MODE_MASTER;

Diff for: libraries/Wire/src/Wire.h

+15-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,21 @@ class TwoWire: public Stream
7676
//call setPins() first, so that begin() can be called without arguments from libraries
7777
bool setPins(int sda, int scl);
7878

79-
bool begin(int sda=-1, int scl=-1, uint32_t frequency=0); // returns true, if successful init of i2c bus
80-
bool begin(uint8_t slaveAddr, int sda=-1, int scl=-1, uint32_t frequency=0);
79+
bool begin(int sda, int scl, uint32_t frequency=0); // returns true, if successful init of i2c bus
80+
bool begin(uint8_t slaveAddr, int sda, int scl, uint32_t frequency);
81+
// Explicit Overload for Arduino MainStream API compatibility
82+
inline bool begin()
83+
{
84+
return begin(-1, -1, static_cast<uint32_t>(0));
85+
}
86+
inline bool begin(uint8_t addr)
87+
{
88+
return begin(addr, -1, -1, 0);
89+
}
90+
inline bool begin(int addr)
91+
{
92+
return begin(static_cast<uint8_t>(addr), -1, -1, 0);
93+
}
8194
bool end();
8295

8396
void setTimeOut(uint16_t timeOutMillis); // default timeout of i2c transactions is 50ms

0 commit comments

Comments
 (0)