Skip to content

feat(wire): std::functional Wire slave callback functions #11582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

SuGlider
Copy link
Collaborator

@SuGlider SuGlider commented Jul 10, 2025

Description of Change

Modify Wire.h and Wire.cpp to allow the Wire Slave callback functions to be declared as std::functional.
Adds example and changes the documentation.

Tests scenarios

CI + ESP32/ESP32-C3/ESP32-C6/ESP32-S3 using new WireSlaveFunctionalCallback.ino example

#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() {}

Related links

Closes #11497

@SuGlider SuGlider added this to the 3.2.1 milestone Jul 10, 2025
@SuGlider SuGlider self-assigned this Jul 10, 2025
@SuGlider SuGlider requested a review from me-no-dev as a code owner July 10, 2025 20:03
@SuGlider SuGlider added Type: Feature request Feature request for Arduino ESP32 Area: Peripherals API Relates to peripheral's APIs. labels Jul 10, 2025
@SuGlider SuGlider requested a review from Copilot July 10, 2025 20:03
@SuGlider SuGlider marked this pull request as draft July 10, 2025 20:03
Copy link
Contributor

github-actions bot commented Jul 10, 2025

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello SuGlider, we appreciate your contribution to this project!


📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more.

🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project.

Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against f2fce44

@SuGlider SuGlider moved this from Todo to In Progress in Arduino ESP32 Core Project Roadmap Jul 10, 2025
Copy link
Contributor

github-actions bot commented Jul 10, 2025

Test Results

 76 files   76 suites   15m 4s ⏱️
 38 tests  38 ✅ 0 💤 0 ❌
241 runs  241 ✅ 0 💤 0 ❌

Results for commit f2fce44.

♻️ This comment has been updated with latest results.

Copilot

This comment was marked as outdated.

@SuGlider SuGlider requested a review from Copilot July 10, 2025 20:23
Copilot

This comment was marked as outdated.

@SuGlider SuGlider requested a review from Copilot July 10, 2025 20:45
Copilot

This comment was marked as outdated.

@SuGlider SuGlider requested a review from Copilot July 10, 2025 20:53
Copilot

This comment was marked as outdated.

@SuGlider SuGlider changed the title feat(wire): adds std::functional to slave callback functions feat(wire): adds std::functional to Wire slave callback functions Jul 10, 2025
@SuGlider SuGlider changed the title feat(wire): adds std::functional to Wire slave callback functions feat(wire): std::functional Wire slave callback functions Jul 10, 2025
Copy link
Contributor

