Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3f32903

Browse files
Merge branch 'master' into release/v3.3.x
2 parents ce7ef9c + 82d56bc commit 3f32903

File tree

14 files changed

+552
-18
lines changed

14 files changed

+552
-18
lines changed

‎.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# CI
1313
/.github/ @lucasssvaz @me-no-dev @P-R-O-C-H-Y
14+
/.gitlab/ @lucasssvaz
1415
/tests/ @lucasssvaz @P-R-O-C-H-Y
1516

1617
# Tools

‎.github/scripts/update-version.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ cat docs/conf_common.py | \
4545
sed "s/.. |version| replace:: .*/.. |version| replace:: $ESP_ARDUINO_VERSION/g" | \
4646
sed "s/.. |idf_version| replace:: .*/.. |idf_version| replace:: $ESP_IDF_VERSION/g" > docs/__conf_common.py && mv docs/__conf_common.py docs/conf_common.py
4747

48+
echo "Updating .gitlab/workflows/common.yml..."
49+
cat .gitlab/workflows/common.yml | \
50+
sed "s/ESP_IDF_VERSION:.*/ESP_IDF_VERSION: \"$ESP_IDF_VERSION\"/g" | \
51+
sed "s/ESP_ARDUINO_VERSION:.*/ESP_ARDUINO_VERSION: \"$ESP_ARDUINO_VERSION\"/g" > .gitlab/workflows/__common.yml && mv .gitlab/workflows/__common.yml .gitlab/workflows/common.yml
52+
4853
echo "Updating cores/esp32/esp_arduino_version.h..."
4954
cat cores/esp32/esp_arduino_version.h | \
5055
sed "s/#define ESP_ARDUINO_VERSION_MAJOR.*/#define ESP_ARDUINO_VERSION_MAJOR $ESP_ARDUINO_VERSION_MAJOR/g" | \

‎.gitlab-ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
workflow:
2+
rules:
3+
# Disable those non-protected push triggered pipelines
4+
- if: '$CI_COMMIT_REF_NAME != "master" && $CI_COMMIT_BRANCH !~ /^release\/v/ && $CI_COMMIT_TAG !~ /^\d+\.\d+(\.\d+)?($|-)/ && $CI_PIPELINE_SOURCE == "push"'
5+
when: never
6+
# when running merged result pipelines, CI_COMMIT_SHA represents the temp commit it created.
7+
# Please use PIPELINE_COMMIT_SHA at all places that require a commit sha of the original commit.
8+
- if: $CI_OPEN_MERGE_REQUESTS != null
9+
variables:
10+
PIPELINE_COMMIT_SHA: $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA
11+
IS_MR_PIPELINE: 1
12+
- if: $CI_OPEN_MERGE_REQUESTS == null
13+
variables:
14+
PIPELINE_COMMIT_SHA: $CI_COMMIT_SHA
15+
IS_MR_PIPELINE: 0
16+
- if: '$CI_PIPELINE_SOURCE == "schedule"'
17+
variables:
18+
IS_SCHEDULED_RUN: "true"
19+
- when: always
20+
21+
# Place the default settings in `.gitlab/workflows/common.yml` instead
22+
23+
include:
24+
- ".gitlab/workflows/common.yml"
25+
- ".gitlab/workflows/sample.yml"

‎.gitlab/workflows/common.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#####################
2+
# Default Variables #
3+
#####################
4+
5+
stages:
6+
- pre_check
7+
- build
8+
- test
9+
- result
10+
11+
variables:
12+
ESP_IDF_VERSION: "5.4"
13+
ESP_ARDUINO_VERSION: "3.2.1"
14+
15+
#############
16+
# `default` #
17+
#############
18+
19+
default:
20+
retry:
21+
max: 2
22+
when:
23+
# In case of a runner failure we could hop to another one, or a network error could go away.
24+
- runner_system_failure
25+
# Job execution timeout may be caused by a network issue.
26+
- job_execution_timeout

‎.gitlab/workflows/sample.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
hello-world:
2+
stage: test
3+
script:
4+
- echo "Hello, World from GitLab CI!"
5+
rules:
6+
- if: $CI_PIPELINE_SOURCE == "push"

‎cores/esp32/HardwareI2C.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <inttypes.h>
2222
#include "Stream.h"
23+
#include <functional>
2324

