From 0f9615d56605ab97e32c53d5cafd8a537666318b Mon Sep 17 00:00:00 2001 From: Seth Rickard Date: Tue, 23 Aug 2022 10:22:32 -0500 Subject: [PATCH 1/9] Update KVS to handle zero length elements (#21977) * allow for nullptr in KVS write * complete audit with chip_support_enable_storage_api_audit=true --- .../cc13x2_26x2/CC13X2_26X2Config.cpp | 83 +++++++++++-------- .../cc13x2_26x2/KeyValueStoreManagerImpl.cpp | 7 +- .../cc32xx/KeyValueStoreManagerImpl.cpp | 7 +- 3 files changed, 57 insertions(+), 40 deletions(-) diff --git a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp index 09e3393e07b1b1..8d25d6673f5ea1 100644 --- a/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp +++ b/src/platform/cc13x2_26x2/CC13X2_26X2Config.cpp @@ -28,6 +28,7 @@ #include #include +#include #include #include @@ -165,7 +166,7 @@ CHIP_ERROR CC13X2_26X2Config::ReadConfigValueBin(Key key, uint8_t * buf, size_t /* Iterate through the key range to find a key that matches. */ static uint8_t FindKVSSubID(const char * key, uint16_t & subID) { - char key_scratch[32]; // 32 characters seems large enough for a key + char key_scratch[PersistentStorageDelegate::kKeyLengthMax + 1]; NVINTF_nvProxy_t nvProxy = { 0 }; uint8_t status = NVINTF_SUCCESS; @@ -209,20 +210,23 @@ CHIP_ERROR CC13X2_26X2Config::ReadKVS(const char * key, void * value, size_t val val_item.subID = subID; len = sNvoctpFps.getItemLen(val_item); - VerifyOrExit(len > 0, err = CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND); // key not found - if ((offset_bytes + value_size) > len) + if (value_size >= (len - offset_bytes)) { - // trying to read up to the end of the element + // reading to end of element read_len = len - offset_bytes; } else { read_len = value_size; + err = CHIP_ERROR_BUFFER_TOO_SMALL; } - VerifyOrExit(sNvoctpFps.readItem(val_item, (uint16_t) offset_bytes, read_len, value) == NVINTF_SUCCESS, - err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + if (read_len > 0) + { + VerifyOrExit(sNvoctpFps.readItem(val_item, (uint16_t) offset_bytes, read_len, value) == NVINTF_SUCCESS, + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + } if (read_bytes_size) { @@ -264,22 +268,14 @@ CHIP_ERROR CC13X2_26X2Config::WriteKVS(const char * key, const void * value, siz CHIP_ERROR err = CHIP_NO_ERROR; uint16_t subID; - if (FindKVSSubID(key, subID) == NVINTF_SUCCESS) - { - NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; - // key already exists, update value - val_item.subID = subID; - VerifyOrExit(sNvoctpFps.updateItem(val_item, (uint16_t) value_size, (void *) value) == NVINTF_SUCCESS, - err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); - } - else + NVINTF_itemID_t key_item = CC13X2_26X2Config::kConfigKey_KVS_key.nvID; + NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; + + if (FindKVSSubID(key, subID) != NVINTF_SUCCESS) { - // key does not exist, likely case + // key item not found, find an empty subID intptr_t lock_key = sNvoctpFps.lockNV(); - NVINTF_itemID_t key_item = CC13X2_26X2Config::kConfigKey_KVS_key.nvID; - NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; - /* Iterate through the subID range to find an unused subID in the * keyspace. SubID is a 10 bit value, reference * `/source/ti/common/nv/nvocmp.c:MVOCMP_MAXSUBID`. @@ -289,26 +285,39 @@ CHIP_ERROR CC13X2_26X2Config::WriteKVS(const char * key, const void * value, siz key_item.subID = i; if (sNvoctpFps.getItemLen(key_item) == 0U) { - val_item.subID = i; + subID = i; break; } } + sNvoctpFps.unlockNV(lock_key); + // write they key item - if (sNvoctpFps.writeItem(key_item, (uint16_t) strlen(key), (void *) key) == NVINTF_SUCCESS) + VerifyOrExit(sNvoctpFps.writeItem(key_item, (uint16_t) strlen(key), (void *) key) == NVINTF_SUCCESS, + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED); + } + + key_item.subID = subID; + val_item.subID = subID; + + if (value_size == 0U) + { + // delete the value item if it exists + int8_t ret = sNvoctpFps.deleteItem(val_item); + if (ret != NVINTF_SUCCESS && ret != NVINTF_NOTFOUND) { - if (sNvoctpFps.writeItem(val_item, (uint16_t) value_size, (void *) value) != NVINTF_SUCCESS) - { - // try to delete the key item - sNvoctpFps.deleteItem(key_item); - err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; - } + err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; } - else + } + else + { + if (sNvoctpFps.writeItem(val_item, (uint16_t) value_size, (void *) value) != NVINTF_SUCCESS) { + // try to delete the key item + sNvoctpFps.deleteItem(key_item); err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; } - sNvoctpFps.unlockNV(lock_key); } + exit: return err; } @@ -325,25 +334,31 @@ CHIP_ERROR CC13X2_26X2Config::WriteConfigValueBin(Key key, const uint8_t * data, CHIP_ERROR CC13X2_26X2Config::ClearKVS(const char * key) { - CHIP_ERROR err = CHIP_NO_ERROR; + CHIP_ERROR err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; uint16_t subID; NVINTF_itemID_t key_item = CC13X2_26X2Config::kConfigKey_KVS_key.nvID; NVINTF_itemID_t val_item = CC13X2_26X2Config::kConfigKey_KVS_value.nvID; if (FindKVSSubID(key, subID) == NVINTF_SUCCESS) { + int8_t ret; + key_item.subID = subID; val_item.subID = subID; - // delete the value item - if (sNvoctpFps.deleteItem(val_item) != NVINTF_SUCCESS) + // delete the value item if it exists + ret = sNvoctpFps.deleteItem(val_item); + if (ret != NVINTF_SUCCESS && ret != NVINTF_NOTFOUND) { err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; } - // delete the key item - if (sNvoctpFps.deleteItem(key_item) != NVINTF_SUCCESS) + // delete the key item if it exists + ret = sNvoctpFps.deleteItem(key_item); + if (ret != NVINTF_SUCCESS && ret != NVINTF_NOTFOUND) { err = CHIP_ERROR_PERSISTED_STORAGE_FAILED; } + + err = CHIP_NO_ERROR; } return err; diff --git a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp b/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp index b74146c1de3704..5227b55e5e65df 100644 --- a/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp +++ b/src/platform/cc13x2_26x2/KeyValueStoreManagerImpl.cpp @@ -44,7 +44,10 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t CHIP_ERROR err; VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + if (0U != value_size) + { + VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + } err = CC13X2_26X2Config::ReadKVS(key, value, value_size, read_bytes_size, offset_bytes); @@ -58,8 +61,6 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size) { VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value_size > 0, CHIP_ERROR_INVALID_ARGUMENT); return CC13X2_26X2Config::WriteKVS(key, value, value_size); } diff --git a/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp b/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp index 13c1a023443594..ea0f2e546ce6c4 100644 --- a/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp +++ b/src/platform/cc32xx/KeyValueStoreManagerImpl.cpp @@ -42,7 +42,10 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t size_t offset_bytes) const { VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + if (0U != value_size) + { + VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); + } return CC32XXConfig::ReadKVS(key, value, value_size, read_bytes_size, offset_bytes); } @@ -50,8 +53,6 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value, size_t value_size) { VerifyOrReturnError(key, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT); - VerifyOrReturnError(value_size > 0, CHIP_ERROR_INVALID_ARGUMENT); return CC32XXConfig::WriteKVS(key, value, value_size); } From 8702d3ab976f06815e3f4d69d2f2a6bdda1852e4 Mon Sep 17 00:00:00 2001 From: Wang Qixiang <43193572+wqx6@users.noreply.github.com> Date: Tue, 23 Aug 2022 23:40:33 +0800 Subject: [PATCH 2/9] Support lighting-app on ESP32H2-beta2 with idf tag v5.0-beta1 (#22064) --- config/esp32/components/chip/CMakeLists.txt | 12 ++++++--- docs/guides/esp32/setup_idf_chip.md | 6 ++--- examples/lighting-app/esp32/main/Button.cpp | 18 +++++++++++++ .../lighting-app/esp32/main/CMakeLists.txt | 2 +- .../lighting-app/esp32/main/LEDWidget.cpp | 18 +++++++++++-- .../esp32/main/include/LEDWidget.h | 4 +++ .../esp32/sdkconfig.defaults.esp32h2 | 24 ++++++++---------- .../esp32/common/CommonDeviceCallbacks.cpp | 25 +++++++++++++++---- src/lib/shell/streamer_esp32.cpp | 6 ++++- src/platform/ESP32/ESP32Config.cpp | 6 +++++ src/platform/ESP32/OpenthreadLauncher.c | 2 +- src/platform/ESP32/nimble/BLEManagerImpl.cpp | 7 ++++-- 12 files changed, 98 insertions(+), 32 deletions(-) diff --git a/config/esp32/components/chip/CMakeLists.txt b/config/esp32/components/chip/CMakeLists.txt index 63dff3ee1f5589..74b79dffc93466 100644 --- a/config/esp32/components/chip/CMakeLists.txt +++ b/config/esp32/components/chip/CMakeLists.txt @@ -31,7 +31,11 @@ endif() include(${CMAKE_CURRENT_LIST_DIR}/ota-image.cmake) -set(CHIP_REQURIE_COMPONENTS freertos lwip bt mdns mbedtls fatfs app_update console openthread) +set(CHIP_REQURIE_COMPONENTS freertos lwip bt mbedtls fatfs app_update console openthread nvs_flash) + +if(NOT "${IDF_TARGET}" STREQUAL "esp32h2") + list(APPEND CHIP_REQURIE_COMPONENTS mdns) +endif() if (NOT CMAKE_BUILD_EARLY_EXPANSION) if (CONFIG_COMPILER_OPTIMIZATION_DEFAULT OR CONFIG_COMPILER_OPTIMIZATION_NONE) @@ -270,7 +274,9 @@ if(CONFIG_BT_ENABLED) idf_component_get_property(bt_lib bt COMPONENT_LIB) idf_component_get_property(bt_dir bt COMPONENT_DIR) list(APPEND chip_libraries $) - list(APPEND chip_libraries ${bt_dir}/controller/lib_esp32h2/esp32h2-bt-lib/libcontroller_5p0_seq.a) + if(CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2) + list(APPEND chip_libraries ${bt_dir}/controller/lib_esp32h2/esp32h2-bt-lib/beta2/libble_app.a) + endif() else() idf_component_get_property(bt_lib bt COMPONENT_LIB) list(APPEND chip_libraries $ -lbtdm_app) @@ -287,7 +293,7 @@ if(CONFIG_OPENTHREAD_ENABLED) list(APPEND chip_libraries $) endif() -if(NOT CONFIG_USE_MINIMAL_MDNS) +if(NOT CONFIG_USE_MINIMAL_MDNS AND NOT CONFIG_IDF_TARGET_ESP32H2) idf_component_get_property(mdns_lib mdns COMPONENT_LIB) list(APPEND chip_libraries $) endif() diff --git a/docs/guides/esp32/setup_idf_chip.md b/docs/guides/esp32/setup_idf_chip.md index acc001e67a6874..f6c7f649834fd7 100644 --- a/docs/guides/esp32/setup_idf_chip.md +++ b/docs/guides/esp32/setup_idf_chip.md @@ -39,13 +39,13 @@ step. $ ./install.sh ``` -- For ESP32H2, please checkout commit id - [10f3aba770](https://github.com/espressif/esp-idf/tree/10f3aba770), +- For ESP32H2, please checkout tag + [v5.0-beta1](https://github.com/espressif/esp-idf/tree/v5.0-beta1), currently only lighting-app is supported on H2 ``` $ cd esp-idf - $ git checkout 10f3aba770 + $ git checkout v5.0-beta1 $ git submodule update --init $ ./install.sh ``` diff --git a/examples/lighting-app/esp32/main/Button.cpp b/examples/lighting-app/esp32/main/Button.cpp index 73a3758818070f..aadae002bc2d08 100644 --- a/examples/lighting-app/esp32/main/Button.cpp +++ b/examples/lighting-app/esp32/main/Button.cpp @@ -1,4 +1,22 @@ +/* + * + * Copyright (c) 2022 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + #include "Button.h" +#include "esp_attr.h" #define GPIO_INPUT_IO_0 9 #define GPIO_INPUT_PIN_SEL (1ULL << GPIO_INPUT_IO_0) diff --git a/examples/lighting-app/esp32/main/CMakeLists.txt b/examples/lighting-app/esp32/main/CMakeLists.txt index 097f5ba8c41357..233b25d29ada1f 100644 --- a/examples/lighting-app/esp32/main/CMakeLists.txt +++ b/examples/lighting-app/esp32/main/CMakeLists.txt @@ -65,7 +65,7 @@ idf_component_register(PRIV_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-requestor" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server" "${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/group-key-mgmt-server" - PRIV_REQUIRES chip QRCode bt led_strip app_update openthread) + PRIV_REQUIRES chip QRCode bt led_strip app_update openthread driver nvs_flash) set_property(TARGET ${COMPONENT_LIB} PROPERTY CXX_STANDARD 17) target_compile_options(${COMPONENT_LIB} PRIVATE "-DCHIP_HAVE_CONFIG_H") diff --git a/examples/lighting-app/esp32/main/LEDWidget.cpp b/examples/lighting-app/esp32/main/LEDWidget.cpp index 12cbf0f6d3295a..bf2221b26446c9 100644 --- a/examples/lighting-app/esp32/main/LEDWidget.cpp +++ b/examples/lighting-app/esp32/main/LEDWidget.cpp @@ -17,6 +17,7 @@ #include "LEDWidget.h" #include "ColorFormat.h" +#include "led_strip.h" static const char * TAG = "LEDWidget"; @@ -26,6 +27,14 @@ void LEDWidget::Init(void) mBrightness = UINT8_MAX; #if CONFIG_LED_TYPE_RMT +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + led_strip_config_t strip_config = { + .strip_gpio_num = CONFIG_LED_GPIO, + .max_leds = 1, + }; + + led_strip_new_rmt_device(&strip_config, &mStrip); +#else rmt_config_t config = RMT_DEFAULT_CONFIG_TX((gpio_num_t) CONFIG_LED_GPIO, (rmt_channel_t) CONFIG_LED_RMT_CHANNEL); led_strip_config_t strip_config = LED_STRIP_DEFAULT_CONFIG(1, (led_strip_dev_t) config.channel); @@ -33,7 +42,8 @@ void LEDWidget::Init(void) rmt_config(&config); rmt_driver_install(config.channel, 0, 0); - mStrip = led_strip_new_rmt_ws2812(&strip_config); + mStrip = led_strip_new_rmt_ws2812(&strip_config); +#endif mHue = 0; mSaturation = 0; #else @@ -121,9 +131,13 @@ void LEDWidget::DoSet(void) { HsvColor_t hsv = { mHue, mSaturation, brightness }; RgbColor_t rgb = HsvToRgb(hsv); - +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + led_strip_set_pixel(mStrip, 0, rgb.r, rgb.g, rgb.b); + led_strip_refresh(mStrip); +#else mStrip->set_pixel(mStrip, 0, rgb.r, rgb.g, rgb.b); mStrip->refresh(mStrip, 100); +#endif } #else ESP_LOGI(TAG, "DoSet to GPIO number %d", mGPIONum); diff --git a/examples/lighting-app/esp32/main/include/LEDWidget.h b/examples/lighting-app/esp32/main/include/LEDWidget.h index c390d63ac1024f..f9d00a2b6882a9 100644 --- a/examples/lighting-app/esp32/main/include/LEDWidget.h +++ b/examples/lighting-app/esp32/main/include/LEDWidget.h @@ -50,7 +50,11 @@ class LEDWidget #if CONFIG_LED_TYPE_RMT uint8_t mHue; uint8_t mSaturation; +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + led_strip_handle_t mStrip; +#else led_strip_t * mStrip; +#endif #else gpio_num_t mGPIONum; #endif diff --git a/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 b/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 index 3a6d8da8ff4033..dc637d31dc7a2e 100644 --- a/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 +++ b/examples/lighting-app/esp32/sdkconfig.defaults.esp32h2 @@ -1,4 +1,5 @@ CONFIG_IDF_TARGET="esp32h2" +CONFIG_IDF_TARGET_ESP32H2_BETA_VERSION_2=y # Default to 921600 baud when flashing and monitoring device CONFIG_ESPTOOLPY_BAUD_921600B=y @@ -16,14 +17,9 @@ CONFIG_LIBSODIUM_USE_MBEDTLS_SHA=y # NIMBLE CONFIG_BT_ENABLED=y -CONFIG_BT_BLUEDROID_ENABLED=n CONFIG_BT_NIMBLE_ENABLED=y -CONFIG_BT_NIMBLE_50_FEATURE_SUPPORT=y CONFIG_BT_NIMBLE_EXT_ADV=n -CONFIG_BT_NIMBLE_USE_ESP_TIMER=n -CONFIG_BTDM_CTRL_MODE_BLE_ONLY=y -CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n -CONFIG_BTDM_CTRL_MODE_BTDM=n +CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE=70 CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE=n # Enable OpenThread @@ -45,22 +41,19 @@ CONFIG_LWIP_MULTICAST_PING=y CONFIG_MBEDTLS_HARDWARE_AES=n CONFIG_MBEDTLS_HARDWARE_MPI=n CONFIG_MBEDTLS_HARDWARE_SHA=n +CONFIG_MBEDTLS_HARDWARE_ECC=y CONFIG_MBEDTLS_ATCA_HW_ECDSA_SIGN=n CONFIG_MBEDTLS_ATCA_HW_ECDSA_VERIFY=n CONFIG_MBEDTLS_CMAC_C=y CONFIG_MBEDTLS_SSL_PROTO_DTLS=y CONFIG_MBEDTLS_KEY_EXCHANGE_ECJPAKE=y +# rtc clk for ble +# CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y + # MDNS platform CONFIG_USE_MINIMAL_MDNS=n - -# Increase stacks size -CONFIG_NIMBLE_CONTROLLER_TASK_STACK_SIZE=5120 -CONFIG_NIMBLE_HOST_TASK_STACK_SIZE=5120 - -# ESP32H2 BLE using a ext 32k crystal -CONFIG_ESP32H2_RTC_CLK_SRC_EXT_CRYS=y -CONFIG_ESP32H2_RTC_CLK_CAL_CYCLES=576 +CONFIG_ENABLE_EXTENDED_DISCOVERY=y # FreeRTOS should use legacy API CONFIG_FREERTOS_ENABLE_BACKWARD_COMPATIBILITY=y @@ -71,3 +64,6 @@ CONFIG_ENABLE_WIFI_AP=n # Enable OTA Requestor CONFIG_ENABLE_OTA_REQUESTOR=y + +# Enable chip shell +CONFIG_ENABLE_CHIP_SHELL=y diff --git a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp index e975dce62914f2..ba9eafc19c1397 100644 --- a/examples/platform/esp32/common/CommonDeviceCallbacks.cpp +++ b/examples/platform/esp32/common/CommonDeviceCallbacks.cpp @@ -20,7 +20,9 @@ #if CONFIG_BT_ENABLED #include "esp_bt.h" #if CONFIG_BT_NIMBLE_ENABLED +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include "esp_nimble_hci.h" +#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include "nimble/nimble_port.h" #endif // CONFIG_BT_NIMBLE_ENABLED #endif // CONFIG_BT_ENABLED @@ -45,6 +47,9 @@ using namespace chip::DeviceLayer; using namespace chip::System; DeviceCallbacksDelegate * appDelegate = nullptr; +#if CONFIG_ENABLE_OTA_REQUESTOR +static bool isOTAInitialized = false; +#endif void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, intptr_t arg) { @@ -62,17 +67,30 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i ESP_LOGI(TAG, "CHIPoBLE disconnected"); break; + case DeviceEventType::kThreadConnectivityChange: +#if CONFIG_ENABLE_OTA_REQUESTOR + if (event->ThreadConnectivityChange.Result == kConnectivity_Established && !isOTAInitialized) + { + OTAHelpers::Instance().InitOTARequestor(); + isOTAInitialized = true; + } +#endif + break; + case DeviceEventType::kCommissioningComplete: { ESP_LOGI(TAG, "Commissioning complete"); #if CONFIG_BT_NIMBLE_ENABLED && CONFIG_DEINIT_BLE_ON_COMMISSIONING_COMPLETE if (ble_hs_is_enabled()) { - int ret = nimble_port_stop(); + int ret = nimble_port_stop(); + esp_err_t err = ESP_OK; if (ret == 0) { nimble_port_deinit(); - esp_err_t err = esp_nimble_hci_and_controller_deinit(); +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) + err = esp_nimble_hci_and_controller_deinit(); +#endif // ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) err += esp_bt_mem_release(ESP_BT_MODE_BLE); if (err == ESP_OK) { @@ -114,9 +132,6 @@ void CommonDeviceCallbacks::DeviceEventCallback(const ChipDeviceEvent * event, i void CommonDeviceCallbacks::OnInternetConnectivityChange(const ChipDeviceEvent * event) { -#if CONFIG_ENABLE_OTA_REQUESTOR - static bool isOTAInitialized = false; -#endif appDelegate = DeviceCallbacksDelegate::Instance().GetAppDelegate(); if (event->InternetConnectivityChange.IPv4 == kConnectivity_Established) { diff --git a/src/lib/shell/streamer_esp32.cpp b/src/lib/shell/streamer_esp32.cpp index c35abed55c5eb0..7d51afd7399cbe 100644 --- a/src/lib/shell/streamer_esp32.cpp +++ b/src/lib/shell/streamer_esp32.cpp @@ -62,7 +62,11 @@ int streamer_esp32_init(streamer_t * streamer) .stop_bits = UART_STOP_BITS_1, .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, .rx_flow_ctrl_thresh = 0, - .source_clk = UART_SCLK_APB, +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + .source_clk = UART_SCLK_DEFAULT, +#else + .source_clk = UART_SCLK_APB, +#endif }; ESP_ERROR_CHECK(uart_param_config(CONFIG_ESP_CONSOLE_UART_NUM, &uart_config)); esp_vfs_dev_uart_use_driver(0); diff --git a/src/platform/ESP32/ESP32Config.cpp b/src/platform/ESP32/ESP32Config.cpp index 537ec90375c754..dc65ab772d696d 100644 --- a/src/platform/ESP32/ESP32Config.cpp +++ b/src/platform/ESP32/ESP32Config.cpp @@ -353,8 +353,14 @@ CHIP_ERROR ESP32Config::ClearConfigValue(Key key) bool ESP32Config::ConfigValueExists(Key key) { +#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) + nvs_iterator_t iterator = NULL; + esp_err_t err = nvs_entry_find(NVS_DEFAULT_PART_NAME, key.Namespace, NVS_TYPE_ANY, &iterator); + for (; iterator && err == ESP_OK; err = nvs_entry_next(&iterator)) +#else nvs_iterator_t iterator = nvs_entry_find(NVS_DEFAULT_PART_NAME, key.Namespace, NVS_TYPE_ANY); for (; iterator; iterator = nvs_entry_next(iterator)) +#endif { nvs_entry_info_t info; nvs_entry_info(iterator, &info); diff --git a/src/platform/ESP32/OpenthreadLauncher.c b/src/platform/ESP32/OpenthreadLauncher.c index c9ef95fb5cb4de..c1ad467e032174 100644 --- a/src/platform/ESP32/OpenthreadLauncher.c +++ b/src/platform/ESP32/OpenthreadLauncher.c @@ -53,7 +53,7 @@ static void ot_task_worker(void * context) // Initialize the OpenThread stack ESP_ERROR_CHECK(esp_openthread_init(&config)); // The OpenThread log level directly matches ESP log level - (void) otLoggingSetLevel(OT_LOG_LEVEL_INFO); + (void) otLoggingSetLevel(CONFIG_LOG_DEFAULT_LEVEL); // Initialize the esp_netif bindings openthread_netif = init_openthread_netif(&config); diff --git a/src/platform/ESP32/nimble/BLEManagerImpl.cpp b/src/platform/ESP32/nimble/BLEManagerImpl.cpp index 2cf626c1751c50..b4459196fd9baa 100644 --- a/src/platform/ESP32/nimble/BLEManagerImpl.cpp +++ b/src/platform/ESP32/nimble/BLEManagerImpl.cpp @@ -40,7 +40,9 @@ #include #include "esp_log.h" +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) #include "esp_nimble_hci.h" +#endif #include "host/ble_hs.h" #include "host/ble_hs_pvcy.h" #include "host/ble_uuid.h" @@ -152,7 +154,7 @@ CHIP_ERROR BLEManagerImpl::_Init() mFlags.ClearAll().Set(Flags::kAdvertisingEnabled, CHIP_DEVICE_CONFIG_CHIPOBLE_ENABLE_ADVERTISING_AUTOSTART); mFlags.Set(Flags::kFastAdvertisingEnabled, true); mNumGAPCons = 0; - memset(mCons, 0, sizeof(mCons)); + memset(reinterpret_cast(mCons), 0, sizeof(mCons)); mServiceMode = ConnectivityManager::kCHIPoBLEServiceMode_Enabled; memset(mDeviceName, 0, sizeof(mDeviceName)); @@ -613,9 +615,10 @@ CHIP_ERROR BLEManagerImpl::InitESPBleLayer(void) { mSubscribedConIds[i] = BLE_CONNECTION_UNINITIALIZED; } - +#if ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(5, 0, 0) err = MapBLEError(esp_nimble_hci_and_controller_init()); SuccessOrExit(err); +#endif nimble_port_init(); From 27ca0452dd86d6b777e24ad90b9939e79ce2e9e8 Mon Sep 17 00:00:00 2001 From: pankore <86098180+pankore@users.noreply.github.com> Date: Wed, 24 Aug 2022 00:08:00 +0800 Subject: [PATCH 3/9] [KVS] Check NULL pointer for getPref_bin_new (#21854) * [KVS] Add NULL pointer check for getPref_bin_new Invalid read_bytes_size pointer could cause hard fault on getPref_bin_new function. * [KVS] Pass in dummy_read_bytes when read_bytes is nullptr * [Restyle] Fix styling * [KVS] Add nullptr check after pvPortMalloc * [Restyle] Fix style Co-authored-by: Andrei Litvin --- src/platform/Ameba/KeyValueStoreManagerImpl.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/platform/Ameba/KeyValueStoreManagerImpl.cpp b/src/platform/Ameba/KeyValueStoreManagerImpl.cpp index 74e8a2882f6cb7..93ec38b8611b58 100644 --- a/src/platform/Ameba/KeyValueStoreManagerImpl.cpp +++ b/src/platform/Ameba/KeyValueStoreManagerImpl.cpp @@ -49,7 +49,20 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t return (err = CHIP_ERROR_NOT_IMPLEMENTED); } - ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, read_bytes_size); + if (read_bytes_size) + { + ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, read_bytes_size); + } + else + { + size_t * dummy_read_bytes_size = (size_t *) pvPortMalloc(sizeof(size_t)); + if (!dummy_read_bytes_size) + { + return CHIP_ERROR_INTERNAL; + } + ret = getPref_bin_new(key, key, (uint8_t *) value, value_size, dummy_read_bytes_size); + vPortFree(dummy_read_bytes_size); + } switch (ret) { case 0: From 1a1d887dfe015a4f85a98846d7a5eddcc1fa4b15 Mon Sep 17 00:00:00 2001 From: Sharad Binjola <31142146+sharadb-amazon@users.noreply.github.com> Date: Tue, 23 Aug 2022 10:13:00 -0700 Subject: [PATCH 4/9] Fixing typo in mapping mediaPlayback_stopPlayback correctly in CastingServerBridge.mm (#22087) --- .../MatterTvCastingBridge/CastingServerBridge.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm index e854db7092e9eb..2eccbf8242a0a9 100644 --- a/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm +++ b/examples/tv-casting-app/darwin/MatterTvCastingBridge/MatterTvCastingBridge/CastingServerBridge.mm @@ -309,7 +309,7 @@ - (void)mediaPlayback_stopPlayback:(void (^_Nonnull)(bool))responseCallback _mediaPlayback_pauseResponseCallback = responseCallback; dispatch_async(_chipWorkQueue, ^{ - CHIP_ERROR err = CastingServer::GetInstance()->MediaPlayback_Pause([](CHIP_ERROR err) { + CHIP_ERROR err = CastingServer::GetInstance()->MediaPlayback_StopPlayback([](CHIP_ERROR err) { [CastingServerBridge getSharedInstance].mediaPlayback_stopPlaybackResponseCallback(CHIP_NO_ERROR == err); }); dispatch_async(clientQueue, ^{ From c3fcbc1781c4c9e1e1dc8cf986b20837285c0edb Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 23 Aug 2022 13:33:40 -0400 Subject: [PATCH 5/9] Make StartUpColorTemperatureMireds nullable, per spec. (#21858) Fixes https://github.com/project-chip/connectedhomeip/issues/21855 --- .../all-clusters-app.matter | 2 +- ...tnode_extendedcolorlight_8lcaaYJVAa.matter | 2 +- .../light-switch-app.matter | 2 +- .../lighting-common/lighting-app.matter | 2 +- .../placeholder/linux/apps/app1/config.matter | 2 +- .../placeholder/linux/apps/app2/config.matter | 2 +- .../color-control-server.cpp | 16 ++--- .../zcl/data-model/silabs/ha.xml | 2 +- .../data_model/controller-clusters.matter | 2 +- .../CHIPAttributeTLVValueDecoder.cpp | 15 +++-- .../zap-generated/CHIPClustersWrite-JNI.cpp | 12 +++- .../java/zap-generated/CHIPReadCallbacks.cpp | 67 +++++++++++++++++++ .../java/zap-generated/CHIPReadCallbacks.h | 30 +++++++++ .../chip/devicecontroller/ChipClusters.java | 20 ++++-- .../devicecontroller/ClusterReadMapping.java | 4 +- .../python/chip/clusters/Objects.py | 8 +-- .../MTRAttributeTLVValueDecoder.mm | 8 ++- .../CHIP/zap-generated/MTRBaseClusters.h | 4 +- .../CHIP/zap-generated/MTRBaseClusters.mm | 27 +++++--- .../zap-generated/endpoint_config.h | 3 +- .../zap-generated/attributes/Accessors.cpp | 32 +++++++-- .../zap-generated/attributes/Accessors.h | 4 +- .../zap-generated/cluster-objects.h | 8 +-- .../zap-generated/endpoint_config.h | 3 +- .../zap-generated/cluster/Commands.h | 5 +- .../cluster/logging/DataModelLogger.cpp | 2 +- .../chip-tool/zap-generated/test/Commands.h | 2 +- .../zap-generated/cluster/Commands.h | 2 +- .../zap-generated/test/Commands.h | 10 ++- .../zap-generated/endpoint_config.h | 3 +- .../app1/zap-generated/endpoint_config.h | 3 +- .../app2/zap-generated/endpoint_config.h | 3 +- 32 files changed, 238 insertions(+), 69 deletions(-) diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter index 18d7c48c099ad3..96c706ad0ed1fe 100644 --- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter +++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter @@ -2851,7 +2851,7 @@ server cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; diff --git a/examples/chef/devices/rootnode_extendedcolorlight_8lcaaYJVAa.matter b/examples/chef/devices/rootnode_extendedcolorlight_8lcaaYJVAa.matter index e9d7612115a077..7fa6bae61d59dc 100644 --- a/examples/chef/devices/rootnode_extendedcolorlight_8lcaaYJVAa.matter +++ b/examples/chef/devices/rootnode_extendedcolorlight_8lcaaYJVAa.matter @@ -1614,7 +1614,7 @@ server cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute command_id generatedCommandList[] = 65528; readonly attribute command_id acceptedCommandList[] = 65529; readonly attribute attrib_id attributeList[] = 65531; diff --git a/examples/light-switch-app/light-switch-common/light-switch-app.matter b/examples/light-switch-app/light-switch-common/light-switch-app.matter index 0a6d27521c8a74..27a458acdc6195 100644 --- a/examples/light-switch-app/light-switch-common/light-switch-app.matter +++ b/examples/light-switch-app/light-switch-common/light-switch-app.matter @@ -1565,7 +1565,7 @@ client cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute int16u clusterRevision = 65533; request struct MoveToHueRequest { diff --git a/examples/lighting-app/lighting-common/lighting-app.matter b/examples/lighting-app/lighting-common/lighting-app.matter index d538c8232f7bb0..43839293478d6d 100644 --- a/examples/lighting-app/lighting-common/lighting-app.matter +++ b/examples/lighting-app/lighting-common/lighting-app.matter @@ -1511,7 +1511,7 @@ server cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; diff --git a/examples/placeholder/linux/apps/app1/config.matter b/examples/placeholder/linux/apps/app1/config.matter index 48822ed58e83bf..eb235f5eaa24fa 100644 --- a/examples/placeholder/linux/apps/app1/config.matter +++ b/examples/placeholder/linux/apps/app1/config.matter @@ -1916,7 +1916,7 @@ server cluster ColorControl = 768 { readonly attribute int16u currentY = 4; attribute bitmap8 options = 15; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; diff --git a/examples/placeholder/linux/apps/app2/config.matter b/examples/placeholder/linux/apps/app2/config.matter index 48822ed58e83bf..eb235f5eaa24fa 100644 --- a/examples/placeholder/linux/apps/app2/config.matter +++ b/examples/placeholder/linux/apps/app2/config.matter @@ -1916,7 +1916,7 @@ server cluster ColorControl = 768 { readonly attribute int16u currentY = 4; attribute bitmap8 options = 15; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute bitmap32 featureMap = 65532; readonly attribute int16u clusterRevision = 65533; diff --git a/src/app/clusters/color-control-server/color-control-server.cpp b/src/app/clusters/color-control-server/color-control-server.cpp index ec61efd6ac2867..e523921bdaf9b3 100644 --- a/src/app/clusters/color-control-server/color-control-server.cpp +++ b/src/app/clusters/color-control-server/color-control-server.cpp @@ -2071,13 +2071,13 @@ void ColorControlServer::startUpColorTempCommand(EndpointId endpoint) // the StartUpColorTemperatureMireds attribute are listed in the table below. // Value Action on power up // 0x0000-0xffef Set the ColorTemperatureMireds attribute to this value. - // 0xffff Set the ColorTemperatureMireds attribute to its previous value. + // null Set the ColorTemperatureMireds attribute to its previous value. - // Initialize startUpColorTempMireds to "maintain previous value" value 0xFFFF - uint16_t startUpColorTemp = 0xFFFF; - EmberAfStatus status = Attributes::StartUpColorTemperatureMireds::Get(endpoint, &startUpColorTemp); + // Initialize startUpColorTempMireds to "maintain previous value" value null + app::DataModel::Nullable startUpColorTemp; + EmberAfStatus status = Attributes::StartUpColorTemperatureMireds::Get(endpoint, startUpColorTemp); - if (status == EMBER_ZCL_STATUS_SUCCESS) + if (status == EMBER_ZCL_STATUS_SUCCESS && !startUpColorTemp.IsNull()) { uint16_t updatedColorTemp = MAX_TEMPERATURE_VALUE; status = Attributes::ColorTemperature::Get(endpoint, &updatedColorTemp); @@ -2090,13 +2090,13 @@ void ColorControlServer::startUpColorTempCommand(EndpointId endpoint) uint16_t tempPhysicalMax = MAX_TEMPERATURE_VALUE; Attributes::ColorTempPhysicalMaxMireds::Get(endpoint, &tempPhysicalMax); - if (tempPhysicalMin <= startUpColorTemp && startUpColorTemp <= tempPhysicalMax) + if (tempPhysicalMin <= startUpColorTemp.Value() && startUpColorTemp.Value() <= tempPhysicalMax) { // Apply valid startup color temp value that is within physical limits of device. // Otherwise, the startup value is outside the device's supported range, and the // existing setting of ColorTemp attribute will be left unchanged (i.e., treated as - // if startup color temp was set to 0xFFFF). - updatedColorTemp = startUpColorTemp; + // if startup color temp was set to null). + updatedColorTemp = startUpColorTemp.Value(); status = Attributes::ColorTemperature::Set(endpoint, updatedColorTemp); if (status == EMBER_ZCL_STATUS_SUCCESS) diff --git a/src/app/zap-templates/zcl/data-model/silabs/ha.xml b/src/app/zap-templates/zcl/data-model/silabs/ha.xml index f9ea448209d444..b40807c1b39211 100644 --- a/src/app/zap-templates/zcl/data-model/silabs/ha.xml +++ b/src/app/zap-templates/zcl/data-model/silabs/ha.xml @@ -243,7 +243,7 @@ limitations under the License. CoupleColorTempToLevelMinMireds - + StartUpColorTemperatureMireds diff --git a/src/controller/data_model/controller-clusters.matter b/src/controller/data_model/controller-clusters.matter index f8a88c7b66bb5f..2d71e362638858 100644 --- a/src/controller/data_model/controller-clusters.matter +++ b/src/controller/data_model/controller-clusters.matter @@ -3178,7 +3178,7 @@ client cluster ColorControl = 768 { readonly attribute int16u colorTempPhysicalMinMireds = 16395; readonly attribute int16u colorTempPhysicalMaxMireds = 16396; readonly attribute int16u coupleColorTempToLevelMinMireds = 16397; - attribute access(write: manage) int16u startUpColorTemperatureMireds = 16400; + attribute access(write: manage) nullable int16u startUpColorTemperatureMireds = 16400; readonly attribute command_id generatedCommandList[] = 65528; readonly attribute command_id acceptedCommandList[] = 65529; readonly attribute attrib_id attributeList[] = 65531; diff --git a/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp b/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp index fe0eb5ce4cd193..d20ce4a2f36cf0 100644 --- a/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp +++ b/src/controller/java/zap-generated/CHIPAttributeTLVValueDecoder.cpp @@ -12925,10 +12925,17 @@ jobject DecodeAttributeValue(const app::ConcreteAttributePath & aPath, TLV::TLVR return nullptr; } jobject value; - std::string valueClassName = "java/lang/Integer"; - std::string valueCtorSignature = "(I)V"; - chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), - cppValue, value); + if (cppValue.IsNull()) + { + value = nullptr; + } + else + { + std::string valueClassName = "java/lang/Integer"; + std::string valueCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(valueClassName.c_str(), valueCtorSignature.c_str(), + cppValue.Value(), value); + } return value; } case Attributes::GeneratedCommandList::Id: { diff --git a/src/controller/java/zap-generated/CHIPClustersWrite-JNI.cpp b/src/controller/java/zap-generated/CHIPClustersWrite-JNI.cpp index 4612f4b7b96bae..e453c781ffd1f4 100644 --- a/src/controller/java/zap-generated/CHIPClustersWrite-JNI.cpp +++ b/src/controller/java/zap-generated/CHIPClustersWrite-JNI.cpp @@ -4488,8 +4488,16 @@ JNI_METHOD(void, ColorControlCluster, writeStartUpColorTemperatureMiredsAttribut std::vector> cleanupByteArrays; std::vector> cleanupStrings; - cppValue = - static_cast>(chip::JniReferences::GetInstance().IntegerToPrimitive(value)); + if (value == nullptr) + { + cppValue.SetNull(); + } + else + { + auto & nonNullValue_0 = cppValue.SetNonNull(); + nonNullValue_0 = static_cast>( + chip::JniReferences::GetInstance().IntegerToPrimitive(value)); + } std::unique_ptr onSuccess( Platform::New(callback), Platform::Delete); diff --git a/src/controller/java/zap-generated/CHIPReadCallbacks.cpp b/src/controller/java/zap-generated/CHIPReadCallbacks.cpp index 2dab6e13780b9d..d6c410be3f605e 100644 --- a/src/controller/java/zap-generated/CHIPReadCallbacks.cpp +++ b/src/controller/java/zap-generated/CHIPReadCallbacks.cpp @@ -18957,6 +18957,73 @@ void CHIPColorControlColorPointBIntensityAttributeCallback::CallbackFn(void * co env->CallVoidMethod(javaCallbackRef, javaMethod, javaValue); } +CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback::CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback( + jobject javaCallback, bool keepAlive) : + chip::Callback::Callback(CallbackFn, this), + keepAlive(keepAlive) +{ + JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + return; + } + + javaCallbackRef = env->NewGlobalRef(javaCallback); + if (javaCallbackRef == nullptr) + { + ChipLogError(Zcl, "Could not create global reference for Java callback"); + } +} + +CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback::~CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback() +{ + JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); + if (env == nullptr) + { + ChipLogError(Zcl, "Could not delete global reference for Java callback"); + return; + } + env->DeleteGlobalRef(javaCallbackRef); +} + +void CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback::CallbackFn( + void * context, const chip::app::DataModel::Nullable & value) +{ + chip::DeviceLayer::StackUnlock unlock; + CHIP_ERROR err = CHIP_NO_ERROR; + JNIEnv * env = chip::JniReferences::GetInstance().GetEnvForCurrentThread(); + jobject javaCallbackRef; + + VerifyOrReturn(env != nullptr, ChipLogError(Zcl, "Could not get JNI env")); + std::unique_ptr cppCallback( + reinterpret_cast(context), maybeDestroy); + + // It's valid for javaCallbackRef to be nullptr if the Java code passed in a null callback. + javaCallbackRef = cppCallback.get()->javaCallbackRef; + VerifyOrReturn(javaCallbackRef != nullptr, + ChipLogProgress(Zcl, "Early return from attribute callback since Java callback is null")); + + jmethodID javaMethod; + err = chip::JniReferences::GetInstance().FindMethod(env, javaCallbackRef, "onSuccess", "(Ljava/lang/Integer;)V", &javaMethod); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Could not find onSuccess() method")); + + jobject javaValue; + if (value.IsNull()) + { + javaValue = nullptr; + } + else + { + std::string javaValueClassName = "java/lang/Integer"; + std::string javaValueCtorSignature = "(I)V"; + chip::JniReferences::GetInstance().CreateBoxedObject(javaValueClassName.c_str(), javaValueCtorSignature.c_str(), + value.Value(), javaValue); + } + + env->CallVoidMethod(javaCallbackRef, javaMethod, javaValue); +} + CHIPColorControlGeneratedCommandListAttributeCallback::CHIPColorControlGeneratedCommandListAttributeCallback(jobject javaCallback, bool keepAlive) : chip::Callback::Callback(CallbackFn, this), diff --git a/src/controller/java/zap-generated/CHIPReadCallbacks.h b/src/controller/java/zap-generated/CHIPReadCallbacks.h index f5dc7866c0e0c9..d1a4b63b04c84e 100644 --- a/src/controller/java/zap-generated/CHIPReadCallbacks.h +++ b/src/controller/java/zap-generated/CHIPReadCallbacks.h @@ -7912,6 +7912,36 @@ class CHIPColorControlColorPointBIntensityAttributeCallback bool keepAlive; }; +class CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback + : public chip::Callback::Callback +{ +public: + CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback(jobject javaCallback, bool keepAlive = false); + + ~CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback(); + + static void maybeDestroy(CHIPColorControlStartUpColorTemperatureMiredsAttributeCallback * callback) + { + if (!callback->keepAlive) + { + callback->Cancel(); + chip::Platform::Delete(callback); + } + } + + static void CallbackFn(void * context, const chip::app::DataModel::Nullable & value); + static void OnSubscriptionEstablished(void * context) + { + CHIP_ERROR err = chip::JniReferences::GetInstance().CallSubscriptionEstablished( + reinterpret_cast(context)->javaCallbackRef); + VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(Zcl, "Error calling onSubscriptionEstablished: %s", ErrorStr(err))); + }; + +private: + jobject javaCallbackRef; + bool keepAlive; +}; + class CHIPColorControlGeneratedCommandListAttributeCallback : public chip::Callback::Callback { diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java index 73c28214ab6173..bd9914f596dbab 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ChipClusters.java @@ -16188,6 +16188,14 @@ public interface ColorPointBIntensityAttributeCallback { default void onSubscriptionEstablished() {} } + public interface StartUpColorTemperatureMiredsAttributeCallback { + void onSuccess(@Nullable Integer value); + + void onError(Exception ex); + + default void onSubscriptionEstablished() {} + } + public interface GeneratedCommandListAttributeCallback { void onSuccess(List valueList); @@ -16784,7 +16792,8 @@ public void subscribeCoupleColorTempToLevelMinMiredsAttribute( chipClusterPtr, callback, minInterval, maxInterval); } - public void readStartUpColorTemperatureMiredsAttribute(IntegerAttributeCallback callback) { + public void readStartUpColorTemperatureMiredsAttribute( + StartUpColorTemperatureMiredsAttributeCallback callback) { readStartUpColorTemperatureMiredsAttribute(chipClusterPtr, callback); } @@ -16800,7 +16809,7 @@ public void writeStartUpColorTemperatureMiredsAttribute( } public void subscribeStartUpColorTemperatureMiredsAttribute( - IntegerAttributeCallback callback, int minInterval, int maxInterval) { + StartUpColorTemperatureMiredsAttributeCallback callback, int minInterval, int maxInterval) { subscribeStartUpColorTemperatureMiredsAttribute( chipClusterPtr, callback, minInterval, maxInterval); } @@ -17262,7 +17271,7 @@ private native void subscribeCoupleColorTempToLevelMinMiredsAttribute( long chipClusterPtr, IntegerAttributeCallback callback, int minInterval, int maxInterval); private native void readStartUpColorTemperatureMiredsAttribute( - long chipClusterPtr, IntegerAttributeCallback callback); + long chipClusterPtr, StartUpColorTemperatureMiredsAttributeCallback callback); private native void writeStartUpColorTemperatureMiredsAttribute( long chipClusterPtr, @@ -17271,7 +17280,10 @@ private native void writeStartUpColorTemperatureMiredsAttribute( @Nullable Integer timedWriteTimeoutMs); private native void subscribeStartUpColorTemperatureMiredsAttribute( - long chipClusterPtr, IntegerAttributeCallback callback, int minInterval, int maxInterval); + long chipClusterPtr, + StartUpColorTemperatureMiredsAttributeCallback callback, + int minInterval, + int maxInterval); private native void readGeneratedCommandListAttribute( long chipClusterPtr, GeneratedCommandListAttributeCallback callback); diff --git a/src/controller/java/zap-generated/chip/devicecontroller/ClusterReadMapping.java b/src/controller/java/zap-generated/chip/devicecontroller/ClusterReadMapping.java index bb881021b50feb..a059be7651a3a9 100644 --- a/src/controller/java/zap-generated/chip/devicecontroller/ClusterReadMapping.java +++ b/src/controller/java/zap-generated/chip/devicecontroller/ClusterReadMapping.java @@ -8715,7 +8715,9 @@ public Map> getReadAttributeMap() { (cluster, callback, commandArguments) -> { ((ChipClusters.ColorControlCluster) cluster) .readStartUpColorTemperatureMiredsAttribute( - (ChipClusters.IntegerAttributeCallback) callback); + (ChipClusters.ColorControlCluster + .StartUpColorTemperatureMiredsAttributeCallback) + callback); }, () -> new ClusterInfoMapping.DelegatedIntegerAttributeCallback(), readColorControlStartUpColorTemperatureMiredsCommandParams); diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index d8032d8f508063..94dbba01c44523 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -18134,7 +18134,7 @@ def descriptor(cls) -> ClusterObjectDescriptor: ClusterObjectFieldDescriptor(Label="colorTempPhysicalMinMireds", Tag=0x0000400B, Type=typing.Optional[uint]), ClusterObjectFieldDescriptor(Label="colorTempPhysicalMaxMireds", Tag=0x0000400C, Type=typing.Optional[uint]), ClusterObjectFieldDescriptor(Label="coupleColorTempToLevelMinMireds", Tag=0x0000400D, Type=typing.Optional[uint]), - ClusterObjectFieldDescriptor(Label="startUpColorTemperatureMireds", Tag=0x00004010, Type=typing.Optional[uint]), + ClusterObjectFieldDescriptor(Label="startUpColorTemperatureMireds", Tag=0x00004010, Type=typing.Union[None, Nullable, uint]), ClusterObjectFieldDescriptor(Label="generatedCommandList", Tag=0x0000FFF8, Type=typing.List[uint]), ClusterObjectFieldDescriptor(Label="acceptedCommandList", Tag=0x0000FFF9, Type=typing.List[uint]), ClusterObjectFieldDescriptor(Label="attributeList", Tag=0x0000FFFB, Type=typing.List[uint]), @@ -18193,7 +18193,7 @@ def descriptor(cls) -> ClusterObjectDescriptor: colorTempPhysicalMinMireds: 'typing.Optional[uint]' = None colorTempPhysicalMaxMireds: 'typing.Optional[uint]' = None coupleColorTempToLevelMinMireds: 'typing.Optional[uint]' = None - startUpColorTemperatureMireds: 'typing.Optional[uint]' = None + startUpColorTemperatureMireds: 'typing.Union[None, Nullable, uint]' = None generatedCommandList: 'typing.List[uint]' = None acceptedCommandList: 'typing.List[uint]' = None attributeList: 'typing.List[uint]' = None @@ -19501,9 +19501,9 @@ def attribute_id(cls) -> int: @ChipUtility.classproperty def attribute_type(cls) -> ClusterObjectFieldDescriptor: - return ClusterObjectFieldDescriptor(Type=typing.Optional[uint]) + return ClusterObjectFieldDescriptor(Type=typing.Union[None, Nullable, uint]) - value: 'typing.Optional[uint]' = None + value: 'typing.Union[None, Nullable, uint]' = None @dataclass class GeneratedCommandList(ClusterAttributeDescriptor): diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm index 671a368001c51d..4e215d6702d9b5 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRAttributeTLVValueDecoder.mm @@ -11155,8 +11155,12 @@ id MTRDecodeAttributeValue(const ConcreteAttributePath & aPath, TLV::TLVReader & if (*aError != CHIP_NO_ERROR) { return nil; } - NSNumber * _Nonnull value; - value = [NSNumber numberWithUnsignedShort:cppValue]; + NSNumber * _Nullable value; + if (cppValue.IsNull()) { + value = nil; + } else { + value = [NSNumber numberWithUnsignedShort:cppValue.Value()]; + } return value; } case Attributes::GeneratedCommandList::Id: { diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h index 201b0844d66305..90980c2f1a0f2c 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h +++ b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.h @@ -13792,9 +13792,9 @@ NS_ASSUME_NONNULL_BEGIN - (void)readAttributeStartUpColorTemperatureMiredsWithCompletionHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completionHandler; -- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull)value +- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable)value completionHandler:(StatusCompletion)completionHandler; -- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull)value +- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable)value params:(MTRWriteParams * _Nullable)params completionHandler:(StatusCompletion)completionHandler; /** diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm index 1d1c90e8e4359c..7bc25323f1a8d8 100644 --- a/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm +++ b/src/darwin/Framework/CHIP/zap-generated/MTRBaseClusters.mm @@ -57847,24 +57847,24 @@ new MTRInt16uAttributeCallbackBridge(queue, completionHandler, ^(Cancelable * su - (void)readAttributeStartUpColorTemperatureMiredsWithCompletionHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completionHandler { - new MTRInt16uAttributeCallbackBridge(self.callbackQueue, self.device, completionHandler, + new MTRNullableInt16uAttributeCallbackBridge(self.callbackQueue, self.device, completionHandler, ^(ExchangeManager & exchangeManager, const SessionHandle & session, Cancelable * success, Cancelable * failure) { using TypeInfo = ColorControl::Attributes::StartUpColorTemperatureMireds::TypeInfo; - auto successFn = Callback::FromCancelable(success); + auto successFn = Callback::FromCancelable(success); auto failureFn = Callback::FromCancelable(failure); chip::Controller::ColorControlCluster cppCluster(exchangeManager, session, self->_endpoint); return cppCluster.ReadAttribute(successFn->mContext, successFn->mCall, failureFn->mCall); }); } -- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull)value +- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable)value completionHandler:(StatusCompletion)completionHandler { - [self writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull) value + [self writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable) value params:nil completionHandler:completionHandler]; } -- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nonnull)value +- (void)writeAttributeStartUpColorTemperatureMiredsWithValue:(NSNumber * _Nullable)value params:(MTRWriteParams * _Nullable)params completionHandler:(StatusCompletion)completionHandler { @@ -57888,7 +57888,12 @@ new MTRDefaultSuccessCallbackBridge( ListFreer listFreer; using TypeInfo = ColorControl::Attributes::StartUpColorTemperatureMireds::TypeInfo; TypeInfo::Type cppValue; - cppValue = value.unsignedShortValue; + if (value == nil) { + cppValue.SetNull(); + } else { + auto & nonNullValue_0 = cppValue.SetNonNull(); + nonNullValue_0 = value.unsignedShortValue; + } auto successFn = Callback::FromCancelable(success); auto failureFn = Callback::FromCancelable(failure); @@ -57910,7 +57915,7 @@ - (void)subscribeAttributeStartUpColorTemperatureMiredsWithMinInterval:(NSNumber minInterval = [minInterval copy]; maxInterval = [maxInterval copy]; params = [params copy]; - new MTRInt16uAttributeCallbackSubscriptionBridge( + new MTRNullableInt16uAttributeCallbackSubscriptionBridge( self.callbackQueue, self.device, reportHandler, ^(ExchangeManager & exchangeManager, const SessionHandle & session, Cancelable * success, Cancelable * failure) { if (params != nil && params.autoResubscribe != nil && ![params.autoResubscribe boolValue]) { @@ -57918,13 +57923,13 @@ new MTRInt16uAttributeCallbackSubscriptionBridge( return CHIP_ERROR_INVALID_ARGUMENT; } using TypeInfo = ColorControl::Attributes::StartUpColorTemperatureMireds::TypeInfo; - auto successFn = Callback::FromCancelable(success); + auto successFn = Callback::FromCancelable(success); auto failureFn = Callback::FromCancelable(failure); chip::Controller::ColorControlCluster cppCluster(exchangeManager, session, self->_endpoint); return cppCluster.SubscribeAttribute(successFn->mContext, successFn->mCall, failureFn->mCall, [minInterval unsignedShortValue], [maxInterval unsignedShortValue], - MTRInt16uAttributeCallbackSubscriptionBridge::OnSubscriptionEstablished, nil, + MTRNullableInt16uAttributeCallbackSubscriptionBridge::OnSubscriptionEstablished, nil, params == nil || params.fabricFiltered == nil || [params.fabricFiltered boolValue], params != nil && params.keepPreviousSubscriptions != nil && [params.keepPreviousSubscriptions boolValue]); }, @@ -57937,7 +57942,7 @@ + (void)readAttributeStartUpColorTemperatureMiredsWithAttributeCache:(MTRAttribu completionHandler:(void (^)(NSNumber * _Nullable value, NSError * _Nullable error))completionHandler { - new MTRInt16uAttributeCallbackBridge(queue, completionHandler, ^(Cancelable * success, Cancelable * failure) { + new MTRNullableInt16uAttributeCallbackBridge(queue, completionHandler, ^(Cancelable * success, Cancelable * failure) { if (attributeCacheContainer.cppAttributeCache) { chip::app::ConcreteAttributePath path; using TypeInfo = ColorControl::Attributes::StartUpColorTemperatureMireds::TypeInfo; @@ -57946,7 +57951,7 @@ new MTRInt16uAttributeCallbackBridge(queue, completionHandler, ^(Cancelable * su path.mAttributeId = TypeInfo::GetAttributeId(); TypeInfo::DecodableType value; CHIP_ERROR err = attributeCacheContainer.cppAttributeCache->Get(path, value); - auto successFn = Callback::FromCancelable(success); + auto successFn = Callback::FromCancelable(success); if (err == CHIP_NO_ERROR) { successFn->mCall(successFn->mContext, value); } diff --git a/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h b/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h index 64446dd4aec170..6a2279cb2179ca 100644 --- a/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h +++ b/zzz_generated/all-clusters-app/zap-generated/endpoint_config.h @@ -1153,7 +1153,8 @@ { 0x0000400B, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0000) }, /* ColorTempPhysicalMinMireds */ \ { 0x0000400C, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0xFEFF) }, /* ColorTempPhysicalMaxMireds */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_EMPTY_DEFAULT() }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(37) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0x1F) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp index d1b8ec87b5220a..60f4de6eae617f 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.cpp @@ -19517,24 +19517,27 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value) namespace StartUpColorTemperatureMireds { -EmberAfStatus Get(chip::EndpointId endpoint, uint16_t * value) +EmberAfStatus Get(chip::EndpointId endpoint, DataModel::Nullable & value) { using Traits = NumericAttributeTraits; Traits::StorageType temp; uint8_t * readable = Traits::ToAttributeStoreRepresentation(temp); EmberAfStatus status = emberAfReadServerAttribute(endpoint, Clusters::ColorControl::Id, Id, readable, sizeof(temp)); VerifyOrReturnError(EMBER_ZCL_STATUS_SUCCESS == status, status); - if (!Traits::CanRepresentValue(/* isNullable = */ false, temp)) + if (Traits::IsNullValue(temp)) { - return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; + value.SetNull(); + } + else + { + value.SetNonNull() = Traits::StorageToWorking(temp); } - *value = Traits::StorageToWorking(temp); return status; } EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value) { using Traits = NumericAttributeTraits; - if (!Traits::CanRepresentValue(/* isNullable = */ false, value)) + if (!Traits::CanRepresentValue(/* isNullable = */ true, value)) { return EMBER_ZCL_STATUS_CONSTRAINT_ERROR; } @@ -19544,6 +19547,25 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value) return emberAfWriteServerAttribute(endpoint, Clusters::ColorControl::Id, Id, writable, ZCL_INT16U_ATTRIBUTE_TYPE); } +EmberAfStatus SetNull(chip::EndpointId endpoint) +{ + using Traits = NumericAttributeTraits; + Traits::StorageType value; + Traits::SetNull(value); + uint8_t * writable = Traits::ToAttributeStoreRepresentation(value); + return emberAfWriteServerAttribute(endpoint, Clusters::ColorControl::Id, Id, writable, ZCL_INT16U_ATTRIBUTE_TYPE); +} + +EmberAfStatus Set(chip::EndpointId endpoint, const chip::app::DataModel::Nullable & value) +{ + if (value.IsNull()) + { + return SetNull(endpoint); + } + + return Set(endpoint, value.Value()); +} + } // namespace StartUpColorTemperatureMireds namespace FeatureMap { diff --git a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h index d26576e7723a10..73deb29ea144ab 100644 --- a/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h +++ b/zzz_generated/app-common/app-common/zap-generated/attributes/Accessors.h @@ -3270,8 +3270,10 @@ EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value); } // namespace CoupleColorTempToLevelMinMireds namespace StartUpColorTemperatureMireds { -EmberAfStatus Get(chip::EndpointId endpoint, uint16_t * value); // int16u +EmberAfStatus Get(chip::EndpointId endpoint, DataModel::Nullable & value); // int16u EmberAfStatus Set(chip::EndpointId endpoint, uint16_t value); +EmberAfStatus SetNull(chip::EndpointId endpoint); +EmberAfStatus Set(chip::EndpointId endpoint, const chip::app::DataModel::Nullable & value); } // namespace StartUpColorTemperatureMireds namespace FeatureMap { diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h index 5500c0d3c8ce28..924bfe735eef96 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h @@ -19205,9 +19205,9 @@ struct TypeInfo namespace StartUpColorTemperatureMireds { struct TypeInfo { - using Type = uint16_t; - using DecodableType = uint16_t; - using DecodableArgType = uint16_t; + using Type = chip::app::DataModel::Nullable; + using DecodableType = chip::app::DataModel::Nullable; + using DecodableArgType = const chip::app::DataModel::Nullable &; static constexpr ClusterId GetClusterId() { return Clusters::ColorControl::Id; } static constexpr AttributeId GetAttributeId() { return Attributes::StartUpColorTemperatureMireds::Id; } @@ -19305,7 +19305,7 @@ struct TypeInfo Attributes::ColorTempPhysicalMaxMireds::TypeInfo::DecodableType colorTempPhysicalMaxMireds = static_cast(0); Attributes::CoupleColorTempToLevelMinMireds::TypeInfo::DecodableType coupleColorTempToLevelMinMireds = static_cast(0); - Attributes::StartUpColorTemperatureMireds::TypeInfo::DecodableType startUpColorTemperatureMireds = static_cast(0); + Attributes::StartUpColorTemperatureMireds::TypeInfo::DecodableType startUpColorTemperatureMireds; Attributes::GeneratedCommandList::TypeInfo::DecodableType generatedCommandList; Attributes::AcceptedCommandList::TypeInfo::DecodableType acceptedCommandList; Attributes::AttributeList::TypeInfo::DecodableType attributeList; diff --git a/zzz_generated/chef-rootnode_extendedcolorlight_8lcaaYJVAa/zap-generated/endpoint_config.h b/zzz_generated/chef-rootnode_extendedcolorlight_8lcaaYJVAa/zap-generated/endpoint_config.h index 58cae4639d8ccf..e7f99834ec16d9 100644 --- a/zzz_generated/chef-rootnode_extendedcolorlight_8lcaaYJVAa/zap-generated/endpoint_config.h +++ b/zzz_generated/chef-rootnode_extendedcolorlight_8lcaaYJVAa/zap-generated/endpoint_config.h @@ -505,7 +505,8 @@ { 0x0000400B, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0000) }, /* ColorTempPhysicalMinMireds */ \ { 0x0000400C, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0xFEFF) }, /* ColorTempPhysicalMaxMireds */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0000) }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(3) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0x1f) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ diff --git a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h index 897d45dff7d486..a812e26aec450c 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/cluster/Commands.h @@ -11499,8 +11499,9 @@ void registerClusterColorControl(Commands & commands, CredentialIssuerCommands * credsIssuerConfig), // make_unique>>( Id, "color-point-bintensity", 0, UINT8_MAX, Attributes::ColorPointBIntensity::Id, credsIssuerConfig), // - make_unique>(Id, "start-up-color-temperature-mireds", 0, UINT16_MAX, - Attributes::StartUpColorTemperatureMireds::Id, credsIssuerConfig), // + make_unique>>( + Id, "start-up-color-temperature-mireds", 0, UINT16_MAX, Attributes::StartUpColorTemperatureMireds::Id, + credsIssuerConfig), // make_unique(Id, credsIssuerConfig), // make_unique(Id, "current-hue", Attributes::CurrentHue::Id, credsIssuerConfig), // make_unique(Id, "current-saturation", Attributes::CurrentSaturation::Id, credsIssuerConfig), // diff --git a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp index 3c74e880afe835..d0e87f6efe4086 100644 --- a/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp +++ b/zzz_generated/chip-tool/zap-generated/cluster/logging/DataModelLogger.cpp @@ -7866,7 +7866,7 @@ CHIP_ERROR DataModelLogger::LogAttribute(const chip::app::ConcreteDataAttributeP return DataModelLogger::LogValue("CoupleColorTempToLevelMinMireds", 1, value); } case ColorControl::Attributes::StartUpColorTemperatureMireds::Id: { - uint16_t value; + chip::app::DataModel::Nullable value; ReturnErrorOnFailure(chip::app::DataModel::Decode(*data, value)); return DataModelLogger::LogValue("StartUpColorTemperatureMireds", 1, value); } diff --git a/zzz_generated/chip-tool/zap-generated/test/Commands.h b/zzz_generated/chip-tool/zap-generated/test/Commands.h index 1179318cf4ecb9..5a0c3c87c27d82 100644 --- a/zzz_generated/chip-tool/zap-generated/test/Commands.h +++ b/zzz_generated/chip-tool/zap-generated/test/Commands.h @@ -3751,7 +3751,7 @@ class Test_TC_CC_2_1Suite : public TestCommand case 23: VerifyOrReturn(CheckValue("status", chip::to_underlying(status.mStatus), 0)); { - uint16_t value; + chip::app::DataModel::Nullable value; VerifyOrReturn(CheckDecodeValue(chip::app::DataModel::Decode(*data, value))); VerifyOrReturn(CheckConstraintType("value", "int16u", "int16u")); VerifyOrReturn(CheckConstraintMinValue("value", value, 0U)); diff --git a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h index 59a1a11c980eb2..ec3f6fbaf1e027 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h @@ -57788,7 +57788,7 @@ class WriteColorControlStartUpColorTemperatureMireds : public WriteAttribute { params.timedWriteTimeout = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil; params.dataVersion = mDataVersion.HasValue() ? [NSNumber numberWithUnsignedInt:mDataVersion.Value()] : nil; - NSNumber * _Nonnull value = [NSNumber numberWithUnsignedShort:mValue]; + NSNumber * _Nullable value = [NSNumber numberWithUnsignedShort:mValue]; [cluster writeAttributeStartUpColorTemperatureMiredsWithValue:value diff --git a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h index 3e6b294d6b85c1..2d5a690968a3c5 100644 --- a/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h +++ b/zzz_generated/darwin-framework-tool/zap-generated/test/Commands.h @@ -6267,9 +6267,13 @@ class Test_TC_CC_2_1 : public TestCommandBridge { VerifyOrReturn(CheckValue("status", err ? err.code : 0, 0)); - VerifyOrReturn(CheckConstraintType("startUpColorTemperatureMireds", "int16u", "int16u")); - VerifyOrReturn(CheckConstraintMinValue("startUpColorTemperatureMireds", [value unsignedShortValue], 0U)); - VerifyOrReturn(CheckConstraintMaxValue("startUpColorTemperatureMireds", [value unsignedShortValue], 65279U)); + if (value != nil) { + + VerifyOrReturn(CheckConstraintType("startUpColorTemperatureMireds", "int16u", "int16u")); + VerifyOrReturn(CheckConstraintMinValue("startUpColorTemperatureMireds", [value unsignedShortValue], 0U)); + VerifyOrReturn( + CheckConstraintMaxValue("startUpColorTemperatureMireds", [value unsignedShortValue], 65279U)); + } NextTest(); }]; diff --git a/zzz_generated/lighting-app/zap-generated/endpoint_config.h b/zzz_generated/lighting-app/zap-generated/endpoint_config.h index 1361aff82ab860..4db663755aea03 100644 --- a/zzz_generated/lighting-app/zap-generated/endpoint_config.h +++ b/zzz_generated/lighting-app/zap-generated/endpoint_config.h @@ -532,7 +532,8 @@ { 0x0000400B, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x0000) }, /* ColorTempPhysicalMinMireds */ \ { 0x0000400C, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0xFEFF) }, /* ColorTempPhysicalMaxMireds */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_EMPTY_DEFAULT() }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(3) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0x1F) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ diff --git a/zzz_generated/placeholder/app1/zap-generated/endpoint_config.h b/zzz_generated/placeholder/app1/zap-generated/endpoint_config.h index 765846c3745642..9f3438484cfb72 100644 --- a/zzz_generated/placeholder/app1/zap-generated/endpoint_config.h +++ b/zzz_generated/placeholder/app1/zap-generated/endpoint_config.h @@ -626,7 +626,8 @@ { 0x00000004, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x607D) }, /* CurrentY */ \ { 0x0000000F, ZAP_TYPE(BITMAP8), 1, ZAP_ATTRIBUTE_MASK(WRITABLE), ZAP_SIMPLE_DEFAULT(0x00) }, /* Options */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_EMPTY_DEFAULT() }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(16) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ diff --git a/zzz_generated/placeholder/app2/zap-generated/endpoint_config.h b/zzz_generated/placeholder/app2/zap-generated/endpoint_config.h index 765846c3745642..9f3438484cfb72 100644 --- a/zzz_generated/placeholder/app2/zap-generated/endpoint_config.h +++ b/zzz_generated/placeholder/app2/zap-generated/endpoint_config.h @@ -626,7 +626,8 @@ { 0x00000004, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(0x607D) }, /* CurrentY */ \ { 0x0000000F, ZAP_TYPE(BITMAP8), 1, ZAP_ATTRIBUTE_MASK(WRITABLE), ZAP_SIMPLE_DEFAULT(0x00) }, /* Options */ \ { 0x0000400D, ZAP_TYPE(INT16U), 2, 0, ZAP_EMPTY_DEFAULT() }, /* CoupleColorTempToLevelMinMireds */ \ - { 0x00004010, ZAP_TYPE(INT16U), 2, ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE), \ + { 0x00004010, ZAP_TYPE(INT16U), 2, \ + ZAP_ATTRIBUTE_MASK(MIN_MAX) | ZAP_ATTRIBUTE_MASK(WRITABLE) | ZAP_ATTRIBUTE_MASK(NULLABLE), \ ZAP_MIN_MAX_DEFAULTS_INDEX(16) }, /* StartUpColorTemperatureMireds */ \ { 0x0000FFFC, ZAP_TYPE(BITMAP32), 4, 0, ZAP_SIMPLE_DEFAULT(0) }, /* FeatureMap */ \ { 0x0000FFFD, ZAP_TYPE(INT16U), 2, 0, ZAP_SIMPLE_DEFAULT(5) }, /* ClusterRevision */ \ From f740b750cd5ba8ca079ca42e3698567320991aec Mon Sep 17 00:00:00 2001 From: yunhanw-google Date: Tue, 23 Aug 2022 10:54:32 -0700 Subject: [PATCH 6/9] urgent event needs to honor min interval for subscription. (#21938) * Improve urgent event -- In latest spec, urgent event needs to honor min interval for subscription. -- Add new fflag, urgentEvent, and remove unused flag, SuppressResponse -- ForceDirty would be used when recieving the initial request, where it mark the corresponding handler with dirtiness. -- When there is urgent event, we would set new flag, UrgentEvent, in readHandler instead of setting ForceDirty, after minInterval elapsed, the urgent event would be sent out. Modify the existing urgent event test and check if event can be generated after minInterval elapsed. * address comments * address comment --- src/app/ReadHandler.cpp | 2 +- src/app/ReadHandler.h | 16 +++------ src/app/reporting/Engine.cpp | 42 ++-------------------- src/app/reporting/Engine.h | 6 ---- src/app/tests/TestReadInteraction.cpp | 51 ++++++++++++++++++--------- 5 files changed, 43 insertions(+), 74 deletions(-) diff --git a/src/app/ReadHandler.cpp b/src/app/ReadHandler.cpp index 4422edaf6d0e35..6b609098a87cf4 100644 --- a/src/app/ReadHandler.cpp +++ b/src/app/ReadHandler.cpp @@ -243,7 +243,7 @@ CHIP_ERROR ReadHandler::SendReportData(System::PacketBufferHandle && aPayload, b if (!aMoreChunks) { mPreviousReportsBeginGeneration = mCurrentReportsBeginGeneration; - ClearDirty(); + ClearForceDirtyFlag(); InteractionModelEngine::GetInstance()->ReleaseDataVersionFilterList(mpDataVersionFilterList); } diff --git a/src/app/ReadHandler.h b/src/app/ReadHandler.h index 88b8ad8e13f2b5..b07ef01b2c956a 100644 --- a/src/app/ReadHandler.h +++ b/src/app/ReadHandler.h @@ -198,9 +198,7 @@ class ReadHandler : public Messaging::ExchangeDelegate enum class ReadHandlerFlags : uint8_t { // mHoldReport is used to prevent subscription data delivery while we are - // waiting for the min reporting interval to elapse. If we have to send a - // report immediately due to an urgent event being queued, - // UnblockUrgentEventDelivery can be used to force mHoldReport to false. + // waiting for the min reporting interval to elapse. HoldReport = (1 << 0), // mHoldSync is used to prevent subscription empty report delivery while we @@ -219,7 +217,6 @@ class ReadHandler : public Messaging::ExchangeDelegate PrimingReports = (1 << 3), ActiveSubscription = (1 << 4), FabricFiltered = (1 << 5), - // For subscriptions, we record the dirty set generation when we started to generate the last report. // The mCurrentReportsBeginGeneration records the generation at the start of the current report. This only/ // has a meaningful value while IsReporting() is true. @@ -227,6 +224,8 @@ class ReadHandler : public Messaging::ExchangeDelegate // mPreviousReportsBeginGeneration will be set to mCurrentReportsBeginGeneration after we send the last // chunk of the current report. Anything that was dirty with a generation earlier than // mPreviousReportsBeginGeneration has had its value sent to the client. + // when receiving initial request, it needs mark current handler as dirty. + // when there is urgent event, it needs mark current handler as dirty. ForceDirty = (1 << 6), // Don't need the response for report data if true @@ -300,8 +299,7 @@ class ReadHandler : public Messaging::ExchangeDelegate { return (mDirtyGeneration > mPreviousReportsBeginGeneration) || mFlags.Has(ReadHandlerFlags::ForceDirty); } - void ClearDirty() { mFlags.Clear(ReadHandlerFlags::ForceDirty); } - + void ClearForceDirtyFlag() { mFlags.Clear(ReadHandlerFlags::ForceDirty); } NodeId GetInitiatorNodeId() const { auto session = GetSession(); @@ -319,11 +317,7 @@ class ReadHandler : public Messaging::ExchangeDelegate auto GetTransactionStartGeneration() const { return mTransactionStartGeneration; } - void UnblockUrgentEventDelivery() - { - mFlags.Clear(ReadHandlerFlags::HoldReport); - mFlags.Set(ReadHandlerFlags::ForceDirty); - } + void UnblockUrgentEventDelivery() { mFlags.Set(ReadHandlerFlags::ForceDirty); } const AttributeValueEncoder::AttributeEncodeState & GetAttributeEncodeState() const { return mAttributeEncoderState; } void SetAttributeEncodeState(const AttributeValueEncoder::AttributeEncodeState & aState) { mAttributeEncoderState = aState; } diff --git a/src/app/reporting/Engine.cpp b/src/app/reporting/Engine.cpp index 792631f58acdac..b1c2f5a3db54ea 100644 --- a/src/app/reporting/Engine.cpp +++ b/src/app/reporting/Engine.cpp @@ -653,8 +653,7 @@ void Engine::Run() bool allReadClean = true; - imEngine->mReadHandlers.ForEachActiveObject([this, &allReadClean](ReadHandler * handler) { - UpdateReadHandlerDirty(*handler); + imEngine->mReadHandlers.ForEachActiveObject([&allReadClean](ReadHandler * handler) { if (handler->IsDirty()) { allReadClean = false; @@ -850,41 +849,6 @@ CHIP_ERROR Engine::SetDirty(AttributePathParams & aAttributePath) return CHIP_NO_ERROR; } -void Engine::UpdateReadHandlerDirty(ReadHandler & aReadHandler) -{ - if (!aReadHandler.IsDirty()) - { - return; - } - - if (!aReadHandler.IsType(ReadHandler::InteractionType::Subscribe)) - { - return; - } - - bool intersected = false; - for (auto object = aReadHandler.GetAttributePathList(); object != nullptr; object = object->mpNext) - { - mGlobalDirtySet.ForEachActiveObject([&](auto * path) { - if (path->Intersects(object->mValue) && path->mGeneration > aReadHandler.mPreviousReportsBeginGeneration) - { - intersected = true; - return Loop::Break; - } - return Loop::Continue; - }); - if (intersected) - { - break; - } - } - if (!intersected) - { - aReadHandler.ClearDirty(); - ChipLogDetail(InteractionModel, "clear read handler dirty in UpdateReadHandlerDirty!"); - } -} - CHIP_ERROR Engine::SendReport(ReadHandler * apReadHandler, System::PacketBufferHandle && aPayload, bool aHasMoreChunks) { CHIP_ERROR err = CHIP_NO_ERROR; @@ -974,8 +938,8 @@ CHIP_ERROR Engine::ScheduleEventDelivery(ConcreteEventPath & aPath, uint32_t aBy if (isUrgentEvent) { - ChipLogDetail(DataManagement, "urgent event schedule run"); - return ScheduleRun(); + ChipLogDetail(DataManagement, "urgent event would be sent after min interval"); + return CHIP_NO_ERROR; } return ScheduleBufferPressureEventDelivery(aBytesWritten); diff --git a/src/app/reporting/Engine.h b/src/app/reporting/Engine.h index dc6b6f5ea920a5..45754b490ee7c8 100644 --- a/src/app/reporting/Engine.h +++ b/src/app/reporting/Engine.h @@ -170,12 +170,6 @@ class Engine bool IsClusterDataVersionMatch(const ObjectList * aDataVersionFilterList, const ConcreteReadAttributePath & aPath); - /** - * Check all active subscription, if the subscription has no paths that intersect with global dirty set, - * it would clear dirty flag for that subscription - * - */ - void UpdateReadHandlerDirty(ReadHandler & aReadHandler); /** * Send Report via ReadHandler * diff --git a/src/app/tests/TestReadInteraction.cpp b/src/app/tests/TestReadInteraction.cpp index d97b11f3213a8d..f96f5279e75023 100644 --- a/src/app/tests/TestReadInteraction.cpp +++ b/src/app/tests/TestReadInteraction.cpp @@ -1515,9 +1515,8 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a { app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(), delegate, chip::app::ReadClient::InteractionType::Subscribe); - readPrepareParams.mpEventPathParamsList[0].mIsUrgentEvent = true; - delegate.mGotReport = false; - err = readClient.SendRequest(readPrepareParams); + delegate.mGotReport = false; + err = readClient.SendRequest(readPrepareParams); NL_TEST_ASSERT(apSuite, err == CHIP_NO_ERROR); ctx.DrainAndServiceIO(); @@ -1532,8 +1531,6 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); - NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty()); chip::app::AttributePathParams dirtyPath1; dirtyPath1.mClusterId = kTestClusterId; dirtyPath1.mEndpointId = kTestEndpointId; @@ -1563,6 +1560,7 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a // Test report with 2 different path delegate.mpReadHandler->mFlags.Set(ReadHandler::ReadHandlerFlags::HoldReport, false); delegate.mGotReport = false; + delegate.mGotEventResponse = false; delegate.mNumAttributeResponse = 0; printf("HereHere\n"); @@ -1575,6 +1573,7 @@ void TestReadInteraction::TestSubscribeRoundtrip(nlTestSuite * apSuite, void * a ctx.DrainAndServiceIO(); NL_TEST_ASSERT(apSuite, delegate.mGotReport); + NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse == true); NL_TEST_ASSERT(apSuite, delegate.mNumAttributeResponse == 2); // Test report with 2 different path, and 1 same path @@ -1701,6 +1700,8 @@ void TestReadInteraction::TestSubscribeUrgentWildcardEvent(nlTestSuite * apSuite ctx.DrainAndServiceIO(); + System::Clock::Timestamp startTime = System::SystemClock().GetMonotonicTimestamp(); + NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers() == 1); NL_TEST_ASSERT(apSuite, engine->ActiveHandlerAt(0) != nullptr); delegate.mpReadHandler = engine->ActiveHandlerAt(0); @@ -1711,12 +1712,37 @@ void TestReadInteraction::TestSubscribeUrgentWildcardEvent(nlTestSuite * apSuite NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); + NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty() == true); delegate.mGotEventResponse = false; delegate.mGotReport = false; - ctx.DrainAndServiceIO(); - NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse); + + // wait for min interval 2 seconds(in test, we use 1.9second considering the time variation), expect no event is received, + // then wait for 0.5 seconds, then the urgent event would be sent out + // currently DriveIOUntil will call `DriveIO` at least once, which means that if there is any CPU scheduling issues, + // there's a chance 1.9s will already have elapsed by the time we get there, which will result in DriveIO being called when + // it shouldn't. Better fix could happen inside DriveIOUntil, not sure the sideeffect there. + while (true) + { + if ((System::SystemClock().GetMonotonicTimestamp() - startTime) >= System::Clock::Milliseconds32(1900)) + { + break; + } + ctx.GetIOContext().DriveIO(); // at least one IO loop is guaranteed + } + + NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse != true); + + startTime = System::SystemClock().GetMonotonicTimestamp(); + while (true) + { + if ((System::SystemClock().GetMonotonicTimestamp() - startTime) >= System::Clock::Milliseconds32(500)) + { + break; + } + ctx.GetIOContext().DriveIO(); // at least one IO loop is guaranteed + } + NL_TEST_ASSERT(apSuite, delegate.mGotEventResponse == true); } // By now we should have closed all exchanges and sent all pending acks, so @@ -2228,7 +2254,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripStatusReportTimeout(nlTestSu { app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(), delegate, chip::app::ReadClient::InteractionType::Subscribe); - readPrepareParams.mpEventPathParamsList[0].mIsUrgentEvent = true; printf("\nSend first subscribe request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId); delegate.mGotReport = false; err = readClient.SendRequest(readPrepareParams); @@ -2246,8 +2271,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripStatusReportTimeout(nlTestSu NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); - NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty()); chip::app::AttributePathParams dirtyPath1; dirtyPath1.mClusterId = kTestClusterId; dirtyPath1.mEndpointId = kTestEndpointId; @@ -2548,7 +2571,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripChunkStatusReportTimeout(nlT { app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(), delegate, chip::app::ReadClient::InteractionType::Subscribe); - readPrepareParams.mpEventPathParamsList[0].mIsUrgentEvent = true; printf("\nSend first subscribe request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId); delegate.mGotReport = false; err = readClient.SendRequest(readPrepareParams); @@ -2565,8 +2587,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripChunkStatusReportTimeout(nlT NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); - NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty()); chip::app::AttributePathParams dirtyPath1; dirtyPath1.mClusterId = Test::MockClusterId(2); dirtyPath1.mEndpointId = Test::kMockEndpoint3; @@ -2645,7 +2665,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripChunkReportTimeout(nlTestSui { app::ReadClient readClient(chip::app::InteractionModelEngine::GetInstance(), &ctx.GetExchangeManager(), delegate, chip::app::ReadClient::InteractionType::Subscribe); - readPrepareParams.mpEventPathParamsList[0].mIsUrgentEvent = true; printf("\nSend first subscribe request message to Node: %" PRIu64 "\n", chip::kTestDeviceNodeId); delegate.mGotReport = false; err = readClient.SendRequest(readPrepareParams); @@ -2662,8 +2681,6 @@ void TestReadInteraction::TestPostSubscribeRoundtripChunkReportTimeout(nlTestSui NL_TEST_ASSERT(apSuite, engine->GetNumActiveReadHandlers(ReadHandler::InteractionType::Subscribe) == 1); GenerateEvents(apSuite, apContext); - NL_TEST_ASSERT(apSuite, !delegate.mpReadHandler->mFlags.Has(ReadHandler::ReadHandlerFlags::HoldReport)); - NL_TEST_ASSERT(apSuite, delegate.mpReadHandler->IsDirty()); chip::app::AttributePathParams dirtyPath1; dirtyPath1.mClusterId = Test::MockClusterId(2); dirtyPath1.mEndpointId = Test::kMockEndpoint3; From 245830b2d3a08b47d32b7bf1c9277e8ddf3f6694 Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven <67962328+jepenven-silabs@users.noreply.github.com> Date: Tue, 23 Aug 2022 14:59:05 -0400 Subject: [PATCH 7/9] Fix building thermostat (#22073) --- .../platform/efr32/display/demo-ui-bitmaps.h | 30 +++++++++++++++++++ examples/thermostat/efr32/BUILD.gn | 11 +++++-- examples/thermostat/efr32/include/AppConfig.h | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/examples/platform/efr32/display/demo-ui-bitmaps.h b/examples/platform/efr32/display/demo-ui-bitmaps.h index 6f77ce4b733139..4eca9c0c48e7aa 100644 --- a/examples/platform/efr32/display/demo-ui-bitmaps.h +++ b/examples/platform/efr32/display/demo-ui-bitmaps.h @@ -264,6 +264,36 @@ 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +#elif IS_DEMO_THERMOSTAT +#define ON_DEMO_BITMAP \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xE0, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x81, 0x81, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC1, 0x83, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, \ + 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, \ + 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, \ + 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0x00, 0x00, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0x0F, 0x00, 0x00, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0x00, 0x00, \ + 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x80, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x07, 0xE0, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF +#define OFF_DEMO_BITMAP ON_DEMO_BITMAP + #else // Unknown demo.... #define ON_DEMO_BITMAP \ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, \ diff --git a/examples/thermostat/efr32/BUILD.gn b/examples/thermostat/efr32/BUILD.gn index 7e4e923992ff70..415d9c5e80d212 100644 --- a/examples/thermostat/efr32/BUILD.gn +++ b/examples/thermostat/efr32/BUILD.gn @@ -245,8 +245,15 @@ efr32_executable("thermostat_app") { } if (!disable_lcd) { - sources += [ "${examples_plat_dir}/display/lcd.c" ] - defines += [ "DISPLAY_ENABLED" ] + sources += [ + "${examples_plat_dir}/display/demo-ui.c", + "${examples_plat_dir}/display/lcd.cpp", + ] + include_dirs += [ "${examples_plat_dir}/display" ] + defines += [ + "DISPLAY_ENABLED", + "IS_DEMO_THERMOSTAT=1", + ] if (show_qr_code) { defines += [ "QR_CODE_ENABLED" ] deps += [ "${chip_root}/examples/common/QRCode" ] diff --git a/examples/thermostat/efr32/include/AppConfig.h b/examples/thermostat/efr32/include/AppConfig.h index 91501d889a6234..946b593cab50a4 100644 --- a/examples/thermostat/efr32/include/AppConfig.h +++ b/examples/thermostat/efr32/include/AppConfig.h @@ -32,7 +32,7 @@ extern "C" { #endif -void efr32LogInit(void); +void efr32InitLog(void); void efr32Log(const char * aFormat, ...); #define EFR32_LOG(...) efr32Log(__VA_ARGS__); From fee403eeb94824bd759f7dd34e2c6e2a2dcf16be Mon Sep 17 00:00:00 2001 From: Michael Spang Date: Tue, 23 Aug 2022 15:56:32 -0400 Subject: [PATCH 8/9] Fix shutdown ordering in DeviceControllerSystemState::Shutdown (#22048) DeviceControllerSystemState shuts down PlatformMgr before higher level objects that use timers such as ExchangeMgr. This leads to calls into the system layer after it has been shut down. Fix the ordering so that PlatformMgr is shut down last. Co-authored-by: Andrei Litvin --- .../CHIPDeviceControllerFactory.cpp | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/controller/CHIPDeviceControllerFactory.cpp b/src/controller/CHIPDeviceControllerFactory.cpp index 1c06e8217f3eeb..45ab785e508640 100644 --- a/src/controller/CHIPDeviceControllerFactory.cpp +++ b/src/controller/CHIPDeviceControllerFactory.cpp @@ -419,19 +419,6 @@ void DeviceControllerSystemState::Shutdown() mTransportMgr = nullptr; } -#if CONFIG_DEVICE_LAYER - // - // We can safely call PlatformMgr().Shutdown(), which like DeviceController::Shutdown(), - // expects to be called with external thread synchronization and will not try to acquire the - // stack lock. - // - // Actually stopping the event queue is a separable call that applications will have to sequence. - // Consumers are expected to call PlaformMgr().StopEventLoopTask() before calling - // DeviceController::Shutdown() in the CONFIG_DEVICE_LAYER configuration - // - DeviceLayer::PlatformMgr().Shutdown(); -#endif - if (mExchangeMgr != nullptr) { mExchangeMgr->Shutdown(); @@ -483,6 +470,19 @@ void DeviceControllerSystemState::Shutdown() // so that SetupController/Commissioner can use it mFabrics = nullptr; } + +#if CONFIG_DEVICE_LAYER + // + // We can safely call PlatformMgr().Shutdown(), which like DeviceController::Shutdown(), + // expects to be called with external thread synchronization and will not try to acquire the + // stack lock. + // + // Actually stopping the event queue is a separable call that applications will have to sequence. + // Consumers are expected to call PlaformMgr().StopEventLoopTask() before calling + // DeviceController::Shutdown() in the CONFIG_DEVICE_LAYER configuration + // + DeviceLayer::PlatformMgr().Shutdown(); +#endif } } // namespace Controller From fa24ab6f8c19bdf4817542aba8562142a1ae1c60 Mon Sep 17 00:00:00 2001 From: mkardous-silabs <84793247+mkardous-silabs@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:40:44 -0400 Subject: [PATCH 9/9] [EFR32] Add Board Support for efr32 boards (#22099) * add BRD2703A config files * Add Explorer Board to gn files * Update sdk build files * Fix external flash issue * Update submodule to main * remove unwanted change * Add support for BRD4162A --- examples/chef/efr32/BUILD.gn | 5 +++-- examples/light-switch-app/efr32/BUILD.gn | 5 +++-- examples/lighting-app/efr32/BUILD.gn | 5 +++-- examples/lock-app/efr32/BUILD.gn | 5 +++-- examples/thermostat/efr32/BUILD.gn | 5 +++-- examples/window-app/efr32/BUILD.gn | 5 +++-- third_party/silabs/efr32_board.gni | 8 +++++++- third_party/silabs/efr32_sdk.gni | 17 +++++++++++++++-- third_party/silabs/matter_support | 2 +- 9 files changed, 41 insertions(+), 16 deletions(-) diff --git a/examples/chef/efr32/BUILD.gn b/examples/chef/efr32/BUILD.gn index e23b747fcad1dd..3d1bf35352fa93 100644 --- a/examples/chef/efr32/BUILD.gn +++ b/examples/chef/efr32/BUILD.gn @@ -91,8 +91,9 @@ chip_data_model("chef-common") { is_server = true } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/light-switch-app/efr32/BUILD.gn b/examples/light-switch-app/efr32/BUILD.gn index 2d628f537f9f6e..4b6c15741224d0 100644 --- a/examples/light-switch-app/efr32/BUILD.gn +++ b/examples/light-switch-app/efr32/BUILD.gn @@ -84,8 +84,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/lighting-app/efr32/BUILD.gn b/examples/lighting-app/efr32/BUILD.gn index fbd5a88a7909b9..6301fede13a30a 100644 --- a/examples/lighting-app/efr32/BUILD.gn +++ b/examples/lighting-app/efr32/BUILD.gn @@ -84,8 +84,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/lock-app/efr32/BUILD.gn b/examples/lock-app/efr32/BUILD.gn index e76b9cd48f1d1e..d757da6c50c4ff 100644 --- a/examples/lock-app/efr32/BUILD.gn +++ b/examples/lock-app/efr32/BUILD.gn @@ -84,8 +84,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/thermostat/efr32/BUILD.gn b/examples/thermostat/efr32/BUILD.gn index 415d9c5e80d212..bb4e2cb7a17e61 100644 --- a/examples/thermostat/efr32/BUILD.gn +++ b/examples/thermostat/efr32/BUILD.gn @@ -81,8 +81,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/examples/window-app/efr32/BUILD.gn b/examples/window-app/efr32/BUILD.gn index a9aa7cf402911c..a9e0c030a9c292 100644 --- a/examples/window-app/efr32/BUILD.gn +++ b/examples/window-app/efr32/BUILD.gn @@ -77,8 +77,9 @@ if (chip_enable_wifi) { assert(use_rs911x || use_wf200) } -# ThunderBoards (No LCD) -if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B") { +# ThunderBoards and Explorer Kit (No LCD) +if (efr32_board == "BRD4166A" || efr32_board == "BRD2601B" || + efr32_board == "BRD2703A") { show_qr_code = false disable_lcd = true } diff --git a/third_party/silabs/efr32_board.gni b/third_party/silabs/efr32_board.gni index b697d2bb3afbc8..3de8aa1337bc6a 100644 --- a/third_party/silabs/efr32_board.gni +++ b/third_party/silabs/efr32_board.gni @@ -44,6 +44,9 @@ if (efr32_board == "BRD4304A") { } else if (efr32_board == "BRD4161A") { efr32_family = "efr32mg12" efr32_mcu = "EFR32MG12P432F1024GL125" +} else if (efr32_board == "BRD4162A") { + efr32_family = "efr32mg12" + efr32_mcu = "EFR32MG12P332F1024GL125" } else if (efr32_board == "BRD4163A") { efr32_family = "efr32mg12" efr32_mcu = "EFR32MG12P433F1024GL125" @@ -75,8 +78,11 @@ if (efr32_board == "BRD4304A") { } else if (efr32_board == "BRD2601B") { efr32_family = "efr32mg24" efr32_mcu = "EFR32MG24B310F1536IM48" +} else if (efr32_board == "BRD2703A") { + efr32_family = "efr32mg24" + efr32_mcu = "EFR32MG24B020F1536IM48" } else { print( - "Please provide a valid value for EFR32_BOARD env variable (currently supported BRD4304A, BRD4161A, BRD4163A, BRD4164A BRD4166A, BRD4170A, BRD4186C, BRD4187C, BRD2601B)") + "Please provide a valid value for EFR32_BOARD env variable (currently supported BRD4304A, BRD4161A, BRD4163A, BRD4164A BRD4166A, BRD4170A, BRD4186C, BRD4187C, BRD2601B, BRD2703A)") assert(false, "The board ${efr32_board} is unsupported") } diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 727ecea7acd5ef..93354bcc5594e6 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -33,6 +33,11 @@ declare_args() { use_external_flash = true } +# Explorer Kit does not have external flash +if (efr32_board == "BRD2703A") { + use_external_flash = false +} + assert(efr32_sdk_root != "", "efr32_sdk_root must be specified") # Defines an efr32 SDK build target. @@ -210,13 +215,14 @@ template("efr32_sdk") { if (defined(invoker.use_external_flash) && use_external_flash) { defines += [ "CONFIG_USE_EXTERNAL_FLASH" ] + + _include_dirs += [ "${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/inc/sl_mx25_flash_shutdown_usart" ] } _include_dirs += [ "${efr32_sdk_root}/platform/emdrv/uartdrv/inc", "${efr32_sdk_root}/platform/emdrv/uartdrv/config", "${efr32_sdk_root}/hardware/driver/memlcd/inc/memlcd_usart", - "${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/inc/sl_mx25_flash_shutdown_usart", ] } @@ -226,6 +232,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/radio/rail_lib/chip/efr32/efr32xg1x", "${efr32_sdk_root}/util/third_party/freertos/kernel/portable/GCC/ARM_CM4F", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg1x/config", + "${efr32_sdk_root}/platform/service/device_init/config/s1/", ] libs += [ @@ -243,6 +250,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/util/third_party/freertos/kernel/portable/GCC/ARM_CM33_NTZ/non_secure", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg21", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg21/config", + "${efr32_sdk_root}/platform/service/device_init/config/s2/", ] libs += [ @@ -263,6 +271,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/util/third_party/freertos/kernel/portable/GCC/ARM_CM33_NTZ/non_secure", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg24", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/efr32xg24/config", + "${efr32_sdk_root}/platform/service/device_init/config/s2/", ] libs += [ @@ -365,6 +374,7 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/radio/rail_lib/hal/efr32/hal_efr.c", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/pa-conversions/pa_conversions_efr32.c", "${efr32_sdk_root}/platform/radio/rail_lib/plugin/rail_util_pti/sl_rail_util_pti.c", + "${efr32_sdk_root}/platform/service/device_init/src/sl_device_init_lfrco.c", "${efr32_sdk_root}/platform/service/device_init/src/sl_device_init_nvic.c", "${efr32_sdk_root}/platform/service/hfxo_manager/src/sl_hfxo_manager.c", "${efr32_sdk_root}/platform/service/legacy_hal/src/token_legacy.c", @@ -527,13 +537,16 @@ template("efr32_sdk") { (defined(invoker.use_external_flash) && use_external_flash)) { sources += [ "${efr32_sdk_root}/hardware/driver/memlcd/src/memlcd_usart/sl_memlcd_spi.c", - "${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/src/sl_mx25_flash_shutdown_usart/sl_mx25_flash_shutdown.c", "${efr32_sdk_root}/platform/emdrv/uartdrv/src/uartdrv.c", "${efr32_sdk_root}/platform/emlib/src/em_eusart.c", "${efr32_sdk_root}/platform/emlib/src/em_leuart.c", "${efr32_sdk_root}/platform/emlib/src/em_usart.c", "${sdk_support_root}/matter/efr32/${efr32_family}/${efr32_board}/autogen/sl_uartdrv_init.c", ] + + if (defined(invoker.use_external_flash) && use_external_flash) { + sources += [ "${efr32_sdk_root}/hardware/driver/mx25_flash_shutdown/src/sl_mx25_flash_shutdown_usart/sl_mx25_flash_shutdown.c" ] + } } if ((defined(invoker.show_qr_code) && invoker.show_qr_code) || diff --git a/third_party/silabs/matter_support b/third_party/silabs/matter_support index 16c1ed8eca039b..0c84c861c036fb 160000 --- a/third_party/silabs/matter_support +++ b/third_party/silabs/matter_support @@ -1 +1 @@ -Subproject commit 16c1ed8eca039bb9527421411bd605de8ce21442 +Subproject commit 0c84c861c036fba5ba35eccca3f366925700b2b5