github-actions bot commented Jul 10, 2025

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32P40⚠️ +7720.00⚠️ +0.220⚠️ +480.00⚠️ +0.20
ESP32S30⚠️ +8600.00⚠️ +0.260⚠️ +480.00⚠️ +0.22
ESP32S20⚠️ +8560.00⚠️ +0.290⚠️ +480.00⚠️ +0.29
ESP32C30⚠️ +7760.00⚠️ +0.250⚠️ +320.00⚠️ +0.26
ESP32C60⚠️ +7740.00⚠️ +0.290⚠️ +480.00⚠️ +0.34
ESP32H20⚠️ +7780.00⚠️ +0.250⚠️ +480.00⚠️ +0.34
ESP32💚 -16⚠️ +8440.00⚠️ +0.250⚠️ +480.00⚠️ +0.22
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32P4ESP32S3ESP32S2ESP32C3ESP32C6ESP32H2ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
ArduinoOTA/examples/BasicOTA0000000000--00
AsyncUDP/examples/AsyncUDPClient0000000000--00
AsyncUDP/examples/AsyncUDPMulticastServer0000000000--00
AsyncUDP/examples/AsyncUDPServer00⚠️ +160000000--00
DNSServer/examples/CaptivePortal0000000000--00
EEPROM/examples/eeprom_class00000000000000
EEPROM/examples/eeprom_extra00000000000000
EEPROM/examples/eeprom_write00000000000000
ESP32/examples/AnalogOut/LEDCFade00000000000000
ESP32/examples/AnalogOut/LEDCGammaFade00------0000--
ESP32/examples/AnalogOut/LEDCSingleChannel00000000000000
ESP32/examples/AnalogOut/LEDCSoftwareFade00000000000000
ESP32/examples/AnalogOut/SigmaDelta00000000000000
ESP32/examples/AnalogOut/ledcFrequency00000000000000
ESP32/examples/AnalogOut/ledcWrite_RGB00000000000000
ESP32/examples/AnalogRead00000000000000
ESP32/examples/AnalogReadContinuous00000000000000
ESP32/examples/ArduinoStackSize00000000000000
ESP32/examples/CI/CIBoardsTest⚠️ +448⚠️ +48⚠️ +472⚠️ +48⚠️ +468⚠️ +48⚠️ +456⚠️ +32⚠️ +456⚠️ +48⚠️ +452⚠️ +48⚠️ +476⚠️ +48
ESP32/examples/ChipID/GetChipID00000000000000
ESP32/examples/DeepSleep/TimerWakeUp0000000000--00
ESP32/examples/DeepSleep/TouchWakeUp000000------00
ESP32/examples/FreeRTOS/BasicMultiThreading00000000000000
ESP32/examples/FreeRTOS/Mutex00000000000000
ESP32/examples/FreeRTOS/Queue00000000000000
ESP32/examples/FreeRTOS/Semaphore00000000000000
ESP32/examples/GPIO/BlinkRGB00000000000000
ESP32/examples/GPIO/FunctionalInterrupt00000000000000
ESP32/examples/GPIO/FunctionalInterruptStruct00000000000000
ESP32/examples/GPIO/GPIOInterrupt00000000000000
ESP32/examples/HWCDC_Events0000--000000--
ESP32/examples/MacAddress/GetMacAddress00000000000000
ESP32/examples/RMT/Legacy_RMT_Driver_Compatible00000000000000
ESP32/examples/RMT/RMTCallback00000000000000
ESP32/examples/RMT/RMTLoopback00000000000000
ESP32/examples/RMT/RMTReadXJT00000000000000
ESP32/examples/RMT/RMTWrite_RGB_LED00000000000000
ESP32/examples/RMT/RMT_CPUFreq_Test00000000000000
ESP32/examples/RMT/RMT_EndOfTransmissionState00000000000000
ESP32/examples/RMT/RMT_LED_Blink00000000000000
ESP32/examples/ResetReason/ResetReason00000000000000
ESP32/examples/ResetReason/ResetReason200000000000000
ESP32/examples/Serial/BaudRateDetect_Demo00000000000000
ESP32/examples/Serial/OnReceiveError_BREAK_Demo00000000000000
ESP32/examples/Serial/OnReceive_Demo00000000000000
ESP32/examples/Serial/RS485_Echo_Demo00000000000000
ESP32/examples/Serial/RxFIFOFull_Demo00000000000000
ESP32/examples/Serial/RxTimeout_Demo00000000000000
ESP32/examples/Serial/Serial_All_CPU_Freqs00000000000000
ESP32/examples/Serial/Serial_STD_Func_OnReceive00000000000000
ESP32/examples/Serial/onReceiveExample00000000000000
ESP32/examples/TWAI/TWAIreceive00000000000000
ESP32/examples/TWAI/TWAItransmit00000000000000
ESP32/examples/Template/ExampleTemplate00000000000000
ESP32/examples/Time/SimpleTime0000000000--00
ESP32/examples/Timer/RepeatTimer00000000000000
ESP32/examples/Timer/WatchdogTimer00000000000000
ESP32/examples/Touch/TouchInterrupt000000------00
ESP32/examples/Touch/TouchRead000000------00
ESP32/examples/Utilities/HEXBuilder00000000000000
ESP32/examples/Utilities/MD5Builder00000000000000
ESP32/examples/Utilities/SHA1Builder00000000000000
ESP_I2S/examples/ES8388_loopback⚠️ +444⚠️ +48⚠️ +476⚠️ +48⚠️ +472⚠️ +48⚠️ +446⚠️ +32⚠️ +446⚠️ +48⚠️ +448⚠️ +48⚠️ +464⚠️ +48
ESP_I2S/examples/Record_to_WAV0000--------00
ESP_I2S/examples/Simple_tone00000000000000
ESPmDNS/examples/mDNS-SD_Extended0000000000--00
ESPmDNS/examples/mDNS_Web_Server0000000000--00
Ethernet/examples/ETH_TLK11000----------00
Ethernet/examples/ETH_W5500_Arduino_SPI00000000000000
Ethernet/examples/ETH_W5500_IDF_SPI00000000000000
Ethernet/examples/ETH_WIFI_BRIDGE0000000000--00
FFat/examples/FFat_Test00000000000000
FFat/examples/FFat_time0000000000--00
HTTPClient/examples/Authorization0000000000--00
HTTPClient/examples/BasicHttpClient0000000000--00
HTTPClient/examples/BasicHttpsClient0000000000--00
HTTPClient/examples/ReuseConnection0000000000--00
HTTPClient/examples/StreamHttpClient0000000000--00
HTTPUpdate/examples/httpUpdate0000000000--00
HTTPUpdate/examples/httpUpdateSPIFFS0000000000--00
HTTPUpdate/examples/httpUpdateSecure0000000000--00
HTTPUpdateServer/examples/WebUpdater0000000000--00
LittleFS/examples/LITTLEFS_test00000000000000
LittleFS/examples/LITTLEFS_time0000000000--00
NetBIOS/examples/ESP_NBNST0000000000--00
NetworkClientSecure/examples/WiFiClientInsecure0000000000--00
NetworkClientSecure/examples/WiFiClientPSK0000000000--00
NetworkClientSecure/examples/WiFiClientSecure0000000000--00
NetworkClientSecure/examples/WiFiClientSecureProtocolUpgrade0000000000--00
NetworkClientSecure/examples/WiFiClientShowPeerCredentials0000000000--00
NetworkClientSecure/examples/WiFiClientTrustOnFirstUse0000000000--00
PPP/examples/PPP_Basic00000000000000
PPP/examples/PPP_WIFI_BRIDGE0000000000--00
Preferences/examples/Prefs2Struct00000000000000
Preferences/examples/StartCounter00000000000000
SD/examples/SD_Test00000000000000
SD/examples/SD_time0000000000--00
SD_MMC/examples/SD2USBMSC0000----------
SD_MMC/examples/SDMMC_Test0000--------00
SD_MMC/examples/SDMMC_time0000--------00
SPI/examples/SPI_Multiple_Buses00000000000000
SPIFFS/examples/SPIFFS_Test00000000000000
SPIFFS/examples/SPIFFS_time0000000000--00
TFLiteMicro/examples/hello_world00000000000000
Ticker/examples/Blinker00000000000000
Ticker/examples/TickerBasic00000000000000
Ticker/examples/TickerParameter00000000000000
USB/examples/CompositeDevice000000--------
USB/examples/ConsumerControl000000--------
USB/examples/CustomHIDDevice000000--------
USB/examples/FirmwareMSC000000--------
USB/examples/Gamepad000000--------
USB/examples/HIDVendor000000--------
USB/examples/Keyboard/KeyboardLogout000000--------
USB/examples/Keyboard/KeyboardMessage000000--------
USB/examples/Keyboard/KeyboardReprogram000000--------
USB/examples/Keyboard/KeyboardSerial000000--------
USB/examples/KeyboardAndMouseControl000000--------
USB/examples/MIDI/MidiController000000--------
USB/examples/MIDI/MidiInterface000000--------
USB/examples/MIDI/MidiMusicBox000000--------
USB/examples/MIDI/ReceiveMidi000000--------
USB/examples/Mouse/ButtonMouseControl000000--------
USB/examples/SystemControl000000--------
USB/examples/USBMSC000000--------
USB/examples/USBSerial000000--------
USB/examples/USBVendor000000--------
Update/examples/AWS_S3_OTA_Update0000000000--00
Update/examples/HTTPS_OTA_Update0000000000--00
Update/examples/HTTP_Client_AES_OTA_Update0000000000--00
Update/examples/HTTP_Server_AES_OTA_Update0000000000--00
Update/examples/OTAWebUpdater0000000000--00
Update/examples/SD_Update00000000000000
WebServer/examples/AdvancedWebServer0000000000--00
WebServer/examples/FSBrowser0000000000--00
WebServer/examples/Filters0000000000--00
WebServer/examples/HelloServer0000000000--00
WebServer/examples/HttpAdvancedAuth0000000000--00
WebServer/examples/HttpAuthCallback0000000000--00
WebServer/examples/HttpAuthCallbackInline0000000000--00
WebServer/examples/HttpBasicAuth0000000000--00
WebServer/examples/HttpBasicAuthSHA10000000000--00
WebServer/examples/HttpBasicAuthSHA1orBearerToken0000000000--00
WebServer/examples/MultiHomedServers0000000000--00
WebServer/examples/PathArgServer0000000000--00
WebServer/examples/SDWebServer0000000000--00
WebServer/examples/SimpleAuthentification0000000000--00
WebServer/examples/UploadHugeFile0000000000--00
WebServer/examples/WebServer0000000000--00
WebServer/examples/WebUpdate0000000000--00
WiFi/examples/FTM/FTM_Initiator0000000000--00
WiFi/examples/FTM/FTM_Responder0000000000--00
WiFi/examples/SimpleWiFiServer0000000000--00
WiFi/examples/WiFiAccessPoint0000000000--00
WiFi/examples/WiFiClient0000000000--00
WiFi/examples/WiFiClientBasic0000000000--00
WiFi/examples/WiFiClientConnect0000000000--00
WiFi/examples/WiFiClientEvents0000000000--00
WiFi/examples/WiFiClientStaticIP0000000000--00
WiFi/examples/WiFiExtender0000000000--00
WiFi/examples/WiFiIPv60000000000--00
WiFi/examples/WiFiMulti0000000000--00
WiFi/examples/WiFiMultiAdvanced0000000000--00
WiFi/examples/WiFiScan0000000000--00
WiFi/examples/WiFiScanAsync0000000000--00
WiFi/examples/WiFiScanDualAntenna0000000000--00
WiFi/examples/WiFiScanTime0000000000--00
WiFi/examples/WiFiTelnetToSerial0000000000--00
WiFi/examples/WiFiUDPClient0000000000--00
Wire/examples/WireMaster⚠️ +448⚠️ +48⚠️ +472⚠️ +48⚠️ +468⚠️ +48⚠️ +452⚠️ +32⚠️ +448⚠️ +48⚠️ +450⚠️ +48⚠️ +460⚠️ +48
Wire/examples/WireScan⚠️ +448⚠️ +48⚠️ +472⚠️ +48⚠️ +468⚠️ +48⚠️ +454⚠️ +32⚠️ +448⚠️ +48⚠️ +450⚠️ +48⚠️ +460⚠️ +48
Wire/examples/WireSlave⚠️ +772⚠️ +48⚠️ +860⚠️ +48⚠️ +856⚠️ +48⚠️ +776⚠️ +32⚠️ +774⚠️ +48⚠️ +778⚠️ +48⚠️ +844⚠️ +48
Wire/examples/WireSlaveFunctionalCallback--------------
BLE/examples/BLE5_extended_scan--00--000000--
BLE/examples/BLE5_multi_advertising--00--000000--
BLE/examples/BLE5_periodic_advertising--00--000000--
BLE/examples/BLE5_periodic_sync--00--000000--
BLE/examples/Beacon_Scanner--00--00000000
BLE/examples/Client--00--00000000
BLE/examples/EddystoneTLM_Beacon--00--00000000
BLE/examples/EddystoneURL_Beacon--00--00000000
BLE/examples/Notify--00--00000000
BLE/examples/Scan--00--00000000
BLE/examples/Server--00--00000000
BLE/examples/Server_multiconnect--00--00000000
BLE/examples/UART--00--00000000
BLE/examples/Write--00--00000000
BLE/examples/iBeacon--00--00000000
ESP32/examples/Camera/CameraWebServer (1)--0000------00
ESP32/examples/Camera/CameraWebServer (2)--0000------00
ESP32/examples/Camera/CameraWebServer (3)--00----------
ESP32/examples/DeepSleep/ExternalWakeUp--0000------00
ESP_NOW/examples/ESP_NOW_Broadcast_Master--00000000--00
ESP_NOW/examples/ESP_NOW_Broadcast_Slave--00000000--00
ESP_NOW/examples/ESP_NOW_Network--00000000--00
ESP_NOW/examples/ESP_NOW_Serial--00000000--00
ESP_SR/examples/Basic--00----------
HTTPClient/examples/HTTPClientEnterprise--⚠️ +448⚠️ +48⚠️ +444⚠️ +48⚠️ +454⚠️ +16⚠️ +450⚠️ +48--⚠️ +476⚠️ +48
Insights/examples/DiagnosticsSmokeTest--00000000--00
Insights/examples/MinimalDiagnostics--00000000--00
Matter/examples/MatterColorLight--00000000--00
Matter/examples/MatterCommissionTest--00000000--00
Matter/examples/MatterComposedLights--00000000--00
Matter/examples/MatterContactSensor--00000000--00
Matter/examples/MatterDimmableLight--00000000--00
Matter/examples/MatterEnhancedColorLight--00000000--00
Matter/examples/MatterEvents--00000000--00
Matter/examples/MatterFan--00000000--00
Matter/examples/MatterHumiditySensor--00000000--00
Matter/examples/MatterMinimum--00000000--00
Matter/examples/MatterOccupancySensor--00000000--00
Matter/examples/MatterOnIdentify--00000000--00
Matter/examples/MatterOnOffLight--00000000--00
Matter/examples/MatterOnOffPlugin--00000000--💚 -160
Matter/examples/MatterPressureSensor--00000000--00
Matter/examples/MatterSmartButon--00000000--00
Matter/examples/MatterTemperatureLight--00000000--00
Matter/examples/MatterTemperatureSensor--00000000--00
Matter/examples/MatterThermostat--00000000--00
Matter/examples/WiFiProvWithinMatter--00000000--00
NetworkClientSecure/examples/WiFiClientSecureEnterprise--⚠️ +428⚠️ +48⚠️ +496⚠️ +48⚠️ +454⚠️ +16⚠️ +450⚠️ +48--⚠️ +464⚠️ +48
RainMaker/examples/RMakerCustom--00000000----
RainMaker/examples/RMakerCustomAirCooler--00000000----
RainMaker/examples/RMakerSonoffDualR3--00000000----
RainMaker/examples/RMakerSwitch--00000000----
SimpleBLE/examples/SimpleBleDevice--00--00000000
WebServer/examples/Middleware--00000000--00
WiFi/examples/WPS--00000000--00
WiFi/examples/WiFiBlueToothSwitch--00--0000--00
WiFi/examples/WiFiClientEnterprise--00000000--00
WiFi/examples/WiFiSmartConfig--00000000--00
WiFiProv/examples/WiFiProv--00000000--00
Zigbee/examples/Zigbee_Analog_Input_Output--000000000000
Zigbee/examples/Zigbee_Color_Dimmer_Switch--000000000000
Zigbee/examples/Zigbee_Electrical_AC_Sensor--000000000000
Zigbee/examples/Zigbee_Electrical_AC_Sensor_MultiPhase--000000000000
Zigbee/examples/Zigbee_Fan_Control--000000000000
Zigbee/examples/Zigbee_Gateway--000000----00
Zigbee/examples/Zigbee_On_Off_Switch--000000000000
Zigbee/examples/Zigbee_Range_Extender--000000000000
Zigbee/examples/Zigbee_Thermostat--000000000000
OpenThread/examples/CLI/COAP/coap_lamp--------0000--
OpenThread/examples/CLI/COAP/coap_switch--------0000--
OpenThread/examples/CLI/SimpleCLI--------0000--
OpenThread/examples/CLI/SimpleNode--------0000--
OpenThread/examples/CLI/SimpleThreadNetwork/ExtendedRouterNode--------0000--
OpenThread/examples/CLI/SimpleThreadNetwork/LeaderNode--------0000--
OpenThread/examples/CLI/SimpleThreadNetwork/RouterNode--------0000--
OpenThread/examples/CLI/ThreadScan--------0000--
OpenThread/examples/CLI/onReceive--------0000--
OpenThread/examples/Native/SimpleThreadNetwork/LeaderNode--------0000--
OpenThread/examples/Native/SimpleThreadNetwork/RouterNode--------0000--
Zigbee/examples/Zigbee_Binary_Input--------0000--
Zigbee/examples/Zigbee_CarbonDioxide_Sensor--------0000--
Zigbee/examples/Zigbee_Color_Dimmable_Light--------0000--
Zigbee/examples/Zigbee_Contact_Switch--------0000--
Zigbee/examples/Zigbee_Dimmable_Light--------0000--
Zigbee/examples/Zigbee_Electrical_DC_Sensor--------0000--
Zigbee/examples/Zigbee_Illuminance_Sensor--------0000--
Zigbee/examples/Zigbee_OTA_Client--------0000--
Zigbee/examples/Zigbee_Occupancy_Sensor--------0000--
Zigbee/examples/Zigbee_On_Off_Light--------0000--
Zigbee/examples/Zigbee_On_Off_MultiSwitch--------0000--
Zigbee/examples/Zigbee_PM25_Sensor--------0000--
Zigbee/examples/Zigbee_Power_Outlet--------0000--
Zigbee/examples/Zigbee_Pressure_Flow_Sensor--------0000--
Zigbee/examples/Zigbee_Scan_Networks--------0000--
Zigbee/examples/Zigbee_Temp_Hum_Sensor_Sleepy--------0000--
Zigbee/examples/Zigbee_Temperature_Sensor--------0000--
Zigbee/examples/Zigbee_Vibration_Sensor--------0000--
Zigbee/examples/Zigbee_Wind_Speed_Sensor--------0000--
Zigbee/examples/Zigbee_Window_Covering--------0000--
BluetoothSerial/examples/DiscoverConnect------------00
BluetoothSerial/examples/GetLocalMAC------------00
BluetoothSerial/examples/SerialToSerialBT------------00
BluetoothSerial/examples/SerialToSerialBTM------------00
BluetoothSerial/examples/SerialToSerialBT_Legacy------------00
BluetoothSerial/examples/SerialToSerialBT_SSP------------00
BluetoothSerial/examples/bt_classic_device_discovery------------00
BluetoothSerial/examples/bt_remove_paired_devices------------00
ESP32/examples/DeepSleep/SmoothBlink_ULP_Code------------00
Ethernet/examples/ETH_LAN8720------------00