2425
class HardwareI2C : public Stream {
2526
public:
@@ -36,6 +37,7 @@ class HardwareI2C : public Stream {
3637
virtual size_t requestFrom(uint8_t address, size_t len, bool stopBit) = 0;
3738
virtual size_t requestFrom(uint8_t address, size_t len) = 0;
3839

39-
virtual void onReceive(void (*)(int)) = 0;
40-
virtual void onRequest(void (*)(void)) = 0;
40+
// Update base class to use std::function
41+
virtual void onReceive(const std::function<void(int)> &) = 0;
42+
virtual void onRequest(const std::function<void()> &) = 0;
4143
};

‎docs/en/api/i2c.rst

Lines changed: 131 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,20 +347,147 @@ This function will return ``true`` if the peripheral was initialized correctly.
347347
onReceive
348348
^^^^^^^^^
349349

350-
The ``onReceive`` function is used to define the callback for the data received from the master.
350+
The ``onReceive`` function is used to define the callback for data received from the master device.
351351

352352
.. code-block:: arduino
353353
354-
void onReceive( void (*)(int) );
354+
void onReceive(const std::function<void(int)>& callback);
355+
356+
**Function Signature:**
357+
358+
The callback function must have the signature ``void(int numBytes)`` where ``numBytes`` indicates how many bytes were received from the master.
359+
360+
**Usage Examples:**
361+
362+
.. code-block:: arduino
363+
364+
// Method 1: Regular function
365+
void handleReceive(int numBytes) {
366+
Serial.printf("Received %d bytes: ", numBytes);
367+
while (Wire.available()) {
368+
char c = Wire.read();
369+
Serial.print(c);
370+
}
371+
Serial.println();
372+
}
373+
Wire.onReceive(handleReceive);
374+
375+
// Method 2: Lambda function
376+
Wire.onReceive([](int numBytes) {
377+
Serial.printf("Master sent %d bytes\n", numBytes);
378+
while (Wire.available()) {
379+
uint8_t data = Wire.read();
380+
// Process received data
381+
Serial.printf("Data: 0x%02X\n", data);
382+
}
383+
});
384+
385+
// Method 3: Lambda with capture (for accessing variables)
386+
int deviceId = 42;
387+
Wire.onReceive([deviceId](int numBytes) {
388+
Serial.printf("Device %d received %d bytes\n", deviceId, numBytes);
389+
// Process data...
390+
});
391+
392+
// Method 4: Using std::function variable
393+
std::function<void(int)> receiveHandler = [](int bytes) {
394+
Serial.printf("Handling %d received bytes\n", bytes);
395+
};
396+
Wire.onReceive(receiveHandler);
397+
398+
// Method 5: Class member function (using lambda wrapper)
399+
class I2CDevice {
400+
private:
401+
int deviceAddress;
402+
public:
403+
I2CDevice(int addr) : deviceAddress(addr) {}
404+
405+
void handleReceive(int numBytes) {
406+
Serial.printf("Device 0x%02X received %d bytes\n", deviceAddress, numBytes);
407+
}
408+
409+
void setup() {
410+
Wire.onReceive([this](int bytes) {
411+
this->handleReceive(bytes);
412+
});
413+
}
414+
};
415+
416+
.. note::
417+
The ``onReceive`` callback is triggered when the I2C master sends data to this slave device.
418+
Use ``Wire.available()`` and ``Wire.read()`` inside the callback to retrieve the received data.
355419

356420
onRequest
357421
^^^^^^^^^
358422

359-
The ``onRequest`` function is used to define the callback for the data to be send to the master.
423+
The ``onRequest`` function is used to define the callback for responding to master read requests.
424+
425+
.. code-block:: arduino
426+
427+
void onRequest(const std::function<void()>& callback);
428+
429+
**Function Signature:**
430+
431+
The callback function must have the signature ``void()`` with no parameters. This callback is triggered when the master requests data from this slave device.
432+
433+
**Usage Examples:**
360434

361435
.. code-block:: arduino
362436
363-
void onRequest( void (*)(void) );
437+
// Method 1: Regular function
438+
void handleRequest() {
439+
static int counter = 0;
440+
Wire.printf("Response #%d", counter++);
441+
}
442+
Wire.onRequest(handleRequest);
443+
444+
// Method 2: Lambda function
445+
Wire.onRequest([]() {
446+
// Send sensor data to master
447+
int sensorValue = analogRead(A0);
448+
Wire.write(sensorValue >> 8); // High byte
449+
Wire.write(sensorValue & 0xFF); // Low byte
450+
});
451+
452+
// Method 3: Lambda with capture (for accessing variables)
453+
int deviceStatus = 1;
454+
String deviceName = "Sensor1";
455+
Wire.onRequest([&deviceStatus, &deviceName]() {
456+
Wire.write(deviceStatus);
457+
Wire.write(deviceName.c_str(), deviceName.length());
458+
});
459+
460+
// Method 4: Using std::function variable
461+
std::function<void()> requestHandler = []() {
462+
Wire.write("Hello Master!");
463+
};
464+
Wire.onRequest(requestHandler);
465+
466+
// Method 5: Class member function (using lambda wrapper)
467+
class TemperatureSensor {
468+
private:
469+
float temperature;
470+
public:
471+
void updateTemperature() {
472+
temperature = 25.5; // Read from actual sensor
473+
}
474+
475+
void sendTemperature() {
476+
// Convert float to bytes and send
477+
uint8_t* tempBytes = (uint8_t*)&temperature;
478+
Wire.write(tempBytes, sizeof(float));
479+
}
480+
481+
void setup() {
482+
Wire.onRequest([this]() {
483+
this->sendTemperature();
484+
});
485+
}
486+
};
487+
488+
.. note::
489+
The ``onRequest`` callback is triggered when the I2C master requests data from this slave device.
490+
Use ``Wire.write()`` inside the callback to send response data back to the master.
364491

365492
slaveWrite
366493
^^^^^^^^^^

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /