From 45261f9f052a23be85425ab924eaeb5908d164f5 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 4 Sep 2024 12:11:28 -0300 Subject: [PATCH 01/42] feat(matter): partition file for matter The declaration includes a partition for keys and SSL certificates. --- .../esp_matter_llight/partitions.csv | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 idf_component_examples/esp_matter_llight/partitions.csv diff --git a/idf_component_examples/esp_matter_llight/partitions.csv b/idf_component_examples/esp_matter_llight/partitions.csv new file mode 100644 index 00000000000..ffe5f242e76 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/partitions.csv @@ -0,0 +1,10 @@ +# Name, Type, SubType, Offset, Size, Flags +# Note: Firmware partition offset needs to be 64K aligned, initial 36K (9 sectors) are reserved for bootloader and partition table +esp_secure_cert, 0x3F, ,0xd000, 0x2000, encrypted +nvs, data, nvs, 0x10000, 0xC000, +nvs_keys, data, nvs_keys,, 0x1000, encrypted +otadata, data, ota, , 0x2000 +phy_init, data, phy, , 0x1000, +ota_0, app, ota_0, 0x20000, 0x1E0000, +ota_1, app, ota_1, 0x200000, 0x1E0000, +fctry, data, nvs, 0x3E0000, 0x6000 From 2d5ed93caf5e206be7b1760f7e1813598b6b8a87 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 4 Sep 2024 12:12:51 -0300 Subject: [PATCH 02/42] feat(matter): matter light source code Adds necessary Matter + Arduino source code that will create a Matter compatible Light. --- .../esp_matter_llight/main/CMakeLists.txt | 5 + .../esp_matter_llight/main/builtinLED.cpp | 250 ++++++++++++ .../esp_matter_llight/main/builtinLED.h | 76 ++++ .../esp_matter_llight/main/idf_component.yml | 8 + .../main/matter_accessory_driver.cpp | 101 +++++ .../main/matter_accessory_driver.h | 28 ++ .../esp_matter_llight/main/matter_light.cpp | 369 ++++++++++++++++++ 7 files changed, 837 insertions(+) create mode 100644 idf_component_examples/esp_matter_llight/main/CMakeLists.txt create mode 100644 idf_component_examples/esp_matter_llight/main/builtinLED.cpp create mode 100644 idf_component_examples/esp_matter_llight/main/builtinLED.h create mode 100644 idf_component_examples/esp_matter_llight/main/idf_component.yml create mode 100644 idf_component_examples/esp_matter_llight/main/matter_accessory_driver.cpp create mode 100644 idf_component_examples/esp_matter_llight/main/matter_accessory_driver.h create mode 100644 idf_component_examples/esp_matter_llight/main/matter_light.cpp diff --git a/idf_component_examples/esp_matter_llight/main/CMakeLists.txt b/idf_component_examples/esp_matter_llight/main/CMakeLists.txt new file mode 100644 index 00000000000..833af61132a --- /dev/null +++ b/idf_component_examples/esp_matter_llight/main/CMakeLists.txt @@ -0,0 +1,5 @@ +idf_component_register(SRC_DIRS "." + INCLUDE_DIRS ".") + +set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) +target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") \ No newline at end of file diff --git a/idf_component_examples/esp_matter_llight/main/builtinLED.cpp b/idf_component_examples/esp_matter_llight/main/builtinLED.cpp new file mode 100644 index 00000000000..10d10b914f9 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/main/builtinLED.cpp @@ -0,0 +1,250 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. + + This will implement the onboard WS2812b LED as a LED indicator + It can be used to indicate some state or status of the device + The LED can be controlled using RGB, HSV or color temperature, brightness + + In this example, the LED Indicator class is used as the Matter light accessory +*/ + +#include "builtinLED.h" + +typedef struct { + 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} +}; + +/* 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, +}; + +BuiltInLED::BuiltInLED() { + pin_number = (uint8_t) -1; // no pin number + state = false; // LED is off + hsv_color.value = 0; // black color +} + +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; + + 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; + } 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); + } + } + 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; + + 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) { + case 0: + 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; + case 2: + 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; + case 4: + 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; + } + + // 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; + write(); + } else { + log_e("Invalid pin (%d) number", pin); + } +} +void BuiltInLED::end(){ + state = false; + write(); + 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 { + rgbLedWrite(pin_number, 0, 0, 0); + } + return true; + } else { + log_e("Invalid pin (%d) number", pin_number); + return false; + } +} + +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); +} + diff --git a/idf_component_examples/esp_matter_llight/main/builtinLED.h b/idf_component_examples/esp_matter_llight/main/builtinLED.h new file mode 100644 index 00000000000..160cdc984a9 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/main/builtinLED.h @@ -0,0 +1,76 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. + + This will implement the onboard WS2812b LED as a LED indicator + It can be used to indicate some state or status of the device + The LED can be controlled using RGB, HSV or color temperature, brightness + + In this example, the BuiltInLED class is used as the Matter light accessory +*/ + +#pragma once + +#include + +#define MAX_HUE 360 +#define MAX_SATURATION 255 +#define MAX_BRIGHTNESS 255 +#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. */ + }; +} 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. */ + }; +} led_indicator_color_rgb_t; + +class BuiltInLED { +private: + uint8_t pin_number; + bool state;BuiltInLED + led_indicator_color_hsv_t hsv_color; + +public: + 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); + + void begin(uint8_t pin); + void end(); + + void on(); + void off(); + void toggle(); + bool getState(); + + 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); +}; diff --git a/idf_component_examples/esp_matter_llight/main/idf_component.yml b/idf_component_examples/esp_matter_llight/main/idf_component.yml new file mode 100644 index 00000000000..7b0693203c4 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/main/idf_component.yml @@ -0,0 +1,8 @@ +dependencies: + espressif/esp_matter: + version: "^1.3.0" + # Adds Arduino Core from GitHub repository using main branch + espressif/arduino-esp32: + version: "master" # branch or commit + git: https://github.com/espressif/arduino-esp32.git + diff --git a/idf_component_examples/esp_matter_llight/main/matter_accessory_driver.cpp b/idf_component_examples/esp_matter_llight/main/matter_accessory_driver.cpp new file mode 100644 index 00000000000..9fe2b16c68d --- /dev/null +++ b/idf_component_examples/esp_matter_llight/main/matter_accessory_driver.cpp @@ -0,0 +1,101 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include +#include +#include "builtinLED.h" +#include "matter_accessory_driver.h" + +// set your board WS2812b pin here (e.g. 48 is the default pin for the ESP32-S3 devkit) +#define WS2812_PIN 48 + +/* 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_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; +} + +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_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; + + const uint8_t pin = WS2812_PIN; // set your board WS2812b pin here + builtinLED.begin(pin); + builtinLED.setHSV({DEFAULT_HUE, DEFAULT_SATURATION, DEFAULT_BRIGHTNESS}); + builtinLED.write(); + return (app_driver_handle_t) &builtinLED; +} diff --git a/idf_component_examples/esp_matter_llight/main/matter_accessory_driver.h b/idf_component_examples/esp_matter_llight/main/matter_accessory_driver.h new file mode 100644 index 00000000000..b3b6692e350 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/main/matter_accessory_driver.h @@ -0,0 +1,28 @@ +#include + +/** Standard max values (used for remapping attributes) */ +#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_TEMPERATURE_FACTOR 1000000 + +/** Default attribute values used during initialization */ +#define DEFAULT_POWER true +#define DEFAULT_BRIGHTNESS 64 +#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_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(); diff --git a/idf_component_examples/esp_matter_llight/main/matter_light.cpp b/idf_component_examples/esp_matter_llight/main/matter_light.cpp new file mode 100644 index 00000000000..76d5cfe6fa6 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/main/matter_light.cpp @@ -0,0 +1,369 @@ +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. +*/ +#include +#include "matter_accessory_driver.h" + +#include + +#include +#include +#include + +#include +#include + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include +#include "esp_openthread_types.h" + +#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_PORT_CONFIG() \ + { \ + .storage_partition_name = "nvs", .netif_queue_size = 10, .task_queue_size = 10, \ + } +#endif + +uint16_t light_endpoint_id = 0; + +using namespace esp_matter; +using namespace esp_matter::attribute; +using namespace esp_matter::endpoint; +using namespace chip::app::Clusters; + +constexpr auto k_timeout_seconds = 300; + +#if CONFIG_ENABLE_ENCRYPTED_OTA +extern const char decryption_key_start[] asm("_binary_esp_image_encryption_key_pem_start"); +extern const char decryption_key_end[] asm("_binary_esp_image_encryption_key_pem_end"); + +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 + +static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) +{ + switch (event->Type) { + case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: + log_i("Interface IP Address changed"); + 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::kCommissioningSessionStarted: + log_i("Commissioning session started"); + 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::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 + * 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; + } + + 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; + } +} + +static uint32_t button_time_stamp = 0; +static void button_driver_down_cb() +{ + button_time_stamp = millis(); +} + + +static void button_driver_up_cb() +{ + uint32_t time_diff = millis() - button_time_stamp; + // Factory reset is triggered if the button is pressed for more than 3 seconds + if (time_diff > 3000) { + log_i("Factory reset triggered. Light will retored to factory settings."); + esp_matter::factory_reset(); + return; + } + + // Toggle button is pressed - toggle the light + log_i("Toggle button pressed"); + uint16_t endpoint_id = light_endpoint_id; + uint32_t cluster_id = OnOff::Id; + uint32_t attribute_id = OnOff::Attributes::OnOff::Id; + + node_t *node = node::get(); + endpoint_t *endpoint = endpoint::get(node, endpoint_id); + cluster_t *cluster = cluster::get(endpoint, cluster_id); + attribute_t *attribute = attribute::get(cluster, attribute_id); + + esp_matter_attr_val_t val = esp_matter_invalid(NULL); + attribute::get_val(attribute, &val); + val.val.b = !val.val.b; + attribute::update(endpoint_id, cluster_id, attribute_id, &val); +} + +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 */ + uint8_t pin = 0; // set your board button pin here + pinMode(pin, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(pin), button_driver_down_cb, FALLING); // pressed + attachInterrupt(digitalPinToInterrupt(pin), button_driver_up_cb, RISING); // released +} + +// 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; + + 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; +} + +// 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; +} + +void setup() +{ + esp_err_t err = ESP_OK; + + /* Initialize the ESP NVS layer */ + //nvs_flash_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; + + // 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; + + // 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); + + /* 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); + +#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); +#endif + + /* Matter start */ + err = esp_matter::start(app_event_cb); + if (err != ESP_OK) { + log_e("Failed to start Matter, err:%d", err); + abort(); + } + + /* Starting driver with default values */ + matter_light_set_defaults(light_endpoint_id); + +#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 + +#if CONFIG_ENABLE_CHIP_SHELL + esp_matter::console::diagnostics_register_commands(); + esp_matter::console::wifi_register_commands(); +#if CONFIG_OPENTHREAD_CLI + esp_matter::console::otcli_register_commands(); +#endif + esp_matter::console::init(); +#endif +} + +void loop() { + delay(1000); +} From 8c39ce0c8b4751db728a1f15550f4a9d2c8f9300 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 4 Sep 2024 12:15:02 -0300 Subject: [PATCH 03/42] feat(matter): adds sdkconfig and CMake files Adds target sdkconfig files and the CMakeLists.txt in orde to build the application using Arduino+Matter as IDF component --- .../esp_matter_llight/CMakeLists.txt | 28 +++ .../esp_matter_llight/sdkconfig.defaults | 58 ++++++ .../sdkconfig.defaults.c6_thread | 60 ++++++ .../sdkconfig.defaults.esp32c2 | 185 ++++++++++++++++++ .../sdkconfig.defaults.esp32c3 | 21 ++ .../sdkconfig.defaults.esp32c6 | 52 +++++ .../sdkconfig.defaults.esp32h2 | 76 +++++++ .../sdkconfig.defaults.esp32s2 | 40 ++++ .../sdkconfig.defaults.esp32s3 | 53 +++++ 9 files changed, 573 insertions(+) create mode 100644 idf_component_examples/esp_matter_llight/CMakeLists.txt create mode 100644 idf_component_examples/esp_matter_llight/sdkconfig.defaults create mode 100644 idf_component_examples/esp_matter_llight/sdkconfig.defaults.c6_thread create mode 100644 idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c2 create mode 100644 idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c3 create mode 100644 idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c6 create mode 100644 idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32h2 create mode 100644 idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s2 create mode 100644 idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s3 diff --git a/idf_component_examples/esp_matter_llight/CMakeLists.txt b/idf_component_examples/esp_matter_llight/CMakeLists.txt new file mode 100644 index 00000000000..aed85dd3116 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/CMakeLists.txt @@ -0,0 +1,28 @@ +# 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.5) + +set(PROJECT_VER "1.0") +set(PROJECT_VER_NUMBER 1) + +# This should be done before using the IDF_TARGET variable. +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + +project(arduino_managed_component_light) + +# WARNING: This is just an example for using key for decrypting the encrypted OTA image +# Please do not use it as is. +if(CONFIG_ENABLE_ENCRYPTED_OTA) + target_add_binary_data(light.elf "esp_image_encryption_key.pem" TEXT) +endif() + +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(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) + diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults b/idf_component_examples/esp_matter_llight/sdkconfig.defaults new file mode 100644 index 00000000000..7671a912f46 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/sdkconfig.defaults @@ -0,0 +1,58 @@ +# 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_VERBOSE=y +# IDF Log Level +CONFIG_LOG_DEFAULT_LEVEL_WARN=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 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 + +# 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 + diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.c6_thread b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.c6_thread new file mode 100644 index 00000000000..de4607c18cc --- /dev/null +++ b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.c6_thread @@ -0,0 +1,60 @@ +CONFIG_IDF_TARGET="esp32c6" + +# libsodium +CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y + +# NIMBLE +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_EXT_ADV=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=n + +# FreeRTOS should use legacy API +CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y + +# Enable OpenThread +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_SRP_CLIENT=y +CONFIG_OPENTHREAD_DNS_CLIENT=y +CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC=n +CONFIG_OPENTHREAD_LOG_LEVEL_NOTE=y +CONFIG_OPENTHREAD_CLI=n + +# Disable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=n + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" + +# LwIP config for OpenThread +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_LWIP_MULTICAST_PING=y + +# MDNS platform +CONFIG_USE_MINIMAL_MDNS=n +CONFIG_ENABLE_EXTENDED_DISCOVERY=y + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=y + +# Disable STA and AP for ESP32C6 +CONFIG_ENABLE_WIFI_STATION=n +CONFIG_ENABLE_WIFI_AP=n + +# Button +CONFIG_BUTTON_PERIOD_TIME_MS=20 +CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y + +# Disable persist subscriptions +CONFIG_ENABLE_PERSIST_SUBSCRIPTIONS=n + +# MRP configs +CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL_FOR_THREAD=5000 +CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL_FOR_THREAD=5000 +CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST_FOR_THREAD=5000 +CONFIG_MRP_MAX_RETRANS=3 diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c2 b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c2 new file mode 100644 index 00000000000..7f138be8ca0 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c2 @@ -0,0 +1,185 @@ +# Bluetooth +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +## NimBLE Options +CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1 +CONFIG_BT_NIMBLE_MAX_BONDS=2 +CONFIG_BT_NIMBLE_MAX_CCCDS=2 +CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=3072 +CONFIG_BT_NIMBLE_ROLE_CENTRAL=n +CONFIG_BT_NIMBLE_ROLE_OBSERVER=n +CONFIG_BT_NIMBLE_MSYS_1_BLOCK_COUNT=10 +CONFIG_BT_NIMBLE_MSYS_1_BLOCK_SIZE=100 +CONFIG_BT_NIMBLE_MSYS_2_BLOCK_COUNT=4 +CONFIG_BT_NIMBLE_ACL_BUF_COUNT=5 +CONFIG_BT_NIMBLE_HCI_EVT_HI_BUF_COUNT=5 +CONFIG_BT_NIMBLE_HCI_EVT_LO_BUF_COUNT=3 +CONFIG_BT_NIMBLE_GATT_MAX_PROCS=1 +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n +CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=n +CONFIG_BT_NIMBLE_WHITELIST_SIZE=1 +## Controller Options +CONFIG_BT_LE_CONTROLLER_TASK_STACK_SIZE=3072 +CONFIG_BT_LE_LL_RESOLV_LIST_SIZE=1 +CONFIG_BT_LE_LL_DUP_SCAN_LIST_COUNT=1 + +# Release BT IRAM memory +CONFIG_BT_RELEASE_IRAM=y + +# SPI Configuration +CONFIG_SPI_MASTER_ISR_IN_IRAM=n +CONFIG_SPI_SLAVE_ISR_IN_IRAM=n + +# Ethernet +CONFIG_ETH_USE_SPI_ETHERNET=n + +# Event Loop Library +CONFIG_ESP_EVENT_POST_FROM_ISR=n + +# Chip revision +CONFIG_ESP32C2_REV2_DEVELOPMENT=y + +# Main XTAL Config +CONFIG_XTAL_FREQ_26=y +CONFIG_XTAL_FREQ_40=n + +# ESP Ringbuf +CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y +CONFIG_RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH=y + +# ESP System Settings +CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=16 +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048 +CONFIG_ESP_MAIN_TASK_STACK_SIZE=3072 + +## Memory protection +CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT=n + +# High resolution timer (esp_timer) +CONFIG_ESP_TIMER_TASK_STACK_SIZE=2048 + +# Wi-Fi +CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=n +CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=3 +CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=6 +CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=6 +CONFIG_ESP32_WIFI_IRAM_OPT=n +CONFIG_ESP32_WIFI_RX_IRAM_OPT=n +CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=n +CONFIG_ESP32_WIFI_ENABLE_WPA3_OWE_STA=n +CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=n +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n + +# FreeRTOS +## Kernel +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y +## Port +CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=n +CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y +CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y + +# Hardware Abstraction Layer (HAL) and Low Level (LL) +CONFIG_HAL_ASSERTION_DISABLE=y + +# LWIP +CONFIG_LWIP_MAX_SOCKETS=5 +CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=16 +CONFIG_LWIP_DHCPS=n +CONFIG_LWIP_IPV6_AUTOCONFIG=y +CONFIG_LWIP_MAX_ACTIVE_TCP=5 +CONFIG_LWIP_MAX_LISTENING_TCP=5 +CONFIG_LWIP_TCP_HIGH_SPEED_RETRANSMISSION=n +CONFIG_LWIP_TCP_SYNMAXRTX=12 +CONFIG_LWIP_TCP_MSL=40000 +CONFIG_LWIP_TCP_FIN_WAIT_TIMEOUT=16000 +CONFIG_LWIP_TCP_SND_BUF_DEFAULT=4096 +CONFIG_LWIP_TCP_WND_DEFAULT=2440 +CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS=y +CONFIG_LWIP_TCP_RTO_TIME=1500 +CONFIG_LWIP_MAX_UDP_PCBS=8 +CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=2560 +CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y +CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y + +# mbedTLS +CONFIG_MBEDTLS_DYNAMIC_BUFFER=y +CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y +CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT=y +CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH=y +CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=n +CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y +CONFIG_MBEDTLS_TLS_CLIENT_ONLY=y +CONFIG_MBEDTLS_SSL_PROTO_SSL3=n +CONFIG_MBEDTLS_SSL_PROTO_TLS1=n +CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=n + +# ESP-MQTT Configurations +CONFIG_MQTT_PROTOCOL_311=n + +# Protocomm +CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_1=n +CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2=n + +# SPI Flash driver +CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=n +CONFIG_SPI_FLASH_ROM_IMPL=y + +# Websocket +CONFIG_WS_TRANSPORT=n + +# Virtual file system +CONFIG_VFS_SUPPORT_DIR=n +CONFIG_VFS_SUPPORT_SELECT=n +CONFIG_VFS_SUPPORT_TERMIOS=n + +# Wear Levelling +CONFIG_WL_SECTOR_SIZE_512=y + +# CHIP Core +## General Options +CONFIG_MAX_EXCHANGE_CONTEXTS=6 +CONFIG_MAX_BINDINGS=6 +CONFIG_MAX_PEER_NODES=12 +CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS=6 +CONFIG_ENABLE_CHIP_SHELL=n +CONFIG_DISABLE_IPV4=y +CONFIG_BUILD_CHIP_TESTS=n +## Networking Options +CONFIG_NUM_TCP_ENDPOINTS=1 +CONFIG_NUM_UDP_ENDPOINTS=6 +## System Options +CONFIG_NUM_TIMERS=24 +CONFIG_ENABLE_OTA_REQUESTOR=y + +# CHIP Device Layer +## General Options +CONFIG_CHIP_TASK_STACK_SIZE=6144 +CONFIG_MAX_EVENT_QUEUE_SIZE=20 +## Event Logging Options +CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE=256 +CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE=256 +CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE=256 + +# ESP Matter +CONFIG_ESP_MATTER_MAX_DEVICE_TYPE_COUNT=4 +CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=4 + +# CMake Utilities +CONFIG_CU_RELINKER_ENABLE=y +CONFIG_CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES=y +CONFIG_CU_RELINKER_CUSTOMIZED_CONFIGURATION_FILES_PATH="../common/relinker/esp32c2" + +# ESP32-C2-DevKitM-1 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 +# LEDs +CONFIG_BSP_LEDS_NUM=1 +CONFIG_BSP_LED_TYPE_RGB_CLASSIC=y +CONFIG_BSP_LED_RGB_RED_GPIO=0 +CONFIG_BSP_LED_RGB_GREEN_GPIO=1 +CONFIG_BSP_LED_RGB_BLUE_GPIO=8 + diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c3 b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c3 new file mode 100644 index 00000000000..1c873a0cf65 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c3 @@ -0,0 +1,21 @@ +CONFIG_IDF_TARGET="esp32c3" + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=y + +# Disable AP +CONFIG_ENABLE_WIFI_STATION=y +CONFIG_ENABLE_WIFI_AP=n + +# ESP32-C3-DevKitC-02 Settings +# Buttons +CONFIG_BSP_BUTTONS_NUM=1 +CONFIG_BSP_BUTTON_1_TYPE_GPIO=y +CONFIG_BSP_BUTTON_1_GPIO=9 +CONFIG_BSP_BUTTON_1_LEVEL=0 +# LEDs +CONFIG_BSP_LEDS_NUM=1 +CONFIG_BSP_LED_TYPE_RGB=y +CONFIG_BSP_LED_RGB_GPIO=8 +CONFIG_BSP_LED_RGB_BACKEND_RMT=y + diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c6 b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c6 new file mode 100644 index 00000000000..abc81be8261 --- /dev/null +++ b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c6 @@ -0,0 +1,52 @@ +CONFIG_IDF_TARGET="esp32c6" + +# libsodium +CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y + +# NIMBLE +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_EXT_ADV=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=y + +# FreeRTOS should use legacy API +CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y + +# Disable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" + +# Use minimal mDNS +CONFIG_USE_MINIMAL_MDNS=y +CONFIG_ENABLE_EXTENDED_DISCOVERY=y + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=y + +# Disable AP +CONFIG_ENABLE_WIFI_STATION=y +CONFIG_ENABLE_WIFI_AP=n + +# Button +CONFIG_BUTTON_PERIOD_TIME_MS=20 +CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y + +# ESP32-C6-DevKitM-1 Settings +# Buttons +CONFIG_BSP_BUTTONS_NUM=1 +CONFIG_BSP_BUTTON_1_TYPE_GPIO=y +CONFIG_BSP_BUTTON_1_GPIO=9 +CONFIG_BSP_BUTTON_1_LEVEL=0 +# LEDs +CONFIG_BSP_LEDS_NUM=1 +CONFIG_BSP_LED_TYPE_RGB=y +CONFIG_BSP_LED_RGB_GPIO=8 +CONFIG_BSP_LED_RGB_BACKEND_RMT=y + diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32h2 b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32h2 new file mode 100644 index 00000000000..35b7c03fa8f --- /dev/null +++ b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32h2 @@ -0,0 +1,76 @@ +CONFIG_IDF_TARGET="esp32h2" + +# libsodium +CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y + +# NIMBLE +CONFIG_BT_ENABLED=y +CONFIG_BT_NIMBLE_ENABLED=y +CONFIG_BT_NIMBLE_EXT_ADV=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=n + +# FreeRTOS should use legacy API +CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y + +# Enable OpenThread +CONFIG_OPENTHREAD_ENABLED=y +CONFIG_OPENTHREAD_SRP_CLIENT=y +CONFIG_OPENTHREAD_DNS_CLIENT=y +CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC=n +CONFIG_OPENTHREAD_LOG_LEVEL_NOTE=y +CONFIG_OPENTHREAD_CLI=n + + +# Disable lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=n + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" + +# LwIP config for OpenThread +CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 +CONFIG_LWIP_MULTICAST_PING=y + +# MDNS platform +CONFIG_USE_MINIMAL_MDNS=n +CONFIG_ENABLE_EXTENDED_DISCOVERY=y + +# Enable OTA Requestor +CONFIG_ENABLE_OTA_REQUESTOR=y + +# Disable STA and AP for ESP32H2 +CONFIG_ENABLE_WIFI_STATION=n +CONFIG_ENABLE_WIFI_AP=n + +# Button +CONFIG_BUTTON_PERIOD_TIME_MS=20 +CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y + +# Enable DS Peripheral +CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=y + +# ESP32-H2-DevKitM-1 Settings +# Buttons +CONFIG_BSP_BUTTONS_NUM=1 +CONFIG_BSP_BUTTON_1_TYPE_GPIO=y +CONFIG_BSP_BUTTON_1_GPIO=9 +CONFIG_BSP_BUTTON_1_LEVEL=0 +# LEDs +CONFIG_BSP_LEDS_NUM=1 +CONFIG_BSP_LED_TYPE_RGB=y +CONFIG_BSP_LED_RGB_GPIO=8 +CONFIG_BSP_LED_RGB_BACKEND_RMT=y + +# Disable persist subscriptions +CONFIG_ENABLE_PERSIST_SUBSCRIPTIONS=n + +# MRP configs +CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL_FOR_THREAD=5000 +CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL_FOR_THREAD=5000 +CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST_FOR_THREAD=5000 +CONFIG_MRP_MAX_RETRANS=3 diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s2 b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s2 new file mode 100644 index 00000000000..cfab472663f --- /dev/null +++ b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s2 @@ -0,0 +1,40 @@ +# 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 lwip ipv6 autoconfig +CONFIG_LWIP_IPV6_AUTOCONFIG=y + +# Use a custom partition table +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y + +#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 BLE +CONFIG_ENABLE_CHIPOBLE=n + +# ESP32-S2-DevKitM-1 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 +# LEDs +CONFIG_BSP_LEDS_NUM=1 +CONFIG_BSP_LED_TYPE_RGB=y +CONFIG_BSP_LED_RGB_GPIO=18 +CONFIG_BSP_LED_RGB_BACKEND_RMT=y diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s3 b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s3 new file mode 100644 index 00000000000..111eb7ebd9f --- /dev/null +++ b/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s3 @@ -0,0 +1,53 @@ +#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 + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y + +#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 + +# 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 + +# ESP32-S3-DevKitC-1 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 +# 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 From 4f0f2d0b8f9fcd1d1679be020b42a5f37af1e6bf Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 4 Sep 2024 12:28:51 -0300 Subject: [PATCH 04/42] fix(matter): wrong folder name --- .../{esp_matter_llight => esp_matter_light}/CMakeLists.txt | 0 .../{esp_matter_llight => esp_matter_light}/main/CMakeLists.txt | 0 .../{esp_matter_llight => esp_matter_light}/main/builtinLED.cpp | 0 .../{esp_matter_llight => esp_matter_light}/main/builtinLED.h | 0 .../main/idf_component.yml | 0 .../main/matter_accessory_driver.cpp | 0 .../main/matter_accessory_driver.h | 0 .../{esp_matter_llight => esp_matter_light}/main/matter_light.cpp | 0 .../{esp_matter_llight => esp_matter_light}/partitions.csv | 0 .../{esp_matter_llight => esp_matter_light}/sdkconfig.defaults | 0 .../sdkconfig.defaults.c6_thread | 0 .../sdkconfig.defaults.esp32c2 | 0 .../sdkconfig.defaults.esp32c3 | 0 .../sdkconfig.defaults.esp32c6 | 0 .../sdkconfig.defaults.esp32h2 | 0 .../sdkconfig.defaults.esp32s2 | 0 .../sdkconfig.defaults.esp32s3 | 0 17 files changed, 0 insertions(+), 0 deletions(-) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/CMakeLists.txt (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/main/CMakeLists.txt (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/main/builtinLED.cpp (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/main/builtinLED.h (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/main/idf_component.yml (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/main/matter_accessory_driver.cpp (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/main/matter_accessory_driver.h (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/main/matter_light.cpp (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/partitions.csv (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/sdkconfig.defaults (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/sdkconfig.defaults.c6_thread (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/sdkconfig.defaults.esp32c2 (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/sdkconfig.defaults.esp32c3 (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/sdkconfig.defaults.esp32c6 (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/sdkconfig.defaults.esp32h2 (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/sdkconfig.defaults.esp32s2 (100%) rename idf_component_examples/{esp_matter_llight => esp_matter_light}/sdkconfig.defaults.esp32s3 (100%) diff --git a/idf_component_examples/esp_matter_llight/CMakeLists.txt b/idf_component_examples/esp_matter_light/CMakeLists.txt similarity index 100% rename from idf_component_examples/esp_matter_llight/CMakeLists.txt rename to idf_component_examples/esp_matter_light/CMakeLists.txt diff --git a/idf_component_examples/esp_matter_llight/main/CMakeLists.txt b/idf_component_examples/esp_matter_light/main/CMakeLists.txt similarity index 100% rename from idf_component_examples/esp_matter_llight/main/CMakeLists.txt rename to idf_component_examples/esp_matter_light/main/CMakeLists.txt diff --git a/idf_component_examples/esp_matter_llight/main/builtinLED.cpp b/idf_component_examples/esp_matter_light/main/builtinLED.cpp similarity index 100% rename from idf_component_examples/esp_matter_llight/main/builtinLED.cpp rename to idf_component_examples/esp_matter_light/main/builtinLED.cpp diff --git a/idf_component_examples/esp_matter_llight/main/builtinLED.h b/idf_component_examples/esp_matter_light/main/builtinLED.h similarity index 100% rename from idf_component_examples/esp_matter_llight/main/builtinLED.h rename to idf_component_examples/esp_matter_light/main/builtinLED.h diff --git a/idf_component_examples/esp_matter_llight/main/idf_component.yml b/idf_component_examples/esp_matter_light/main/idf_component.yml similarity index 100% rename from idf_component_examples/esp_matter_llight/main/idf_component.yml rename to idf_component_examples/esp_matter_light/main/idf_component.yml diff --git a/idf_component_examples/esp_matter_llight/main/matter_accessory_driver.cpp b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp similarity index 100% rename from idf_component_examples/esp_matter_llight/main/matter_accessory_driver.cpp rename to idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp diff --git a/idf_component_examples/esp_matter_llight/main/matter_accessory_driver.h b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.h similarity index 100% rename from idf_component_examples/esp_matter_llight/main/matter_accessory_driver.h rename to idf_component_examples/esp_matter_light/main/matter_accessory_driver.h diff --git a/idf_component_examples/esp_matter_llight/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp similarity index 100% rename from idf_component_examples/esp_matter_llight/main/matter_light.cpp rename to idf_component_examples/esp_matter_light/main/matter_light.cpp diff --git a/idf_component_examples/esp_matter_llight/partitions.csv b/idf_component_examples/esp_matter_light/partitions.csv similarity index 100% rename from idf_component_examples/esp_matter_llight/partitions.csv rename to idf_component_examples/esp_matter_light/partitions.csv diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults b/idf_component_examples/esp_matter_light/sdkconfig.defaults similarity index 100% rename from idf_component_examples/esp_matter_llight/sdkconfig.defaults rename to idf_component_examples/esp_matter_light/sdkconfig.defaults diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.c6_thread b/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread similarity index 100% rename from idf_component_examples/esp_matter_llight/sdkconfig.defaults.c6_thread rename to idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c2 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c2 similarity index 100% rename from idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c2 rename to idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c2 diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 similarity index 100% rename from idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c3 rename to idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c6 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 similarity index 100% rename from idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32c6 rename to idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32h2 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32h2 similarity index 100% rename from idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32h2 rename to idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32h2 diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s2 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s2 similarity index 100% rename from idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s2 rename to idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s2 diff --git a/idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 similarity index 100% rename from idf_component_examples/esp_matter_llight/sdkconfig.defaults.esp32s3 rename to idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 From 293f066349cbb50d2669a2d773ec0f3e91085e31 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 4 Sep 2024 12:31:29 -0300 Subject: [PATCH 05/42] feat(matter): include example into registry --- idf_component.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/idf_component.yml b/idf_component.yml index 18742001118..49926ec0021 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -97,3 +97,4 @@ dependencies: examples: - path: ./idf_component_examples/hello_world - path: ./idf_component_examples/hw_cdc_hello_world + - path: ./idf_component_examples/esp_matter_light From 2951f6a978e2ab1bf32defcaf555c65b8df2c913 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Thu, 12 Sep 2024 19:05:53 -0300 Subject: [PATCH 06/42] fix(matter): error with type in wrong place A declaration was incorrect due to a typo error. Sintax was corrected by deleting `BuiltInLED`. --- idf_component_examples/esp_matter_light/main/builtinLED.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/main/builtinLED.h b/idf_component_examples/esp_matter_light/main/builtinLED.h index 160cdc984a9..27345a80fdd 100644 --- a/idf_component_examples/esp_matter_light/main/builtinLED.h +++ b/idf_component_examples/esp_matter_light/main/builtinLED.h @@ -46,7 +46,7 @@ typedef struct { class BuiltInLED { private: uint8_t pin_number; - bool state;BuiltInLED + bool state; led_indicator_color_hsv_t hsv_color; public: From 37ed1d582ab0dde7f4d451ebd27a5c305533e2f5 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Sat, 14 Sep 2024 01:34:47 -0300 Subject: [PATCH 07/42] feat(matter): add readme documentation --- .../esp_matter_light/README.md | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 idf_component_examples/esp_matter_light/README.md diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md new file mode 100644 index 00000000000..5c4c6d9a0cb --- /dev/null +++ b/idf_component_examples/esp_matter_light/README.md @@ -0,0 +1,87 @@ +| Supported Targets | ESP32-S3 | 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 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. + +The code is based on the Arduino API and uses Arduino as an IDF Component. + +## How to use it + +Once the device runs for the first time, it must be commissioned to the Matter Fabric of the available Matter Environment. +Possible Matter Environments are: +- Amazon Alexa +- Google Home Assistant +- Apple Home +- Open Source Home Assistant + +There is no QR Code to be used when the Smartphone APP wants to add the Matter Device. +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.` file. + +## LED Status and Factory Mode + +The WS2812b built-in LED will turn purple as soon as the device is flashed and runs for the first time. +The purple color indicates that the Matter Accessory has not been commissioned yet. +After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no WiFi connection. + +Once it connects to the WiFi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. + +The Matter and WiFi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and WiFi Network again once it is reset. + +The Matter Smartphone APP will control the light state (ON/OFF), temperature (Warm/Cold White), and brightness. + +## On Board Light toggle button + +The built-in BOOT button will toggle On/Off and replicate the new state to the Matter Environment, making it visible in the Matter Smartphone APP as well. + +## Returning to the Factory State + +Holding the BOOT button pressed for more than 10 seconds and then releasing it will erase all Matter and WiFi configuration, forcing it to reset to factory state. After that, the device needs to be commissioned again. Previous setups done in the Smartphone APP won't work again; therefore, the virtual device shall be removed from the APP. + +## 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 + +The project will download all necessary components, inluding the Arduino Core. +Run `idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults..idf" -p flash monitor` + +Example for ESP32-S3/Linux|MacOS: +`idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32s3" -p /dev/ttyACM0 flash monitor` +Example for ESP32-C3/Windows: +`idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32c3" -p com3 flash monitor` + +It may be necessary to delete some folders and files before running `idf.py` +Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock` +Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock` + +There is a configuration file for these SoC: esp32s3, 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` +`idf.py menuconfig` and change the Menu Option `Light Matter Accessory` + +## 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. +In order to build the application that will use Thread Networking instead of WiFi, please execute: + +Example for ESP32-S3/Linux|MacOS: +`idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p /dev/ttyACM0 flash monitor` +Example for ESP32-C3/Windows: +`idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p com3 flash monitor` + +It may be necessary to delete some folders and files before running `idf.py` +Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock` +Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock` From d4183637fb4bfb7eade43a6f415e64d8fd0c35a7 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Sat, 14 Sep 2024 01:37:06 -0300 Subject: [PATCH 08/42] feat(matter): remove soc with no wifi or no ble --- .../esp_matter_light/sdkconfig.defaults | 58 ------ .../sdkconfig.defaults.esp32c2 | 185 ------------------ .../sdkconfig.defaults.esp32h2 | 76 ------- .../sdkconfig.defaults.esp32s2 | 40 ---- 4 files changed, 359 deletions(-) delete mode 100644 idf_component_examples/esp_matter_light/sdkconfig.defaults delete mode 100644 idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c2 delete mode 100644 idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32h2 delete mode 100644 idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s2 diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults b/idf_component_examples/esp_matter_light/sdkconfig.defaults deleted file mode 100644 index 7671a912f46..00000000000 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults +++ /dev/null @@ -1,58 +0,0 @@ -# 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_VERBOSE=y -# IDF Log Level -CONFIG_LOG_DEFAULT_LEVEL_WARN=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 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 - -# 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 - diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c2 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c2 deleted file mode 100644 index 7f138be8ca0..00000000000 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c2 +++ /dev/null @@ -1,185 +0,0 @@ -# Bluetooth -CONFIG_BT_ENABLED=y -CONFIG_BT_NIMBLE_ENABLED=y -## NimBLE Options -CONFIG_BT_NIMBLE_MAX_CONNECTIONS=1 -CONFIG_BT_NIMBLE_MAX_BONDS=2 -CONFIG_BT_NIMBLE_MAX_CCCDS=2 -CONFIG_BT_NIMBLE_HOST_TASK_STACK_SIZE=3072 -CONFIG_BT_NIMBLE_ROLE_CENTRAL=n -CONFIG_BT_NIMBLE_ROLE_OBSERVER=n -CONFIG_BT_NIMBLE_MSYS_1_BLOCK_COUNT=10 -CONFIG_BT_NIMBLE_MSYS_1_BLOCK_SIZE=100 -CONFIG_BT_NIMBLE_MSYS_2_BLOCK_COUNT=4 -CONFIG_BT_NIMBLE_ACL_BUF_COUNT=5 -CONFIG_BT_NIMBLE_HCI_EVT_HI_BUF_COUNT=5 -CONFIG_BT_NIMBLE_HCI_EVT_LO_BUF_COUNT=3 -CONFIG_BT_NIMBLE_GATT_MAX_PROCS=1 -CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n -CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=n -CONFIG_BT_NIMBLE_WHITELIST_SIZE=1 -## Controller Options -CONFIG_BT_LE_CONTROLLER_TASK_STACK_SIZE=3072 -CONFIG_BT_LE_LL_RESOLV_LIST_SIZE=1 -CONFIG_BT_LE_LL_DUP_SCAN_LIST_COUNT=1 - -# Release BT IRAM memory -CONFIG_BT_RELEASE_IRAM=y - -# SPI Configuration -CONFIG_SPI_MASTER_ISR_IN_IRAM=n -CONFIG_SPI_SLAVE_ISR_IN_IRAM=n - -# Ethernet -CONFIG_ETH_USE_SPI_ETHERNET=n - -# Event Loop Library -CONFIG_ESP_EVENT_POST_FROM_ISR=n - -# Chip revision -CONFIG_ESP32C2_REV2_DEVELOPMENT=y - -# Main XTAL Config -CONFIG_XTAL_FREQ_26=y -CONFIG_XTAL_FREQ_40=n - -# ESP Ringbuf -CONFIG_RINGBUF_PLACE_FUNCTIONS_INTO_FLASH=y -CONFIG_RINGBUF_PLACE_ISR_FUNCTIONS_INTO_FLASH=y - -# ESP System Settings -CONFIG_ESP_SYSTEM_EVENT_QUEUE_SIZE=16 -CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048 -CONFIG_ESP_MAIN_TASK_STACK_SIZE=3072 - -## Memory protection -CONFIG_ESP_SYSTEM_PMP_IDRAM_SPLIT=n - -# High resolution timer (esp_timer) -CONFIG_ESP_TIMER_TASK_STACK_SIZE=2048 - -# Wi-Fi -CONFIG_ESP32_WIFI_SW_COEXIST_ENABLE=n -CONFIG_ESP32_WIFI_STATIC_RX_BUFFER_NUM=3 -CONFIG_ESP32_WIFI_DYNAMIC_RX_BUFFER_NUM=6 -CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM=6 -CONFIG_ESP32_WIFI_IRAM_OPT=n -CONFIG_ESP32_WIFI_RX_IRAM_OPT=n -CONFIG_ESP32_WIFI_ENABLE_WPA3_SAE=n -CONFIG_ESP32_WIFI_ENABLE_WPA3_OWE_STA=n -CONFIG_ESP_WIFI_STA_DISCONNECTED_PM_ENABLE=n -CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n - -# FreeRTOS -## Kernel -CONFIG_FREERTOS_HZ=1000 -CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS=y -## Port -CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER=n -CONFIG_FREERTOS_PLACE_FUNCTIONS_INTO_FLASH=y -CONFIG_FREERTOS_PLACE_SNAPSHOT_FUNS_INTO_FLASH=y - -# Hardware Abstraction Layer (HAL) and Low Level (LL) -CONFIG_HAL_ASSERTION_DISABLE=y - -# LWIP -CONFIG_LWIP_MAX_SOCKETS=5 -CONFIG_LWIP_TCPIP_RECVMBOX_SIZE=16 -CONFIG_LWIP_DHCPS=n -CONFIG_LWIP_IPV6_AUTOCONFIG=y -CONFIG_LWIP_MAX_ACTIVE_TCP=5 -CONFIG_LWIP_MAX_LISTENING_TCP=5 -CONFIG_LWIP_TCP_HIGH_SPEED_RETRANSMISSION=n -CONFIG_LWIP_TCP_SYNMAXRTX=12 -CONFIG_LWIP_TCP_MSL=40000 -CONFIG_LWIP_TCP_FIN_WAIT_TIMEOUT=16000 -CONFIG_LWIP_TCP_SND_BUF_DEFAULT=4096 -CONFIG_LWIP_TCP_WND_DEFAULT=2440 -CONFIG_LWIP_TCP_OVERSIZE_QUARTER_MSS=y -CONFIG_LWIP_TCP_RTO_TIME=1500 -CONFIG_LWIP_MAX_UDP_PCBS=8 -CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=2560 -CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y -CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y - -# mbedTLS -CONFIG_MBEDTLS_DYNAMIC_BUFFER=y -CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y -CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT=y -CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH=y -CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE=n -CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_CMN=y -CONFIG_MBEDTLS_TLS_CLIENT_ONLY=y -CONFIG_MBEDTLS_SSL_PROTO_SSL3=n -CONFIG_MBEDTLS_SSL_PROTO_TLS1=n -CONFIG_MBEDTLS_SSL_PROTO_TLS1_1=n - -# ESP-MQTT Configurations -CONFIG_MQTT_PROTOCOL_311=n - -# Protocomm -CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_1=n -CONFIG_ESP_PROTOCOMM_SUPPORT_SECURITY_VERSION_2=n - -# SPI Flash driver -CONFIG_SPI_FLASH_ROM_DRIVER_PATCH=n -CONFIG_SPI_FLASH_ROM_IMPL=y - -# Websocket -CONFIG_WS_TRANSPORT=n - -# Virtual file system -CONFIG_VFS_SUPPORT_DIR=n -CONFIG_VFS_SUPPORT_SELECT=n -CONFIG_VFS_SUPPORT_TERMIOS=n - -# Wear Levelling -CONFIG_WL_SECTOR_SIZE_512=y - -# CHIP Core -## General Options -CONFIG_MAX_EXCHANGE_CONTEXTS=6 -CONFIG_MAX_BINDINGS=6 -CONFIG_MAX_PEER_NODES=12 -CONFIG_MAX_UNSOLICITED_MESSAGE_HANDLERS=6 -CONFIG_ENABLE_CHIP_SHELL=n -CONFIG_DISABLE_IPV4=y -CONFIG_BUILD_CHIP_TESTS=n -## Networking Options -CONFIG_NUM_TCP_ENDPOINTS=1 -CONFIG_NUM_UDP_ENDPOINTS=6 -## System Options -CONFIG_NUM_TIMERS=24 -CONFIG_ENABLE_OTA_REQUESTOR=y - -# CHIP Device Layer -## General Options -CONFIG_CHIP_TASK_STACK_SIZE=6144 -CONFIG_MAX_EVENT_QUEUE_SIZE=20 -## Event Logging Options -CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE=256 -CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE=256 -CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE=256 - -# ESP Matter -CONFIG_ESP_MATTER_MAX_DEVICE_TYPE_COUNT=4 -CONFIG_ESP_MATTER_MAX_DYNAMIC_ENDPOINT_COUNT=4 - -# CMake Utilities -CONFIG_CU_RELINKER_ENABLE=y -CONFIG_CU_RELINKER_ENABLE_CUSTOMIZED_CONFIGURATION_FILES=y -CONFIG_CU_RELINKER_CUSTOMIZED_CONFIGURATION_FILES_PATH="../common/relinker/esp32c2" - -# ESP32-C2-DevKitM-1 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 -# LEDs -CONFIG_BSP_LEDS_NUM=1 -CONFIG_BSP_LED_TYPE_RGB_CLASSIC=y -CONFIG_BSP_LED_RGB_RED_GPIO=0 -CONFIG_BSP_LED_RGB_GREEN_GPIO=1 -CONFIG_BSP_LED_RGB_BLUE_GPIO=8 - diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32h2 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32h2 deleted file mode 100644 index 35b7c03fa8f..00000000000 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32h2 +++ /dev/null @@ -1,76 +0,0 @@ -CONFIG_IDF_TARGET="esp32h2" - -# libsodium -CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y - -# NIMBLE -CONFIG_BT_ENABLED=y -CONFIG_BT_NIMBLE_ENABLED=y -CONFIG_BT_NIMBLE_EXT_ADV=n -CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 -CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=n - -# FreeRTOS should use legacy API -CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y - -# Enable OpenThread -CONFIG_OPENTHREAD_ENABLED=y -CONFIG_OPENTHREAD_SRP_CLIENT=y -CONFIG_OPENTHREAD_DNS_CLIENT=y -CONFIG_OPENTHREAD_LOG_LEVEL_DYNAMIC=n -CONFIG_OPENTHREAD_LOG_LEVEL_NOTE=y -CONFIG_OPENTHREAD_CLI=n - - -# Disable lwip ipv6 autoconfig -CONFIG_LWIP_IPV6_AUTOCONFIG=n - -# Use a custom partition table -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" - -# LwIP config for OpenThread -CONFIG_LWIP_IPV6_NUM_ADDRESSES=8 -CONFIG_LWIP_MULTICAST_PING=y - -# MDNS platform -CONFIG_USE_MINIMAL_MDNS=n -CONFIG_ENABLE_EXTENDED_DISCOVERY=y - -# Enable OTA Requestor -CONFIG_ENABLE_OTA_REQUESTOR=y - -# Disable STA and AP for ESP32H2 -CONFIG_ENABLE_WIFI_STATION=n -CONFIG_ENABLE_WIFI_AP=n - -# Button -CONFIG_BUTTON_PERIOD_TIME_MS=20 -CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 - -# Enable chip shell -CONFIG_ENABLE_CHIP_SHELL=y - -# Enable DS Peripheral -CONFIG_ESP_SECURE_CERT_DS_PERIPHERAL=y - -# ESP32-H2-DevKitM-1 Settings -# Buttons -CONFIG_BSP_BUTTONS_NUM=1 -CONFIG_BSP_BUTTON_1_TYPE_GPIO=y -CONFIG_BSP_BUTTON_1_GPIO=9 -CONFIG_BSP_BUTTON_1_LEVEL=0 -# LEDs -CONFIG_BSP_LEDS_NUM=1 -CONFIG_BSP_LED_TYPE_RGB=y -CONFIG_BSP_LED_RGB_GPIO=8 -CONFIG_BSP_LED_RGB_BACKEND_RMT=y - -# Disable persist subscriptions -CONFIG_ENABLE_PERSIST_SUBSCRIPTIONS=n - -# MRP configs -CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL_FOR_THREAD=5000 -CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL_FOR_THREAD=5000 -CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST_FOR_THREAD=5000 -CONFIG_MRP_MAX_RETRANS=3 diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s2 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s2 deleted file mode 100644 index cfab472663f..00000000000 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s2 +++ /dev/null @@ -1,40 +0,0 @@ -# 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 lwip ipv6 autoconfig -CONFIG_LWIP_IPV6_AUTOCONFIG=y - -# Use a custom partition table -CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" - -# Enable chip shell -CONFIG_ENABLE_CHIP_SHELL=y - -#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 BLE -CONFIG_ENABLE_CHIPOBLE=n - -# ESP32-S2-DevKitM-1 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 -# LEDs -CONFIG_BSP_LEDS_NUM=1 -CONFIG_BSP_LED_TYPE_RGB=y -CONFIG_BSP_LED_RGB_GPIO=18 -CONFIG_BSP_LED_RGB_BACKEND_RMT=y From 04391c96bcf7644fc7e32898f92d92c73c9ab158 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Sat, 14 Sep 2024 01:38:23 -0300 Subject: [PATCH 09/42] feat(matter): adjust all sdkconfig files --- .../sdkconfig.defaults.c6_thread | 32 +++++-- .../sdkconfig.defaults.esp32c3 | 85 ++++++++++++----- .../sdkconfig.defaults.esp32c6 | 93 ++++++++++++------- .../sdkconfig.defaults.esp32s3 | 47 ++++++---- 4 files changed, 179 insertions(+), 78 deletions(-) diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread b/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread index de4607c18cc..389c72c4bc1 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread @@ -1,5 +1,25 @@ 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 + # libsodium CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y @@ -37,18 +57,14 @@ CONFIG_USE_MINIMAL_MDNS=n CONFIG_ENABLE_EXTENDED_DISCOVERY=y # Enable OTA Requestor -CONFIG_ENABLE_OTA_REQUESTOR=y +CONFIG_ENABLE_OTA_REQUESTOR=n # Disable STA and AP for ESP32C6 CONFIG_ENABLE_WIFI_STATION=n CONFIG_ENABLE_WIFI_AP=n -# Button -CONFIG_BUTTON_PERIOD_TIME_MS=20 -CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 - # Enable chip shell -CONFIG_ENABLE_CHIP_SHELL=y +CONFIG_ENABLE_CHIP_SHELL=n # Disable persist subscriptions CONFIG_ENABLE_PERSIST_SUBSCRIPTIONS=n @@ -58,3 +74,7 @@ CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL_FOR_THREAD=5000 CONFIG_MRP_LOCAL_IDLE_RETRY_INTERVAL_FOR_THREAD=5000 CONFIG_MRP_RETRY_INTERVAL_SENDER_BOOST_FOR_THREAD=5000 CONFIG_MRP_MAX_RETRANS=3 + +# Enable HKDF in mbedtls +CONFIG_MBEDTLS_HKDF_C=y + diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 index 1c873a0cf65..f534f3b7d1a 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 @@ -1,21 +1,64 @@ -CONFIG_IDF_TARGET="esp32c3" - -# Enable OTA Requestor -CONFIG_ENABLE_OTA_REQUESTOR=y - -# Disable AP -CONFIG_ENABLE_WIFI_STATION=y -CONFIG_ENABLE_WIFI_AP=n - -# ESP32-C3-DevKitC-02 Settings -# Buttons -CONFIG_BSP_BUTTONS_NUM=1 -CONFIG_BSP_BUTTON_1_TYPE_GPIO=y -CONFIG_BSP_BUTTON_1_GPIO=9 -CONFIG_BSP_BUTTON_1_LEVEL=0 -# LEDs -CONFIG_BSP_LEDS_NUM=1 -CONFIG_BSP_LED_TYPE_RGB=y -CONFIG_BSP_LED_RGB_GPIO=8 -CONFIG_BSP_LED_RGB_BACKEND_RMT=y - +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 diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 index abc81be8261..301ee1a4e57 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 @@ -1,52 +1,79 @@ CONFIG_IDF_TARGET="esp32c6" -# libsodium -CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y +# Arduino Settings +CONFIG_FREERTOS_HZ=1000 +CONFIG_AUTOSTART_ARDUINO=y -# NIMBLE +# 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 -CONFIG_BT_NIMBLE_EXT_ADV=n -CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 -CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=y -# FreeRTOS should use legacy API -CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y +#disable BT connection reattempt +CONFIG_BT_NIMBLE_ENABLE_CONN_REATTEMPT=n -# Disable lwip ipv6 autoconfig +#enable lwip ipv6 autoconfig CONFIG_LWIP_IPV6_AUTOCONFIG=y # Use a custom partition table CONFIG_PARTITION_TABLE_CUSTOM=y -CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_OFFSET=0xC000 -# Use minimal mDNS -CONFIG_USE_MINIMAL_MDNS=y -CONFIG_ENABLE_EXTENDED_DISCOVERY=y +# Disable chip shell +CONFIG_ENABLE_CHIP_SHELL=n # Enable OTA Requestor -CONFIG_ENABLE_OTA_REQUESTOR=y +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 AP +# disable softap by default +CONFIG_ESP_WIFI_SOFTAP_SUPPORT=n CONFIG_ENABLE_WIFI_STATION=y CONFIG_ENABLE_WIFI_AP=n -# Button -CONFIG_BUTTON_PERIOD_TIME_MS=20 -CONFIG_BUTTON_LONG_PRESS_TIME_MS=5000 - -# Enable chip shell -CONFIG_ENABLE_CHIP_SHELL=y - -# ESP32-C6-DevKitM-1 Settings -# Buttons -CONFIG_BSP_BUTTONS_NUM=1 -CONFIG_BSP_BUTTON_1_TYPE_GPIO=y -CONFIG_BSP_BUTTON_1_GPIO=9 -CONFIG_BSP_BUTTON_1_LEVEL=0 -# LEDs -CONFIG_BSP_LEDS_NUM=1 -CONFIG_BSP_LED_TYPE_RGB=y -CONFIG_BSP_LED_RGB_GPIO=8 -CONFIG_BSP_LED_RGB_BACKEND_RMT=y +# 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 + +# NIMBLE +CONFIG_BT_NIMBLE_EXT_ADV=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 +CONFIG_USE_BLE_ONLY_FOR_COMMISSIONING=y + +# FreeRTOS should use legacy API +CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y + +# Use minimal mDNS +CONFIG_USE_MINIMAL_MDNS=y +CONFIG_ENABLE_EXTENDED_DISCOVERY=y diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 index 111eb7ebd9f..c7ecfa7714a 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 @@ -1,3 +1,25 @@ +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 @@ -13,19 +35,20 @@ CONFIG_PARTITION_TABLE_CUSTOM=y CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" CONFIG_PARTITION_TABLE_OFFSET=0xC000 -# Enable chip shell -CONFIG_ENABLE_CHIP_SHELL=y +# 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 -# 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 @@ -39,15 +62,3 @@ 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 - -# ESP32-S3-DevKitC-1 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 -# 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 From 196f63d798a1e5cd5a9dac6669d9ec480f967367 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Sat, 14 Sep 2024 01:41:18 -0300 Subject: [PATCH 10/42] feat(matter): improve code and led status --- .../esp_matter_light/main/builtinLED.cpp | 497 +++++++++--------- .../esp_matter_light/main/builtinLED.h | 150 +++--- .../main/matter_accessory_driver.cpp | 10 +- .../main/matter_accessory_driver.h | 75 ++- .../esp_matter_light/main/matter_light.cpp | 162 ++++-- 5 files changed, 485 insertions(+), 409 deletions(-) diff --git a/idf_component_examples/esp_matter_light/main/builtinLED.cpp b/idf_component_examples/esp_matter_light/main/builtinLED.cpp index 10d10b914f9..d1f6e4ea5c5 100644 --- a/idf_component_examples/esp_matter_light/main/builtinLED.cpp +++ b/idf_component_examples/esp_matter_light/main/builtinLED.cpp @@ -1,250 +1,247 @@ -/* - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. - - This will implement the onboard WS2812b LED as a LED indicator - It can be used to indicate some state or status of the device - The LED can be controlled using RGB, HSV or color temperature, brightness - - In this example, the LED Indicator class is used as the Matter light accessory -*/ - -#include "builtinLED.h" - -typedef struct { - 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} -}; - -/* 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, -}; - -BuiltInLED::BuiltInLED() { - pin_number = (uint8_t) -1; // no pin number - state = false; // LED is off - hsv_color.value = 0; // black color -} - -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; - - 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; - } 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); - } - } - 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; - - 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) { - case 0: - 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; - case 2: - 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; - case 4: - 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; - } - - // 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; - write(); - } else { - log_e("Invalid pin (%d) number", pin); - } -} -void BuiltInLED::end(){ - state = false; - write(); - 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 { - rgbLedWrite(pin_number, 0, 0, 0); - } - return true; - } else { - log_e("Invalid pin (%d) number", pin_number); - return false; - } -} - -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); -} - +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. + This will implement the onboard WS2812b LED as a LED indicator + It can be used to indicate some state or status of the device + The LED can be controlled using RGB, HSV or color temperature, brightness + + In this example, the LED Indicator class is used as the Matter light accessory +*/ + +#include "builtinLED.h" + +typedef struct { + 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} +}; + +/* 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, +}; + +BuiltInLED::BuiltInLED() { + pin_number = (uint8_t) -1; // no pin number + state = false; // LED is off + hsv_color.value = 0; // black color +} + +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; + + 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; + } 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); + } + } + 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; + + 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) { + case 0: + 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; + case 2: + 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; + case 4: + 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; + } + + // 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); + } 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 { + rgbLedWrite(pin_number, 0, 0, 0); + } + return true; + } else { + log_e("Invalid pin (%d) number", pin_number); + return false; + } +} + +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); +} \ No newline at end of file diff --git a/idf_component_examples/esp_matter_light/main/builtinLED.h b/idf_component_examples/esp_matter_light/main/builtinLED.h index 27345a80fdd..d9d21814e12 100644 --- a/idf_component_examples/esp_matter_light/main/builtinLED.h +++ b/idf_component_examples/esp_matter_light/main/builtinLED.h @@ -1,76 +1,74 @@ -/* - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. - - This will implement the onboard WS2812b LED as a LED indicator - It can be used to indicate some state or status of the device - The LED can be controlled using RGB, HSV or color temperature, brightness - - In this example, the BuiltInLED class is used as the Matter light accessory -*/ - -#pragma once - -#include - -#define MAX_HUE 360 -#define MAX_SATURATION 255 -#define MAX_BRIGHTNESS 255 -#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. */ - }; -} 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. */ - }; -} led_indicator_color_rgb_t; - -class BuiltInLED { -private: - uint8_t pin_number; - bool state; - led_indicator_color_hsv_t hsv_color; - -public: - 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); - - void begin(uint8_t pin); - void end(); - - void on(); - void off(); - void toggle(); - bool getState(); - - 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); -}; +/* + This example code is in the Public Domain (or CC0 licensed, at your option.) + Unless required by applicable law or agreed to in writing, this + software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR + CONDITIONS OF ANY KIND, either express or implied. + This will implement the onboard WS2812b LED as a LED indicator + It can be used to indicate some state or status of the device + The LED can be controlled using RGB, HSV or color temperature, brightness + + In this example, the BuiltInLED class is used as the Matter light accessory +*/ + +#pragma once + +#include + +#define MAX_HUE 360 +#define MAX_SATURATION 255 +#define MAX_BRIGHTNESS 255 +#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. */ + }; +} 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. */ + }; +} led_indicator_color_rgb_t; + +class BuiltInLED { +private: + uint8_t pin_number; + bool state; + led_indicator_color_hsv_t hsv_color; + +public: + 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); + + void begin(uint8_t pin); + void end(); + + void on(); + void off(); + void toggle(); + bool getState(); + + 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); +}; \ No newline at end of file diff --git a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp index 9fe2b16c68d..9fa7d362b52 100644 --- a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp @@ -1,6 +1,5 @@ /* This example code is in the Public Domain (or CC0 licensed, at your option.) - Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -11,9 +10,6 @@ #include "builtinLED.h" #include "matter_accessory_driver.h" -// set your board WS2812b pin here (e.g. 48 is the default pin for the ESP32-S3 devkit) -#define WS2812_PIN 48 - /* Do any conversions/remapping for the actual value here */ esp_err_t light_accessory_set_power(void *led, uint8_t val) { @@ -95,7 +91,7 @@ app_driver_handle_t light_accessory_init() const uint8_t pin = WS2812_PIN; // set your board WS2812b pin here builtinLED.begin(pin); - builtinLED.setHSV({DEFAULT_HUE, DEFAULT_SATURATION, DEFAULT_BRIGHTNESS}); - builtinLED.write(); + // builtinLED.setHSV({DEFAULT_HUE, DEFAULT_SATURATION, DEFAULT_BRIGHTNESS}); + // builtinLED.write(); return (app_driver_handle_t) &builtinLED; -} +} \ No newline at end of file diff --git a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.h b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.h index b3b6692e350..8d816c799a8 100644 --- a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.h +++ b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.h @@ -1,28 +1,47 @@ -#include - -/** Standard max values (used for remapping attributes) */ -#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_TEMPERATURE_FACTOR 1000000 - -/** Default attribute values used during initialization */ -#define DEFAULT_POWER true -#define DEFAULT_BRIGHTNESS 64 -#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_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(); +#include +#include + +// 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 +#else +#define WS2812_PIN CONFIG_WS2812_PIN // From sdkconfig.defaults. +#endif + +#ifndef RGB_BUILTIN +#define RGB_BUILTIN WS2812_PIN +#endif + +// 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 +#else +#define BUTTON_PIN CONFIG_BUTTON_PIN // From sdkconfig.defaults. +#endif + +/** Standard max values (used for remapping attributes) */ +#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_TEMPERATURE_FACTOR 1000000 + +/** Default attribute values used during initialization */ +#define DEFAULT_POWER true +#define DEFAULT_BRIGHTNESS 64 +#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_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(); \ No newline at end of file diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index 76d5cfe6fa6..a69a922d146 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -1,6 +1,5 @@ /* This example code is in the Public Domain (or CC0 licensed, at your option.) - Unless required by applicable law or agreed to in writing, this software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -37,6 +36,9 @@ } #endif +// set your board button pin here +const uint8_t button_gpio = BUTTON_PIN; // GPIO BOOT Button + uint16_t light_endpoint_id = 0; using namespace esp_matter; @@ -54,11 +56,29 @@ 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 +bool isAccessoryCommissioned() { + return chip::Server::GetInstance().GetFabricTable().FabricCount() > 0; +} + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +bool isWifiConnected() { + return chip::DeviceLayer::ConnectivityMgr().IsWiFiStationConnected(); +} +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +bool isThreadConnected() { + return chip::DeviceLayer::ConnectivityMgr().IsThreadAttached(); +} +#endif + static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) { switch (event->Type) { case chip::DeviceLayer::DeviceEventType::kInterfaceIpAddressChanged: - log_i("Interface IP Address changed"); + log_i("Interface %s Address changed", + event->InterfaceIpAddressChanged.Type == chip::DeviceLayer::InterfaceIpChangeType::kIpV4_Assigned ? + "IPv4" : "IPV6" ); break; case chip::DeviceLayer::DeviceEventType::kCommissioningComplete: @@ -129,40 +149,6 @@ static void app_event_cb(const ChipDeviceEvent *event, intptr_t arg) } } -static uint32_t button_time_stamp = 0; -static void button_driver_down_cb() -{ - button_time_stamp = millis(); -} - - -static void button_driver_up_cb() -{ - uint32_t time_diff = millis() - button_time_stamp; - // Factory reset is triggered if the button is pressed for more than 3 seconds - if (time_diff > 3000) { - log_i("Factory reset triggered. Light will retored to factory settings."); - esp_matter::factory_reset(); - return; - } - - // Toggle button is pressed - toggle the light - log_i("Toggle button pressed"); - uint16_t endpoint_id = light_endpoint_id; - uint32_t cluster_id = OnOff::Id; - uint32_t attribute_id = OnOff::Attributes::OnOff::Id; - - node_t *node = node::get(); - endpoint_t *endpoint = endpoint::get(node, endpoint_id); - cluster_t *cluster = cluster::get(endpoint, cluster_id); - attribute_t *attribute = attribute::get(cluster, attribute_id); - - esp_matter_attr_val_t val = esp_matter_invalid(NULL); - attribute::get_val(attribute, &val); - val.val.b = !val.val.b; - attribute::update(endpoint_id, cluster_id, attribute_id, &val); -} - 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) { @@ -241,10 +227,7 @@ esp_err_t matter_light_set_defaults(uint16_t endpoint_id) void button_driver_init() { /* Initialize button */ - uint8_t pin = 0; // set your board button pin here - pinMode(pin, INPUT_PULLUP); - attachInterrupt(digitalPinToInterrupt(pin), button_driver_down_cb, FALLING); // pressed - attachInterrupt(digitalPinToInterrupt(pin), button_driver_up_cb, RISING); // released + pinMode(button_gpio, INPUT_PULLUP); } // This callback is called for every attribute update. The callback implementation shall @@ -277,9 +260,6 @@ void setup() { esp_err_t err = ESP_OK; - /* Initialize the ESP NVS layer */ - //nvs_flash_init(); - /* Initialize driver */ app_driver_handle_t light_handle = light_accessory_init(); button_driver_init(); @@ -309,7 +289,7 @@ void setup() 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); @@ -343,9 +323,6 @@ void setup() abort(); } - /* Starting driver with default values */ - matter_light_set_defaults(light_endpoint_id); - #if CONFIG_ENABLE_ENCRYPTED_OTA err = esp_matter_ota_requestor_encrypted_init(s_decryption_key, s_decryption_key_len); if (err != ESP_OK) { @@ -365,5 +342,94 @@ void setup() } void loop() { - delay(1000); + static uint32_t button_time_stamp = 0; + static bool button_state = false; + static bool started = false; + + 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 +#endif + delay(5000); + return; + } + +#if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + 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 +#endif + delay(5000); + return; + } +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + 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 +#endif + delay(5000); + return; + } +#endif + + // Once all network connections are established, the accessory is ready for use + // Run it only once + if (!started) { + log_i("Accessory is commissioned and connected to Wi-Fi. Ready for use."); + started = true; + // Starting driver with default values + matter_light_set_defaults(light_endpoint_id); + } + + // 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. + + // Toggle button is pressed - toggle the light + log_i("Toggle button pressed"); + + endpoint_t *endpoint = endpoint::get(node::get(), light_endpoint_id); + cluster_t *cluster = cluster::get(endpoint, OnOff::Id); + attribute_t *attribute = attribute::get(cluster, OnOff::Attributes::OnOff::Id); + + esp_matter_attr_val_t val = esp_matter_invalid(NULL); + attribute::get_val(attribute, &val); + val.val.b = !val.val.b; + attribute::update(light_endpoint_id, OnOff::Id, OnOff::Attributes::OnOff::Id, &val); + } + + // 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. + + // 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(); + } + } + + delay(50); // WDT is happier with a delay } + +//#if CHIP_DEVICE_CONFIG_ENABLE_THREAD + // If Thread is Provisioned, publish the dns service +// if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() && +// (chip::Server::GetInstance().GetFabricTable().FabricCount() != 0)) { +// chip::app::DnssdServer::Instance().StartServer(); +// } +//#endif + +// chip::DeviceLayer::PlatformMgr().LockChipStack(); +// chip::DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision(); +// chip::DeviceLayer::PlatformMgr().UnlockChipStack(); + +// return chip::DeviceLayer::ConnectivityMgr().IsWiFiStationProvisioned(); From 63c8e83c6aa827e81b3f1fcaf53daec3da771efc Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Sat, 14 Sep 2024 01:42:09 -0300 Subject: [PATCH 11/42] feat(matter): add button and led gpio with kconfig --- .../esp_matter_light/main/Kconfig.projbuild | 102 ++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 idf_component_examples/esp_matter_light/main/Kconfig.projbuild diff --git a/idf_component_examples/esp_matter_light/main/Kconfig.projbuild b/idf_component_examples/esp_matter_light/main/Kconfig.projbuild new file mode 100644 index 00000000000..4aa40fbdcdc --- /dev/null +++ b/idf_component_examples/esp_matter_light/main/Kconfig.projbuild @@ -0,0 +1,102 @@ +menu "Light Matter Accessory" + menu "On Board Light ON/OFF Button" + config BUTTON_PIN + int + prompt "Button 1 GPIO" + default ENV_GPIO_BOOT_BUTTON + 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 + 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_MAX + int + default 19 + # GPIOs 20/21 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_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 + +endmenu From 6fe9d264fcc1c11555ee8a15250b123b7786d017 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Sat, 14 Sep 2024 01:48:49 -0300 Subject: [PATCH 12/42] fix(matter): remove commented lines --- .../esp_matter_light/main/matter_accessory_driver.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp index 9fa7d362b52..8e3cc7ec413 100644 --- a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp @@ -91,7 +91,5 @@ app_driver_handle_t light_accessory_init() const uint8_t pin = WS2812_PIN; // set your board WS2812b pin here builtinLED.begin(pin); - // builtinLED.setHSV({DEFAULT_HUE, DEFAULT_SATURATION, DEFAULT_BRIGHTNESS}); - // builtinLED.write(); return (app_driver_handle_t) &builtinLED; -} \ No newline at end of file +} From 1be6b0eb6ea5971a886be4ab0a24905fa362f011 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Sat, 14 Sep 2024 01:51:26 -0300 Subject: [PATCH 13/42] fix(matter): remove commented lines --- .../esp_matter_light/main/matter_light.cpp | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index a69a922d146..7cdb18ccfe3 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -419,17 +419,3 @@ void loop() { delay(50); // WDT is happier with a delay } - -//#if CHIP_DEVICE_CONFIG_ENABLE_THREAD - // If Thread is Provisioned, publish the dns service -// if (chip::DeviceLayer::ConnectivityMgr().IsThreadProvisioned() && -// (chip::Server::GetInstance().GetFabricTable().FabricCount() != 0)) { -// chip::app::DnssdServer::Instance().StartServer(); -// } -//#endif - -// chip::DeviceLayer::PlatformMgr().LockChipStack(); -// chip::DeviceLayer::ConnectivityMgr().ClearWiFiStationProvision(); -// chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - -// return chip::DeviceLayer::ConnectivityMgr().IsWiFiStationProvisioned(); From b392e8ad6855574890e3f18fd167c852e38bb31b Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 16 Sep 2024 11:40:39 -0300 Subject: [PATCH 14/42] feat(matter): added a 2.4GHz SSID note Both the ESP32 device and the Smartphone running the Matter APP shall be in the same WiFi Network in order to achieve a successful commissioning process. --- idf_component_examples/esp_matter_light/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 5c4c6d9a0cb..e27d5c19dfe 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -35,6 +35,7 @@ The purple color indicates that the Matter Accessory has not been commissioned y After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no WiFi connection. Once it connects to the WiFi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. +Please note that Matter over WiFi using an ESP32 device will connect to a 2.4GHz WiFi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID. The Matter and WiFi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and WiFi Network again once it is reset. From f30ad99c77526c7d74d756edead19744f3aa0ce5 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 16 Sep 2024 11:44:45 -0300 Subject: [PATCH 15/42] feat(matter): arduino managed comonent version Preparing the Arduino Managed Component to use Core version 3.0.5 or higher. --- .../esp_matter_light/main/idf_component.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/idf_component_examples/esp_matter_light/main/idf_component.yml b/idf_component_examples/esp_matter_light/main/idf_component.yml index 7b0693203c4..be3d4afbb6f 100644 --- a/idf_component_examples/esp_matter_light/main/idf_component.yml +++ b/idf_component_examples/esp_matter_light/main/idf_component.yml @@ -3,6 +3,11 @@ dependencies: version: "^1.3.0" # Adds Arduino Core from GitHub repository using main branch espressif/arduino-esp32: + # version: "^3.0.5" + # override_path: "../../../" + # pre_release: true + + # testing - using Arduino from the repository version: "master" # branch or commit git: https://github.com/espressif/arduino-esp32.git From fe502970b70234f6ef35a7fb4b14be8cb2dfe83d Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 17 Sep 2024 08:22:24 -0300 Subject: [PATCH 16/42] feat(matter): adds information about google Goggle Home Assistant requires special configurtation in order to allow the Light to show up in the GHA APP. --- idf_component_examples/esp_matter_light/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index e27d5c19dfe..449503e8b5f 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -17,10 +17,12 @@ The code is based on the Arduino API and uses Arduino as an IDF Component. Once the device runs for the first time, it must be commissioned to the Matter Fabric of the available Matter Environment. Possible Matter Environments are: - Amazon Alexa -- Google Home Assistant +- Google Home Assistant (*) - Apple Home - Open Source Home Assistant +(*) Google Home Assistant requires the user to set up a Matter Light using the [Google Home Developer Console](https://developers.home.google.com/codelabs/matter-device#2). It is necessary to create a Matter Light device with VID = 0xFFF1 and PID = 0x8000. Otherwise, the Light won't show up in the GHA APP. This action is necessary because the Firmware uses Testing credentials and Google requires the user to create the testing device before using it. + There is no QR Code to be used when the Smartphone APP wants to add the Matter Device. Please enter the code manually: `34970112332` From 2c1848907865624afabf2c761b556cd4bd0b30b1 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Tue, 17 Sep 2024 08:27:09 -0300 Subject: [PATCH 17/42] feat(matter): arduino component version Set final Arduino Managed Component to 3.0.5 necessary because of -DESP32=ESP32, in order to compile the project. --- .../esp_matter_light/main/idf_component.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/idf_component_examples/esp_matter_light/main/idf_component.yml b/idf_component_examples/esp_matter_light/main/idf_component.yml index be3d4afbb6f..424b6a93da2 100644 --- a/idf_component_examples/esp_matter_light/main/idf_component.yml +++ b/idf_component_examples/esp_matter_light/main/idf_component.yml @@ -3,11 +3,11 @@ dependencies: version: "^1.3.0" # Adds Arduino Core from GitHub repository using main branch espressif/arduino-esp32: - # version: "^3.0.5" - # override_path: "../../../" - # pre_release: true + version: "^3.0.5" + override_path: "../../../" + pre_release: true # testing - using Arduino from the repository - version: "master" # branch or commit - git: https://github.com/espressif/arduino-esp32.git + # version: "master" # branch or commit + # git: https://github.com/espressif/arduino-esp32.git From 2dd56d1c30e6a05a4828032b0a42dfd31b610df4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 08:24:14 +0000 Subject: [PATCH 18/42] ci(pre-commit): Apply automatic fixes --- .../esp_matter_light/CMakeLists.txt | 1 - .../esp_matter_light/README.md | 180 +++---- .../esp_matter_light/main/CMakeLists.txt | 2 +- .../esp_matter_light/main/Kconfig.projbuild | 204 ++++---- .../esp_matter_light/main/builtinLED.cpp | 340 +++++++------- .../esp_matter_light/main/builtinLED.h | 78 +-- .../esp_matter_light/main/idf_component.yml | 5 +- .../main/matter_accessory_driver.cpp | 132 +++--- .../main/matter_accessory_driver.h | 28 +- .../esp_matter_light/main/matter_light.cpp | 443 ++++++++---------- .../sdkconfig.defaults.c6_thread | 3 +- .../sdkconfig.defaults.esp32c3 | 128 ++--- .../sdkconfig.defaults.esp32c6 | 2 +- .../sdkconfig.defaults.esp32s3 | 2 +- 14 files changed, 746 insertions(+), 802 deletions(-) diff --git a/idf_component_examples/esp_matter_light/CMakeLists.txt b/idf_component_examples/esp_matter_light/CMakeLists.txt index aed85dd3116..16a7533f2a5 100644 --- a/idf_component_examples/esp_matter_light/CMakeLists.txt +++ b/idf_component_examples/esp_matter_light/CMakeLists.txt @@ -25,4 +25,3 @@ 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) - diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 449503e8b5f..1359fb5fab0 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -1,90 +1,90 @@ -| Supported Targets | ESP32-S3 | 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 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. - -The code is based on the Arduino API and uses Arduino as an IDF Component. - -## How to use it - -Once the device runs for the first time, it must be commissioned to the Matter Fabric of the available Matter Environment. -Possible Matter Environments are: -- Amazon Alexa -- Google Home Assistant (*) -- Apple Home -- Open Source Home Assistant - -(*) Google Home Assistant requires the user to set up a Matter Light using the [Google Home Developer Console](https://developers.home.google.com/codelabs/matter-device#2). It is necessary to create a Matter Light device with VID = 0xFFF1 and PID = 0x8000. Otherwise, the Light won't show up in the GHA APP. This action is necessary because the Firmware uses Testing credentials and Google requires the user to create the testing device before using it. - -There is no QR Code to be used when the Smartphone APP wants to add the Matter Device. -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.` file. - -## LED Status and Factory Mode - -The WS2812b built-in LED will turn purple as soon as the device is flashed and runs for the first time. -The purple color indicates that the Matter Accessory has not been commissioned yet. -After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no WiFi connection. - -Once it connects to the WiFi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. -Please note that Matter over WiFi using an ESP32 device will connect to a 2.4GHz WiFi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID. - -The Matter and WiFi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and WiFi Network again once it is reset. - -The Matter Smartphone APP will control the light state (ON/OFF), temperature (Warm/Cold White), and brightness. - -## On Board Light toggle button - -The built-in BOOT button will toggle On/Off and replicate the new state to the Matter Environment, making it visible in the Matter Smartphone APP as well. - -## Returning to the Factory State - -Holding the BOOT button pressed for more than 10 seconds and then releasing it will erase all Matter and WiFi configuration, forcing it to reset to factory state. After that, the device needs to be commissioned again. Previous setups done in the Smartphone APP won't work again; therefore, the virtual device shall be removed from the APP. - -## 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 - -The project will download all necessary components, inluding the Arduino Core. -Run `idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults..idf" -p flash monitor` - -Example for ESP32-S3/Linux|MacOS: -`idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32s3" -p /dev/ttyACM0 flash monitor` -Example for ESP32-C3/Windows: -`idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32c3" -p com3 flash monitor` - -It may be necessary to delete some folders and files before running `idf.py` -Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock` -Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock` - -There is a configuration file for these SoC: esp32s3, 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` -`idf.py menuconfig` and change the Menu Option `Light Matter Accessory` - -## 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. -In order to build the application that will use Thread Networking instead of WiFi, please execute: - -Example for ESP32-S3/Linux|MacOS: -`idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p /dev/ttyACM0 flash monitor` -Example for ESP32-C3/Windows: -`idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p com3 flash monitor` - -It may be necessary to delete some folders and files before running `idf.py` -Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock` -Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock` +| Supported Targets | ESP32-S3 | 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 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. + +The code is based on the Arduino API and uses Arduino as an IDF Component. + +## How to use it + +Once the device runs for the first time, it must be commissioned to the Matter Fabric of the available Matter Environment. +Possible Matter Environments are: +- Amazon Alexa +- Google Home Assistant (*) +- Apple Home +- Open Source Home Assistant + +(*) Google Home Assistant requires the user to set up a Matter Light using the [Google Home Developer Console](https://developers.home.google.com/codelabs/matter-device#2). It is necessary to create a Matter Light device with VID = 0xFFF1 and PID = 0x8000. Otherwise, the Light won't show up in the GHA APP. This action is necessary because the Firmware uses Testing credentials and Google requires the user to create the testing device before using it. + +There is no QR Code to be used when the Smartphone APP wants to add the Matter Device. +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.` file. + +## LED Status and Factory Mode + +The WS2812b built-in LED will turn purple as soon as the device is flashed and runs for the first time. +The purple color indicates that the Matter Accessory has not been commissioned yet. +After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no WiFi connection. + +Once it connects to the WiFi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. +Please note that Matter over WiFi using an ESP32 device will connect to a 2.4GHz WiFi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID. + +The Matter and WiFi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and WiFi Network again once it is reset. + +The Matter Smartphone APP will control the light state (ON/OFF), temperature (Warm/Cold White), and brightness. + +## On Board Light toggle button + +The built-in BOOT button will toggle On/Off and replicate the new state to the Matter Environment, making it visible in the Matter Smartphone APP as well. + +## Returning to the Factory State + +Holding the BOOT button pressed for more than 10 seconds and then releasing it will erase all Matter and WiFi configuration, forcing it to reset to factory state. After that, the device needs to be commissioned again. Previous setups done in the Smartphone APP won't work again; therefore, the virtual device shall be removed from the APP. + +## 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 + +The project will download all necessary components, inluding the Arduino Core. +Run `idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults..idf" -p flash monitor` + +Example for ESP32-S3/Linux|MacOS: +`idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32s3" -p /dev/ttyACM0 flash monitor` +Example for ESP32-C3/Windows: +`idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32c3" -p com3 flash monitor` + +It may be necessary to delete some folders and files before running `idf.py` +Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock` +Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock` + +There is a configuration file for these SoC: esp32s3, 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` +`idf.py menuconfig` and change the Menu Option `Light Matter Accessory` + +## 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. +In order to build the application that will use Thread Networking instead of WiFi, please execute: + +Example for ESP32-S3/Linux|MacOS: +`idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p /dev/ttyACM0 flash monitor` +Example for ESP32-C3/Windows: +`idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p com3 flash monitor` + +It may be necessary to delete some folders and files before running `idf.py` +Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock` +Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock` diff --git a/idf_component_examples/esp_matter_light/main/CMakeLists.txt b/idf_component_examples/esp_matter_light/main/CMakeLists.txt index 833af61132a..6b91a8cf510 100644 --- a/idf_component_examples/esp_matter_light/main/CMakeLists.txt +++ b/idf_component_examples/esp_matter_light/main/CMakeLists.txt @@ -2,4 +2,4 @@ idf_component_register(SRC_DIRS "." INCLUDE_DIRS ".") set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) -target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") \ No newline at end of file +target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") diff --git a/idf_component_examples/esp_matter_light/main/Kconfig.projbuild b/idf_component_examples/esp_matter_light/main/Kconfig.projbuild index 4aa40fbdcdc..6e6abcb7fcf 100644 --- a/idf_component_examples/esp_matter_light/main/Kconfig.projbuild +++ b/idf_component_examples/esp_matter_light/main/Kconfig.projbuild @@ -1,102 +1,102 @@ -menu "Light Matter Accessory" - menu "On Board Light ON/OFF Button" - config BUTTON_PIN - int - prompt "Button 1 GPIO" - default ENV_GPIO_BOOT_BUTTON - 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 - 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_MAX - int - default 19 - # GPIOs 20/21 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_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 - -endmenu +menu "Light Matter Accessory" + menu "On Board Light ON/OFF Button" + config BUTTON_PIN + int + prompt "Button 1 GPIO" + default ENV_GPIO_BOOT_BUTTON + 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 + 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_MAX + int + default 19 + # GPIOs 20/21 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_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 + +endmenu diff --git a/idf_component_examples/esp_matter_light/main/builtinLED.cpp b/idf_component_examples/esp_matter_light/main/builtinLED.cpp index d1f6e4ea5c5..8795dde2756 100644 --- a/idf_component_examples/esp_matter_light/main/builtinLED.cpp +++ b/idf_component_examples/esp_matter_light/main/builtinLED.cpp @@ -6,242 +6,232 @@ This will implement the onboard WS2812b LED as a LED indicator It can be used to indicate some state or status of the device The LED can be controlled using RGB, HSV or color temperature, brightness - + In this example, the LED Indicator class is used as the Matter light accessory */ #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; - - 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; + 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; + + 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; +} + +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"); } - - // 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); - } else { - log_e("Invalid pin (%d) number", pin); - } +void BuiltInLED::on() { + state = true; } -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::off(){ - state = false; +void BuiltInLED::toggle() { + state = !state; } -void BuiltInLED::toggle(){ - state = !state; +bool BuiltInLED::getState() { + return 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 { - rgbLedWrite(pin_number, 0, 0, 0); - } - return true; +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_number); - return false; + rgbLedWrite(pin_number, 0, 0, 0); } + return true; + } else { + log_e("Invalid pin (%d) number", pin_number); + return false; + } } -void BuiltInLED::setBrightness(uint8_t brightness){ - hsv_color.v = brightness; +void BuiltInLED::setBrightness(uint8_t brightness) { + hsv_color.v = brightness; } -uint8_t BuiltInLED::getBrightness(){ - return hsv_color.v; +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; +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; +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); +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); +led_indicator_color_rgb_t BuiltInLED::getRGB() { + return hsv2rgb(hsv_color); } -void BuiltInLED::setTemperature(uint32_t temperature){ - uint16_t hue; - uint8_t saturation; +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; + 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 { - if (temperature > 10000) { - hue = 222; - saturation = 21 + (temperature - 10000) * 41 / 990000; - } else { - temperature -= 600; - temperature /= 100; - hue = temperatureTable[temperature].hue; - saturation = temperatureTable[temperature].saturation; - } + 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); -} \ No newline at end of file + } + 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); +} diff --git a/idf_component_examples/esp_matter_light/main/builtinLED.h b/idf_component_examples/esp_matter_light/main/builtinLED.h index d9d21814e12..1ca8c935569 100644 --- a/idf_component_examples/esp_matter_light/main/builtinLED.h +++ b/idf_component_examples/esp_matter_light/main/builtinLED.h @@ -6,7 +6,7 @@ This will implement the onboard WS2812b LED as a LED indicator It can be used to indicate some state or status of the device The LED can be controlled using RGB, HSV or color temperature, brightness - + In this example, the BuiltInLED class is used as the Matter light accessory */ @@ -14,61 +14,61 @@ #include -#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); -}; \ No newline at end of file + 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); +}; diff --git a/idf_component_examples/esp_matter_light/main/idf_component.yml b/idf_component_examples/esp_matter_light/main/idf_component.yml index 424b6a93da2..2b4ae4b34a4 100644 --- a/idf_component_examples/esp_matter_light/main/idf_component.yml +++ b/idf_component_examples/esp_matter_light/main/idf_component.yml @@ -6,8 +6,7 @@ dependencies: version: "^3.0.5" override_path: "../../../" pre_release: true - + # testing - using Arduino from the repository - # version: "master" # branch or commit + # version: "master" # branch or commit # git: https://github.com/espressif/arduino-esp32.git - diff --git a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp index 8e3cc7ec413..523c38e6855 100644 --- a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.cpp @@ -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; } diff --git a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.h b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.h index 8d816c799a8..3bf6655ab16 100644 --- a/idf_component_examples/esp_matter_light/main/matter_accessory_driver.h +++ b/idf_component_examples/esp_matter_light/main/matter_accessory_driver.h @@ -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. +#define WS2812_PIN CONFIG_WS2812_PIN // From sdkconfig.defaults. #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. +#define BUTTON_PIN CONFIG_BUTTON_PIN // From sdkconfig.defaults. #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(); \ No newline at end of file +app_driver_handle_t light_accessory_init(); diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index 7cdb18ccfe3..2dd845da45f 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -20,24 +20,18 @@ #include #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()); + } } + } + break; + } - case chip::DeviceLayer::DeviceEventType::kFabricWillBeRemoved: - log_i("Fabric will be removed"); - break; + 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::kFabricUpdated: log_i("Fabric is updated"); break; - case chip::DeviceLayer::DeviceEventType::kFabricCommitted: - log_i("Fabric is committed"); - 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; + case chip::DeviceLayer::DeviceEventType::kBLEDeinitialized: log_i("BLE deinitialized and memory reclaimed"); break; - default: - 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); - } - } +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; + } + 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); +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_brightness(led, val.val.u8); - - /* Setting color */ - cluster = cluster::get(endpoint, ColorControl::Id); - attribute = attribute::get(cluster, ColorControl::Attributes::ColorMode::Id); + err |= light_accessory_set_hue(led, val.val.u8); + /* Setting saturation */ + attribute = attribute::get(cluster, ColorControl::Attributes::CurrentSaturation::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); + 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_power(led, val.val.b); + 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; + return err; } -void button_driver_init() -{ - /* Initialize button */ - pinMode(button_gpio, INPUT_PULLUP); +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; - - 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); - } +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); + } - 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; - - // 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(); - } + 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(); + } - 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); + 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 } @@ -345,21 +308,21 @@ void loop() { static uint32_t button_time_stamp = 0; 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; + return; } #if CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 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); @@ -406,16 +369,16 @@ void loop() { } // Check if the button is released and handle the factory reset - uint32_t time_diff = millis() - button_time_stamp; + 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 retored to factory settings."); + esp_matter::factory_reset(); } } - delay(50); // WDT is happier with a delay + delay(50); // WDT is happier with a delay } diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread b/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread index 389c72c4bc1..66fd62e26bc 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread @@ -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 @@ -77,4 +77,3 @@ CONFIG_MRP_MAX_RETRANS=3 # Enable HKDF in mbedtls CONFIG_MBEDTLS_HKDF_C=y - diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 index f534f3b7d1a..3282666c426 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 @@ -1,64 +1,64 @@ -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 +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 diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 index 301ee1a4e57..207c8431e58 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 @@ -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 diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 index c7ecfa7714a..087ce651d72 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 @@ -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 From 9f1c7060dda51d5f505c28de70a21bf5cd536063 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:21:15 -0300 Subject: [PATCH 19/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 1359fb5fab0..821676eb821 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -56,7 +56,7 @@ Holding the BOOT button pressed for more than 10 seconds and then releasing it w 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 -The project will download all necessary components, inluding the Arduino Core. +The project will download all necessary components, including the Arduino Core. Run `idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults..idf" -p flash monitor` Example for ESP32-S3/Linux|MacOS: From 6b561951f1fdb0be2ae37675e04a752abb2e61ce Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:21:31 -0300 Subject: [PATCH 20/42] fix(typo): typo and commentaries --- .../esp_matter_light/sdkconfig.defaults.c6_thread | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread b/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread index 66fd62e26bc..502480f94b1 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.c6_thread @@ -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 From 40ead465e9d376c0318f748bcb9b8608393e8ecb Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:21:55 -0300 Subject: [PATCH 21/42] fix(typo): typo and commentaries --- .../esp_matter_light/sdkconfig.defaults.esp32c3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 index 3282666c426..df6d6b0d585 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c3 @@ -38,7 +38,7 @@ CONFIG_PARTITION_TABLE_OFFSET=0xC000 # Disable chip shell CONFIG_ENABLE_CHIP_SHELL=n -# Enable OTA Requestor +# Enable OTA Requester CONFIG_ENABLE_OTA_REQUESTOR=n #enable lwIP route hooks From e361e757cdc0310b900b73767c5983531e2c1342 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:22:07 -0300 Subject: [PATCH 22/42] fix(typo): typo and commentaries --- .../esp_matter_light/sdkconfig.defaults.esp32c6 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 index 207c8431e58..f228f3158c8 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32c6 @@ -38,7 +38,7 @@ CONFIG_PARTITION_TABLE_OFFSET=0xC000 # Disable chip shell CONFIG_ENABLE_CHIP_SHELL=n -# Enable OTA Requestor +# Enable OTA Requester CONFIG_ENABLE_OTA_REQUESTOR=n #enable lwIP route hooks From 14eee603197123de45fed9ce6e0d6f13e2818c7a Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:22:18 -0300 Subject: [PATCH 23/42] fix(typo): typo and commentaries --- .../esp_matter_light/sdkconfig.defaults.esp32s3 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 index 087ce651d72..9c1aa36b6c9 100644 --- a/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 +++ b/idf_component_examples/esp_matter_light/sdkconfig.defaults.esp32s3 @@ -38,7 +38,7 @@ CONFIG_PARTITION_TABLE_OFFSET=0xC000 # Disable chip shell CONFIG_ENABLE_CHIP_SHELL=n -# Enable OTA Requestor +# Enable OTA Requester CONFIG_ENABLE_OTA_REQUESTOR=n #enable lwIP route hooks From d46fafc33bb95c9b1b65dc94ec9c24f507097d61 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:22:36 -0300 Subject: [PATCH 24/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 821676eb821..89d98131556 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -65,7 +65,7 @@ Example for ESP32-C3/Windows: `idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32c3" -p com3 flash monitor` It may be necessary to delete some folders and files before running `idf.py` -Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock` +Linux/macOS: `rm -rf build managed_components sdkconfig dependencies.lock` Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock` There is a configuration file for these SoC: esp32s3, esp32c3, esp32c6. From ea5f261e78981541706aa1f6a9019dd5f8fec06a Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:22:50 -0300 Subject: [PATCH 25/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 89d98131556..a76341037ed 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -69,7 +69,7 @@ Linux/macOS: `rm -rf build managed_components sdkconfig dependencies.lock` Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock` There is a configuration file for these SoC: esp32s3, esp32c3, esp32c6. -Those are the tested devices that have a WS2812 RGB LED and can run BLE, WiFi and Matter. +Those are the tested devices that have a WS2812 RGB LED and can run BLE, Wi-Fi and Matter. In case it is necessary to change the Button Pin or the REG LED Pin, please use the `menuconfig` `idf.py menuconfig` and change the Menu Option `Light Matter Accessory` From 4d576d4e1d17bf88a71b636d3ebc2842c83bee7d Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:23:03 -0300 Subject: [PATCH 26/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index a76341037ed..7303f9cf396 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -78,7 +78,7 @@ In case it is necessary to change the Button Pin or the REG LED Pin, please use 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. -In order to build the application that will use Thread Networking instead of WiFi, please execute: +In order to build the application that will use Thread Networking instead of Wi-Fi, please execute: Example for ESP32-S3/Linux|MacOS: `idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p /dev/ttyACM0 flash monitor` From 99dc865ab8aa874195e9064b78b8759df4a88a78 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:23:16 -0300 Subject: [PATCH 27/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 7303f9cf396..80841fc9bbd 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -80,7 +80,7 @@ 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. In order to build the application that will use Thread Networking instead of Wi-Fi, please execute: -Example for ESP32-S3/Linux|MacOS: +Example for ESP32-S3/Linux | macOS: `idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p /dev/ttyACM0 flash monitor` Example for ESP32-C3/Windows: `idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p com3 flash monitor` From 91a06eee1b4574ec8b6d8e22c16b5b4d57a75dc7 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:23:28 -0300 Subject: [PATCH 28/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 80841fc9bbd..6bbd7d31c85 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -86,5 +86,5 @@ Example for ESP32-C3/Windows: `idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.c6_thread" -p com3 flash monitor` It may be necessary to delete some folders and files before running `idf.py` -Linux/MacOS: `rm -rf build managed_components sdkconfig dependencies.lock` +Linux/macOS: `rm -rf build managed_components sdkconfig dependencies.lock` Windows: `rmdir /s/q build managed_components` and `del sdkconfig dependencies.lock` From 7efd65e4ed43f95d03fe0e1ca212676ff963b28f Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:23:58 -0300 Subject: [PATCH 29/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/main/matter_light.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index 2dd845da45f..61c63ad6dad 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -375,7 +375,7 @@ void loop() { // 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."); + log_i("Factory reset triggered. Light will restored to factory settings."); esp_matter::factory_reset(); } } From e7623e2913c1fb0f9bb0f0da1634e4e8a95d568b Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:24:22 -0300 Subject: [PATCH 30/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 6bbd7d31c85..a34f09ef4a1 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -59,7 +59,7 @@ This example has been tested with Arduino Core 3.0.4 The project will download all necessary components, including the Arduino Core. Run `idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults..idf" -p flash monitor` -Example for ESP32-S3/Linux|MacOS: +Example for ESP32-S3/Linux | macOS: `idf.py SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32s3" -p /dev/ttyACM0 flash monitor` Example for ESP32-C3/Windows: `idf.py -D SDKCONFIG_DEFAULTS="sdkconfig.defaults.esp32c3" -p com3 flash monitor` From fd0278179a2d196cd12c1212d7878875295e132a Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:24:40 -0300 Subject: [PATCH 31/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index a34f09ef4a1..7db6a010fa0 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -34,7 +34,7 @@ Please change it in `main/matter_accessory_driver.h` or in the `sdkconfig.defaul The WS2812b built-in LED will turn purple as soon as the device is flashed and runs for the first time. The purple color indicates that the Matter Accessory has not been commissioned yet. -After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no WiFi connection. +After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no Wi-Fi connection. Once it connects to the WiFi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. Please note that Matter over WiFi using an ESP32 device will connect to a 2.4GHz WiFi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID. From a9527de0440ebc5beaae64a3f133ca74e9a71c9d Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:24:56 -0300 Subject: [PATCH 32/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 7db6a010fa0..41d03126792 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -36,7 +36,7 @@ The WS2812b built-in LED will turn purple as soon as the device is flashed and r The purple color indicates that the Matter Accessory has not been commissioned yet. After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no Wi-Fi connection. -Once it connects to the WiFi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. +Once it connects to the Wi-Fi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. Please note that Matter over WiFi using an ESP32 device will connect to a 2.4GHz WiFi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID. The Matter and WiFi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and WiFi Network again once it is reset. From dc90ee8a15277a008ac2aace6e939a0e2a087334 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:25:13 -0300 Subject: [PATCH 33/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 41d03126792..6ed5bbe31e7 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -37,7 +37,7 @@ The purple color indicates that the Matter Accessory has not been commissioned y After using a Matter provider Smartphone APP to add a Matter device to your Home Application, it may turn orange to indicate that it has no Wi-Fi connection. Once it connects to the Wi-Fi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. -Please note that Matter over WiFi using an ESP32 device will connect to a 2.4GHz WiFi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID. +Please note that Matter over Wi-Fi using an ESP32 device will connect to a 2.4 GHz Wi-Fi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID. The Matter and WiFi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and WiFi Network again once it is reset. From 27383e09943e36b24febae377fd2cf8860c1128f Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:25:30 -0300 Subject: [PATCH 34/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 6ed5bbe31e7..a29680623a8 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -39,7 +39,7 @@ After using a Matter provider Smartphone APP to add a Matter device to your Home Once it connects to the Wi-Fi network, the LED will turn white to indicate that Matter is working and the device is connected to the Matter Environment. Please note that Matter over Wi-Fi using an ESP32 device will connect to a 2.4 GHz Wi-Fi SSID, therefore the Commissioner APP Smartphone shall be connected to this SSID. -The Matter and WiFi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and WiFi Network again once it is reset. +The Matter and Wi-Fi configuration will be stored in NVS to ensure that it will connect to the Matter Fabric and Wi-Fi Network again once it is reset. The Matter Smartphone APP will control the light state (ON/OFF), temperature (Warm/Cold White), and brightness. From bdf04b44f299d0b96750676f60fcadaab82f0069 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:25:46 -0300 Subject: [PATCH 35/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index a29680623a8..45adcc3010b 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -51,7 +51,7 @@ The built-in BOOT button will toggle On/Off and replicate the new state to the M Holding the BOOT button pressed for more than 10 seconds and then releasing it will erase all Matter and WiFi configuration, forcing it to reset to factory state. After that, the device needs to be commissioned again. Previous setups done in the Smartphone APP won't work again; therefore, the virtual device shall be removed from the APP. -## Building the Application using WiFi and Matter +## Building the Application using Wi-Fi 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 From 13a95f890ff8f1c53fccdcca29efeb748396afd7 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:26:04 -0300 Subject: [PATCH 36/42] fix(typo): typo and commentaries --- idf_component_examples/esp_matter_light/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/README.md b/idf_component_examples/esp_matter_light/README.md index 45adcc3010b..13a55f8ef64 100644 --- a/idf_component_examples/esp_matter_light/README.md +++ b/idf_component_examples/esp_matter_light/README.md @@ -49,7 +49,7 @@ The built-in BOOT button will toggle On/Off and replicate the new state to the M ## Returning to the Factory State -Holding the BOOT button pressed for more than 10 seconds and then releasing it will erase all Matter and WiFi configuration, forcing it to reset to factory state. After that, the device needs to be commissioned again. Previous setups done in the Smartphone APP won't work again; therefore, the virtual device shall be removed from the APP. +Holding the BOOT button pressed for more than 10 seconds and then releasing it will erase all Matter and Wi-Fi configuration, forcing it to reset to factory state. After that, the device needs to be commissioned again. Previous setups done in the Smartphone APP won't work again; therefore, the virtual device shall be removed from the APP. ## Building the Application using Wi-Fi and Matter From 7713e03f85b4ae76ea49240dbc3b39177a108a94 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:28:10 -0300 Subject: [PATCH 37/42] fix(matter): spell check ignore for CI --- idf_component_examples/esp_matter_light/main/matter_light.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index 61c63ad6dad..020acba2205 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -264,7 +264,7 @@ void setup() { 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_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id); // spell-check-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); From 9b55b765aa5c05c0625c91202d8ef18552d50632 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:29:00 +0000 Subject: [PATCH 38/42] ci(pre-commit): Apply automatic fixes --- idf_component_examples/esp_matter_light/main/matter_light.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index 020acba2205..3746b112ac7 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -264,7 +264,7 @@ void setup() { 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); // spell-check-ignore + attribute_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id); // spell-check-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); From 5b5a2a8410df081f34436fbb9998ca013987a9cb Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:32:58 -0300 Subject: [PATCH 39/42] fix(matter): spell check ignore for CI --- idf_component_examples/esp_matter_light/main/matter_light.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index 3746b112ac7..b4fb4789959 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -264,7 +264,8 @@ void setup() { 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); // spell-check-ignore + // spell-check-ignore + 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); From ca6344383b5c64fc0d4405234da5cb175fa8baa5 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:36:06 -0300 Subject: [PATCH 40/42] fix(matter): spell check ignore for CI --- idf_component_examples/esp_matter_light/main/matter_light.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index b4fb4789959..a56904a0cea 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -264,7 +264,7 @@ void setup() { 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); - // spell-check-ignore + // Ignore Spelling: CurrentY 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); From 9db98d39a72f9dd02847f8df317412cd41180bde Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Wed, 18 Sep 2024 08:43:40 -0300 Subject: [PATCH 41/42] fix(matter): spell check ignore for CI --- idf_component_examples/esp_matter_light/main/matter_light.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index a56904a0cea..3fb84753151 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -264,8 +264,7 @@ void setup() { 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); - // Ignore Spelling: CurrentY - attribute_t *current_y_attribute = attribute::get(color_control_cluster, ColorControl::Attributes::CurrentY::Id); + 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); From fef5da397553efed8a1060019ac720fceb0b7011 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Wed, 18 Sep 2024 11:44:27 +0000 Subject: [PATCH 42/42] ci(pre-commit): Apply automatic fixes --- idf_component_examples/esp_matter_light/main/matter_light.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idf_component_examples/esp_matter_light/main/matter_light.cpp b/idf_component_examples/esp_matter_light/main/matter_light.cpp index 3fb84753151..6079ce46add 100644 --- a/idf_component_examples/esp_matter_light/main/matter_light.cpp +++ b/idf_component_examples/esp_matter_light/main/matter_light.cpp @@ -264,7 +264,7 @@ void setup() { 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_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);