@SuGlider SuGlider requested a review from Copilot July 10, 2025 23:22
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the Wire library to support std::function–based callbacks for I2C slave mode, enabling the use of lambdas and captured contexts.

  • Replaces raw function pointers in TwoWire and HardwareI2C with std::function for onRequest and onReceive
  • Updates constructors, method signatures, and default initializations to use std::function
  • Adds new example sketch, CI config, and documentation updates demonstrating the functional callback API

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
libraries/Wire/src/Wire.h Swapped C-style callback pointers for std::function members
libraries/Wire/src/Wire.cpp Updated constructor initializers and method implementations
libraries/Wire/examples/WireSlaveFunctionalCallback/ci.json Added CI requirement for I2C slave support
libraries/Wire/examples/WireSlaveFunctionalCallback/WireSlaveFunctionalCallback.ino New example illustrating functional callbacks
docs/en/api/i2c.rst Revised API docs for onReceive/onRequest to show std::function
cores/esp32/HardwareI2C.h Updated base class to use std::function and included <functional>
Comments suppressed due to low confidence (4)

docs/en/api/i2c.rst:440

  • [nitpick] The example uses Wire.printf, but TwoWire may not support printf across all cores; consider using Wire.print/Wire.write or ensure printf is available.
        Wire.printf("Response #%d", counter++);

