Arduino core 3.2.1

This commit is contained in:
Jason2866
2025-07-03 17:12:25 +02:00
parent da5cb384a5
commit 9bf8b3f10a
76 changed files with 493576 additions and 1697 deletions
@@ -0,0 +1,5 @@
# NimBLE_extended_client example using h2zero Arduino NimBLE stack
BLE 5 client example, using the great [h2zero NimBLE](https://github.com/h2zero/NimBLE-Arduino) implementation.
Thx @h2zero for the great BLE library.
@@ -0,0 +1,53 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env]
platform = espressif32
framework = arduino
monitor_speed = 115200
build_flags =
'-DCONFIG_BT_NIMBLE_EXT_ADV=1'
lib_deps =
https://github.com/h2zero/NimBLE-Arduino
lib_ignore =
BLE
BluetoothSerial
SimpleBLE
WiFiProv
custom_component_remove =
espressif/esp_hosted
espressif/esp_wifi_remote
espressif/esp-dsp
espressif/network_provisioning
espressif/esp_rainmaker
espressif/rmaker_common
espressif/esp_insights
espressif/esp_diag_data_store
espressif/esp_diagnostics
espressif/libsodium
espressif/esp-modbus
espressif/esp-cbor
espressif/esp-sr
espressif/esp32-camera
[env:esp32s3]
board = esp32-s3-devkitc-1
[env:esp32c2]
board = esp32-c2-devkitm-1
[env:esp32c3]
board = esp32-c3-devkitm-1
[env:esp32c6]
board = esp32-c6-devkitm-1
[env:esp32h2]
board = esp32-h2-devkitm-1
@@ -0,0 +1,150 @@
/** NimBLE Extended Client Demo:
*
* Demonstrates the Bluetooth 5.x client capabilities.
*
* Created: on April 2 2022
* Author: H2zero
*
*/
#include <Arduino.h>
#include <NimBLEDevice.h>
#if !CONFIG_BT_NIMBLE_EXT_ADV
# error Must enable extended advertising, see nimconfig.h file.
#endif
#define SERVICE_UUID "ABCD"
#define CHARACTERISTIC_UUID "1234"
static const NimBLEAdvertisedDevice* advDevice;
static bool doConnect = false;
static uint32_t scanTime = 10 * 1000; // In milliseconds, 0 = scan forever
/** Define the PHY's to use when connecting to peer devices, can be 1, 2, or all 3 (default).*/
static uint8_t connectPhys = BLE_GAP_LE_PHY_CODED_MASK | BLE_GAP_LE_PHY_1M_MASK /*| BLE_GAP_LE_PHY_2M_MASK */;
/** Define a class to handle the callbacks for client connection events */
class ClientCallbacks : public NimBLEClientCallbacks {
void onConnect(NimBLEClient* pClient) override { Serial.printf("Connected\n"); };
void onDisconnect(NimBLEClient* pClient, int reason) override {
Serial.printf("%s Disconnected, reason = %d - Starting scan\n", pClient->getPeerAddress().toString().c_str(), reason);
NimBLEDevice::getScan()->start(scanTime);
}
} clientCallbacks;
/** Define a class to handle the callbacks when advertisements are received */
class scanCallbacks : public NimBLEScanCallbacks {
void onResult(const NimBLEAdvertisedDevice* advertisedDevice) override {
Serial.printf("Advertised Device found: %s\n", advertisedDevice->toString().c_str());
if (advertisedDevice->isAdvertisingService(NimBLEUUID("ABCD"))) {
Serial.printf("Found Our Service\n");
doConnect = true;
/** Save the device reference in a global for the client to use*/
advDevice = advertisedDevice;
/** stop scan before connecting */
NimBLEDevice::getScan()->stop();
}
}
/** Callback to process the results of the completed scan or restart it */
void onScanEnd(const NimBLEScanResults& results, int rc) override { Serial.printf("Scan Ended\n"); }
} scanCallbacks;
/** Handles the provisioning of clients and connects / interfaces with the server */
bool connectToServer() {
NimBLEClient* pClient = nullptr;
pClient = NimBLEDevice::createClient();
pClient->setClientCallbacks(&clientCallbacks, false);
/**
* Set the PHY's to use for this connection. This is a bitmask that represents the PHY's:
* * 0x01 BLE_GAP_LE_PHY_1M_MASK
* * 0x02 BLE_GAP_LE_PHY_2M_MASK
* * 0x04 BLE_GAP_LE_PHY_CODED_MASK
* Combine these with OR ("|"), eg BLE_GAP_LE_PHY_1M_MASK | BLE_GAP_LE_PHY_2M_MASK | BLE_GAP_LE_PHY_CODED_MASK;
*/
pClient->setConnectPhy(connectPhys);
/** Set how long we are willing to wait for the connection to complete (milliseconds), default is 30000. */
pClient->setConnectTimeout(10 * 1000);
if (!pClient->connect(advDevice)) {
/** Created a client but failed to connect, don't need to keep it as it has no data */
NimBLEDevice::deleteClient(pClient);
Serial.printf("Failed to connect, deleted client\n");
return false;
}
Serial.printf("Connected to: %s RSSI: %d\n", pClient->getPeerAddress().toString().c_str(), pClient->getRssi());
/** Now we can read/write/subscribe the characteristics of the services we are interested in */
NimBLERemoteService* pSvc = nullptr;
NimBLERemoteCharacteristic* pChr = nullptr;
pSvc = pClient->getService(SERVICE_UUID);
if (pSvc) {
pChr = pSvc->getCharacteristic(CHARACTERISTIC_UUID);
if (pChr) {
if (pChr->canRead()) {
std::string value = pChr->readValue();
Serial.printf("Characteristic value: %s\n", value.c_str());
}
}
} else {
Serial.printf("ABCD service not found.\n");
}
NimBLEDevice::deleteClient(pClient);
Serial.printf("Done with this device!\n");
return true;
}
void setup() {
Serial.begin(115200);
Serial.printf("Starting NimBLE Client\n");
/** Initialize NimBLE and set the device name */
NimBLEDevice::init("NimBLE Extended Client");
/** Create aNimBLE Scan instance and set the callbacks for scan events */
NimBLEScan* pScan = NimBLEDevice::getScan();
pScan->setScanCallbacks(&scanCallbacks);
/** Set scan interval (how often) and window (how long) in milliseconds */
pScan->setInterval(97);
pScan->setWindow(67);
/**
* Active scan will gather scan response data from advertisers
* but will use more energy from both devices
*/
pScan->setActiveScan(true);
/**
* Start scanning for advertisers for the scan time specified (in milliseconds) 0 = forever
* Optional callback for when scanning stops.
*/
pScan->start(scanTime);
Serial.printf("Scanning for peripherals\n");
}
void loop() {
/** Loop here until we find a device we want to connect to */
if (doConnect) {
if (connectToServer()) {
Serial.printf("Success!, scanning for more!\n");
} else {
Serial.printf("Failed to connect, starting scan\n");
}
doConnect = false;
NimBLEDevice::getScan()->start(scanTime);
}
delay(10);
}
+24 -1
View File
@@ -12,6 +12,10 @@ platform = espressif32
framework = arduino
board = esp32-solo1
build_flags = -DLED_BUILTIN=2
lib_ignore = wifi
spiffs
NetworkClientSecure
custom_component_remove =
espressif/esp_hosted
espressif/esp_wifi_remote
@@ -31,6 +35,9 @@ platform = espressif32
framework = arduino
board = esp32-c2-devkitm-1
monitor_speed = 115200
lib_ignore = wifi
spiffs
NetworkClientSecure
custom_component_remove = espressif/esp_hosted
espressif/esp_wifi_remote
espressif/esp-dsp
@@ -43,12 +50,16 @@ custom_component_remove = espressif/esp_hosted
espressif/esp_diagnostics
espressif/esp_rainmaker
espressif/rmaker_common
custom_component_add = espressif/cmake_utilities @ 0.*
[env:esp32-s3-arduino_nano_esp32]
platform = espressif32
framework = arduino
board = arduino_nano_esp32
monitor_speed = 115200
lib_ignore = wifi
spiffs
NetworkClientSecure
custom_component_remove = espressif/esp_hosted
espressif/esp_wifi_remote
espressif/esp-dsp
@@ -67,6 +78,9 @@ custom_component_remove = espressif/esp_hosted
platform = espressif32
framework = arduino
board = esp32s3_120_16_8-qio_opi
lib_ignore =
spiffs
NetworkClientSecure
custom_sdkconfig = CONFIG_SPIRAM_MODE_OCT=y
CONFIG_SPIRAM_SPEED_120M=y
CONFIG_LCD_RGB_ISR_IRAM_SAFE=y
@@ -87,13 +101,16 @@ custom_component_remove = espressif/esp_hosted
espressif/esp_diagnostics
espressif/esp_rainmaker
espressif/rmaker_common
custom_component_add = lvgl/lvgl @ ^9.2.2
[env:esp32-c6-devkitc-1]
platform = espressif32
framework = arduino
build_type = debug
board = esp32-c6-devkitc-1
monitor_speed = 115200
lib_ignore = wifi
spiffs
NetworkClientSecure
custom_component_remove = espressif/esp_hosted
espressif/esp_wifi_remote
espressif/mdns
@@ -106,6 +123,9 @@ platform = espressif32
framework = arduino
board = esp32-h2-devkitm-1
monitor_speed = 115200
lib_ignore =
spiffs
NetworkClientSecure
custom_component_remove = espressif/esp_hosted
espressif/esp_wifi_remote
espressif/mdns
@@ -118,6 +138,9 @@ platform = espressif32
framework = arduino
board = esp32-p4
build_flags = -DLED_BUILTIN=2
lib_ignore = wifi
spiffs
NetworkClientSecure
monitor_speed = 115200
custom_component_remove = espressif/esp_hosted
espressif/esp_wifi_remote
+12
View File
@@ -2,6 +2,9 @@
platform = espressif32
framework = arduino
board = esp32-s2-saola-1
lib_ignore = wifi
spiffs
NetworkClientSecure
build_flags = -DBUILTIN_RGBLED_PIN=18
-DNR_OF_LEDS=1
@@ -9,6 +12,9 @@ build_flags = -DBUILTIN_RGBLED_PIN=18
platform = espressif32
framework = arduino
board = esp32-s3-devkitc-1
lib_ignore = wifi
spiffs
NetworkClientSecure
build_flags = -DBUILTIN_RGBLED_PIN=48
-DNR_OF_LEDS=1
@@ -16,6 +22,9 @@ build_flags = -DBUILTIN_RGBLED_PIN=48
platform = espressif32
framework = arduino
board = esp32-c3-devkitm-1
lib_ignore = wifi
spiffs
NetworkClientSecure
build_flags = -DBUILTIN_RGBLED_PIN=8
-DNR_OF_LEDS=1
@@ -23,5 +32,8 @@ build_flags = -DBUILTIN_RGBLED_PIN=8
platform = espressif32
framework = arduino
board = esp32-c6-devkitm-1
lib_ignore = wifi
spiffs
NetworkClientSecure
build_flags = -DBUILTIN_RGBLED_PIN=8
-DNR_OF_LEDS=1
+48
View File
@@ -12,3 +12,51 @@ platform = espressif32
framework = arduino
board = esp-wrover-kit
monitor_speed = 115200
[env:esp32-s2]
platform = espressif32
framework = arduino
board = esp32-s2-saola-1
upload_protocol = esp-prog
monitor_speed = 115200
check_tool = clangtidy
[env:esp32-s3]
platform = espressif32
framework = arduino
board = esp32-s3-devkitc-1
upload_protocol = esp-builtin
monitor_speed = 115200
check_tool = cppcheck
[env:esp32-c2]
platform = espressif32
framework = arduino
board = esp32-c2-devkitm-1
upload_protocol = esp-prog
monitor_speed = 115200
check_tool = clangtidy
custom_component_remove =
espressif/esp-dsp
espressif/network_provisioning
espressif/esp-zboss-lib
espressif/esp-zigbee-lib
espressif/esp_rainmaker
espressif/esp-sr
espressif/esp-modbus
espressif/esp32-camera
[env:esp32-c3]
platform = espressif32
framework = arduino
board = esp32-c3-devkitm-1
upload_protocol = esp-builtin
monitor_speed = 115200
check_tool = pvs-studio
[env:esp32-c6]
platform = espressif32
framework = arduino
board = esp32-c6-devkitm-1
upload_protocol = esp-builtin
monitor_speed = 115200
@@ -1,2 +0,0 @@
.pio
.vscode
@@ -1,4 +0,0 @@
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_compile_definitions(ARDUINO_ARCH_ESP32=1)
project(Arduino_IDF_BLE_scan)
@@ -1,7 +0,0 @@
# Arduino_IDF_BLE_scan example using 3rd party NimBLE stack
BLE scan example, using the great h2zero NimBLE implementation. The needed NimBLE lib is loaded via the IDF component manager -> `idf_component.yml`.
Mandantory not to forget to switch Arduino included BLE libs.
Done in `sdkconfig.defaults`
Thx @h2zero for the great BLE library.
@@ -1,27 +0,0 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env]
platform = espressif32
framework = arduino, espidf
monitor_speed = 115200
board_build.embed_txtfiles =
managed_components/espressif__esp_insights/server_certs/https_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt
lib_ignore =
BLE
BluetoothSerial
SimpleBLE
WiFiProv
[env:esp32]
board = esp32dev
@@ -1,34 +0,0 @@
# CONFIG_AUTOSTART_ARDUINO is not set
# CONFIG_WS2812_LED_ENABLE is not set
CONFIG_FREERTOS_HZ=1000
CONFIG_MBEDTLS_PSK_MODES=y
CONFIG_MBEDTLS_KEY_EXCHANGE_PSK=y
CONFIG_BOOTLOADER_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y
# Override some defaults so BT stack is enabled
# in this example
#
# BT config
#
CONFIG_BT_ENABLED=y
CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y
CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n
CONFIG_BTDM_CTRL_MODE_BTDM=n
CONFIG_BT_BLUEDROID_ENABLED=n
CONFIG_BT_NIMBLE_ENABLED=y
#
# Arduino Configuration
#
#
# Disable all Arduino included BLE libraries
#
CONFIG_ARDUINO_SELECTIVE_COMPILATION=y
# CONFIG_ARDUINO_SELECTIVE_WiFiProv is not set
# CONFIG_ARDUINO_SELECTIVE_BLE is not set
# CONFIG_ARDUINO_SELECTIVE_BluetoothSerial is not set
# CONFIG_ARDUINO_SELECTIVE_SimpleBLE is not set
# end of Arduino Configuration
@@ -1,6 +0,0 @@
# This file was automatically generated for projects
# without default 'CMakeLists.txt' file.
FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
idf_component_register(SRCS ${app_sources})
@@ -1,41 +0,0 @@
dependencies:
# Required IDF version
idf: ">=4.4"
esp-nimble-cpp:
git: https://github.com/h2zero/esp-nimble-cpp.git
version: 877a29a8b1d0022c5e8f67ba8b879316e67b6c3d
# # Defining a dependency from the registry:
# # https://components.espressif.com/component/example/cmp
# example/cmp: "^3.3.3" # Automatically update minor releases
#
# # Other ways to define dependencies
#
# # For components maintained by Espressif only name can be used.
# # Same as `espressif/cmp`
# component: "~1.0.0" # Automatically update bugfix releases
#
# # Or in a longer form with extra parameters
# component2:
# version: ">=2.0.0"
#
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect for the `main` component.
# # All dependencies of `main` are public by default.
# public: true
#
# # For components hosted on non-default registry:
# service_url: "https://componentregistry.company.com"
#
# # For components in git repository:
# test_component:
# path: test_component
# git: ssh://git@gitlab.com/user/components.git
#
# # For test projects during component development
# # components can be used from a local directory
# # with relative or absolute path
# some_local_component:
# path: ../../projects/component
@@ -1,54 +0,0 @@
/*
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
Ported to Arduino ESP32 by Evandro Copercini
Refactored back to IDF by H2zero
*/
/** NimBLE differences highlighted in comment blocks **/
/*******original********
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
***********************/
#include <Arduino.h>
#include <NimBLEDevice.h>
extern "C"{void app_main(void);}
int scanTime = 5 * 1000; // In milliseconds, 0 = scan forever
BLEScan* pBLEScan;
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice* advertisedDevice) {
printf("Advertised Device: %s \n", advertisedDevice->toString().c_str());
}
};
void scanTask (void * parameter){
for(;;) {
// put your main code here, to run repeatedly:
BLEScanResults foundDevices = pBLEScan->getResults(scanTime, false);
printf("Devices found: %d\n", foundDevices.getCount());
printf("Scan done!\n");
pBLEScan->clearResults(); // delete results fromBLEScan buffer to release memory
vTaskDelay(2000/portTICK_PERIOD_MS); // Delay a second between loops.
}
vTaskDelete(NULL);
}
void app_main(void) {
printf("Scanning...\n");
BLEDevice::init("");
pBLEScan = BLEDevice::getScan(); //create new scan
pBLEScan->setScanCallbacks(new MyAdvertisedDeviceCallbacks());
pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster
pBLEScan->setInterval(100);
pBLEScan->setWindow(99); // less or equal setInterval value
xTaskCreate(scanTask, "scanTask", 5000, NULL, 1, NULL);
}
@@ -1,10 +1,14 @@
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.16.0)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(PROJECT_VER "1.0")
set(PROJECT_VER_NUMBER 1)
project(matter-light)
# This should be done before using the IDF_TARGET variable.
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(espidf_arduino_matter_light)
# WARNING: This is just an example for using key for decrypting the encrypted OTA image
# Please do not use it as is.
@@ -16,8 +20,8 @@ if(CONFIG_IDF_TARGET_ESP32C2)
include(relinker)
endif()
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++17;-Os;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(CXX_COMPILE_OPTIONS "-std=gnu++2a;-Os;-DCHIP_HAVE_CONFIG_H" APPEND)
idf_build_set_property(C_COMPILE_OPTIONS "-Os" APPEND)
# For RISCV chips, project_include.cmake sets -Wno-format, but does not clear various
# flags that depend on -Wformat
idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND)
idf_build_set_property(COMPILE_OPTIONS "-Wno-format-nonliteral;-Wno-format-security" APPEND)
+9 -12
View File
@@ -1,14 +1,12 @@
| Supported Targets | ESP32-S3 | ESP32-C3 | ESP32-C6 |
| ----------------- | -------- | -------- | -------- |
| Supported Targets | ESP32-C3 | ESP32-C6 |
| ----------------- | -------- | -------- |
# Managed Component Light
This example is configured by default to work with the ESP32-S3, which has the RGB LED GPIO set as pin 48 and the BOOT button on GPIO 0.
This example is configured by default to work with the ESP32-C6, which has the RGB LED GPIO set as pin 8 and the BOOT button on GPIO 9.
This example creates a Color Temperature Light device using the esp_matter component downloaded from the [Espressif Component Registry](https://components.espressif.com/) instead of an extra component locally, so the example can work without setting up the esp-matter environment.
See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html) for more information about building and flashing the firmware.
This example creates a Color Temperature Light device using the esp_matter component automatically downloaded from the [Espressif Component Registry](https://components.espressif.com/). See the [docs](https://docs.espressif.com/projects/esp-matter/en/latest/esp32/developing.html) for more information about matter.
The code is based on the Arduino API and uses Arduino as an IDF Component.
@@ -27,8 +25,8 @@ There is no QR Code to be used when the Smartphone APP wants to add the Matter D
Please enter the code manually: `34970112332`
The devboard has a built-in LED that will be used as the Matter Light.
The default setting of the code uses pin 48 for the ESP32-S3.
Please change it in `main/matter_accessory_driver.h` or in the `sdkconfig.defaults.<SOC>` file.
The default setting of the code uses pin 8 for the ESP32-C6,
Please change it in `main/matter_accessory_driver.h` or in the `sdkconfig.defaults` file.
## LED Status and Factory Mode
@@ -53,10 +51,9 @@ Holding the BOOT button pressed for more than 10 seconds and then releasing it w
## Building the Application using WiFi and Matter
Use ESP-IDF 5.1.4 from https://github.com/espressif/esp-idf/tree/release/v5.1
This example has been tested with Arduino Core 3.0.4
This example has been tested with Arduino Core 3.2.0. It should work with newer versions too.
There is a configuration file for these SoC: esp32s3, esp32c3, esp32c6.
There is a configuration file for these SoCs: esp32c3, esp32c6.
Those are the tested devices that have a WS2812 RGB LED and can run BLE, WiFi and Matter.
In case it is necessary to change the Button Pin or the REG LED Pin, please use the `menuconfig` and change the Menu Option `Light Matter Accessory`
@@ -64,5 +61,5 @@ In case it is necessary to change the Button Pin or the REG LED Pin, please use
## Using OpenThread with Matter
This is possible with the ESP32-C6.
It is neessasy to have a Thread Border Routed in the Matter Environment. Check you matter hardware provider.
It is necessary to have a Thread Border Router in the Matter Environment. Check your Matter hardware provider.
@@ -3,100 +3,40 @@ menu "Light Matter Accessory"
config BUTTON_PIN
int
prompt "Button 1 GPIO"
default ENV_GPIO_BOOT_BUTTON
default 9 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6
default 0
range -1 ENV_GPIO_IN_RANGE_MAX
help
The GPIO pin for button that will be used to turn on/off the Matter Light. It shall be connected to a push button. It can use the BOOT button of the development board.
endmenu
menu "LEDs"
config WS2812_PIN
int
prompt "WS2812 RGB LED GPIO"
default ENV_GPIO_RGB_LED
default 8 if IDF_TARGET_ESP32C3 || IDF_TARGET_ESP32C6
default 48
range -1 ENV_GPIO_OUT_RANGE_MAX
help
The GPIO pin for the Matter Light that will be driven by RMT. It shall be connected to one single WS2812 RGB LED.
endmenu
# TARGET CONFIGURATION
if IDF_TARGET_ESP32C3
config ENV_GPIO_RANGE_MIN
int
default 0
config ENV_GPIO_RANGE_MIN
int
default 0
config ENV_GPIO_RANGE_MAX
int
default 19
# GPIOs 20/21 are always used by UART in examples
config ENV_GPIO_RANGE_MAX
int
default 19 if IDF_TARGET_ESP32C3
default 30 if IDF_TARGET_ESP32C6
default 48
config ENV_GPIO_IN_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX
config ENV_GPIO_IN_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX
config ENV_GPIO_OUT_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX
config ENV_GPIO_BOOT_BUTTON
int
default 9
config ENV_GPIO_RGB_LED
int
default 8
endif
if IDF_TARGET_ESP32C6
config ENV_GPIO_RANGE_MIN
int
default 0
config ENV_GPIO_RANGE_MAX
int
default 30
# GPIOs 16/17 are always used by UART in examples
config ENV_GPIO_IN_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX
config ENV_GPIO_OUT_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX
config ENV_GPIO_BOOT_BUTTON
int
default 9
config ENV_GPIO_RGB_LED
int
default 8
endif
if IDF_TARGET_ESP32S3
config ENV_GPIO_RANGE_MIN
int
default 0
config ENV_GPIO_RANGE_MAX
int
default 48
config ENV_GPIO_IN_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX
config ENV_GPIO_OUT_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX
config ENV_GPIO_BOOT_BUTTON
int
default 0
config ENV_GPIO_RGB_LED
int
default 48
endif
config ENV_GPIO_OUT_RANGE_MAX
int
default ENV_GPIO_RANGE_MAX
endmenu
@@ -13,235 +13,225 @@
#include "builtinLED.h"
typedef struct {
uint16_t hue;
uint8_t saturation;
uint16_t hue;
uint8_t saturation;
} HS_color_t;
static const HS_color_t temperatureTable[] = {
{4, 100}, {8, 100}, {11, 100}, {14, 100}, {16, 100}, {18, 100}, {20, 100}, {22, 100}, {24, 100}, {25, 100},
{27, 100}, {28, 100}, {30, 100}, {31, 100}, {31, 95}, {30, 89}, {30, 85}, {29, 80}, {29, 76}, {29, 73},
{29, 69}, {28, 66}, {28, 63}, {28, 60}, {28, 57}, {28, 54}, {28, 52}, {27, 49}, {27, 47}, {27, 45},
{27, 43}, {27, 41}, {27, 39}, {27, 37}, {27, 35}, {27, 33}, {27, 31}, {27, 30}, {27, 28}, {27, 26},
{27, 25}, {27, 23}, {27, 22}, {27, 21}, {27, 19}, {27, 18}, {27, 17}, {27, 15}, {28, 14}, {28, 13},
{28, 12}, {29, 10}, {29, 9}, {30, 8}, {31, 7}, {32, 6}, {34, 5}, {36, 4}, {41, 3}, {49, 2},
{0, 0}, {294, 2}, {265, 3}, {251, 4}, {242, 5}, {237, 6}, {233, 7}, {231, 8}, {229, 9}, {228, 10},
{227, 11}, {226, 11}, {226, 12}, {225, 13}, {225, 13}, {224, 14}, {224, 14}, {224, 15}, {224, 15}, {223, 16},
{223, 16}, {223, 17}, {223, 17}, {223, 17}, {222, 18}, {222, 18}, {222, 19}, {222, 19}, {222, 19}, {222, 19},
{222, 20}, {222, 20}, {222, 20}, {222, 21}, {222, 21}
{4, 100}, {8, 100}, {11, 100}, {14, 100}, {16, 100}, {18, 100}, {20, 100}, {22, 100}, {24, 100}, {25, 100}, {27, 100}, {28, 100}, {30, 100}, {31, 100},
{31, 95}, {30, 89}, {30, 85}, {29, 80}, {29, 76}, {29, 73}, {29, 69}, {28, 66}, {28, 63}, {28, 60}, {28, 57}, {28, 54}, {28, 52}, {27, 49},
{27, 47}, {27, 45}, {27, 43}, {27, 41}, {27, 39}, {27, 37}, {27, 35}, {27, 33}, {27, 31}, {27, 30}, {27, 28}, {27, 26}, {27, 25}, {27, 23},
{27, 22}, {27, 21}, {27, 19}, {27, 18}, {27, 17}, {27, 15}, {28, 14}, {28, 13}, {28, 12}, {29, 10}, {29, 9}, {30, 8}, {31, 7}, {32, 6},
{34, 5}, {36, 4}, {41, 3}, {49, 2}, {0, 0}, {294, 2}, {265, 3}, {251, 4}, {242, 5}, {237, 6}, {233, 7}, {231, 8}, {229, 9}, {228, 10},
{227, 11}, {226, 11}, {226, 12}, {225, 13}, {225, 13}, {224, 14}, {224, 14}, {224, 15}, {224, 15}, {223, 16}, {223, 16}, {223, 17}, {223, 17}, {223, 17},
{222, 18}, {222, 18}, {222, 19}, {222, 19}, {222, 19}, {222, 19}, {222, 20}, {222, 20}, {222, 20}, {222, 21}, {222, 21}
};
/* step brightness table: gamma = 2.3 */
static const uint8_t gamma_table[MAX_PROGRESS] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2,
2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5,
5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10,
10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17,
17, 18, 18, 19, 19, 20, 20, 21, 22, 22, 23, 23, 24, 25, 25, 26,
26, 27, 28, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 36, 37,
38, 39, 40, 40, 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 51,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67,
68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 86,
87, 88, 89, 91, 92, 93, 95, 96, 97, 99, 100, 101, 103, 104, 105, 107,
108, 110, 111, 112, 114, 115, 117, 118, 120, 121, 123, 124, 126, 128, 129, 131,
132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 149, 150, 152, 154, 156, 157,
159, 161, 163, 164, 166, 168, 170, 172, 174, 175, 177, 179, 181, 183, 185, 187,
189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219,
221, 223, 226, 228, 230, 232, 234, 236, 239, 241, 243, 245, 248, 250, 252, 255,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8,
8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 12, 12, 13, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20,
21, 22, 22, 23, 23, 24, 25, 25, 26, 26, 27, 28, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 36, 37, 38, 39, 40, 40,
41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68,
69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 86, 87, 88, 89, 91, 92, 93, 95, 96, 97, 99, 100, 101, 103, 104,
105, 107, 108, 110, 111, 112, 114, 115, 117, 118, 120, 121, 123, 124, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 144, 145, 147, 149,
150, 152, 154, 156, 157, 159, 161, 163, 164, 166, 168, 170, 172, 174, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203,
205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 226, 228, 230, 232, 234, 236, 239, 241, 243, 245, 248, 250, 252, 255,
};
BuiltInLED::BuiltInLED() {
pin_number = (uint8_t) -1; // no pin number
state = false; // LED is off
hsv_color.value = 0; // black color
pin_number = (uint8_t)-1; // no pin number
state = false; // LED is off
hsv_color.value = 0; // black color
}
BuiltInLED::~BuiltInLED(){
end();
BuiltInLED::~BuiltInLED() {
end();
}
led_indicator_color_hsv_t BuiltInLED::rgb2hsv(led_indicator_color_rgb_t rgb) {
led_indicator_color_hsv_t hsv;
uint8_t minRGB, maxRGB;
uint8_t delta;
led_indicator_color_hsv_t hsv;
uint8_t minRGB, maxRGB;
uint8_t delta;
minRGB = rgb.r < rgb.g ? (rgb.r < rgb.b ? rgb.r : rgb.b) : (rgb.g < rgb.b ? rgb.g : rgb.b);
maxRGB = rgb.r > rgb.g ? (rgb.r > rgb.b ? rgb.r : rgb.b) : (rgb.g > rgb.b ? rgb.g : rgb.b);
hsv.value = 0;
hsv.v = maxRGB;
delta = maxRGB - minRGB;
minRGB = rgb.r < rgb.g ? (rgb.r < rgb.b ? rgb.r : rgb.b) : (rgb.g < rgb.b ? rgb.g : rgb.b);
maxRGB = rgb.r > rgb.g ? (rgb.r > rgb.b ? rgb.r : rgb.b) : (rgb.g > rgb.b ? rgb.g : rgb.b);
hsv.value = 0;
hsv.v = maxRGB;
delta = maxRGB - minRGB;
if (delta == 0) {
hsv.h = 0;
hsv.s = 0;
if (delta == 0) {
hsv.h = 0;
hsv.s = 0;
} else {
hsv.s = delta * 255 / maxRGB;
if (rgb.r == maxRGB) {
hsv.h = (60 * (rgb.g - rgb.b) / delta + 360) % 360;
} else if (rgb.g == maxRGB) {
hsv.h = (60 * (rgb.b - rgb.r) / delta + 120);
} else {
hsv.s = delta * 255 / maxRGB;
if (rgb.r == maxRGB) {
hsv.h = (60 * (rgb.g - rgb.b) / delta + 360) % 360;
} else if (rgb.g == maxRGB) {
hsv.h = (60 * (rgb.b - rgb.r) / delta + 120);
} else {
hsv.h = (60 * (rgb.r - rgb.g) / delta + 240);
}
hsv.h = (60 * (rgb.r - rgb.g) / delta + 240);
}
return hsv;
}
return hsv;
}
led_indicator_color_rgb_t BuiltInLED::hsv2rgb(led_indicator_color_hsv_t hsv) {
led_indicator_color_rgb_t rgb;
uint8_t rgb_max = hsv.v;
uint8_t rgb_min = rgb_max * (255 - hsv.s) / 255.0f;
led_indicator_color_rgb_t rgb;
uint8_t rgb_max = hsv.v;
uint8_t rgb_min = rgb_max * (255 - hsv.s) / 255.0f;
uint8_t i = hsv.h / 60;
uint8_t diff = hsv.h % 60;
uint8_t i = hsv.h / 60;
uint8_t diff = hsv.h % 60;
// RGB adjustment amount by hue
uint8_t rgb_adj = (rgb_max - rgb_min) * diff / 60;
rgb.value = 0;
switch (i) {
// RGB adjustment amount by hue
uint8_t rgb_adj = (rgb_max - rgb_min) * diff / 60;
rgb.value = 0;
switch (i) {
case 0:
rgb.r = rgb_max;
rgb.g = rgb_min + rgb_adj;
rgb.b = rgb_min;
break;
rgb.r = rgb_max;
rgb.g = rgb_min + rgb_adj;
rgb.b = rgb_min;
break;
case 1:
rgb.r = rgb_max - rgb_adj;
rgb.g = rgb_max;
rgb.b = rgb_min;
break;
rgb.r = rgb_max - rgb_adj;
rgb.g = rgb_max;
rgb.b = rgb_min;
break;
case 2:
rgb.r = rgb_min;
rgb.g = rgb_max;
rgb.b = rgb_min + rgb_adj;
break;
rgb.r = rgb_min;
rgb.g = rgb_max;
rgb.b = rgb_min + rgb_adj;
break;
case 3:
rgb.r = rgb_min;
rgb.g = rgb_max - rgb_adj;
rgb.b = rgb_max;
break;
rgb.r = rgb_min;
rgb.g = rgb_max - rgb_adj;
rgb.b = rgb_max;
break;
case 4:
rgb.r = rgb_min + rgb_adj;
rgb.g = rgb_min;
rgb.b = rgb_max;
break;
rgb.r = rgb_min + rgb_adj;
rgb.g = rgb_min;
rgb.b = rgb_max;
break;
default:
rgb.r = rgb_max;
rgb.g = rgb_min;
rgb.b = rgb_max - rgb_adj;
break;
}
rgb.r = rgb_max;
rgb.g = rgb_min;
rgb.b = rgb_max - rgb_adj;
break;
}
// gamma correction
rgb.r = gamma_table[rgb.r];
rgb.g = gamma_table[rgb.g];
rgb.b = gamma_table[rgb.b];
return rgb;
// gamma correction
rgb.r = gamma_table[rgb.r];
rgb.g = gamma_table[rgb.g];
rgb.b = gamma_table[rgb.b];
return rgb;
}
void BuiltInLED::begin(uint8_t pin){
if (pin < NUM_DIGITAL_PINS) {
pin_number = pin;
log_i("Initializing pin %d", pin);
void BuiltInLED::begin(uint8_t pin) {
if (pin < NUM_DIGITAL_PINS) {
pin_number = pin;
log_i("Initializing pin %d", pin);
} else {
log_e("Invalid pin (%d) number", pin);
}
}
void BuiltInLED::end() {
state = false;
write(); // turn off the LED
if (pin_number < NUM_DIGITAL_PINS) {
if (!rmtDeinit(pin_number)) {
log_e("Failed to deinitialize RMT");
}
}
}
void BuiltInLED::on() {
state = true;
}
void BuiltInLED::off() {
state = false;
}
void BuiltInLED::toggle() {
state = !state;
}
bool BuiltInLED::getState() {
return state;
}
bool BuiltInLED::write() {
led_indicator_color_rgb_t rgb_color = getRGB();
log_d("Writing to pin %d with state = %s", pin_number, state ? "ON" : "OFF");
log_d("HSV: %d, %d, %d", hsv_color.h, hsv_color.s, hsv_color.v);
log_d("RGB: %d, %d, %d", rgb_color.r, rgb_color.g, rgb_color.b);
if (pin_number < NUM_DIGITAL_PINS) {
if (state) {
rgbLedWrite(pin_number, rgb_color.r, rgb_color.g, rgb_color.b);
} else {
log_e("Invalid pin (%d) number", pin);
}
}
void BuiltInLED::end(){
state = false;
write(); // turn off the LED
if (pin_number < NUM_DIGITAL_PINS) {
if (!rmtDeinit(pin_number)) {
log_e("Failed to deinitialize RMT");
}
rgbLedWrite(pin_number, 0, 0, 0);
}
return true;
} else {
log_e("Invalid pin (%d) number", pin_number);
return false;
}
}
void BuiltInLED::on(){
state = true;
void BuiltInLED::setBrightness(uint8_t brightness) {
hsv_color.v = brightness;
}
void BuiltInLED::off(){
state = false;
uint8_t BuiltInLED::getBrightness() {
return hsv_color.v;
}
void BuiltInLED::toggle(){
state = !state;
void BuiltInLED::setHSV(led_indicator_color_hsv_t hsv) {
if (hsv.h > MAX_HUE) {
hsv.h = MAX_HUE;
}
hsv_color.value = hsv.value;
}
bool BuiltInLED::getState(){
return state;
led_indicator_color_hsv_t BuiltInLED::getHSV() {
return hsv_color;
}
bool BuiltInLED::write(){
led_indicator_color_rgb_t rgb_color = getRGB();
log_d("Writing to pin %d with state = %s", pin_number, state ? "ON" : "OFF");
log_d("HSV: %d, %d, %d", hsv_color.h, hsv_color.s, hsv_color.v);
log_d("RGB: %d, %d, %d", rgb_color.r, rgb_color.g, rgb_color.b);
if(pin_number < NUM_DIGITAL_PINS){
if (state) {
rgbLedWrite(pin_number, rgb_color.r, rgb_color.g, rgb_color.b);
} else {
rgbLedWrite(pin_number, 0, 0, 0);
}
return true;
void BuiltInLED::setRGB(led_indicator_color_rgb_t rgb_color) {
hsv_color = rgb2hsv(rgb_color);
}
led_indicator_color_rgb_t BuiltInLED::getRGB() {
return hsv2rgb(hsv_color);
}
void BuiltInLED::setTemperature(uint32_t temperature) {
uint16_t hue;
uint8_t saturation;
log_d("Requested Temperature: %ld", temperature);
//hsv_color.v = gamma_table[((temperature >> 25) & 0x7F)];
temperature &= 0xFFFFFF;
if (temperature < 600) {
hue = 0;
saturation = 100;
} else {
if (temperature > 10000) {
hue = 222;
saturation = 21 + (temperature - 10000) * 41 / 990000;
} else {
log_e("Invalid pin (%d) number", pin_number);
return false;
temperature -= 600;
temperature /= 100;
hue = temperatureTable[temperature].hue;
saturation = temperatureTable[temperature].saturation;
}
}
saturation = (saturation * 255) / 100;
// brightness is not changed
hsv_color.h = hue;
hsv_color.s = saturation;
log_d("Calculated Temperature: %ld, Hue: %d, Saturation: %d, Brightness: %d", temperature, hue, saturation, hsv_color.v);
}
void BuiltInLED::setBrightness(uint8_t brightness){
hsv_color.v = brightness;
}
uint8_t BuiltInLED::getBrightness(){
return hsv_color.v;
}
void BuiltInLED::setHSV(led_indicator_color_hsv_t hsv){
if (hsv.h > MAX_HUE) {
hsv.h = MAX_HUE;
}
hsv_color.value = hsv.value;
}
led_indicator_color_hsv_t BuiltInLED::getHSV(){
return hsv_color;
}
void BuiltInLED::setRGB(led_indicator_color_rgb_t rgb_color){
hsv_color = rgb2hsv(rgb_color);
}
led_indicator_color_rgb_t BuiltInLED::getRGB(){
return hsv2rgb(hsv_color);
}
void BuiltInLED::setTemperature(uint32_t temperature){
uint16_t hue;
uint8_t saturation;
log_d("Requested Temperature: %ld", temperature);
//hsv_color.v = gamma_table[((temperature >> 25) & 0x7F)];
temperature &= 0xFFFFFF;
if (temperature < 600) {
hue = 0;
saturation = 100;
} else {
if (temperature > 10000) {
hue = 222;
saturation = 21 + (temperature - 10000) * 41 / 990000;
} else {
temperature -= 600;
temperature /= 100;
hue = temperatureTable[temperature].hue;
saturation = temperatureTable[temperature].saturation;
}
}
saturation = (saturation * 255) / 100;
// brightness is not changed
hsv_color.h = hue;
hsv_color.s = saturation;
log_d("Calculated Temperature: %ld, Hue: %d, Saturation: %d, Brightness: %d", temperature, hue, saturation, hsv_color.v);
}
@@ -14,61 +14,61 @@
#include <Arduino.h>
#define MAX_HUE 360
#define MAX_HUE 360
#define MAX_SATURATION 255
#define MAX_BRIGHTNESS 255
#define MAX_PROGRESS 256
#define MAX_PROGRESS 256
typedef struct {
union {
struct {
uint32_t v: 8; /*!< Brightness/Value of the LED. 0-255 */
uint32_t s: 8; /*!< Saturation of the LED. 0-255 */
uint32_t h: 9; /*!< Hue of the LED. 0-360 */
};
uint32_t value; /*!< IHSV value of the LED. */
union {
struct {
uint32_t v : 8; /*!< Brightness/Value of the LED. 0-255 */
uint32_t s : 8; /*!< Saturation of the LED. 0-255 */
uint32_t h : 9; /*!< Hue of the LED. 0-360 */
};
uint32_t value; /*!< IHSV value of the LED. */
};
} led_indicator_color_hsv_t;
typedef struct {
union {
struct {
uint32_t r: 8; /*!< Red component of the LED color. Range: 0-255. */
uint32_t g: 8; /*!< Green component of the LED color. Range: 0-255. */
uint32_t b: 8; /*!< Blue component of the LED color. Range: 0-255. */
};
uint32_t value; /*!< Combined RGB value of the LED color. */
union {
struct {
uint32_t r : 8; /*!< Red component of the LED color. Range: 0-255. */
uint32_t g : 8; /*!< Green component of the LED color. Range: 0-255. */
uint32_t b : 8; /*!< Blue component of the LED color. Range: 0-255. */
};
uint32_t value; /*!< Combined RGB value of the LED color. */
};
} led_indicator_color_rgb_t;
class BuiltInLED {
private:
uint8_t pin_number;
bool state;
led_indicator_color_hsv_t hsv_color;
uint8_t pin_number;
bool state;
led_indicator_color_hsv_t hsv_color;
public:
BuiltInLED();
~BuiltInLED();
BuiltInLED();
~BuiltInLED();
static led_indicator_color_hsv_t rgb2hsv(led_indicator_color_rgb_t rgb_value);
static led_indicator_color_rgb_t hsv2rgb(led_indicator_color_hsv_t hsv);
static led_indicator_color_hsv_t rgb2hsv(led_indicator_color_rgb_t rgb_value);
static led_indicator_color_rgb_t hsv2rgb(led_indicator_color_hsv_t hsv);
void begin(uint8_t pin);
void end();
void begin(uint8_t pin);
void end();
void on();
void off();
void toggle();
bool getState();
void on();
void off();
void toggle();
bool getState();
bool write();
bool write();
void setBrightness(uint8_t brightness);
uint8_t getBrightness();
void setHSV(led_indicator_color_hsv_t hsv);
led_indicator_color_hsv_t getHSV();
void setRGB(led_indicator_color_rgb_t color);
led_indicator_color_rgb_t getRGB();
void setTemperature(uint32_t temperature);
};
void setBrightness(uint8_t brightness);
uint8_t getBrightness();
void setHSV(led_indicator_color_hsv_t hsv);
led_indicator_color_hsv_t getHSV();
void setRGB(led_indicator_color_rgb_t color);
led_indicator_color_rgb_t getRGB();
void setTemperature(uint32_t temperature);
};
@@ -1,6 +1,6 @@
dependencies:
espressif/esp_matter:
version: "^1.3.0"
version: ">=1.4.0"
espressif/cmake_utilities:
version: "0.*"
rules:
@@ -11,85 +11,79 @@
#include "matter_accessory_driver.h"
/* Do any conversions/remapping for the actual value here */
esp_err_t light_accessory_set_power(void *led, uint8_t val)
{
BuiltInLED *builtinLED = (BuiltInLED *) led;
esp_err_t err = ESP_OK;
if (val) {
builtinLED->on();
} else {
builtinLED->off();
}
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set power: %d", val);
return err;
esp_err_t light_accessory_set_power(void *led, uint8_t val) {
BuiltInLED *builtinLED = (BuiltInLED *)led;
esp_err_t err = ESP_OK;
if (val) {
builtinLED->on();
} else {
builtinLED->off();
}
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set power: %d", val);
return err;
}
esp_err_t light_accessory_set_brightness(void *led, uint8_t val)
{
esp_err_t err = ESP_OK;
BuiltInLED *builtinLED = (BuiltInLED *) led;
int value = REMAP_TO_RANGE(val, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
esp_err_t light_accessory_set_brightness(void *led, uint8_t val) {
esp_err_t err = ESP_OK;
BuiltInLED *builtinLED = (BuiltInLED *)led;
int value = REMAP_TO_RANGE(val, MATTER_BRIGHTNESS, STANDARD_BRIGHTNESS);
builtinLED->setBrightness(value);
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set brightness: %d", value);
return err;
builtinLED->setBrightness(value);
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set brightness: %d", value);
return err;
}
esp_err_t light_accessory_set_hue(void *led, uint8_t val)
{
esp_err_t err = ESP_OK;
BuiltInLED *builtinLED = (BuiltInLED *) led;
int value = REMAP_TO_RANGE(val, MATTER_HUE, STANDARD_HUE);
led_indicator_color_hsv_t hsv = builtinLED->getHSV();
hsv.h = value;
builtinLED->setHSV(hsv);
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set hue: %d", value);
return err;
esp_err_t light_accessory_set_hue(void *led, uint8_t val) {
esp_err_t err = ESP_OK;
BuiltInLED *builtinLED = (BuiltInLED *)led;
int value = REMAP_TO_RANGE(val, MATTER_HUE, STANDARD_HUE);
led_indicator_color_hsv_t hsv = builtinLED->getHSV();
hsv.h = value;
builtinLED->setHSV(hsv);
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set hue: %d", value);
return err;
}
esp_err_t light_accessory_set_saturation(void *led, uint8_t val)
{
esp_err_t err = ESP_OK;
BuiltInLED *builtinLED = (BuiltInLED *) led;
int value = REMAP_TO_RANGE(val, MATTER_SATURATION, STANDARD_SATURATION);
led_indicator_color_hsv_t hsv = builtinLED->getHSV();
hsv.s = value;
builtinLED->setHSV(hsv);
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set saturation: %d", value);
return err;
esp_err_t light_accessory_set_saturation(void *led, uint8_t val) {
esp_err_t err = ESP_OK;
BuiltInLED *builtinLED = (BuiltInLED *)led;
int value = REMAP_TO_RANGE(val, MATTER_SATURATION, STANDARD_SATURATION);
led_indicator_color_hsv_t hsv = builtinLED->getHSV();
hsv.s = value;
builtinLED->setHSV(hsv);
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set saturation: %d", value);
return err;
}
esp_err_t light_accessory_set_temperature(void *led, uint16_t val)
{
esp_err_t err = ESP_OK;
BuiltInLED *builtinLED = (BuiltInLED *) led;
uint32_t value = REMAP_TO_RANGE_INVERSE(val, STANDARD_TEMPERATURE_FACTOR);
builtinLED->setTemperature(value);
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set temperature: %ld", value);
return err;
esp_err_t light_accessory_set_temperature(void *led, uint16_t val) {
esp_err_t err = ESP_OK;
BuiltInLED *builtinLED = (BuiltInLED *)led;
uint32_t value = REMAP_TO_RANGE_INVERSE(val, STANDARD_TEMPERATURE_FACTOR);
builtinLED->setTemperature(value);
if (!builtinLED->write()) {
err = ESP_FAIL;
}
log_i("LED set temperature: %ld", value);
return err;
}
app_driver_handle_t light_accessory_init()
{
/* Initialize led */
static BuiltInLED builtinLED;
app_driver_handle_t light_accessory_init() {
/* Initialize led */
static BuiltInLED builtinLED;
const uint8_t pin = WS2812_PIN; // set your board WS2812b pin here
builtinLED.begin(pin);
return (app_driver_handle_t) &builtinLED;
const uint8_t pin = WS2812_PIN; // set your board WS2812b pin here
builtinLED.begin(pin);
return (app_driver_handle_t)&builtinLED;
}
@@ -3,9 +3,9 @@
// set your board WS2812b pin here (e.g. 48 is the default pin for the ESP32-S3 devkit)
#ifndef CONFIG_WS2812_PIN
#define WS2812_PIN 48 // ESP32-S3 DevKitC built-in LED
#define WS2812_PIN 48 // ESP32-S3 DevKitC built-in LED
#else
#define WS2812_PIN CONFIG_WS2812_PIN // From sdkconfig.defaults.<soc>
#define WS2812_PIN CONFIG_WS2812_PIN // From sdkconfig.defaults.<soc>
#endif
#ifndef RGB_BUILTIN
@@ -14,34 +14,34 @@
// Set your board button pin here (e.g. 0 is the default pin for the ESP32-S3 devkit)
#ifndef CONFIG_BUTTON_PIN
#define BUTTON_PIN 0 // ESP32-S3 DevKitC built-in button
#define BUTTON_PIN 0 // ESP32-S3 DevKitC built-in button
#else
#define BUTTON_PIN CONFIG_BUTTON_PIN // From sdkconfig.defaults.<soc>
#define BUTTON_PIN CONFIG_BUTTON_PIN // From sdkconfig.defaults.<soc>
#endif
/** Standard max values (used for remapping attributes) */
#define STANDARD_BRIGHTNESS 255
#define STANDARD_HUE 360
#define STANDARD_SATURATION 255
#define STANDARD_BRIGHTNESS 255
#define STANDARD_HUE 360
#define STANDARD_SATURATION 255
#define STANDARD_TEMPERATURE_FACTOR 1000000
/** Matter max values (used for remapping attributes) */
#define MATTER_BRIGHTNESS 254
#define MATTER_HUE 254
#define MATTER_SATURATION 254
#define MATTER_BRIGHTNESS 254
#define MATTER_HUE 254
#define MATTER_SATURATION 254
#define MATTER_TEMPERATURE_FACTOR 1000000
/** Default attribute values used during initialization */
#define DEFAULT_POWER true
#define DEFAULT_POWER true
#define DEFAULT_BRIGHTNESS 64
#define DEFAULT_HUE 128
#define DEFAULT_HUE 128
#define DEFAULT_SATURATION 254
typedef void *app_driver_handle_t;
esp_err_t light_accessory_set_power(void *led, uint8_t val);
esp_err_t light_accessory_set_power(void *led, uint8_t val);
esp_err_t light_accessory_set_brightness(void *led, uint8_t val);
esp_err_t light_accessory_set_hue(void *led, uint8_t val);
esp_err_t light_accessory_set_saturation(void *led, uint8_t val);
esp_err_t light_accessory_set_temperature(void *led, uint16_t val);
app_driver_handle_t light_accessory_init();
app_driver_handle_t light_accessory_init();
@@ -20,24 +20,18 @@
#include <platform/ESP32/OpenthreadLauncher.h>
#include "esp_openthread_types.h"
#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \
{ \
.radio_mode = RADIO_MODE_NATIVE, \
}
#define ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG() \
{ .radio_mode = RADIO_MODE_NATIVE, }
#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \
{ \
.host_connection_mode = HOST_CONNECTION_MODE_NONE, \
}
#define ESP_OPENTHREAD_DEFAULT_HOST_CONFIG() \
{ .host_connection_mode = HOST_CONNECTION_MODE_NONE, }
#define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \
{ \
.storage_partition_name = "nvs", .netif_queue_size = 10, .task_queue_size = 10, \
}
#define ESP_OPENTHREAD_DEFAULT_PORT_CONFIG() \
{ .storage_partition_name = "nvs", .netif_queue_size = 10, .task_queue_size = 10, }
#endif
// set your board button pin here
const uint8_t button_gpio = BUTTON_PIN; // GPIO BOOT Button
const uint8_t button_gpio = BUTTON_PIN; // GPIO BOOT Button
uint16_t light_endpoint_id = 0;
@@ -54,290 +48,259 @@ extern const char decryption_key_end[] asm("_binary_esp_image_encryption_key_pem
static const char *s_decryption_key = decryption_key_start;
static const uint16_t s_decryption_key_len = decryption_key_end - decryption_key_start;
#endif // CONFIG_ENABLE_ENCRYPTED_OTA
#endif // CONFIG_ENABLE_ENCRYPTED_OTA
bool isAccessoryCommissioned() {
return chip::Server::GetInstance().GetFabricTable().FabricCount() > 0;
return chip::Server::GetInstance().GetFabricTable().FabricCount() > 0;
}
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION
bool isWifiConnected() {
return chip::DeviceLayer::ConnectivityMgr().IsWiFiStationConnected();
return chip::DeviceLayer::ConnectivityMgr().IsWiFiStationConnected();
}
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
bool isThreadConnected() {
return chip::DeviceLayer::ConnectivityMgr().IsThreadAttached();
return chip::DeviceLayer::ConnectivityMgr().IsThreadAttached();
}
#endif
static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg)
{
switch (event->Type) {
static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) {
switch (event->Type) {
case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged:
log_i("Interface %s Address changed",
event->InterfaceIpAddressChanged.Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV4_Assigned ?
"IPv4" : "IPV6" );
break;
log_i(
"Interface %s Address changed", event->InterfaceIpAddressChanged.Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV4_Assigned ? "IPv4" : "IPV6"
);
break;
case chip::DeviceLayer::DeviceEventType::kCommissioningComplete:
log_i("Commissioning complete");
break;
case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: log_i("Commissioning complete"); break;
case chip::DeviceLayer::DeviceEventType::kFailSafeTimerExpired:
log_i("Commissioning failed, fail safe timer expired");
break;
case chip::DeviceLayer::DeviceEventType::kFailSafeTimerExpired: log_i("Commissioning failed, fail safe timer expired"); break;
case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStarted:
log_i("Commissioning session started");
break;
case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStarted: log_i("Commissioning session started"); break;
case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStopped:
log_i("Commissioning session stopped");
break;
case chip::DeviceLayer::DeviceEventType::kCommissioningSessionStopped: log_i("Commissioning session stopped"); break;
case chip::DeviceLayer::DeviceEventType::kCommissioningWindowOpened:
log_i("Commissioning window opened");
break;
case chip::DeviceLayer::DeviceEventType::kCommissioningWindowOpened: log_i("Commissioning window opened"); break;
case chip::DeviceLayer::DeviceEventType::kCommissioningWindowClosed:
log_i("Commissioning window closed");
break;
case chip::DeviceLayer::DeviceEventType::kCommissioningWindowClosed: log_i("Commissioning window closed"); break;
case chip::DeviceLayer::DeviceEventType::kFabricRemoved:
{
log_i("Fabric removed successfully");
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0)
{
chip::CommissioningWindowManager & commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager();
constexpr auto kTimeoutSeconds = chip::System::Clock::Seconds16(k_timeout_seconds);
if (!commissionMgr.IsCommissioningWindowOpen())
{
/* After removing last fabric, this example does not remove the Wi-Fi credentials
{
log_i("Fabric removed successfully");
if (chip::Server::GetInstance().GetFabricTable().FabricCount() == 0) {
chip::CommissioningWindowManager &commissionMgr = chip::Server::GetInstance().GetCommissioningWindowManager();
constexpr auto kTimeoutSeconds = chip::System::Clock::Seconds16(k_timeout_seconds);
if (!commissionMgr.IsCommissioningWindowOpen()) {
/* After removing last fabric, this example does not remove the Wi-Fi credentials
* and still has IP connectivity so, only advertising on DNS-SD.
*/
CHIP_ERROR err = commissionMgr.OpenBasicCommissioningWindow(kTimeoutSeconds,
chip::CommissioningWindowAdvertisement::kDnssdOnly);
if (err != CHIP_NO_ERROR)
{
log_e("Failed to open commissioning window, err:%" CHIP_ERROR_FORMAT, err.Format());
}
}
}
break;
CHIP_ERROR err = commissionMgr.OpenBasicCommissioningWindow(kTimeoutSeconds, chip::CommissioningWindowAdvertisement::kDnssdOnly);
if (err != CHIP_NO_ERROR) {
log_e("Failed to open commissioning window, err:%" CHIP_ERROR_FORMAT, err.Format());
}
}
case chip::DeviceLayer::DeviceEventType::kFabricWillBeRemoved:
log_i("Fabric will be removed");
break;
case chip::DeviceLayer::DeviceEventType::kFabricUpdated:
log_i("Fabric is updated");
break;
case chip::DeviceLayer::DeviceEventType::kFabricCommitted:
log_i("Fabric is committed");
break;
case chip::DeviceLayer::DeviceEventType::kBLEDeinitialized:
log_i("BLE deinitialized and memory reclaimed");
break;
default:
break;
}
}
esp_err_t matter_light_attribute_update(app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id,
uint32_t attribute_id, esp_matter_attr_val_t *val)
{
esp_err_t err = ESP_OK;
if (endpoint_id == light_endpoint_id) {
void *led = (void *)driver_handle;
if (cluster_id == OnOff::Id) {
if (attribute_id == OnOff::Attributes::OnOff::Id) {
err = light_accessory_set_power(led, val->val.b);
}
} else if (cluster_id == LevelControl::Id) {
if (attribute_id == LevelControl::Attributes::CurrentLevel::Id) {
err = light_accessory_set_brightness(led, val->val.u8);
}
} else if (cluster_id == ColorControl::Id) {
if (attribute_id == ColorControl::Attributes::CurrentHue::Id) {
err = light_accessory_set_hue(led, val->val.u8);
} else if (attribute_id == ColorControl::Attributes::CurrentSaturation::Id) {
err = light_accessory_set_saturation(led, val->val.u8);
} else if (attribute_id == ColorControl::Attributes::ColorTemperatureMireds::Id) {
err = light_accessory_set_temperature(led, val->val.u16);
}
}
}
return err;
}
esp_err_t matter_light_set_defaults(uint16_t endpoint_id)
{
esp_err_t err = ESP_OK;
void *led = endpoint::get_priv_data(endpoint_id);
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = NULL;
attribute_t *attribute = NULL;
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
/* Setting brightness */
cluster = cluster::get(endpoint, LevelControl::Id);
attribute = attribute::get(cluster, LevelControl::Attributes::CurrentLevel::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_brightness(led, val.val.u8);
/* Setting color */
cluster = cluster::get(endpoint, ColorControl::Id);
attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id);
attribute::get_val(attribute, &val);
if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kCurrentHueAndCurrentSaturation) {
/* Setting hue */
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentHue::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_hue(led, val.val.u8);
/* Setting saturation */
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_saturation(led, val.val.u8);
} else if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kColorTemperature) {
/* Setting temperature */
attribute = attribute::get(cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_temperature(led, val.val.u16);
} else {
log_e("Color mode not supported");
}
break;
}
/* Setting power */
cluster = cluster::get(endpoint, OnOff::Id);
attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_power(led, val.val.b);
case chip::DeviceLayer::DeviceEventType::kFabricWillBeRemoved: log_i("Fabric will be removed"); break;
return err;
case chip::DeviceLayer::DeviceEventType::kFabricUpdated: log_i("Fabric is updated"); break;
case chip::DeviceLayer::DeviceEventType::kFabricCommitted: log_i("Fabric is committed"); break;
case chip::DeviceLayer::DeviceEventType::kBLEDeinitialized: log_i("BLE deinitialized and memory reclaimed"); break;
default: break;
}
}
void button_driver_init()
{
/* Initialize button */
pinMode(button_gpio, INPUT_PULLUP);
esp_err_t matter_light_attribute_update(
app_driver_handle_t driver_handle, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val
) {
esp_err_t err = ESP_OK;
if (endpoint_id == light_endpoint_id) {
void *led = (void *)driver_handle;
if (cluster_id == OnOff::Id) {
if (attribute_id == OnOff::Attributes::OnOff::Id) {
err = light_accessory_set_power(led, val->val.b);
}
} else if (cluster_id == LevelControl::Id) {
if (attribute_id == LevelControl::Attributes::CurrentLevel::Id) {
err = light_accessory_set_brightness(led, val->val.u8);
}
} else if (cluster_id == ColorControl::Id) {
if (attribute_id == ColorControl::Attributes::CurrentHue::Id) {
err = light_accessory_set_hue(led, val->val.u8);
} else if (attribute_id == ColorControl::Attributes::CurrentSaturation::Id) {
err = light_accessory_set_saturation(led, val->val.u8);
} else if (attribute_id == ColorControl::Attributes::ColorTemperatureMireds::Id) {
err = light_accessory_set_temperature(led, val->val.u16);
}
}
}
return err;
}
esp_err_t matter_light_set_defaults(uint16_t endpoint_id) {
esp_err_t err = ESP_OK;
void *led = endpoint::get_priv_data(endpoint_id);
node_t *node = node::get();
endpoint_t *endpoint = endpoint::get(node, endpoint_id);
cluster_t *cluster = NULL;
attribute_t *attribute = NULL;
esp_matter_attr_val_t val = esp_matter_invalid(NULL);
/* Setting brightness */
cluster = cluster::get(endpoint, LevelControl::Id);
attribute = attribute::get(cluster, LevelControl::Attributes::CurrentLevel::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_brightness(led, val.val.u8);
/* Setting color */
cluster = cluster::get(endpoint, ColorControl::Id);
attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id);
attribute::get_val(attribute, &val);
if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kCurrentHueAndCurrentSaturation) {
/* Setting hue */
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentHue::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_hue(led, val.val.u8);
/* Setting saturation */
attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_saturation(led, val.val.u8);
} else if (val.val.u8 == (uint8_t)ColorControl::ColorMode::kColorTemperature) {
/* Setting temperature */
attribute = attribute::get(cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_temperature(led, val.val.u16);
} else {
log_e("Color mode not supported");
}
/* Setting power */
cluster = cluster::get(endpoint, OnOff::Id);
attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id);
attribute::get_val(attribute, &val);
err |= light_accessory_set_power(led, val.val.b);
return err;
}
void button_driver_init() {
/* Initialize button */
pinMode(button_gpio, INPUT_PULLUP);
}
// This callback is called for every attribute update. The callback implementation shall
// handle the desired attributes and return an appropriate error code. If the attribute
// is not of your interest, please do not return an error code and strictly return ESP_OK.
static esp_err_t app_attribute_update_cb(attribute::callback_type_t type, uint16_t endpoint_id, uint32_t cluster_id,
uint32_t attribute_id, esp_matter_attr_val_t *val, void *priv_data)
{
esp_err_t err = ESP_OK;
static esp_err_t app_attribute_update_cb(
attribute::callback_type_t type, uint16_t endpoint_id, uint32_t cluster_id, uint32_t attribute_id, esp_matter_attr_val_t *val, void *priv_data
) {
esp_err_t err = ESP_OK;
if (type == PRE_UPDATE) {
/* Driver update */
app_driver_handle_t driver_handle = (app_driver_handle_t)priv_data;
err = matter_light_attribute_update(driver_handle, endpoint_id, cluster_id, attribute_id, val);
}
if (type == PRE_UPDATE) {
/* Driver update */
app_driver_handle_t driver_handle = (app_driver_handle_t)priv_data;
err = matter_light_attribute_update(driver_handle, endpoint_id, cluster_id, attribute_id, val);
}
return err;
return err;
}
// This callback is invoked when clients interact with the Identify Cluster.
// In the callback implementation, an endpoint can identify itself. (e.g., by flashing an LED or light).
static esp_err_t app_identification_cb(identification::callback_type_t type, uint16_t endpoint_id, uint8_t effect_id,
uint8_t effect_variant, void *priv_data)
{
log_i("Identification callback: type: %u, effect: %u, variant: %u", type, effect_id, effect_variant);
return ESP_OK;
static esp_err_t app_identification_cb(identification::callback_type_t type, uint16_t endpoint_id, uint8_t effect_id, uint8_t effect_variant, void *priv_data) {
log_i("Identification callback: type: %u, effect: %u, variant: %u", type, effect_id, effect_variant);
return ESP_OK;
}
void setup()
{
esp_err_t err = ESP_OK;
void setup() {
esp_err_t err = ESP_OK;
/* Initialize driver */
app_driver_handle_t light_handle = light_accessory_init();
button_driver_init();
/* Initialize driver */
app_driver_handle_t light_handle = light_accessory_init();
button_driver_init();
/* Create a Matter node and add the mandatory Root Node device type on endpoint 0 */
node::config_t node_config;
/* Create a Matter node and add the mandatory Root Node device type on endpoint 0 */
node::config_t node_config;
// node handle can be used to add/modify other endpoints.
node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb);
if (node == nullptr) {
log_e("Failed to create Matter node");
abort();
}
// node handle can be used to add/modify other endpoints.
node_t *node = node::create(&node_config, app_attribute_update_cb, app_identification_cb);
if (node == nullptr) {
log_e("Failed to create Matter node");
abort();
}
extended_color_light::config_t light_config;
light_config.on_off.on_off = DEFAULT_POWER;
light_config.on_off.lighting.start_up_on_off = nullptr;
light_config.level_control.current_level = DEFAULT_BRIGHTNESS;
light_config.level_control.lighting.start_up_current_level = DEFAULT_BRIGHTNESS;
light_config.color_control.color_mode = (uint8_t)ColorControl::ColorMode::kColorTemperature;
light_config.color_control.enhanced_color_mode = (uint8_t)ColorControl::ColorMode::kColorTemperature;
light_config.color_control.color_temperature.startup_color_temperature_mireds = nullptr;
extended_color_light::config_t light_config;
light_config.on_off.on_off = DEFAULT_POWER;
light_config.on_off.lighting.start_up_on_off = nullptr;
light_config.level_control.current_level = DEFAULT_BRIGHTNESS;
light_config.level_control.lighting.start_up_current_level = DEFAULT_BRIGHTNESS;
light_config.color_control.color_mode = (uint8_t)ColorControl::ColorMode::kColorTemperature;
light_config.color_control.enhanced_color_mode = (uint8_t)ColorControl::ColorMode::kColorTemperature;
light_config.color_control.color_temperature.startup_color_temperature_mireds = nullptr;
// endpoint handles can be used to add/modify clusters.
endpoint_t *endpoint = extended_color_light::create(node, &light_config, ENDPOINT_FLAG_NONE, light_handle);
if (endpoint == nullptr) {
log_e("Failed to create extended color light endpoint");
abort();
}
// endpoint handles can be used to add/modify clusters.
endpoint_t *endpoint = extended_color_light::create(node, &light_config, ENDPOINT_FLAG_NONE, light_handle);
if (endpoint == nullptr) {
log_e("Failed to create extended color light endpoint");
abort();
}
light_endpoint_id = endpoint::get_id(endpoint);
log_i("Light created with endpoint_id %d", light_endpoint_id);
light_endpoint_id = endpoint::get_id(endpoint);
log_i("Light created with endpoint_id %d", light_endpoint_id);
/* Mark deferred persistence for some attributes that might be changed rapidly */
cluster_t *level_control_cluster = cluster::get(endpoint, LevelControl::Id);
attribute_t *current_level_attribute = attribute::get(level_control_cluster, LevelControl::Attributes::CurrentLevel::Id);
attribute::set_deferred_persistence(current_level_attribute);
/* Mark deferred persistence for some attributes that might be changed rapidly */
cluster_t *level_control_cluster = cluster::get(endpoint, LevelControl::Id);
attribute_t *current_level_attribute = attribute::get(level_control_cluster, LevelControl::Attributes::CurrentLevel::Id);
attribute::set_deferred_persistence(current_level_attribute);
cluster_t *color_control_cluster = cluster::get(endpoint, ColorControl::Id);
attribute_t *current_x_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentX::Id);
attribute::set_deferred_persistence(current_x_attribute);
attribute_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id);
attribute::set_deferred_persistence(current_y_attribute);
attribute_t *color_temp_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
attribute::set_deferred_persistence(color_temp_attribute);
cluster_t *color_control_cluster = cluster::get(endpoint, ColorControl::Id);
attribute_t *current_x_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentX::Id);
attribute::set_deferred_persistence(current_x_attribute);
attribute_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id); // codespell:ignore
attribute::set_deferred_persistence(current_y_attribute);
attribute_t *color_temp_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::ColorTemperatureMireds::Id);
attribute::set_deferred_persistence(color_temp_attribute);
#if CHIP_DEVICE_CONFIG_ENABLE_THREAD
/* Set OpenThread platform config */
esp_openthread_platform_config_t config = {
.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(),
.host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(),
.port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),
};
set_openthread_platform_config(&config);
/* Set OpenThread platform config */
esp_openthread_platform_config_t config = {
.radio_config = ESP_OPENTHREAD_DEFAULT_RADIO_CONFIG(),
.host_config = ESP_OPENTHREAD_DEFAULT_HOST_CONFIG(),
.port_config = ESP_OPENTHREAD_DEFAULT_PORT_CONFIG(),
};
set_openthread_platform_config(&config);
#endif
/* Matter start */
err = esp_matter::start(app_event_cb);
if (err != ESP_OK) {
log_e("Failed to start Matter, err:%d", err);
abort();
}
/* Matter start */
err = esp_matter::start(app_event_cb);
if (err != ESP_OK) {
log_e("Failed to start Matter, err:%d", err);
abort();
}
#if CONFIG_ENABLE_ENCRYPTED_OTA
err = esp_matter_ota_requestor_encrypted_init(s_decryption_key, s_decryption_key_len);
if (err != ESP_OK) {
log_e("Failed to initialized the encrypted OTA, err: %d", err);
abort();
}
#endif // CONFIG_ENABLE_ENCRYPTED_OTA
err = esp_matter_ota_requestor_encrypted_init(s_decryption_key, s_decryption_key_len);
if (err != ESP_OK) {
log_e("Failed to initialized the encrypted OTA, err: %d", err);
abort();
}
#endif // CONFIG_ENABLE_ENCRYPTED_OTA
#if CONFIG_ENABLE_CHIP_SHELL
esp_matter::console::diagnostics_register_commands();
esp_matter::console::wifi_register_commands();
esp_matter::console::diagnostics_register_commands();
esp_matter::console::wifi_register_commands();
#if CONFIG_OPENTHREAD_CLI
esp_matter::console::otcli_register_commands();
esp_matter::console::otcli_register_commands();
#endif
esp_matter::console::init();
esp_matter::console::init();
#endif
}
@@ -346,10 +309,10 @@ void loop() {
static bool button_state = false;
static bool started = false;
if(!isAccessoryCommissioned()) {
if (!isAccessoryCommissioned()) {
log_w("Accessory not commissioned yet. Waiting for commissioning.");
#ifdef RGB_BUILTIN
rgbLedWrite(RGB_BUILTIN, 48, 0, 20); // Purple indicates accessory not commissioned
rgbLedWrite(RGB_BUILTIN, 48, 0, 20); // Purple indicates accessory not commissioned
#endif
delay(5000);
return;
@@ -359,7 +322,7 @@ void loop() {
if (!isWifiConnected()) {
log_w("Wi-Fi not connected yet. Waiting for connection.");
#ifdef RGB_BUILTIN
rgbLedWrite(RGB_BUILTIN, 48, 20, 0); // Orange indicates accessory not connected to Wi-Fi
rgbLedWrite(RGB_BUILTIN, 48, 20, 0); // Orange indicates accessory not connected to Wi-Fi
#endif
delay(5000);
return;
@@ -370,7 +333,7 @@ void loop() {
if (!isThreadConnected()) {
log_w("Thread not connected yet. Waiting for connection.");
#ifdef RGB_BUILTIN
rgbLedWrite(RGB_BUILTIN, 0, 20, 48); // Blue indicates accessory not connected to Trhead
rgbLedWrite(RGB_BUILTIN, 0, 20, 48); // Blue indicates accessory not connected to Trhead
#endif
delay(5000);
return;
@@ -389,10 +352,10 @@ void loop() {
// Check if the button is pressed and toggle the light right away
if (digitalRead(button_gpio) == LOW && !button_state) {
// deals with button debounce
button_time_stamp = millis(); // record the time while the button is pressed.
button_state = true; // pressed.
button_time_stamp = millis(); // record the time while the button is pressed.
button_state = true; // pressed.
// Toggle button is pressed - toggle the light
// Toggle button is pressed - toggle the light
log_i("Toggle button pressed");
endpoint_t *endpoint = endpoint::get(node::get(), light_endpoint_id);
@@ -408,14 +371,14 @@ void loop() {
// Check if the button is released and handle the factory reset
uint32_t time_diff = millis() - button_time_stamp;
if (button_state && time_diff > 100 && digitalRead(button_gpio) == HIGH) {
button_state = false; // released. It can be pressed again after 100ms debounce.
button_state = false; // released. It can be pressed again after 100ms debounce.
// Factory reset is triggered if the button is pressed for more than 10 seconds
if (time_diff > 10000) {
log_i("Factory reset triggered. Light will retored to factory settings.");
esp_matter::factory_reset();
log_i("Factory reset triggered. Light will restored to factory settings.");
esp_matter::factory_reset();
}
}
delay(50); // WDT is happier with a delay
delay(50); // WDT is happier with a delay
}
@@ -17,10 +17,16 @@ platform = espressif32
framework = arduino, espidf
board_build.partitions = partitions.csv
monitor_speed = 115200
build_unflags =
-std=c++17
-std=gnu++2b
build_flags =
-std=gnu++2a
-Wno-missing-field-initializers
[env:esp32s3]
board = esp32-s3-devkitc-1
[env:esp32c6]
board = esp32-c6-devkitc-1
board_build.embed_txtfiles =
managed_components/espressif__esp_insights/server_certs/https_server.crt
managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt
@@ -1,3 +1,5 @@
CONFIG_IDF_TARGET="esp32c6"
# Arduino Settings
CONFIG_FREERTOS_HZ=1000
CONFIG_AUTOSTART_ARDUINO=y
@@ -6,9 +8,17 @@ CONFIG_AUTOSTART_ARDUINO=y
# Boot Messages - Log level
CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y
# Arduino Log Level
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_VERBOSE=y
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO=y
# IDF Log Level
CONFIG_LOG_DEFAULT_LEVEL_WARN=y
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
# Default to 921600 baud when flashing and monitoring device
CONFIG_ESPTOOLPY_BAUD_921600B=y
CONFIG_ESPTOOLPY_BAUD=921600
CONFIG_ESPTOOLPY_COMPRESSED=y
CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y
CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
#enable BT
CONFIG_BT_ENABLED=y
@@ -17,6 +27,11 @@ CONFIG_BT_NIMBLE_ENABLED=y
#disable BT connection reattempt
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
# NIMBLE
CONFIG_BT_NIMBLE_EXT_ADV=n
CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70
CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=y
#enable lwip ipv6 autoconfig
CONFIG_LWIP_IPV6_AUTOCONFIG=y
@@ -28,16 +43,17 @@ CONFIG_PARTITION_TABLE_OFFSET=0xC000
# Disable chip shell
CONFIG_ENABLE_CHIP_SHELL=n
# Enable OTA Requester
CONFIG_ENABLE_OTA_REQUESTOR=n
#enable lwIP route hooks
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
# Button
CONFIG_BUTTON_PERIOD_TIME_MS=20
CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000
# disable softap by default
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
CONFIG_ENABLE_WIFI_STATION=y
CONFIG_ENABLE_WIFI_AP=n
# Disable DS Peripheral
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
@@ -52,15 +68,23 @@ CONFIG_MBEDTLS_HKDF_C=y
# unique local addresses for fabrics(MAX_FABRIC), a link local address(1)
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6
# libsodium
CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
# ESP32-S3-DevKitC-1 Settings
# FreeRTOS should use legacy API
CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y
# Use minimal mDNS
CONFIG_USE_MINIMAL_MDNS=y
CONFIG_ENABLE_EXTENDED_DISCOVERY=y
# ESP32-C6-DevKit Settings
# Buttons
CONFIG_BSP_BUTTONS_NUM=1
CONFIG_BSP_BUTTON_1_TYPE_GPIO=y
CONFIG_BSP_BUTTON_1_GPIO=0
CONFIG_BSP_BUTTON_1_LEVEL=0
CONFIG_BUTTON_PIN=9
# LEDs
CONFIG_BSP_LEDS_NUM=1
CONFIG_BSP_LED_TYPE_RGB=y
CONFIG_BSP_LED_RGB_GPIO=48
CONFIG_BSP_LED_RGB_BACKEND_RMT=y
CONFIG_WS2812_PIN=8
# max GPIO
CONFIG_ENV_GPIO_RANGE_MIN=0
CONFIG_ENV_GPIO_RANGE_MAX=30
CONFIG_ENV_GPIO_IN_RANGE_MAX=30
CONFIG_ENV_GPIO_OUT_RANGE_MAX=30
@@ -5,7 +5,7 @@ CONFIG_FREERTOS_HZ=1000
CONFIG_AUTOSTART_ARDUINO=y
# Log Levels
# Boot Messages - Log level
# Boot Messages - Log level
CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y
# Arduino Log Level
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO=y
@@ -56,7 +56,7 @@ CONFIG_LWIP_MULTICAST_PING=y
CONFIG_USE_MINIMAL_MDNS=n
CONFIG_ENABLE_EXTENDED_DISCOVERY=y
# Enable OTA Requestor
# Enable OTA Requester
CONFIG_ENABLE_OTA_REQUESTOR=n
# Disable STA and AP for ESP32C6
@@ -77,4 +77,3 @@ CONFIG_MRP_MAX_RETRANS=3
# Enable HKDF in mbedtls
CONFIG_MBEDTLS_HKDF_C=y
@@ -1,64 +0,0 @@
CONFIG_IDF_TARGET="esp32c3"
# Arduino Settings
CONFIG_FREERTOS_HZ=1000
CONFIG_AUTOSTART_ARDUINO=y
# Log Levels
# Boot Messages - Log level
CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y
# Arduino Log Level
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO=y
# IDF Log Level
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
# Default to 921600 baud when flashing and monitoring device
CONFIG_ESPTOOLPY_BAUD_921600B=y
CONFIG_ESPTOOLPY_BAUD=921600
CONFIG_ESPTOOLPY_COMPRESSED=y
CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y
CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
#enable BT
CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y
#disable BT connection reattempt
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
#enable lwip ipv6 autoconfig
CONFIG_LWIP_IPV6_AUTOCONFIG=y
# Use a custom partition table
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0xC000
# Disable chip shell
CONFIG_ENABLE_CHIP_SHELL=n
# Enable OTA Requestor
CONFIG_ENABLE_OTA_REQUESTOR=n
#enable lwIP route hooks
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
# disable softap by default
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
CONFIG_ENABLE_WIFI_STATION=y
CONFIG_ENABLE_WIFI_AP=n
# Disable DS Peripheral
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
# Use compact attribute storage mode
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
# Enable HKDF in mbedtls
CONFIG_MBEDTLS_HKDF_C=y
# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1)
# unique local addresses for fabrics(MAX_FABRIC), a link local address(1)
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6
@@ -1,68 +1,5 @@
CONFIG_IDF_TARGET="esp32c6"
# Arduino Settings
CONFIG_FREERTOS_HZ=1000
CONFIG_AUTOSTART_ARDUINO=y
# Log Levels
# Boot Messages - Log level
CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y
# Arduino Log Level
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO=y
# IDF Log Level
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
# Default to 921600 baud when flashing and monitoring device
CONFIG_ESPTOOLPY_BAUD_921600B=y
CONFIG_ESPTOOLPY_BAUD=921600
CONFIG_ESPTOOLPY_COMPRESSED=y
CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y
CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
#enable BT
CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y
#disable BT connection reattempt
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
#enable lwip ipv6 autoconfig
CONFIG_LWIP_IPV6_AUTOCONFIG=y
# Use a custom partition table
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0xC000
# Disable chip shell
CONFIG_ENABLE_CHIP_SHELL=n
# Enable OTA Requestor
CONFIG_ENABLE_OTA_REQUESTOR=n
#enable lwIP route hooks
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
# disable softap by default
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
CONFIG_ENABLE_WIFI_STATION=y
CONFIG_ENABLE_WIFI_AP=n
# Disable DS Peripheral
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
# Use compact attribute storage mode
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
# Enable HKDF in mbedtls
CONFIG_MBEDTLS_HKDF_C=y
# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1)
# unique local addresses for fabrics(MAX_FABRIC), a link local address(1)
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6
# libsodium
CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y
@@ -1,64 +0,0 @@
CONFIG_IDF_TARGET="esp32s3"
# Arduino Settings
CONFIG_FREERTOS_HZ=1000
CONFIG_AUTOSTART_ARDUINO=y
# Log Levels
# Boot Messages - Log level
CONFIG_BOOTLOADER_LOG_LEVEL_ERROR=y
# Arduino Log Level
CONFIG_ARDUHAL_LOG_DEFAULT_LEVEL_INFO=y
# IDF Log Level
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
# Default to 921600 baud when flashing and monitoring device
CONFIG_ESPTOOLPY_BAUD_921600B=y
CONFIG_ESPTOOLPY_BAUD=921600
CONFIG_ESPTOOLPY_COMPRESSED=y
CONFIG_ESPTOOLPY_MONITOR_BAUD_115200B=y
CONFIG_ESPTOOLPY_MONITOR_BAUD=115200
CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y
#enable BT
CONFIG_BT_ENABLED=y
CONFIG_BT_NIMBLE_ENABLED=y
#disable BT connection reattempt
CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n
#enable lwip ipv6 autoconfig
CONFIG_LWIP_IPV6_AUTOCONFIG=y
# Use a custom partition table
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_OFFSET=0xC000
# Disable chip shell
CONFIG_ENABLE_CHIP_SHELL=n
# Enable OTA Requestor
CONFIG_ENABLE_OTA_REQUESTOR=n
#enable lwIP route hooks
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
# disable softap by default
CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n
CONFIG_ENABLE_WIFI_STATION=y
CONFIG_ENABLE_WIFI_AP=n
# Disable DS Peripheral
CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=n
# Use compact attribute storage mode
CONFIG_ESP_MATTER_NVS_USE_COMPACT_ATTR_STORAGE=y
# Enable HKDF in mbedtls
CONFIG_MBEDTLS_HKDF_C=y
# Increase LwIP IPv6 address number to 6 (MAX_FABRIC + 1)
# unique local addresses for fabrics(MAX_FABRIC), a link local address(1)
CONFIG_LWIP_IPV6_NUM_ADDRESSES=6
+10 -1
View File
@@ -13,7 +13,6 @@ framework = espidf
board = esp32dev
monitor_speed = 115200
build_flags =
; https://docs.espressif.com/projects/esp-idf/en/latest/get-started/get-started-wrover-kit.html#rgb-led
-D CONFIG_BLINK_GPIO=2
-D CONFIG_BLINK_LED_GPIO=2
-D CONFIG_BLINK_PERIOD=1000
@@ -37,3 +36,13 @@ build_flags =
-D CONFIG_BLINK_GPIO=2
-D CONFIG_BLINK_LED_GPIO=2
-D CONFIG_BLINK_PERIOD=1000
[env:esp32-p4]
platform = espressif32
framework = espidf
board = esp32-p4
monitor_speed = 115200
build_flags =
-D CONFIG_BLINK_GPIO=2
-D CONFIG_BLINK_LED_GPIO=2
-D CONFIG_BLINK_PERIOD=1000
@@ -18,3 +18,6 @@ board_build.embed_txtfiles =
[env:esp-wrover-kit]
board = esp-wrover-kit
build_flags =
-D SHOW_METRICS
+5 -3
View File
@@ -29,13 +29,15 @@ lib_ignore = ${env:tasmota32_base.lib_ignore}
NetworkClientSecure
Zigbee
custom_sdkconfig = https://raw.githubusercontent.com/pioarduino/sdkconfig/refs/heads/main/sdkconfig_tasmota_esp32
'# CONFIG_BT_ENABLED is not set'
'# CONFIG_BT_NIMBLE_ENABLED is not set'
'# CONFIG_BT_CONTROLLER_ENABLED is not set'
CONFIG_BT_CONTROLLER_DISABLED=y
'# CONFIG_ETH_USE_ESP32_EMAC is not set'
'# CONFIG_ETH_PHY_INTERFACE_RMII is not set'
'# CONFIG_ETH_RMII_CLK_INPUT is not set'
'# CONFIG_ETH_RMII_CLK_IN_GPIO is not set'
custom_component_remove = espressif/esp_hosted
espressif/esp_wifi_remote
espressif/esp-dsp
custom_component_remove =
espressif/network_provisioning
espressif/esp-zboss-lib
espressif/esp-zigbee-lib