Skip to content

Commit df3db3c

Browse files
authored
Merge branch 'master' into release/v3.3.x
2 parents ccc0a69 + 6a5839a commit df3db3c

File tree

17 files changed

+435
-29
lines changed

17 files changed

+435
-29
lines changed

.github/workflows/dangerjs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ jobs:
2424
instructions-cla-link: "https://cla-assistant.io/espressif/arduino-esp32"
2525
instructions-contributions-file: "docs/en/contributing.rst"
2626
rule-max-commits: "false"
27+
rule-target-branch: "false"
2728
commit-messages-min-summary-length: "10"

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ set(ARDUINO_LIBRARY_Zigbee_SRCS
306306
libraries/Zigbee/src/ep/ZigbeeElectricalMeasurement.cpp
307307
libraries/Zigbee/src/ep/ZigbeeBinary.cpp
308308
libraries/Zigbee/src/ep/ZigbeePowerOutlet.cpp
309+
libraries/Zigbee/src/ep/ZigbeeFanControl.cpp
309310
)
310311

311312
set(ARDUINO_LIBRARY_BLE_SRCS

boards.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51016,10 +51016,12 @@ rakwireless_rak3112.build.dfu_on_boot=0
5101651016
rakwireless_rak3112.build.f_cpu=240000000L
5101751017
rakwireless_rak3112.build.flash_size=16MB
5101851018
rakwireless_rak3112.build.flash_freq=80m
51019-
rakwireless_rak3112.build.flash_mode=dio
51020-
rakwireless_rak3112.build.boot=dio
51019+
rakwireless_rak3112.build.flash_mode=qio
51020+
rakwireless_rak3112.build.boot=qio
5102151021
rakwireless_rak3112.build.partitions=default
5102251022
rakwireless_rak3112.build.defines=
51023+
rakwireless_rak3112.build.psram_type=opi
51024+
rakwireless_rak3112.build.memory_type={build.boot}_{build.psram_type}
5102351025

5102451026
rakwireless_rak3112.menu.PSRAM.enabled=Enabled
5102551027
rakwireless_rak3112.menu.PSRAM.enabled.build.defines=-DBOARD_HAS_PSRAM

cores/esp32/esp32-hal-i2c-ng.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ static bool i2cDetachBus(void *bus_i2c_num) {
5656
return true;
5757
}
5858

59+
void *i2cBusHandle(uint8_t i2c_num) {
60+
if (i2c_num >= SOC_I2C_NUM) {
61+
return NULL;
62+
}
63+
return bus[i2c_num].bus_handle;
64+
}
65+
5966
bool i2cIsInit(uint8_t i2c_num) {
6067
if (i2c_num >= SOC_I2C_NUM) {
6168
return false;

cores/esp32/esp32-hal-i2c.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "soc/soc_caps.h"
2121
#if SOC_I2C_SUPPORTED
22+
#include "esp_idf_version.h"
2223

2324
#ifdef __cplusplus
2425
extern "C" {
@@ -39,6 +40,10 @@ esp_err_t i2cWriteReadNonStop(
3940
);
4041
bool i2cIsInit(uint8_t i2c_num);
4142

43+
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 4, 0)
44+
void *i2cBusHandle(uint8_t i2c_num);
45+
#endif
46+
4247
#ifdef __cplusplus
4348
}
4449
#endif

libraries/AsyncUDP/src/AsyncUDP.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,8 @@ bool AsyncUDP::listen(const ip_addr_t *addr, uint16_t port) {
582582
}
583583
close();
584584
if (addr) {
585-
IP_SET_TYPE_VAL(_pcb->local_ip, addr->type);
586-
IP_SET_TYPE_VAL(_pcb->remote_ip, addr->type);
585+
IP_SET_TYPE_VAL(_pcb->local_ip, IP_GET_TYPE(addr));
586+
IP_SET_TYPE_VAL(_pcb->remote_ip, IP_GET_TYPE(addr));
587587
}
588588
if (_udp_bind(_pcb, addr, port) != ERR_OK) {
589589
return false;
@@ -692,17 +692,8 @@ bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl
692692
return false;
693693
}
694694

695-
#if CONFIG_LWIP_IPV6
696-
if (IP_IS_V6(addr)) {
697-
IP_SET_TYPE(&bind_addr, IPADDR_TYPE_V6);
698-
ip6_addr_set_any(&bind_addr.u_addr.ip6);
699-
} else {
700-
#endif
701-
IP_SET_TYPE(&bind_addr, IPADDR_TYPE_V4);
702-
ip4_addr_set_any(&bind_addr.u_addr.ip4);
703-
#if CONFIG_LWIP_IPV6
704-
}
705-
#endif
695+
IP_SET_TYPE(&bind_addr, IP_GET_TYPE(addr));
696+
ip_addr_set_any(IP_IS_V6(addr), &bind_addr);
706697
if (!listen(&bind_addr, port)) {
707698
return false;
708699
}

libraries/Wire/src/Wire.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extern "C" {
3939
#include "Arduino.h"
4040

4141
TwoWire::TwoWire(uint8_t bus_num)
42-
: num(bus_num & 1), sda(-1), scl(-1), bufferSize(I2C_BUFFER_LENGTH) // default Wire Buffer Size
42+
: num(bus_num), sda(-1), scl(-1), bufferSize(I2C_BUFFER_LENGTH) // default Wire Buffer Size
4343
,
4444
rxBuffer(NULL), rxIndex(0), rxLength(0), txBuffer(NULL), txLength(0), txAddress(0), _timeOutMillis(50), nonStop(false)
4545
#if !CONFIG_DISABLE_HAL_LOCKS
@@ -62,6 +62,10 @@ TwoWire::~TwoWire() {
6262
#endif
6363
}
6464

65+
uint8_t TwoWire::getBusNum() {
66+
return num;
67+
}
68+
6569
bool TwoWire::initPins(int sdaPin, int sclPin) {
6670
if (sdaPin < 0) { // default param passed
6771
if (num == 0) {

libraries/Wire/src/Wire.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ class TwoWire : public HardwareI2C {
105105

106106
bool end() override;
107107

108+
uint8_t getBusNum();
109+
108110
bool setClock(uint32_t freq) override;
109111

110112
void beginTransmission(uint8_t address) override;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Arduino-ESP32 Zigbee Fan Control Example
2+
3+
This example demonstrates how to use the Zigbee library to create a router device fan control and use it as a Home Automation (HA) fan control device.
4+
5+
# Supported Targets
6+
7+
Currently, this example supports the following targets.
8+
9+
| Supported Targets | ESP32-C6 | ESP32-H2 |
10+
| ----------------- | -------- | -------- |
11+
12+
## Fan Control Functions
13+
14+
1. Initialize a Zigbee fan control device.
15+
2. Control fan modes (OFF, LOW, MEDIUM, HIGH, ON).
16+
3. Respond to fan control commands from the Zigbee network.
17+
18+
## Hardware Required
19+
20+
* ESP32-H2 or ESP32-C6 development board
21+
* A USB cable for power supply and programming
22+
* RGB LED for visual feedback (built-in on most development boards)
23+
24+
### Configure the Project
25+
26+
In this example the RGB LED is used to indicate the current fan control mode.
27+
The LED colors represent different fan modes:
28+
- OFF: No light
29+
- LOW: Blue
30+
- MEDIUM: Yellow
31+
- HIGH: Red
32+
- ON: White
33+
34+
Set the button GPIO by changing the `button` variable. By default, it's the pin `BOOT_PIN` (BOOT button on ESP32-C6 and ESP32-H2).
35+
36+
#### Using Arduino IDE
37+
38+
To get more information about the Espressif boards see [Espressif Development Kits](https://www.espressif.com/en/products/devkits).
39+
40+
* Before Compile/Verify, select the correct board: `Tools -> Board`.
41+
* Select the End device Zigbee mode: `Tools -> Zigbee mode: Zigbee ZCZR (coordinator/router)`
42+
* Select Partition Scheme for Zigbee: `Tools -> Partition Scheme: Zigbee ZCZR 4MB with spiffs`
43+
* Select the COM port: `Tools -> Port: xxx` where the `xxx` is the detected COM port.
44+
* Optional: Set debug level to verbose to see all logs from Zigbee stack: `Tools -> Core Debug Level: Verbose`.
45+
46+
## Troubleshooting
47+
48+
If the End device flashed with this example is not connecting to the coordinator, erase the flash of the End device before flashing the example to the board. It is recommended to do this if you re-flash the coordinator.
49+
You can do the following:
50+
51+
* In the Arduino IDE go to the Tools menu and set `Erase All Flash Before Sketch Upload` to `Enabled`.
52+
* Add to the sketch `Zigbee.factoryReset();` to reset the device and Zigbee stack.
53+
54+
By default, the coordinator network is closed after rebooting or flashing new firmware.
55+
To open the network you have 2 options:
56+
57+
* Open network after reboot by setting `Zigbee.setRebootOpenNetwork(time);` before calling `Zigbee.begin();`.
58+
* In application you can anytime call `Zigbee.openNetwork(time);` to open the network for devices to join.
59+
60+
61+
***Important: Make sure you are using a good quality USB cable and that you have a reliable power source***
62+
63+
* **LED not blinking:** Check the wiring connection and the IO selection.
64+
* **Programming Fail:** If the programming/flash procedure fails, try reducing the serial connection speed.
65+
* **COM port not detected:** Check the USB cable and the USB to Serial driver installation.
66+
67+
If the error persists, you can ask for help at the official [ESP32 forum](https://esp32.com) or see [Contribute](#contribute).
68+
69+
## Contribute
70+
71+
To know how to contribute to this project, see [How to contribute.](https://github.com/espressif/arduino-esp32/blob/master/CONTRIBUTING.rst)
72+
73+
If you have any **feedback** or **issue** to report on this example/library, please open an issue or fix it by creating a new PR. Contributions are more than welcome!
74+
75+
Before creating a new issue, be sure to try Troubleshooting and check if the same issue was already created by someone else.
76+
77+
## Resources
78+
79+
* Official ESP32 Forum: [Link](https://esp32.com)
80+
* Arduino-ESP32 Official Repository: [espressif/arduino-esp32](https://github.com/espressif/arduino-esp32)
81+
* ESP32-C6 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-c6_datasheet_en.pdf)
82+
* ESP32-H2 Datasheet: [Link to datasheet](https://www.espressif.com/sites/default/files/documentation/esp32-h2_datasheet_en.pdf)
83+
* Official ESP-IDF documentation: [ESP-IDF](https://idf.espressif.com)
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright 2025 Espressif Systems (Shanghai) PTE LTD
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/**
16+
* @brief This example demonstrates simple Zigbee fan control.
17+
*
18+
* The example demonstrates how to use Zigbee library to create a router device fan control.
19+
* The fan control is a Zigbee router device, which is controlled by a Zigbee coordinator.
20+
*
21+
* Proper Zigbee mode must be selected in Tools->Zigbee mode
22+
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
23+
*
24+
* Please check the README.md for instructions and more detailed description.
25+
*
26+
* Created by Jan Procházka (https://github.com/P-R-O-C-H-Y/)
27+
*/
28+
29+
#ifndef ZIGBEE_MODE_ZCZR
30+
#error "Zigbee coordinator mode is not selected in Tools->Zigbee mode"
31+
#endif
32+
33+
#include "Zigbee.h"
34+
35+
/* Zigbee light bulb configuration */
36+
#define ZIGBEE_FAN_CONTROL_ENDPOINT 1
37+
38+
#ifdef RGB_BUILTIN
39+
uint8_t led = RGB_BUILTIN; // To demonstrate the current fan control mode
40+
#else
41+
uint8_t led = 2;
42+
#endif
43+
44+
uint8_t button = BOOT_PIN;
45+
46+
ZigbeeFanControl zbFanControl = ZigbeeFanControl(ZIGBEE_FAN_CONTROL_ENDPOINT);
47+
48+
/********************* fan control callback function **************************/
49+
void setFan(ZigbeeFanMode mode) {
50+
switch (mode) {
51+
case FAN_MODE_OFF:
52+
rgbLedWrite(led, 0, 0, 0); // Off
53+
Serial.println("Fan mode: OFF");
54+
break;
55+
case FAN_MODE_LOW:
56+
rgbLedWrite(led, 0, 0, 255); // Blue
57+
Serial.println("Fan mode: LOW");
58+
break;
59+
case FAN_MODE_MEDIUM:
60+
rgbLedWrite(led, 255, 255, 0); // Yellow
61+
Serial.println("Fan mode: MEDIUM");
62+
break;
63+
case FAN_MODE_HIGH:
64+
rgbLedWrite(led, 255, 0, 0); // Red
65+
Serial.println("Fan mode: HIGH");
66+
break;
67+
case FAN_MODE_ON:
68+
rgbLedWrite(led, 255, 255, 255); // White
69+
Serial.println("Fan mode: ON");
70+
break;
71+
default: log_e("Unhandled fan mode: %d", mode); break;
72+
}
73+
}
74+
75+
/********************* Arduino functions **************************/
76+
void setup() {
77+
Serial.begin(115200);
78+
79+
// Init LED that will be used to indicate the current fan control mode
80+
rgbLedWrite(led, 0, 0, 0);
81+
82+
// Init button for factory reset
83+
pinMode(button, INPUT_PULLUP);
84+
85+
//Optional: set Zigbee device name and model
86+
zbFanControl.setManufacturerAndModel("Espressif", "ZBFanControl");
87+
88+
// Set the fan mode sequence to LOW_MED_HIGH
89+
zbFanControl.setFanModeSequence(FAN_MODE_SEQUENCE_LOW_MED_HIGH);
90+
91+
// Set callback function for fan mode change
92+
zbFanControl.onFanModeChange(setFan);
93+
94+
//Add endpoint to Zigbee Core
95+
Serial.println("Adding ZigbeeFanControl endpoint to Zigbee Core");
96+
Zigbee.addEndpoint(&zbFanControl);
97+
98+
// When all EPs are registered, start Zigbee in ROUTER mode
99+
if (!Zigbee.begin(ZIGBEE_ROUTER)) {
100+
Serial.println("Zigbee failed to start!");
101+
Serial.println("Rebooting...");
102+
ESP.restart();
103+
}
104+
Serial.println("Connecting to network");
105+
while (!Zigbee.connected()) {
106+
Serial.print(".");
107+
delay(100);
108+
}
109+
Serial.println();
110+
}
111+
112+
void loop() {
113+
// Checking button for factory reset
114+
if (digitalRead(button) == LOW) { // Push button pressed
115+
// Key debounce handling
116+
delay(100);
117+
int startTime = millis();
118+
while (digitalRead(button) == LOW) {
119+
delay(50);
120+
if ((millis() - startTime) > 3000) {
121+
// If key pressed for more than 3secs, factory reset Zigbee and reboot
122+
Serial.println("Resetting Zigbee to factory and rebooting in 1s.");
123+
delay(1000);
124+
Zigbee.factoryReset();
125+
}
126+
}
127+
}
128+
delay(100);
129+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"fqbn_append": "PartitionScheme=zigbee_zczr,ZigbeeMode=zczr",
3+
"requires": [
4+
"CONFIG_ZB_ENABLED=y"
5+
]
6+
}

0 commit comments

Comments
 (0)