libraries/Wire/src/Wire.cpp:599

  • There are no unit tests verifying that the new std::function–based callbacks are invoked correctly; consider adding tests for both onReceive and onRequest paths.
void TwoWire::onReceive(const std::function<void(int)>& function) {

libraries/Wire/src/Wire.h:76

  • The header uses std::function but <functional> is not included; add #include <functional> at the top of this file to ensure compilation on all platforms.
  std::function<void()> user_onRequest;

libraries/Wire/src/Wire.h:76

  • [nitpick] Using std::function for callbacks can introduce dynamic allocations and overhead on constrained embedded targets; consider documenting this cost or offering a lightweight alternative.
  std::function<void()> user_onRequest;

@SuGlider SuGlider marked this pull request as ready for review July 11, 2025 00:16
@SuGlider SuGlider requested review from lucasssvaz, pedrominatel and a team as code owners July 11, 2025 00:16
@SuGlider SuGlider added the Status: Review needed Issue or PR is awaiting review label Jul 11, 2025
@SuGlider SuGlider moved this from In Progress to In Review in Arduino ESP32 Core Project Roadmap Jul 11, 2025
@SuGlider SuGlider mentioned this pull request Jul 11, 2025
1 task
@SuGlider SuGlider requested a review from P-R-O-C-H-Y July 11, 2025 02:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Peripherals API Relates to peripheral's APIs. Status: Review needed Issue or PR is awaiting review Type: Feature request Feature request for Arduino ESP32
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

functional callbacks
2 participants