From 67c32054401d963884e309b13d93cc5955444656 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Jul 2025 16:58:12 -0300 Subject: [PATCH 01/10] feat(wire): adds std::functional to slave callback functions --- libraries/Wire/src/Wire.cpp | 6 +++--- libraries/Wire/src/Wire.h | 15 +++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index 34c814b5117..598962b4965 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -48,7 +48,7 @@ TwoWire::TwoWire(uint8_t bus_num) #endif #if SOC_I2C_SUPPORT_SLAVE , - is_slave(false), user_onRequest(NULL), user_onReceive(NULL) + is_slave(false), user_onRequest(nullptr), user_onReceive(nullptr) #endif /* SOC_I2C_SUPPORT_SLAVE */ { } @@ -596,14 +596,14 @@ void TwoWire::flush() { //i2cFlush(num); // cleanup } -void TwoWire::onReceive(void (*function)(int)) { +void TwoWire::onReceive(user_onReceive_t function) { #if SOC_I2C_SUPPORT_SLAVE user_onReceive = function; #endif } // sets function called on slave read -void TwoWire::onRequest(void (*function)(void)) { +void TwoWire::onRequest(user_onRequest_t function) { #if SOC_I2C_SUPPORT_SLAVE user_onRequest = function; #endif diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index b84aa5b2131..aacffd57c66 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -48,10 +48,6 @@ #ifndef I2C_BUFFER_LENGTH #define I2C_BUFFER_LENGTH 128 // Default size, if none is set using Wire::setBuffersize(size_t) #endif -#if SOC_I2C_SUPPORT_SLAVE -typedef void (*user_onRequest)(void); -typedef void (*user_onReceive)(uint8_t *, int); -#endif /* SOC_I2C_SUPPORT_SLAVE */ class TwoWire : public HardwareI2C { protected: @@ -77,8 +73,11 @@ class TwoWire : public HardwareI2C { private: #if SOC_I2C_SUPPORT_SLAVE bool is_slave; - void (*user_onRequest)(void); - void (*user_onReceive)(int); + // functional pointers for user callbacks + using user_onRequest_t = void (*)(void); + using user_onReceive_t = void (*)(int); + user_onRequest_t user_onRequest; + user_onReceive_t user_onReceive; static void onRequestService(uint8_t, void *); static void onReceiveService(uint8_t, uint8_t *, size_t, bool, void *); #endif /* SOC_I2C_SUPPORT_SLAVE */ @@ -116,8 +115,8 @@ class TwoWire : public HardwareI2C { size_t requestFrom(uint8_t address, size_t len, bool stopBit) override; size_t requestFrom(uint8_t address, size_t len) override; - void onReceive(void (*)(int)) override; - void onRequest(void (*)(void)) override; + void onReceive(user_onReceive_t) override; + void onRequest(user_onRequest_t) override; //call setPins() first, so that begin() can be called without arguments from libraries bool setPins(int sda, int scl); From c5b3b53d53b4a9b52e5ca189dcb7af09ae3dd464 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Jul 2025 17:13:26 -0300 Subject: [PATCH 02/10] feat(wire): adds std::functional to slave callback functions --- libraries/Wire/src/Wire.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index aacffd57c66..c1964ab46f9 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -74,8 +74,8 @@ class TwoWire : public HardwareI2C { #if SOC_I2C_SUPPORT_SLAVE bool is_slave; // functional pointers for user callbacks - using user_onRequest_t = void (*)(void); - using user_onReceive_t = void (*)(int); + using user_onRequest_t = std::function; + using user_onReceive_t = std::function; user_onRequest_t user_onRequest; user_onReceive_t user_onReceive; static void onRequestService(uint8_t, void *); From e151d4c04b5d6cda68de600e9dba2a918b004f19 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Jul 2025 17:22:13 -0300 Subject: [PATCH 03/10] feat(wire): adds std::functional to slave callback functions --- cores/esp32/HardwareI2C.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cores/esp32/HardwareI2C.h b/cores/esp32/HardwareI2C.h index 65b7e2036b2..3151d6b6b01 100644 --- a/cores/esp32/HardwareI2C.h +++ b/cores/esp32/HardwareI2C.h @@ -20,6 +20,7 @@ #include #include "Stream.h" +#include class HardwareI2C : public Stream { public: @@ -36,6 +37,7 @@ class HardwareI2C : public Stream { virtual size_t requestFrom(uint8_t address, size_t len, bool stopBit) = 0; virtual size_t requestFrom(uint8_t address, size_t len) = 0; - virtual void onReceive(void (*)(int)) = 0; - virtual void onRequest(void (*)(void)) = 0; + // Update base class to use std::function + virtual void onReceive(std::function) = 0; + virtual void onRequest(std::function) = 0; }; From 694df6ff7c78bd178a7907863c8fe90b61f4fc4b Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Jul 2025 17:34:04 -0300 Subject: [PATCH 04/10] fix(wire): fixes C2 no slave --- libraries/Wire/src/Wire.cpp | 4 ++-- libraries/Wire/src/Wire.h | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index 598962b4965..ebea93c1dfa 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -596,14 +596,14 @@ void TwoWire::flush() { //i2cFlush(num); // cleanup } -void TwoWire::onReceive(user_onReceive_t function) { +void TwoWire::onReceive(std::function; - using user_onReceive_t = std::function; - user_onRequest_t user_onRequest; - user_onReceive_t user_onReceive; + std::function user_onRequest; + std::function) override; //call setPins() first, so that begin() can be called without arguments from libraries bool setPins(int sda, int scl); From dbf9750cb33175bb77c1fc3fc7acff442fa4c86e Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Jul 2025 17:43:20 -0300 Subject: [PATCH 05/10] fix(wire): typo and sintax error --- libraries/Wire/src/Wire.cpp | 4 ++-- libraries/Wire/src/Wire.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index ebea93c1dfa..a601bc8e8bb 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -596,14 +596,14 @@ void TwoWire::flush() { //i2cFlush(num); // cleanup } -void TwoWire::onReceive(std::function function) { #if SOC_I2C_SUPPORT_SLAVE user_onReceive = function; #endif } // sets function called on slave read -void TwoWire::onRequest(std::function function) { #if SOC_I2C_SUPPORT_SLAVE user_onRequest = function; #endif diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index 6c9b4419b48..eaeef2a5810 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -75,7 +75,7 @@ class TwoWire : public HardwareI2C { bool is_slave; // functional pointers for user callbacks std::function user_onRequest; - std::function user_onReceive; static void onRequestService(uint8_t, void *); static void onReceiveService(uint8_t, uint8_t *, size_t, bool, void *); #endif /* SOC_I2C_SUPPORT_SLAVE */ @@ -113,7 +113,7 @@ class TwoWire : public HardwareI2C { size_t requestFrom(uint8_t address, size_t len, bool stopBit) override; size_t requestFrom(uint8_t address, size_t len) override; - void onReceive(std::function) override; void onRequest(std::function) override; //call setPins() first, so that begin() can be called without arguments from libraries From a12f4bcf16c659aaefc5a4e6acb55f178c08c5aa Mon Sep 17 00:00:00 2001 From: Sugar Glider Date: Thu, 10 Jul 2025 17:52:38 -0300 Subject: [PATCH 06/10] fix(wire): removing commentary --- libraries/Wire/src/Wire.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index eaeef2a5810..636ea4c74c9 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -73,7 +73,6 @@ class TwoWire : public HardwareI2C { private: #if SOC_I2C_SUPPORT_SLAVE bool is_slave; - // functional pointers for user callbacks std::function user_onRequest; std::function user_onReceive; static void onRequestService(uint8_t, void *); From 12bae35108ff7947561ac1c8c1a01794c7ad974c Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Jul 2025 18:32:50 -0300 Subject: [PATCH 07/10] feat(wire): better callback performance --- cores/esp32/HardwareI2C.h | 4 ++-- libraries/Wire/src/Wire.cpp | 4 ++-- libraries/Wire/src/Wire.h | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cores/esp32/HardwareI2C.h b/cores/esp32/HardwareI2C.h index 3151d6b6b01..d241baa898e 100644 --- a/cores/esp32/HardwareI2C.h +++ b/cores/esp32/HardwareI2C.h @@ -38,6 +38,6 @@ class HardwareI2C : public Stream { virtual size_t requestFrom(uint8_t address, size_t len) = 0; // Update base class to use std::function - virtual void onReceive(std::function) = 0; - virtual void onRequest(std::function) = 0; + virtual void onReceive(const std::function&) = 0; + virtual void onRequest(const std::function&) = 0; }; diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index a601bc8e8bb..4bd8f00a064 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -596,14 +596,14 @@ void TwoWire::flush() { //i2cFlush(num); // cleanup } -void TwoWire::onReceive(std::function function) { +void TwoWire::onReceive(const std::function& function) { #if SOC_I2C_SUPPORT_SLAVE user_onReceive = function; #endif } // sets function called on slave read -void TwoWire::onRequest(std::function function) { +void TwoWire::onRequest(const std::function& function) { #if SOC_I2C_SUPPORT_SLAVE user_onRequest = function; #endif diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index 636ea4c74c9..f601aa81261 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -112,8 +112,8 @@ class TwoWire : public HardwareI2C { size_t requestFrom(uint8_t address, size_t len, bool stopBit) override; size_t requestFrom(uint8_t address, size_t len) override; - void onReceive(std::function) override; - void onRequest(std::function) override; + void onReceive(const std::function&) override; + void onRequest(const std::function&) override; //call setPins() first, so that begin() can be called without arguments from libraries bool setPins(int sda, int scl); From d5e857110c4c801bbf40ac60722b0a72a4a3c318 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Jul 2025 19:29:05 -0300 Subject: [PATCH 08/10] feat(wire): adds a new example using lambda function callback --- .../WireSlaveFunctionalCallback.ino | 37 +++++++++++++++++++ .../WireSlaveFunctionalCallback/ci.json | 5 +++ 2 files changed, 42 insertions(+) create mode 100644 libraries/Wire/examples/WireSlaveFunctionalCallback/WireSlaveFunctionalCallback.ino create mode 100644 libraries/Wire/examples/WireSlaveFunctionalCallback/ci.json diff --git a/libraries/Wire/examples/WireSlaveFunctionalCallback/WireSlaveFunctionalCallback.ino b/libraries/Wire/examples/WireSlaveFunctionalCallback/WireSlaveFunctionalCallback.ino new file mode 100644 index 00000000000..2db1531fcd0 --- /dev/null +++ b/libraries/Wire/examples/WireSlaveFunctionalCallback/WireSlaveFunctionalCallback.ino @@ -0,0 +1,37 @@ +// This example demonstrates the use of functional callbacks with the Wire library +// for I2C slave communication. It shows how to handle requests and data reception + +#include "Wire.h" + +#define I2C_DEV_ADDR 0x55 + +uint32_t i = 0; + +void setup() { + Serial.begin(115200); + Serial.setDebugOutput(true); + + Wire.onRequest([]() { + Wire.print(i++); + Wire.print(" Packets."); + Serial.println("onRequest"); + }); + + Wire.onReceive([](int len) { + Serial.printf("onReceive[%d]: ", len); + while (Wire.available()) { + Serial.write(Wire.read()); + } + Serial.println(); + }); + + Wire.begin((uint8_t)I2C_DEV_ADDR); + +#if CONFIG_IDF_TARGET_ESP32 + char message[64]; + snprintf(message, 64, "%lu Packets.", i++); + Wire.slaveWrite((uint8_t *)message, strlen(message)); +#endif +} + +void loop() {} diff --git a/libraries/Wire/examples/WireSlaveFunctionalCallback/ci.json b/libraries/Wire/examples/WireSlaveFunctionalCallback/ci.json new file mode 100644 index 00000000000..b42d0aa1971 --- /dev/null +++ b/libraries/Wire/examples/WireSlaveFunctionalCallback/ci.json @@ -0,0 +1,5 @@ +{ + "requires": [ + "CONFIG_SOC_I2C_SUPPORT_SLAVE=y" + ] +} \ No newline at end of file From f2fce44a10753025a9db0eb42c6301e9f3813c9c Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 10 Jul 2025 20:21:50 -0300 Subject: [PATCH 09/10] feat(wire): documentation update with new feature --- docs/en/api/i2c.rst | 135 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 131 insertions(+), 4 deletions(-) diff --git a/docs/en/api/i2c.rst b/docs/en/api/i2c.rst index eac04b76a23..cdb4a983e1b 100644 --- a/docs/en/api/i2c.rst +++ b/docs/en/api/i2c.rst @@ -347,21 +347,148 @@ This function will return ``true`` if the peripheral was initialized correctly. onReceive ^^^^^^^^^ -The ``onReceive`` function is used to define the callback for the data received from the master. +The ``onReceive`` function is used to define the callback for data received from the master device. .. code-block:: arduino - void onReceive( void (*)(int) ); + void onReceive(const std::function& callback); + +**Function Signature:** + +The callback function must have the signature ``void(int numBytes)`` where ``numBytes`` indicates how many bytes were received from the master. + +**Usage Examples:** + +.. code-block:: arduino + + // Method 1: Regular function + void handleReceive(int numBytes) { + Serial.printf("Received %d bytes: ", numBytes); + while (Wire.available()) { + char c = Wire.read(); + Serial.print(c); + } + Serial.println(); + } + Wire.onReceive(handleReceive); + + // Method 2: Lambda function + Wire.onReceive([](int numBytes) { + Serial.printf("Master sent %d bytes\n", numBytes); + while (Wire.available()) { + uint8_t data = Wire.read(); + // Process received data + Serial.printf("Data: 0x%02X\n", data); + } + }); + + // Method 3: Lambda with capture (for accessing variables) + int deviceId = 42; + Wire.onReceive([deviceId](int numBytes) { + Serial.printf("Device %d received %d bytes\n", deviceId, numBytes); + // Process data... + }); + + // Method 4: Using std::function variable + std::function receiveHandler = [](int bytes) { + Serial.printf("Handling %d received bytes\n", bytes); + }; + Wire.onReceive(receiveHandler); + + // Method 5: Class member function (using lambda wrapper) + class I2CDevice { + private: + int deviceAddress; + public: + I2CDevice(int addr) : deviceAddress(addr) {} + + void handleReceive(int numBytes) { + Serial.printf("Device 0x%02X received %d bytes\n", deviceAddress, numBytes); + } + + void setup() { + Wire.onReceive([this](int bytes) { + this->handleReceive(bytes); + }); + } + }; + +.. note:: + The ``onReceive`` callback is triggered when the I2C master sends data to this slave device. + Use ``Wire.available()`` and ``Wire.read()`` inside the callback to retrieve the received data. onRequest ^^^^^^^^^ -The ``onRequest`` function is used to define the callback for the data to be send to the master. +The ``onRequest`` function is used to define the callback for responding to master read requests. .. code-block:: arduino - void onRequest( void (*)(void) ); + void onRequest(const std::function& callback); + +**Function Signature:** + +The callback function must have the signature ``void()`` with no parameters. This callback is triggered when the master requests data from this slave device. + +**Usage Examples:** + +.. code-block:: arduino + // Method 1: Regular function + void handleRequest() { + static int counter = 0; + Wire.printf("Response #%d", counter++); + } + Wire.onRequest(handleRequest); + + // Method 2: Lambda function + Wire.onRequest([]() { + // Send sensor data to master + int sensorValue = analogRead(A0); + Wire.write(sensorValue >> 8); // High byte + Wire.write(sensorValue & 0xFF); // Low byte + }); + + // Method 3: Lambda with capture (for accessing variables) + int deviceStatus = 1; + String deviceName = "Sensor1"; + Wire.onRequest([&deviceStatus, &deviceName]() { + Wire.write(deviceStatus); + Wire.write(deviceName.c_str(), deviceName.length()); + }); + + // Method 4: Using std::function variable + std::function requestHandler = []() { + Wire.write("Hello Master!"); + }; + Wire.onRequest(requestHandler); + + // Method 5: Class member function (using lambda wrapper) + class TemperatureSensor { + private: + float temperature; + public: + void updateTemperature() { + temperature = 25.5; // Read from actual sensor + } + + void sendTemperature() { + // Convert float to bytes and send + uint8_t* tempBytes = (uint8_t*)&temperature; + Wire.write(tempBytes, sizeof(float)); + } + + void setup() { + Wire.onRequest([this]() { + this->sendTemperature(); + }); + } + }; + +.. note:: + The ``onRequest`` callback is triggered when the I2C master requests data from this slave device. + Use ``Wire.write()`` inside the callback to send response data back to the master. + slaveWrite ^^^^^^^^^^ From 9fa5a6424d6a92992cb708541001388da975d020 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Fri, 11 Jul 2025 18:44:30 +0000 Subject: [PATCH 10/10] ci(pre-commit): Apply automatic fixes --- cores/esp32/HardwareI2C.h | 4 ++-- docs/en/api/i2c.rst | 18 +++++++++--------- .../WireSlaveFunctionalCallback.ino | 4 ++-- .../WireSlaveFunctionalCallback/ci.json | 2 +- libraries/Wire/src/Wire.cpp | 4 ++-- libraries/Wire/src/Wire.h | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cores/esp32/HardwareI2C.h b/cores/esp32/HardwareI2C.h index d241baa898e..c44f34e1ee7 100644 --- a/cores/esp32/HardwareI2C.h +++ b/cores/esp32/HardwareI2C.h @@ -38,6 +38,6 @@ class HardwareI2C : public Stream { virtual size_t requestFrom(uint8_t address, size_t len) = 0; // Update base class to use std::function - virtual void onReceive(const std::function&) = 0; - virtual void onRequest(const std::function&) = 0; + virtual void onReceive(const std::function &) = 0; + virtual void onRequest(const std::function &) = 0; }; diff --git a/docs/en/api/i2c.rst b/docs/en/api/i2c.rst index cdb4a983e1b..06d4d1953a6 100644 --- a/docs/en/api/i2c.rst +++ b/docs/en/api/i2c.rst @@ -401,11 +401,11 @@ The callback function must have the signature ``void(int numBytes)`` where ``num int deviceAddress; public: I2CDevice(int addr) : deviceAddress(addr) {} - + void handleReceive(int numBytes) { Serial.printf("Device 0x%02X received %d bytes\n", deviceAddress, numBytes); } - + void setup() { Wire.onReceive([this](int bytes) { this->handleReceive(bytes); @@ -413,8 +413,8 @@ The callback function must have the signature ``void(int numBytes)`` where ``num } }; -.. note:: - The ``onReceive`` callback is triggered when the I2C master sends data to this slave device. +.. note:: + The ``onReceive`` callback is triggered when the I2C master sends data to this slave device. Use ``Wire.available()`` and ``Wire.read()`` inside the callback to retrieve the received data. onRequest @@ -471,13 +471,13 @@ The callback function must have the signature ``void()`` with no parameters. Thi void updateTemperature() { temperature = 25.5; // Read from actual sensor } - + void sendTemperature() { // Convert float to bytes and send uint8_t* tempBytes = (uint8_t*)&temperature; Wire.write(tempBytes, sizeof(float)); } - + void setup() { Wire.onRequest([this]() { this->sendTemperature(); @@ -485,10 +485,10 @@ The callback function must have the signature ``void()`` with no parameters. Thi } }; -.. note:: - The ``onRequest`` callback is triggered when the I2C master requests data from this slave device. +.. note:: + The ``onRequest`` callback is triggered when the I2C master requests data from this slave device. Use ``Wire.write()`` inside the callback to send response data back to the master. - + slaveWrite ^^^^^^^^^^ diff --git a/libraries/Wire/examples/WireSlaveFunctionalCallback/WireSlaveFunctionalCallback.ino b/libraries/Wire/examples/WireSlaveFunctionalCallback/WireSlaveFunctionalCallback.ino index 2db1531fcd0..a18fd2f023e 100644 --- a/libraries/Wire/examples/WireSlaveFunctionalCallback/WireSlaveFunctionalCallback.ino +++ b/libraries/Wire/examples/WireSlaveFunctionalCallback/WireSlaveFunctionalCallback.ino @@ -16,9 +16,9 @@ void setup() { Wire.print(" Packets."); Serial.println("onRequest"); }); - + Wire.onReceive([](int len) { - Serial.printf("onReceive[%d]: ", len); + Serial.printf("onReceive[%d]: ", len); while (Wire.available()) { Serial.write(Wire.read()); } diff --git a/libraries/Wire/examples/WireSlaveFunctionalCallback/ci.json b/libraries/Wire/examples/WireSlaveFunctionalCallback/ci.json index b42d0aa1971..3c877975d62 100644 --- a/libraries/Wire/examples/WireSlaveFunctionalCallback/ci.json +++ b/libraries/Wire/examples/WireSlaveFunctionalCallback/ci.json @@ -2,4 +2,4 @@ "requires": [ "CONFIG_SOC_I2C_SUPPORT_SLAVE=y" ] -} \ No newline at end of file +} diff --git a/libraries/Wire/src/Wire.cpp b/libraries/Wire/src/Wire.cpp index 4bd8f00a064..cda098d2d5b 100644 --- a/libraries/Wire/src/Wire.cpp +++ b/libraries/Wire/src/Wire.cpp @@ -596,14 +596,14 @@ void TwoWire::flush() { //i2cFlush(num); // cleanup } -void TwoWire::onReceive(const std::function& function) { +void TwoWire::onReceive(const std::function &function) { #if SOC_I2C_SUPPORT_SLAVE user_onReceive = function; #endif } // sets function called on slave read -void TwoWire::onRequest(const std::function& function) { +void TwoWire::onRequest(const std::function &function) { #if SOC_I2C_SUPPORT_SLAVE user_onRequest = function; #endif diff --git a/libraries/Wire/src/Wire.h b/libraries/Wire/src/Wire.h index f601aa81261..9cebdfaa304 100644 --- a/libraries/Wire/src/Wire.h +++ b/libraries/Wire/src/Wire.h @@ -112,8 +112,8 @@ class TwoWire : public HardwareI2C { size_t requestFrom(uint8_t address, size_t len, bool stopBit) override; size_t requestFrom(uint8_t address, size_t len) override; - void onReceive(const std::function&) override; - void onRequest(const std::function&) override; + void onReceive(const std::function &) override; + void onRequest(const std::function &) override; //call setPins() first, so that begin() can be called without arguments from libraries bool setPins(int sda, int scl);