From 92fb3de8a8f255ea98fe79877e6784e3bf6738dd Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Wed, 21 Sep 2022 09:43:45 -0400 Subject: [PATCH 1/7] Respect $TMPDIR in chip-tool config (#22738) Some systems may have a different temporary directory. Respect this in chip-tool. --- examples/chip-tool/config/PersistentStorage.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/chip-tool/config/PersistentStorage.cpp b/examples/chip-tool/config/PersistentStorage.cpp index f8ceb248095709..62cf6efdfbd890 100644 --- a/examples/chip-tool/config/PersistentStorage.cpp +++ b/examples/chip-tool/config/PersistentStorage.cpp @@ -41,11 +41,19 @@ constexpr LogCategory kDefaultLoggingLevel = kLogCategory_Automation; std::string GetFilename(const char * name) { + const char * tmpdir = getenv("TMPDIR"); + + if (tmpdir == nullptr) + { + tmpdir = "/tmp"; + } + if (name == nullptr) { - return "/tmp/chip_tool_config.ini"; + return std::string(tmpdir) + "/chip_tool_config.ini"; } - return "/tmp/chip_tool_config." + std::string(name) + ".ini"; + + return std::string(tmpdir) + "/chip_tool_config." + std::string(name) + ".ini"; } CHIP_ERROR PersistentStorage::Init(const char * name) From d7df118a990032881e8ffc826c87cd2cba9880d3 Mon Sep 17 00:00:00 2001 From: panliming-tuya Date: Wed, 21 Sep 2022 21:47:07 +0800 Subject: [PATCH 2/7] Fix: Android commissioning complete crash (#22747) When the Thread device is set up first, operationalDatasetBytes has been released, but has not been assigned to nullptr. After setup a non-Thread device, ReleaseByteArrayElements will be called again, and a crash will occur --- src/controller/java/AndroidDeviceControllerWrapper.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/controller/java/AndroidDeviceControllerWrapper.cpp b/src/controller/java/AndroidDeviceControllerWrapper.cpp index f737e9bae81a34..922ad281936e00 100644 --- a/src/controller/java/AndroidDeviceControllerWrapper.cpp +++ b/src/controller/java/AndroidDeviceControllerWrapper.cpp @@ -439,6 +439,7 @@ void AndroidDeviceControllerWrapper::OnCommissioningComplete(NodeId deviceId, CH { env->ReleaseByteArrayElements(operationalDatasetBytes, operationalDataset, 0); env->DeleteGlobalRef(operationalDatasetBytes); + operationalDatasetBytes = nullptr; } } From 4ea64ddcb3306d94dd0126b2f70b08f0ad84e321 Mon Sep 17 00:00:00 2001 From: Timothy Maes Date: Wed, 21 Sep 2022 16:55:38 +0200 Subject: [PATCH 3/7] * Allow overrule of PID/VID/Version at build time (#22787) Used for customer development and simple OTA test image creation --- .../qpg/include/CHIPProjectConfig.h | 4 ++ .../lock-app/qpg/include/CHIPProjectConfig.h | 4 ++ examples/persistent-storage/qpg/BUILD.gn | 1 + .../qpg/include/CHIPProjectConfig.h | 4 ++ .../shell/qpg/include/CHIPProjectConfig.h | 4 ++ third_party/qpg_sdk/qpg_executable.gni | 42 +++++++++++++++++++ 6 files changed, 59 insertions(+) mode change 100755 => 100644 examples/lighting-app/qpg/include/CHIPProjectConfig.h mode change 100755 => 100644 examples/lock-app/qpg/include/CHIPProjectConfig.h mode change 100755 => 100644 examples/persistent-storage/qpg/include/CHIPProjectConfig.h diff --git a/examples/lighting-app/qpg/include/CHIPProjectConfig.h b/examples/lighting-app/qpg/include/CHIPProjectConfig.h old mode 100755 new mode 100644 index 4ad78040b734f0..98f0f4f8992918 --- a/examples/lighting-app/qpg/include/CHIPProjectConfig.h +++ b/examples/lighting-app/qpg/include/CHIPProjectConfig.h @@ -49,14 +49,18 @@ * * 0xFFF1: Test Vendor. */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID #define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 +#endif // CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID /** * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID * * 0x8005: example lighting app */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8005 +#endif // CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION diff --git a/examples/lock-app/qpg/include/CHIPProjectConfig.h b/examples/lock-app/qpg/include/CHIPProjectConfig.h old mode 100755 new mode 100644 index eab7fbbc758070..cd3121bab0be33 --- a/examples/lock-app/qpg/include/CHIPProjectConfig.h +++ b/examples/lock-app/qpg/include/CHIPProjectConfig.h @@ -47,14 +47,18 @@ * * 0xFFF1: Test vendor. */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID #define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 +#endif // CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID /** * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID * * 0x8006: example lock-app */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8006 +#endif // CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION diff --git a/examples/persistent-storage/qpg/BUILD.gn b/examples/persistent-storage/qpg/BUILD.gn index 355f4bb2a6865b..683a5ede278cff 100644 --- a/examples/persistent-storage/qpg/BUILD.gn +++ b/examples/persistent-storage/qpg/BUILD.gn @@ -38,6 +38,7 @@ qpg_executable("persistent_storage_app") { output_name = "chip-${qpg_target_ic}-persistent_storage-example.out" deps = [] + defines = [] public_deps = [ ":sdk", diff --git a/examples/persistent-storage/qpg/include/CHIPProjectConfig.h b/examples/persistent-storage/qpg/include/CHIPProjectConfig.h old mode 100755 new mode 100644 index ea44ed3d315329..e3de1e833ec4c6 --- a/examples/persistent-storage/qpg/include/CHIPProjectConfig.h +++ b/examples/persistent-storage/qpg/include/CHIPProjectConfig.h @@ -45,14 +45,18 @@ * * 0xFFF1: Test vendor. */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID #define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 +#endif // CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID /** * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID * * 0x8009: example persistent-storage */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8009 +#endif // CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION diff --git a/examples/shell/qpg/include/CHIPProjectConfig.h b/examples/shell/qpg/include/CHIPProjectConfig.h index 3df895ea838856..8656d8ae542fbf 100644 --- a/examples/shell/qpg/include/CHIPProjectConfig.h +++ b/examples/shell/qpg/include/CHIPProjectConfig.h @@ -51,14 +51,18 @@ * * 0xFFF1: Test vendor. */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID #define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 +#endif // CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID /** * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID * * 0x8009: example shell */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID #define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8012 +#endif // CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID /** * CHIP_DEVICE_CONFIG_DEVICE_HARDWARE_VERSION diff --git a/third_party/qpg_sdk/qpg_executable.gni b/third_party/qpg_sdk/qpg_executable.gni index 4950939182b1b4..b7f3fe2dc4eedb 100644 --- a/third_party/qpg_sdk/qpg_executable.gni +++ b/third_party/qpg_sdk/qpg_executable.gni @@ -19,6 +19,13 @@ import("${build_root}/toolchain/flashable_executable.gni") import("${chip_root}/src/platform/device.gni") import("qpg_sdk.gni") +declare_args() { + matter_device_vid = "" + matter_device_pid = "" + matter_device_software_version_string = "" + matter_device_software_version = "" +} + # Run the generator script that takes a .HEX file and adds the OTA header to it. # # This requires a Python script, given by ota_header_generator, @@ -66,6 +73,25 @@ template("qpg_executable") { objcopy_image_format = "ihex" objcopy = "arm-none-eabi-objcopy" + defines = [] + if (defined(invoker.defines)) { + defines += invoker.defines + } + + # Overrule CHIPProjectConfig.h settings + if (matter_device_vid != "") { + defines += [ "CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID=${matter_device_vid}" ] + } + if (matter_device_pid != "") { + defines += [ "CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID=${matter_device_pid}" ] + } + if (matter_device_software_version_string != "") { + defines += [ "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING=\"${matter_device_software_version_string}\"" ] + } + if (matter_device_software_version != "") { + defines += [ "CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION=${matter_device_software_version}" ] + } + # Copy flashing dependencies to the output directory so that the output # is collectively self-contained; this allows flashing to work reliably # even if the build and flashing steps take place on different machines @@ -124,6 +150,22 @@ template("qpg_executable") { "--pem_password=test1234", "--sign", ] + + # Use build-time overrules in OTA header creation + # Normally taken from CHIPProjectConfig.h by scripting + if (matter_device_vid != "") { + ota_header_options += [ "-vid=${matter_device_vid}" ] + } + if (matter_device_pid != "") { + ota_header_options += [ "-pid=${matter_device_pid}" ] + } + if (matter_device_software_version != "") { + ota_header_options += [ "-vn=${matter_device_software_version}" ] + } + if (matter_device_software_version_string != "") { + ota_header_options += + [ "-vs=\"${matter_device_software_version_string}\"" ] + } deps = [ ":$executable_target_name" ] } } From 04591702c9d27b11794cf5f7825ab8bb3e5e97ee Mon Sep 17 00:00:00 2001 From: Bill Waters <65681039+billwatersiii@users.noreply.github.com> Date: Wed, 21 Sep 2022 10:01:44 -0700 Subject: [PATCH 4/7] [Infineon] fix to factory reset button behavior (#22746) * fix to factory reset button behavior * Restyled by whitespace * Restyled by clang-format Co-authored-by: Restyled.io --- .../all-clusters-app/infineon/psoc6/include/AppConfig.h | 2 +- .../all-clusters-app/infineon/psoc6/src/ButtonHandler.cpp | 6 +++--- .../infineon/psoc6/include/AppConfig.h | 2 +- .../infineon/psoc6/src/ButtonHandler.cpp | 6 +++--- examples/lighting-app/infineon/psoc6/include/AppConfig.h | 2 +- .../lighting-app/infineon/psoc6/src/ButtonHandler.cpp | 8 ++++---- examples/lock-app/infineon/psoc6/include/AppConfig.h | 2 +- examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp | 8 ++++---- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/examples/all-clusters-app/infineon/psoc6/include/AppConfig.h b/examples/all-clusters-app/infineon/psoc6/include/AppConfig.h index bffd31f0d8a23b..35e45a8aef4223 100644 --- a/examples/all-clusters-app/infineon/psoc6/include/AppConfig.h +++ b/examples/all-clusters-app/infineon/psoc6/include/AppConfig.h @@ -32,7 +32,7 @@ #define APP_LIGHT_BUTTON CYBSP_USER_BTN1 #define APP_FUNCTION_BUTTON CYBSP_USER_BTN2 -#define APP_BUTTON_DEBOUNCE_PERIOD_MS 200 +#define APP_BUTTON_MIN_ASSERT_TIME_MS 30 #define APP_BUTTON_PRESSED 0 #define APP_BUTTON_RELEASED 1 diff --git a/examples/all-clusters-app/infineon/psoc6/src/ButtonHandler.cpp b/examples/all-clusters-app/infineon/psoc6/src/ButtonHandler.cpp index 56c088b46ad83d..7d65fc4134625e 100644 --- a/examples/all-clusters-app/infineon/psoc6/src/ButtonHandler.cpp +++ b/examples/all-clusters-app/infineon/psoc6/src/ButtonHandler.cpp @@ -38,7 +38,7 @@ void ButtonHandler::Init(void) for (uint8_t i = 0; i < kButtonCount; i++) { buttonTimers[i] = xTimerCreate("BtnTmr", // Just a text name, not used by the RTOS kernel - APP_BUTTON_DEBOUNCE_PERIOD_MS, // timer period + APP_BUTTON_MIN_ASSERT_TIME_MS, // timer period false, // no timer reload (==one-shot) (void *) (int) i, // init timer id = button index TimerCallback // timer callback handler (all buttons use @@ -90,7 +90,7 @@ void ButtonHandler::TimerCallback(TimerHandle_t xTimer) { // Get the button index of the expired timer and call button event helper. uint32_t timerId; - uint8_t buttonevent = 0; + uint8_t buttonevent = 1; timerId = (uint32_t) pvTimerGetTimerID(xTimer); switch (timerId) @@ -106,7 +106,7 @@ void ButtonHandler::TimerCallback(TimerHandle_t xTimer) break; } - if (buttonevent) + if (!buttonevent) { GetAppTask().ButtonEventHandler(timerId, APP_BUTTON_PRESSED); } diff --git a/examples/all-clusters-minimal-app/infineon/psoc6/include/AppConfig.h b/examples/all-clusters-minimal-app/infineon/psoc6/include/AppConfig.h index bffd31f0d8a23b..35e45a8aef4223 100644 --- a/examples/all-clusters-minimal-app/infineon/psoc6/include/AppConfig.h +++ b/examples/all-clusters-minimal-app/infineon/psoc6/include/AppConfig.h @@ -32,7 +32,7 @@ #define APP_LIGHT_BUTTON CYBSP_USER_BTN1 #define APP_FUNCTION_BUTTON CYBSP_USER_BTN2 -#define APP_BUTTON_DEBOUNCE_PERIOD_MS 200 +#define APP_BUTTON_MIN_ASSERT_TIME_MS 30 #define APP_BUTTON_PRESSED 0 #define APP_BUTTON_RELEASED 1 diff --git a/examples/all-clusters-minimal-app/infineon/psoc6/src/ButtonHandler.cpp b/examples/all-clusters-minimal-app/infineon/psoc6/src/ButtonHandler.cpp index 56c088b46ad83d..7d65fc4134625e 100644 --- a/examples/all-clusters-minimal-app/infineon/psoc6/src/ButtonHandler.cpp +++ b/examples/all-clusters-minimal-app/infineon/psoc6/src/ButtonHandler.cpp @@ -38,7 +38,7 @@ void ButtonHandler::Init(void) for (uint8_t i = 0; i < kButtonCount; i++) { buttonTimers[i] = xTimerCreate("BtnTmr", // Just a text name, not used by the RTOS kernel - APP_BUTTON_DEBOUNCE_PERIOD_MS, // timer period + APP_BUTTON_MIN_ASSERT_TIME_MS, // timer period false, // no timer reload (==one-shot) (void *) (int) i, // init timer id = button index TimerCallback // timer callback handler (all buttons use @@ -90,7 +90,7 @@ void ButtonHandler::TimerCallback(TimerHandle_t xTimer) { // Get the button index of the expired timer and call button event helper. uint32_t timerId; - uint8_t buttonevent = 0; + uint8_t buttonevent = 1; timerId = (uint32_t) pvTimerGetTimerID(xTimer); switch (timerId) @@ -106,7 +106,7 @@ void ButtonHandler::TimerCallback(TimerHandle_t xTimer) break; } - if (buttonevent) + if (!buttonevent) { GetAppTask().ButtonEventHandler(timerId, APP_BUTTON_PRESSED); } diff --git a/examples/lighting-app/infineon/psoc6/include/AppConfig.h b/examples/lighting-app/infineon/psoc6/include/AppConfig.h index b199aaf7a1b4d5..21b9e9467263fa 100644 --- a/examples/lighting-app/infineon/psoc6/include/AppConfig.h +++ b/examples/lighting-app/infineon/psoc6/include/AppConfig.h @@ -31,7 +31,7 @@ #define APP_LIGHT_BUTTON CYBSP_USER_BTN1 #define APP_FUNCTION_BUTTON CYBSP_USER_BTN2 -#define APP_BUTTON_DEBOUNCE_PERIOD_MS 200 +#define APP_BUTTON_MIN_ASSERT_TIME_MS 30 #define APP_BUTTON_PRESSED 0 #define APP_BUTTON_RELEASED 1 diff --git a/examples/lighting-app/infineon/psoc6/src/ButtonHandler.cpp b/examples/lighting-app/infineon/psoc6/src/ButtonHandler.cpp index e4a0d483d20c69..a722ea001e4fa6 100644 --- a/examples/lighting-app/infineon/psoc6/src/ButtonHandler.cpp +++ b/examples/lighting-app/infineon/psoc6/src/ButtonHandler.cpp @@ -37,7 +37,7 @@ void ButtonHandler::Init(void) for (uint8_t i = 0; i < kButtonCount; i++) { buttonTimers[i] = xTimerCreate("BtnTmr", // Just a text name, not used by the RTOS kernel - APP_BUTTON_DEBOUNCE_PERIOD_MS, // timer period + APP_BUTTON_MIN_ASSERT_TIME_MS, // timer period false, // no timer reload (==one-shot) (void *) (int) i, // init timer id = button index TimerCallback // timer callback handler (all buttons use @@ -88,8 +88,8 @@ void ButtonHandler::TimerCallback(TimerHandle_t xTimer) { // Get the button index of the expired timer and call button event helper. uint32_t timerId; - uint8_t buttonevent = 0; - timerId = (uint32_t) pvTimerGetTimerID(xTimer); + uint8_t buttonevent; + timerId = (uint32_t) pvTimerGetTimerID(xTimer); if (timerId) { buttonevent = cyhal_gpio_read(APP_FUNCTION_BUTTON); @@ -98,7 +98,7 @@ void ButtonHandler::TimerCallback(TimerHandle_t xTimer) { buttonevent = cyhal_gpio_read(APP_LIGHT_BUTTON); } - if (buttonevent) + if (!buttonevent) { GetAppTask().ButtonEventHandler(timerId, APP_BUTTON_PRESSED); } diff --git a/examples/lock-app/infineon/psoc6/include/AppConfig.h b/examples/lock-app/infineon/psoc6/include/AppConfig.h index 5e9c988a389a8f..f20ca007a5a3fc 100644 --- a/examples/lock-app/infineon/psoc6/include/AppConfig.h +++ b/examples/lock-app/infineon/psoc6/include/AppConfig.h @@ -31,7 +31,7 @@ #define APP_LOCK_BUTTON CYBSP_USER_BTN1 #define APP_FUNCTION_BUTTON CYBSP_USER_BTN2 -#define APP_BUTTON_DEBOUNCE_PERIOD_MS 200 +#define APP_BUTTON_MIN_ASSERT_TIME_MS 30 #define APP_BUTTON_PRESSED 0 #define APP_BUTTON_RELEASED 1 diff --git a/examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp b/examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp index 20a7c6bce7d1c0..2eea4c760a20f9 100644 --- a/examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp +++ b/examples/lock-app/infineon/psoc6/src/ButtonHandler.cpp @@ -36,7 +36,7 @@ void ButtonHandler::Init(void) for (uint8_t i = 0; i < kButtonCount; i++) { buttonTimers[i] = xTimerCreate("BtnTmr", // Just a text name, not used by the RTOS kernel - APP_BUTTON_DEBOUNCE_PERIOD_MS, // timer period + APP_BUTTON_MIN_ASSERT_TIME_MS, // timer period false, // no timer reload (==one-shot) (void *) (int) i, // init timer id = button index TimerCallback // timer callback handler (all buttons use @@ -87,8 +87,8 @@ void ButtonHandler::TimerCallback(TimerHandle_t xTimer) { // Get the button index of the expired timer and call button event helper. uint32_t timerId; - uint8_t buttonevent = 0; - timerId = (uint32_t) pvTimerGetTimerID(xTimer); + uint8_t buttonevent; + timerId = (uint32_t) pvTimerGetTimerID(xTimer); if (timerId) { buttonevent = cyhal_gpio_read(APP_FUNCTION_BUTTON); @@ -98,7 +98,7 @@ void ButtonHandler::TimerCallback(TimerHandle_t xTimer) buttonevent = cyhal_gpio_read(APP_LOCK_BUTTON); } - if (buttonevent) + if (!buttonevent) { GetAppTask().ButtonEventHandler(timerId, APP_BUTTON_PRESSED); } From 9bb2f53932fd04586108b0a8591484308a85e532 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 21 Sep 2022 13:02:34 -0400 Subject: [PATCH 5/7] Fix use-after-free in CommissioningWindowOpener. (#22767) Once we call back into our client, it can delete us, so we need to do any logging that uses `mSetupPayload` before we do that. Fixes https://github.com/project-chip/connectedhomeip/issues/22765 --- src/controller/CommissioningWindowOpener.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/controller/CommissioningWindowOpener.cpp b/src/controller/CommissioningWindowOpener.cpp index 689717ba9397e7..f2beabc8d3c750 100644 --- a/src/controller/CommissioningWindowOpener.cpp +++ b/src/controller/CommissioningWindowOpener.cpp @@ -204,9 +204,6 @@ void CommissioningWindowOpener::OnOpenCommissioningWindowSuccess(void * context, self->mNextStep = Step::kAcceptCommissioningStart; if (self->mCommissioningWindowCallback != nullptr) { - self->mCommissioningWindowCallback->mCall(self->mCommissioningWindowCallback->mContext, self->mNodeId, CHIP_NO_ERROR, - self->mSetupPayload); - char payloadBuffer[QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1]; MutableCharSpan manualCode(payloadBuffer); @@ -230,11 +227,18 @@ void CommissioningWindowOpener::OnOpenCommissioningWindowSuccess(void * context, { ChipLogError(Controller, "Unable to generate QR code for setup payload: %" CHIP_ERROR_FORMAT, err.Format()); } + + self->mCommissioningWindowCallback->mCall(self->mCommissioningWindowCallback->mContext, self->mNodeId, CHIP_NO_ERROR, + self->mSetupPayload); + // Don't touch `self` anymore; it might have been destroyed by the + // callee. } else if (self->mBasicCommissioningWindowCallback != nullptr) { self->mBasicCommissioningWindowCallback->mCall(self->mBasicCommissioningWindowCallback->mContext, self->mNodeId, CHIP_NO_ERROR); + // Don't touch `self` anymore; it might have been destroyed by the + // callee. } } From c0f9a8140808acfbab6e84f1faa44f00fa8dfe6c Mon Sep 17 00:00:00 2001 From: AlvinHsiao Date: Thu, 22 Sep 2022 01:06:03 +0800 Subject: [PATCH 6/7] [Infineon] Update CSP to reduce the openthread stack suspending time (#22754) --- third_party/infineon/cyw30739_sdk/repos/30739A0 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/third_party/infineon/cyw30739_sdk/repos/30739A0 b/third_party/infineon/cyw30739_sdk/repos/30739A0 index 0b1cbd5ad614be..85a07264df8533 160000 --- a/third_party/infineon/cyw30739_sdk/repos/30739A0 +++ b/third_party/infineon/cyw30739_sdk/repos/30739A0 @@ -1 +1 @@ -Subproject commit 0b1cbd5ad614be9b315f3bd4e1b8512df2c4502f +Subproject commit 85a07264df8533e8eaea85e340a98b4e648adfa1 From 388c27cc112470f7cdeb38413c453a68dbb86c35 Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Wed, 21 Sep 2022 20:06:41 +0300 Subject: [PATCH 7/7] [Telink] TC-OO-2.4 test fix (#22756) * [Telink] TC-OO-2.4 test fix * [Telink] Restyled --- .../telink/include/LightingManager.h | 12 +++++---- examples/lighting-app/telink/src/AppTask.cpp | 27 +++++++++++-------- .../telink/src/LightingManager.cpp | 19 ++++++++----- .../lighting-app/telink/src/ZclCallbacks.cpp | 24 +++++++++++++---- 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/examples/lighting-app/telink/include/LightingManager.h b/examples/lighting-app/telink/include/LightingManager.h index fdcd37cb4c70d7..2af544ada8625b 100644 --- a/examples/lighting-app/telink/include/LightingManager.h +++ b/examples/lighting-app/telink/include/LightingManager.h @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2022 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -45,17 +45,20 @@ class LightingManager using LightingCallback_fn = void (*)(Action_t, int32_t); - CHIP_ERROR Init(const device * pwmDevice, uint32_t pwmChannel); + CHIP_ERROR Init(const device * pwmDevice, uint32_t pwmChannel, uint8_t aMinLevel, uint8_t aMaxLevel, uint8_t aDefaultLevel = 0); + void Set(bool aOn); bool IsTurnedOn() const { return mState == kState_On; } uint8_t GetLevel() const { return mLevel; } + uint8_t GetMinLevel() const { return mMinLevel; } + uint8_t GetMaxLevel() const { return mMaxLevel; } bool InitiateAction(Action_t aAction, int32_t aActor, uint8_t size, uint8_t * value); void SetCallbacks(LightingCallback_fn aActionInitiated_CB, LightingCallback_fn aActionCompleted_CB); private: - static constexpr uint8_t kMaxLevel = 254; - friend LightingManager & LightingMgr(); State_t mState; + uint8_t mMinLevel; + uint8_t mMaxLevel; uint8_t mLevel; const device * mPwmDevice; uint32_t mPwmChannel; @@ -63,7 +66,6 @@ class LightingManager LightingCallback_fn mActionInitiated_CB; LightingCallback_fn mActionCompleted_CB; - void Set(bool aOn); void SetLevel(uint8_t aLevel); void UpdateLight(); diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp index f882c72a749bca..5c537b26a0d39e 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2022 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -62,6 +63,8 @@ namespace { constexpr int kAppEventQueueSize = 10; constexpr uint8_t kButtonPushEvent = 1; constexpr uint8_t kButtonReleaseEvent = 0; +constexpr uint8_t kDefaultMinLevel = 0; +constexpr uint8_t kDefaultMaxLevel = 254; K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), kAppEventQueueSize, alignof(AppEvent)); @@ -112,6 +115,8 @@ Identify sIdentify = { } // namespace +using namespace ::chip; +using namespace ::chip::app; using namespace ::chip::Credentials; using namespace ::chip::DeviceLayer; using namespace ::chip::DeviceLayer::Internal; @@ -134,13 +139,18 @@ CHIP_ERROR AppTask::Init() InitButtons(); // Init lighting manager - ret = LightingMgr().Init(LIGHTING_PWM_DEVICE, LIGHTING_PWM_CHANNEL); + uint8_t minLightLevel = kDefaultMinLevel; + Clusters::LevelControl::Attributes::MinLevel::Get(1, &minLightLevel); + + uint8_t maxLightLevel = kDefaultMaxLevel; + Clusters::LevelControl::Attributes::MaxLevel::Get(1, &maxLightLevel); + + ret = LightingMgr().Init(LIGHTING_PWM_DEVICE, LIGHTING_PWM_CHANNEL, minLightLevel, maxLightLevel, maxLightLevel); if (ret != CHIP_NO_ERROR) { LOG_ERR("Failed to int lighting manager"); return ret; } - LightingMgr().SetCallbacks(ActionInitiated, ActionCompleted); // Init ZCL Data Model and start server @@ -422,20 +432,15 @@ void AppTask::DispatchEvent(AppEvent * aEvent) void AppTask::UpdateClusterState() { - uint8_t onoff = LightingMgr().IsTurnedOn(); - // write the new on/off value - EmberAfStatus status = - emberAfWriteAttribute(1, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, &onoff, ZCL_BOOLEAN_ATTRIBUTE_TYPE); + EmberAfStatus status = Clusters::OnOff::Attributes::OnOff::Set(1, LightingMgr().IsTurnedOn()); + if (status != EMBER_ZCL_STATUS_SUCCESS) { LOG_ERR("Updating on/off cluster failed: %x", status); } - uint8_t level = LightingMgr().GetLevel(); - - status = - emberAfWriteAttribute(1, ZCL_LEVEL_CONTROL_CLUSTER_ID, ZCL_CURRENT_LEVEL_ATTRIBUTE_ID, &level, ZCL_INT8U_ATTRIBUTE_TYPE); + status = Clusters::LevelControl::Attributes::CurrentLevel::Set(1, LightingMgr().GetLevel()); if (status != EMBER_ZCL_STATUS_SUCCESS) { diff --git a/examples/lighting-app/telink/src/LightingManager.cpp b/examples/lighting-app/telink/src/LightingManager.cpp index d0e729f66a3dd5..c89bbf6bf25aa2 100644 --- a/examples/lighting-app/telink/src/LightingManager.cpp +++ b/examples/lighting-app/telink/src/LightingManager.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2022 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -20,6 +20,8 @@ #include "AppConfig.h" +#include + #include #include #include @@ -28,13 +30,16 @@ LOG_MODULE_DECLARE(app); LightingManager LightingManager::sLight; -CHIP_ERROR LightingManager::Init(const device * pwmDevice, uint32_t pwmChannel) +CHIP_ERROR LightingManager::Init(const device * pwmDevice, uint32_t pwmChannel, uint8_t aMinLevel, uint8_t aMaxLevel, + uint8_t aDefaultLevel) { // We use a gpioPin instead of a LEDWidget here because we want to use PWM // and other features instead of just on/off. mState = kState_On; - mLevel = kMaxLevel; + mMinLevel = aMinLevel; + mMaxLevel = aMaxLevel; + mLevel = aDefaultLevel; mPwmDevice = pwmDevice; mPwmChannel = pwmChannel; @@ -123,7 +128,9 @@ void LightingManager::Set(bool aOn) void LightingManager::UpdateLight() { - constexpr uint32_t kPwmWidthUs = 20000u; - const uint8_t level = mState == kState_On ? mLevel : 0; - pwm_pin_set_usec(mPwmDevice, mPwmChannel, kPwmWidthUs, kPwmWidthUs * level / kMaxLevel, 0); + constexpr uint32_t kPwmWidthUs = 20000u; + const uint8_t maxEffectiveLevel = mMaxLevel - mMinLevel; + const uint8_t effectiveLevel = mState == kState_On ? chip::min(mLevel - mMinLevel, maxEffectiveLevel) : 0; + + pwm_pin_set_usec(mPwmDevice, mPwmChannel, kPwmWidthUs, kPwmWidthUs * effectiveLevel / maxEffectiveLevel, 0); } diff --git a/examples/lighting-app/telink/src/ZclCallbacks.cpp b/examples/lighting-app/telink/src/ZclCallbacks.cpp index 2c315f8e897b17..83a5d7a0a67ba9 100644 --- a/examples/lighting-app/telink/src/ZclCallbacks.cpp +++ b/examples/lighting-app/telink/src/ZclCallbacks.cpp @@ -1,6 +1,6 @@ /* * - * Copyright (c) 2021 Project CHIP Authors + * Copyright (c) 2022 Project CHIP Authors * All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,6 +19,7 @@ #include "AppTask.h" #include "LightingManager.h" +#include #include #include #include @@ -26,29 +27,31 @@ using namespace chip; using namespace chip::app::Clusters; +using namespace chip::app::Clusters::OnOff; void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value) { ClusterId clusterId = attributePath.mClusterId; AttributeId attributeId = attributePath.mAttributeId; - ChipLogProgress(Zcl, "Cluster callback: " ChipLogFormatMEI, ChipLogValueMEI(clusterId)); if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id) { + ChipLogProgress(Zcl, "Cluster OnOff: attribute OnOff set to %u", *value); LightingMgr().InitiateAction(*value ? LightingManager::ON_ACTION : LightingManager::OFF_ACTION, AppEvent::kEventType_Lighting, size, value); } else if (clusterId == LevelControl::Id && attributeId == LevelControl::Attributes::CurrentLevel::Id) { - ChipLogProgress(Zcl, "Value: %u, length %u", *value, size); - if (size == 1) + ChipLogProgress(Zcl, "Cluster LevelControl: attribute CurrentLevel set to %u", *value); + + if (LightingMgr().IsTurnedOn()) { LightingMgr().InitiateAction(LightingManager::LEVEL_ACTION, AppEvent::kEventType_Lighting, size, value); } else { - ChipLogError(Zcl, "wrong length for level: %d", size); + ChipLogDetail(Zcl, "LED is off. Try to use move-to-level-with-on-off instead of move-to-level"); } } } @@ -64,5 +67,16 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & */ void emberAfOnOffClusterInitCallback(EndpointId endpoint) { + EmberAfStatus status; + bool storedValue; + + // Read storedValue on/off value + status = Attributes::OnOff::Get(1, &storedValue); + if (status == EMBER_ZCL_STATUS_SUCCESS) + { + // Set actual state to stored before reboot + LightingMgr().Set(storedValue); + } + GetAppTask().UpdateClusterState(); }