diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index 2d8ec861663b3a..7983d1667b9a04 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -247,16 +247,13 @@ source_set("siwx917-common") { "${wifi_sdk_dir}/ethernetif.cpp", "${wifi_sdk_dir}/lwip_netif.cpp", "${wifi_sdk_dir}/wfx_notify.cpp", + "BaseApplication.cpp", "SiWx917/rsi_if.c", "SiWx917/wfx_rsi_host.c", "init_ccpPlatform.cpp", "matter_config.cpp", ] - if (use_base_app) { - sources += [ "BaseApplication.cpp" ] - } - if (chip_enable_pw_rpc || chip_build_libshell) { sources += [ "uart.cpp" ] } diff --git a/examples/platform/silabs/args.gni b/examples/platform/silabs/args.gni index 47d4cbb5c7bc20..ff5317006bd805 100644 --- a/examples/platform/silabs/args.gni +++ b/examples/platform/silabs/args.gni @@ -22,5 +22,4 @@ chip_system_project_config_include = "" declare_args() { app_data_model = "" - use_base_app = true } diff --git a/examples/platform/silabs/efr32/BUILD.gn b/examples/platform/silabs/efr32/BUILD.gn index 4a7119dbc5398b..6d08c1d47a532b 100644 --- a/examples/platform/silabs/efr32/BUILD.gn +++ b/examples/platform/silabs/efr32/BUILD.gn @@ -280,14 +280,11 @@ source_set("efr32-common") { "${silabs_common_plat_dir}/heap_4_silabs.c", "${silabs_common_plat_dir}/silabs_utils.cpp", "${silabs_common_plat_dir}/syscalls_stubs.cpp", + "BaseApplication.cpp", "init_efrPlatform.cpp", "matter_config.cpp", ] - if (use_base_app) { - sources += [ "BaseApplication.cpp" ] - } - if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli) { sources += [ "uart.cpp" ] } diff --git a/examples/window-app/silabs/BUILD.gn b/examples/window-app/silabs/BUILD.gn index 3536280e5e7ce8..e5c33fdbdeab9e 100644 --- a/examples/window-app/silabs/BUILD.gn +++ b/examples/window-app/silabs/BUILD.gn @@ -18,9 +18,17 @@ import("//build_overrides/efr32_sdk.gni") import("//build_overrides/pigweed.gni") import("${build_root}/config/defaults.gni") +import("${efr32_sdk_build_root}/silabs_executable.gni") + +import("${chip_root}/examples/common/pigweed/pigweed_rpcs.gni") import("${chip_root}/src/platform/device.gni") import("${chip_root}/third_party/silabs/silabs_board.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") + +if (chip_enable_pw_rpc) { + import("//build_overrides/pigweed.gni") + import("$dir_pw_build/target_types.gni") +} + assert(current_os == "freertos") project_dir = "${chip_root}/examples/window-app" @@ -106,10 +114,10 @@ silabs_executable("window_app") { defines = [] sources = [ - "${project_dir}/common/src/WindowApp.cpp", - "${project_dir}/common/src/ZclCallbacks.cpp", - "src/WindowAppImpl.cpp", - "src/main.cpp", + "${examples_common_plat_dir}/main.cpp", + "src/AppTask.cpp", + "src/WindowManager.cpp", + "src/ZclCallbacks.cpp", ] if (!disable_lcd) { diff --git a/examples/window-app/silabs/SiWx917/.gn b/examples/window-app/silabs/SiWx917/.gn deleted file mode 100644 index 0adefc6ff99c6a..00000000000000 --- a/examples/window-app/silabs/SiWx917/.gn +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright (c) 2020 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. - -import("//build_overrides/build.gni") - -# The location of the build configuration file. -buildconfig = "${build_root}/config/BUILDCONFIG.gn" - -# CHIP uses angle bracket includes. -check_system_includes = true - -default_args = { - target_cpu = "arm" - target_os = "freertos" - import("//args.gni") -} diff --git a/examples/window-app/silabs/SiWx917/BUILD.gn b/examples/window-app/silabs/SiWx917/BUILD.gn deleted file mode 100644 index 0d6c06b8fa8c4e..00000000000000 --- a/examples/window-app/silabs/SiWx917/BUILD.gn +++ /dev/null @@ -1,107 +0,0 @@ -# Copyright (c) 2020 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. - -import("//build_overrides/build.gni") -import("//build_overrides/chip.gni") -import("//build_overrides/efr32_sdk.gni") -import("//build_overrides/pigweed.gni") - -import("${build_root}/config/defaults.gni") -import("${chip_root}/src/platform/device.gni") -import("${efr32_sdk_build_root}/SiWx917_sdk.gni") -import("${efr32_sdk_build_root}/silabs_executable.gni") - -assert(current_os == "freertos") - -project_dir = "${chip_root}/examples/window-app" -efr32_project_dir = "${project_dir}/silabs/SiWx917" -examples_plat_dir = "${chip_root}/examples/platform/silabs/SiWx917" -examples_common_plat_dir = "${chip_root}/examples/platform/silabs" -import("${examples_plat_dir}/args.gni") - -declare_args() { - # Dump memory usage at link time. - chip_print_memory_usage = false -} - -siwx917_sdk("sdk") { - sources = [ - "${efr32_project_dir}/include/CHIPProjectConfig.h", - "${examples_plat_dir}/FreeRTOSConfig.h", - ] - - include_dirs = [ - "${chip_root}/src/platform/silabs/SiWx917", - "${efr32_project_dir}/include", - "${examples_plat_dir}", - "${chip_root}/src/lib", - "${examples_common_plat_dir}", - ] -} - -silabs_executable("window_app") { - output_name = "chip-siwx917-window-example.out" - output_dir = root_out_dir - include_dirs = [ - "include", - "${project_dir}/common/include", - ] - defines = [] - - sources = [ - "${project_dir}/common/src/WindowApp.cpp", - "${project_dir}/common/src/ZclCallbacks.cpp", - "src/WindowAppImpl.cpp", - "src/main.cpp", - ] - - if (!disable_lcd) { - sources += [ "src/LcdPainter.cpp" ] - } - - deps = [ - ":sdk", - "${examples_plat_dir}:siwx917-common", - app_data_model, - ] - - ldscript = "${examples_plat_dir}/ldscripts/${silabs_family}.ld" - - inputs = [ ldscript ] - - ldflags = [ "-T" + rebase_path(ldscript, root_build_dir) ] - - if (chip_print_memory_usage) { - ldflags += [ - "-Wl,--print-memory-usage", - "-fstack-usage", - ] - } - - # WiFi Settings - if (chip_enable_wifi) { - ldflags += [ - "-Wl,--defsym", - "-Wl,SILABS_WIFI=1", - ] - } -} - -group("siwx917") { - deps = [ ":window_app" ] -} - -group("default") { - deps = [ ":siwx917" ] -} diff --git a/examples/window-app/silabs/SiWx917/README.md b/examples/window-app/silabs/SiWx917/README.md deleted file mode 100644 index a68345a81187a1..00000000000000 --- a/examples/window-app/silabs/SiWx917/README.md +++ /dev/null @@ -1,166 +0,0 @@ -# Matter SiWx917 Window Covering Example - -An example showing the use of CHIP on the Silicon Labs SiWx917 SoC device. - -
- -- [Matter SiWx917 Window Covering Example](#matter-siwx917-window-covering-example) - - [Introduction](#introduction) - - [Building](#building) - - [Flashing the Application](#flashing-the-application) - - [Viewing Logging Output](#viewing-logging-output) - - [Running the Complete Example](#running-the-complete-example) - - [Notes](#notes) - - [Building options](#building-options) - - [Disabling logging](#disabling-logging) - - [Debug build / release build](#debug-build--release-build) - - [Disabling LCD](#disabling-lcd) - - [KVS maximum entry count](#kvs-maximum-entry-count) - -
- -> **NOTE:** Silicon Laboratories now maintains a public matter GitHub repo with -> frequent releases thoroughly tested and validated. Developers looking to -> develop matter products with silabs hardware are encouraged to use our latest -> release with added tools and documentation. -> [Silabs Matter Github](https://github.com/SiliconLabs/matter/releases) - -## Introduction - -The SiWx917 window-covering example provides a baseline demonstration of a -Window Covering device, built using Matter, the Silicon Labs Gecko SDK, and the -Silicon Labs WiseMCU SDK. It can be controlled by a Chip controller over a Wi-Fi -network. - -The SiWx917 device can be commissioned over Bluetooth Low Energy where the -device and the Chip controller will exchange security information with the -rendezvous procedure. The Wi-Fi Network credentials are provided to the SiWx917 -device which will then join the Wi-Fi network. - -If the LCD is enabled, the LCD on the Silabs WSTK shows a QR Code containing the -needed commissioning information for the BLE connection and starting the -rendezvous procedure. Once the device is commissioned, the displays shows a -representation of the window covering state. - -The window-covering example is intended to serve both as a means to explore the -workings of Matter as well as a template for creating real products based on the -Silicon Labs platform. - -## Building - -- Download the - [Simplicity Commander](https://www.silabs.com/mcu/programming-options) - command line tool, and ensure that `commander` is your shell search path. - (For Mac OS X, `commander` is located inside - `Commander.app/Contents/MacOS/`.) - -- Download and install a suitable ARM gcc tool chain: - [GNU Arm Embedded Toolchain 9-2019-q4-major](https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-rm/downloads) - -- Install some additional tools(likely already present for CHIP developers): - - # Linux - $ sudo apt-get install git ninja-build - - # Mac OS X - $ brew install ninja - -- Supported hardware: - - - > For the latest supported hardware please refer to the - > [Hardware Requirements](https://github.com/SiliconLabs/matter/blob/latest/docs/silabs/general/HARDWARE_REQUIREMENTS.md) - > in the Silicon Labs Matter Github Repo - -* Build the example application: - - cd ~/connectedhomeip - ./scripts/examples/gn_efr32_example.sh ./examples/window-app/silabs/SiWx917/ ./out/window-app BRD4325B - -- To delete generated executable, libraries and object files use: - - $ cd ~/connectedhomeip - $ rm -rf ./out/ - - - -## Flashing the Application - -- Flashing requires the SiWx917 SoC device to be configured in the Ozone - Debugger. -- Once it's configured, it can be run with the Ozone Debugger by loading the - .out file. - - > For detailed instructions, please refer to - > [Running the Matter Demo on SiWx917 SoC](https://github.com/SiliconLabs/matter/blob/latest/docs/silabs/wifi/RUN_DEMO_SiWx917_SoC.md) - > in the Silicon Labs Matter Github Repo - -## Viewing Logging Output - -The example application's logging output can be viewed in the Ozone Debugger. - -## Running the Complete Example - - You can provision the [chip-tool](https://github.com/project-chip/connectedhomeip/blob/master/examples/chip-tool/README.md) - and send ZCL commands to the window covering device. For - instance, to set the window covering lift by percentage: - - - > $SSID and $PSK are the SSID and passcode of your Wi-Fi Access Point. - - ``` - chip-tool pairing ble-wifi 1122 $SSID $PSK 20202021 3840 - - chip-tool onoff on 1 1 - - chip-tool windowcovering go-to-tilt-percentage 50 0 1 1 - ``` - - To see the supported window covering cluster commands, use: - - ``` - chip-tool windowcovering - ``` - -### Notes - -- Depending on your network settings your router might not provide native IPv6 - addresses to your devices (Router / PC). If this is the case, you need to - add a static IPv6 addresses on both devices and then an IPv6 route to the - border router on your PC - - # On PC (Linux) : - $ sudo ip addr add dev 2002::1/64 - - # Add IPv6 route on PC (Linux) - $ sudo ip route add /64 via 2002::2 - -## Building options - -All of Silabs's examples within the Matter repo have all the features enabled by -default, as to provide the best end user experience. However some of those -features can easily be toggled on or off. Here is a short list of options : - -### Disabling logging - -chip_progress_logging, chip_detail_logging, chip_automation_logging - - $ ./scripts/examples/gn_efr32_example.sh ./examples/window-app/silabs/SiWx917 ./out/window-app BRD4325B "chip_detail_logging=false chip_automation_logging=false chip_progress_logging=false" - -### Debug build / release build - -is_debug - - $ ./scripts/examples/gn_efr32_example.sh ./examples/window-app/silabs/SiWx917 ./out/window-app BRD4325B "is_debug=false" - -### Disabling LCD - -show_qr_code - - $ ./scripts/examples/gn_efr32_example.sh ./examples/window-app/silabs/SiWx917 ./out/window-app BRD4325B "show_qr_code=false" - -### KVS maximum entry count - -kvs_max_entries - - Set the maximum Kvs entries that can be stored in NVM (Default 75) - Thresholds: 30 <= kvs_max_entries <= 255 - - $ ./scripts/examples/gn_efr32_example.sh ./examples/window-app/silabs/SiWx917 ./out/window-app BRD4325B kvs_max_entries=50 diff --git a/examples/window-app/silabs/SiWx917/args.gni b/examples/window-app/silabs/SiWx917/args.gni deleted file mode 100644 index 76712544639802..00000000000000 --- a/examples/window-app/silabs/SiWx917/args.gni +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) 2020 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. - -import("//build_overrides/chip.gni") -import("${chip_root}/config/standalone/args.gni") -import("${chip_root}/src/platform/silabs/args.gni") - -silabs_sdk_target = get_label_info(":sdk", "label_no_toolchain") - -app_data_model = "${chip_root}/examples/window-app/common:window-common" -chip_enable_ota_requestor = true - -use_base_app = false diff --git a/examples/window-app/silabs/SiWx917/build_overrides b/examples/window-app/silabs/SiWx917/build_overrides deleted file mode 120000 index 995884e6163eb5..00000000000000 --- a/examples/window-app/silabs/SiWx917/build_overrides +++ /dev/null @@ -1 +0,0 @@ -../../../build_overrides \ No newline at end of file diff --git a/examples/window-app/silabs/SiWx917/include/AppConfig.h b/examples/window-app/silabs/SiWx917/include/AppConfig.h deleted file mode 100644 index 19c64320bf6e7a..00000000000000 --- a/examples/window-app/silabs/SiWx917/include/AppConfig.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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. - */ - -#pragma once - -#include "silabs_utils.h" - -// ---- Window Example App Config ---- -#define APP_TASK_NAME "APP" - -#define LCD_SIZE 128 -#define LCD_MARGIN_SIZE 1 -#define LCD_BORDER_SIZE 2 -#define LCD_FRAME_SIZE (2 * LCD_MARGIN_SIZE + LCD_BORDER_SIZE) -#define LCD_COVER_SIZE (LCD_SIZE - 2 * LCD_FRAME_SIZE) -#define LIFT_OPEN_LIMIT 0 -#define LIFT_CLOSED_LIMIT (LCD_COVER_SIZE - 1) -#define LIFT_DELTA 1000 // 10% -#define TILT_OPEN_LIMIT 0 -#define TILT_CLOSED_LIMIT (LCD_COVER_SIZE / 10 - 1) -#define TILT_DELTA 1000 // 10% - -#define WINDOW_COVER_COUNT 2 - -#ifndef WINDOW_COVER_ENDPOINT1 -#define WINDOW_COVER_ENDPOINT1 1 -#endif - -#ifndef WINDOW_COVER_ENDPOINT2 -#define WINDOW_COVER_ENDPOINT2 2 -#endif - -#ifndef LONG_PRESS_TIMEOUT -#define LONG_PRESS_TIMEOUT 3000 -#endif - -#ifndef COVER_LIFT_TILT_TIMEOUT -#define COVER_LIFT_TILT_TIMEOUT 500 -#endif diff --git a/examples/window-app/silabs/SiWx917/include/CHIPProjectConfig.h b/examples/window-app/silabs/SiWx917/include/CHIPProjectConfig.h deleted file mode 100644 index f1a69277f06079..00000000000000 --- a/examples/window-app/silabs/SiWx917/include/CHIPProjectConfig.h +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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. - */ - -/** - * @file - * Example project configuration file for CHIP. - * - * This is a place to put application or project-specific overrides - * to the default configuration values for general CHIP features. - * - */ - -#pragma once - -// Use a default pairing code if one hasn't been provisioned in flash. -#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE -#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_PIN_CODE 20202021 -#endif - -#ifndef CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR -#define CHIP_DEVICE_CONFIG_USE_TEST_SETUP_DISCRIMINATOR 0xF00 -#endif -// For convenience, Chip Security Test Mode can be enabled and the -// requirement for authentication in various protocols can be disabled. -// -// WARNING: These options make it possible to circumvent basic Chip security functionality, -// including message encryption. Because of this they MUST NEVER BE ENABLED IN PRODUCTION BUILDS. -// -#define CHIP_CONFIG_SECURITY_TEST_MODE 0 - -/** - * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID - * - * 0xFFF1: Test vendor. - */ -#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 0xFFF1 - -/** - * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID - * - * 0x8009: example window app - */ -#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 0x8010 - -/** - * CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE - * - * Enable support for Chip-over-BLE (CHIPoBLE). - */ -#define CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE 1 - -/** - * CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER - * - * Enables the use of a hard-coded default serial number if none - * is found in Chip NV storage. - */ -#define CHIP_DEVICE_CONFIG_TEST_SERIAL_NUMBER "TEST_SN" - -/** - * CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS - * - * Enable recording UTC timestamps. - */ -#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_UTC_TIMESTAMPS 1 - -/** - * CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE - * - * A size, in bytes, of the individual debug event logging buffer. - */ -#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (512) - -/** - * CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL - * - * The interval (in units of 0.625ms) at which the device will send BLE advertisements while - * in fast advertising mode. - * - * 40 (25ms). - */ -#define CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL 40 - -/** - * CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL - * - * The interval (in units of 0.625ms) at which the device will send BLE advertisements while - * in slow advertisement mode. - * - * 800 (500ms). - */ -#define CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL 800 - -/** - * CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_TIMEOUT - * - * The amount of time in miliseconds after which BLE should change his advertisements - * from fast interval to slow interval. - * - * 30000 (30 secondes). - */ -#define CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_TIMEOUT (30 * 1000) - -/** - * @def CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL - * - * @brief - * Active retransmit interval, or time to wait before retransmission after - * subsequent failures in milliseconds. - * - * This is the default value, that might be adjusted by end device depending on its - * needs (e.g. sleeping period) using Service Discovery TXT record CRA key. - * - */ -#define CHIP_CONFIG_MRP_LOCAL_ACTIVE_RETRY_INTERVAL (2000_ms32) - -#define CHIP_DEVICE_CONFIG_ENABLE_EXTENDED_DISCOVERY 1 diff --git a/examples/window-app/silabs/SiWx917/include/DeviceConfig.h b/examples/window-app/silabs/SiWx917/include/DeviceConfig.h deleted file mode 100644 index 350fbb4a904351..00000000000000 --- a/examples/window-app/silabs/SiWx917/include/DeviceConfig.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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. - */ - -#pragma once - -#ifdef SIWX917_USE_COMISSIONABLE_DATA - -uint32_t discriminatorValue = 3840; -uint64_t passcode = 20202021; -uint32_t spake2Interation = 1000; -char spake2Salt[] = "U1BBS0UyUCBLZXkgU2FsdA=="; -char spake2Verifier[] = "uWFwqugDNGiEck/po7KHwwMwwqZgN10XuyBajPGuyzUEV/iree4lOrao5GuwnlQ65CJzbeUB49s31EH+NEkg0JVI5MGCQGMMT/" - "SRPFNRODm3wH/MBiehuFc6FJ/NH6Rmzw=="; -char genSpake2Path[] = ""; -uint32_t productId = 32773; -uint32_t vendorId = 65521; -char productName[] = "silabs_product"; -char vendorName[] = "silabs_vendor"; -char hwVersionString[] = "1.0"; -uint32_t rotatingId; -uint32_t commissionableFlow = 1; -uint8_t rendezvousFlag = 2; - -#endif \ No newline at end of file diff --git a/examples/window-app/silabs/SiWx917/include/LcdPainter.h b/examples/window-app/silabs/SiWx917/include/LcdPainter.h deleted file mode 100644 index 4a30bdede2c3ea..00000000000000 --- a/examples/window-app/silabs/SiWx917/include/LcdPainter.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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. - */ - -#pragma once - -// clang-format off -#include "app-common/app-common/zap-generated/enums.h" -#include "app-common/app-common/zap-generated/cluster-enums.h" -// clang-format on - -#include - -#include - -enum class LcdIcon -{ - None = 0, - One, - Two, - Lift, - Tilt -}; - -class PixelPainter -{ -public: - PixelPainter(uint16_t lift, uint16_t tilt); - virtual ~PixelPainter() = default; - virtual uint8_t Color(uint32_t x, uint32_t y) = 0; - -protected: - uint16_t mLift; - uint16_t mTilt; -}; - -class CompositePainter : public PixelPainter -{ -public: - CompositePainter(uint16_t lift, uint16_t tilt, PixelPainter * painter1, PixelPainter * painter2, PixelPainter * painter3); - uint8_t Color(uint32_t x, uint32_t y); - -private: - PixelPainter * mPainter1; - PixelPainter * mPainter2; - PixelPainter * mPainter3; -}; - -class FramePainter : public PixelPainter -{ - using PixelPainter::PixelPainter; - uint8_t Color(uint32_t x, uint32_t y); -}; - -class IconPainter : public PixelPainter -{ -public: - IconPainter(uint16_t lift, uint16_t tilt, LcdIcon icon); - uint8_t Color(uint32_t x, uint32_t y); - -private: - uint8_t mIconSize; - uint8_t mIconOffset; - LcdIcon mIcon; -}; - -class VerticalShadePainter : public PixelPainter -{ -public: - using PixelPainter::PixelPainter; - uint8_t Color(uint32_t x, uint32_t y); -}; - -class HorizontalShadePainter : public PixelPainter -{ -public: - using PixelPainter::PixelPainter; - uint8_t Color(uint32_t x, uint32_t y); -}; - -class VerticalBlindPainter : public PixelPainter -{ -public: - VerticalBlindPainter(uint16_t lift, uint16_t tilt); - uint8_t Color(uint32_t x, uint32_t y); - -private: - constexpr static uint8_t sBandCount = 12; - uint8_t mBandSize; -}; - -class LcdPainter -{ -public: - static void Paint(SilabsLCD & lcd, chip::app::Clusters::WindowCovering::Type type, uint16_t lift, uint16_t tilt, LcdIcon icon); - -private: - static PixelPainter * GetCoverPainter(chip::app::Clusters::WindowCovering::Type type, uint16_t lift, uint16_t tilt); -}; diff --git a/examples/window-app/silabs/SiWx917/include/WindowAppImpl.h b/examples/window-app/silabs/SiWx917/include/WindowAppImpl.h deleted file mode 100644 index 827e3b120e7992..00000000000000 --- a/examples/window-app/silabs/SiWx917/include/WindowAppImpl.h +++ /dev/null @@ -1,100 +0,0 @@ -/* - * - * Copyright (c) 2021 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. - */ - -#pragma once - -#include - -#include "LEDWidget.h" - -#include -#include -#include - -#include -#include -#include -#ifdef DISPLAY_ENABLED -#include -#endif - -#define SIWx917_BTN0 0 -#define SIWx917_BTN1 1 - -#define SL_SIMPLE_BUTTON_PRESSED 1U ///< BUTTON state is pressed -#define SL_SIMPLE_BUTTON_RELEASED 0U ///< BUTTON state is released - -class WindowAppImpl : public WindowApp -{ -public: - static WindowAppImpl sInstance; - bool mWindowAppInit = false; - - WindowAppImpl(); - CHIP_ERROR Init() override; - CHIP_ERROR Start() override; - void Finish() override; - void PostEvent(const WindowApp::Event & event) override; - void PostAttributeChange(chip::EndpointId endpoint, chip::AttributeId attributeId) override; - void OnButtonChange(uint8_t btn, uint8_t btnAction); - -protected: - struct Timer : public WindowApp::Timer - { - TimerHandle_t mHandler = nullptr; - - Timer(const char * name, uint32_t timeoutInMs, Callback callback, void * context); - void IsrStart(); - void Start() override; - void Stop() override; - - private: - static void TimerCallback(TimerHandle_t xTimer); - }; - - struct Button : public WindowApp::Button - { - Button(Button::Id id, const char * name); - }; - - WindowApp::Timer * CreateTimer(const char * name, uint32_t timeoutInMs, WindowApp::Timer::Callback callback, - void * context) override; - WindowApp::Button * CreateButton(WindowApp::Button::Id id, const char * name) override; - void ProcessEvents(); - void DispatchEvent(const WindowApp::Event & event) override; - void UpdateLEDs(); - void UpdateLCD(); - void OnMainLoop() override; - - static void OnTaskCallback(void * parameter); - static void OnIconTimeout(WindowApp::Timer & timer); - -private: - void DispatchEventAttributeChange(chip::EndpointId endpoint, chip::AttributeId attribute); - TaskHandle_t mHandle = nullptr; - QueueHandle_t mQueue = nullptr; - - LEDWidget mStatusLED; - LEDWidget mActionLED; - - // Get QR Code and emulate its content using NFC tag - char mQRCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1]; -#ifdef DISPLAY_ENABLED - Timer mIconTimer; - LcdIcon mIcon = LcdIcon::None; -#endif -}; diff --git a/examples/window-app/silabs/SiWx917/src/LcdPainter.cpp b/examples/window-app/silabs/SiWx917/src/LcdPainter.cpp deleted file mode 100644 index e1a8041f075c79..00000000000000 --- a/examples/window-app/silabs/SiWx917/src/LcdPainter.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * 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 - -using namespace chip::app::Clusters::WindowCovering; - -constexpr uint32_t sTiltIcon[] = { - 0xffffffff, 0xffffffff, 0xc0000003, 0xc0000003, 0xc0000003, 0xc0000003, 0xc1ffffc3, 0xc1ffffc3, - 0xc1ffffc3, 0xc003c003, 0xc003c003, 0xc003c003, 0xc003c003, 0xc003c003, 0xc003c003, 0xc003c003, - 0xc003c003, 0xc003c003, 0xc003c003, 0xc003c003, 0xc003c003, 0xc003c003, 0xc003c003, 0xc003c003, - 0xc003c003, 0xc003c003, 0xc0000003, 0xc0000003, 0xc0000003, 0xc0000003, 0xffffffff, 0xffffffff, -}; - -constexpr uint32_t sLiftIcon[] = { - 0xffffffff, 0xffffffff, 0xc0000003, 0xc0000003, 0xc0000003, 0xc0000003, 0xc0f00003, 0xc0f00003, - 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0f00003, - 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0f00003, 0xc0ffffc3, - 0xc0ffffc3, 0xc0ffffc3, 0xc0000003, 0xc0000003, 0xc0000003, 0xc0000003, 0xffffffff, 0xffffffff, -}; - -constexpr uint32_t sOneIcon[] = { - 0xffffffff, 0xffffffff, 0xc0000003, 0xc0000003, 0xc0000003, 0xc00fe003, 0xc01fe003, 0xc03fe003, - 0xc07fe003, 0xc0fbe003, 0xc1f3e003, 0xc3e3e003, 0xc003e003, 0xc003e003, 0xc003e003, 0xc003e003, - 0xc003e003, 0xc003e003, 0xc003e003, 0xc003e003, 0xc003e003, 0xc003e003, 0xc003e003, 0xc3ffffc3, - 0xc3ffffc3, 0xc3ffffc3, 0xc3ffffc3, 0xc0000003, 0xc0000003, 0xc0000003, 0xffffffff, 0xffffffff, -}; - -constexpr uint32_t sTwoIcon[] = { - 0xffffffff, 0xffffffff, 0xc0000003, 0xc0000003, 0xc0000003, 0xc07ffe03, 0xc0ffff03, 0xc1ffff83, - 0xc3ffffc3, 0xc3f00fc3, 0xc3e007c3, 0xc3e007c3, 0xc00007c3, 0xc00007c3, 0xc0000fc3, 0xc00fff83, - 0xc03fff03, 0xc07ffe03, 0xc0fc0003, 0xc1f80003, 0xc1f00003, 0xc3e00003, 0xc3e00003, 0xc3ffffc3, - 0xc3ffffc3, 0xc3ffffc3, 0xc3ffffc3, 0xc0000003, 0xc0000003, 0xc0000003, 0xffffffff, 0xffffffff, -}; - -PixelPainter::PixelPainter(uint16_t lift, uint16_t tilt) : mLift(lift), mTilt(tilt) {} - -CompositePainter::CompositePainter(uint16_t lift, uint16_t tilt, PixelPainter * painter1, PixelPainter * painter2, - PixelPainter * painter3) : - PixelPainter(lift, tilt), - mPainter1(painter1), mPainter2(painter2), mPainter3(painter3) -{} - -uint8_t CompositePainter::Color(uint32_t x, uint32_t y) -{ - int8_t pixel = -1; - if (mPainter1) - { - pixel = mPainter1->Color(x, y); - if (pixel >= 0) - { - return pixel; - } - } - if (mPainter2) - { - pixel = mPainter2->Color(x, y); - if (pixel >= 0) - { - return pixel; - } - } - if (mPainter3) - { - pixel = mPainter3->Color(x, y); - if (pixel >= 0) - { - return pixel; - } - } - return pixel; -} - -uint8_t FramePainter::Color(uint32_t x, uint32_t y) -{ - if (x < LCD_FRAME_SIZE || x >= (LCD_SIZE - LCD_FRAME_SIZE) || y < LCD_FRAME_SIZE || y >= (LCD_SIZE - LCD_FRAME_SIZE)) - { - if (x < LCD_MARGIN_SIZE || x >= (LCD_SIZE - LCD_MARGIN_SIZE) || y < LCD_MARGIN_SIZE || y >= (LCD_SIZE - LCD_MARGIN_SIZE)) - { - return 0; - } - else - { - return (x < (LCD_MARGIN_SIZE + LCD_BORDER_SIZE)) || (x >= (LCD_SIZE - LCD_BORDER_SIZE - LCD_MARGIN_SIZE)) || - (y < (LCD_MARGIN_SIZE + LCD_BORDER_SIZE)) || (y >= (LCD_SIZE - LCD_BORDER_SIZE - LCD_MARGIN_SIZE)); - } - } - return -1; -} - -IconPainter::IconPainter(uint16_t lift, uint16_t tilt, LcdIcon icon) : PixelPainter(lift, tilt), mIcon(icon) -{ - mIconSize = sizeof(sTiltIcon) / sizeof(uint32_t); - mIconOffset = (LCD_SIZE - mIconSize) / 2; -} - -uint8_t IconPainter::Color(uint32_t x, uint32_t y) -{ - const uint32_t * icon = nullptr; - switch (mIcon) - { - case LcdIcon::One: - icon = sOneIcon; - break; - case LcdIcon::Two: - icon = sTwoIcon; - break; - case LcdIcon::Lift: - icon = sLiftIcon; - break; - case LcdIcon::Tilt: - icon = sTiltIcon; - break; - default: - return -1; - } - if (x >= mIconOffset && x < (mIconOffset + mIconSize) && y >= mIconOffset && y < (mIconOffset + mIconSize)) - { - uint32_t x0 = x - mIconOffset; - uint32_t y0 = y - mIconOffset; - return (icon[y0] & (1 << (31 - x0))) > 0; - } - return -1; -} - -uint8_t VerticalShadePainter::Color(uint32_t x, uint32_t y) -{ - return (y % 2) && y < (uint32_t)(LCD_FRAME_SIZE + mLift); -} - -uint8_t HorizontalShadePainter::Color(uint32_t x, uint32_t y) -{ - return (x % 2) && x < (uint32_t)(LCD_FRAME_SIZE + mLift); -} - -VerticalBlindPainter::VerticalBlindPainter(uint16_t lift, uint16_t tilt) : PixelPainter(lift, tilt) -{ - mBandSize = (LCD_COVER_SIZE / sBandCount); -} - -uint8_t VerticalBlindPainter::Color(uint32_t x, uint32_t y) -{ - if (x % 2) - { - return 0; - } - else - { - uint32_t closedCount = (mLift + 1) / mBandSize; - uint32_t bandCount = (y - LCD_FRAME_SIZE) / mBandSize; - // ChipLogProgress(Zcl, "BLIND: ccount:%u, ccount:%u", clusterId); - if (bandCount <= closedCount) - { - return y <= (LCD_FRAME_SIZE + mBandSize * bandCount + mTilt); - } - else - { - return 0; - } - } -} - -PixelPainter * LcdPainter::GetCoverPainter(Type type, uint16_t lift, uint16_t tilt) -{ - switch (type) - { - case Type::kRollerShade: - case Type::kRollerShade2Motor: - case Type::kRollerShadeExterior: - case Type::kRollerShadeExterior2Motor: - return new VerticalShadePainter(lift, tilt); - case Type::kDrapery: - case Type::kAwning: - return new HorizontalShadePainter(lift, tilt); - case Type::kShutter: - case Type::kTiltBlindTiltOnly: - case Type::kTiltBlindLiftAndTilt: - return new VerticalBlindPainter(lift, tilt); - case Type::kProjectorScreen: - case Type::kUnknown: - default: - return new VerticalShadePainter(lift, tilt); - } - - return nullptr; -} - -void LcdPainter::Paint(SilabsLCD & lcd, Type type, uint16_t lift, uint16_t tilt, LcdIcon icon) -{ - FramePainter framePaint = FramePainter(lift, tilt); - IconPainter iconPaint = IconPainter(lift, tilt, icon); - PixelPainter * coverPaint = GetCoverPainter(type, lift, tilt); - CompositePainter compositePaint = CompositePainter(lift, tilt, &framePaint, &iconPaint, coverPaint); - void * context = lcd.Context(); - - lcd.Clear(); - - for (int i = 0; i < LCD_SIZE; i++) - { - for (int j = 0; j < LCD_SIZE; j++) - { - if (compositePaint.Color(i, j)) - { - lcd.DrawPixel(context, i, j); - } - } - } - lcd.Update(); - delete coverPaint; -} diff --git a/examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp b/examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp deleted file mode 100644 index a8a4d3f63dd274..00000000000000 --- a/examples/window-app/silabs/SiWx917/src/WindowAppImpl.cpp +++ /dev/null @@ -1,549 +0,0 @@ -/* - * - * Copyright (c) 2021 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 -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef QR_CODE_ENABLED -#include -#else -#include "SilabsDeviceDataProvider.h" -#include -#include -#endif // QR_CODE_ENABLED - -extern "C" void sl_button_on_change(uint8_t btn, uint8_t btnAction); - -#ifdef SL_WIFI -#include "wfx_host_events.h" -#include -#include -#endif - -#ifdef DISPLAY_ENABLED -#include -SilabsLCD slLCD; -#endif - -#include - -#define APP_TASK_STACK_SIZE (4096) -#define APP_TASK_PRIORITY 2 -#define APP_EVENT_QUEUE_SIZE 10 -#define EXAMPLE_VENDOR_ID 0xcafe - -#define LCD_ICON_TIMEOUT 1000 - -using namespace chip::app::Clusters::WindowCovering; -using namespace chip; -using namespace ::chip::DeviceLayer; -#define APP_STATE_LED 0 -#define APP_ACTION_LED 1 - -#ifdef SL_WIFI -chip::app::Clusters::NetworkCommissioning::Instance - sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(chip::DeviceLayer::NetworkCommissioning::SlWiFiDriver::GetInstance())); -#endif -//------------------------------------------------------------------------------ -// Timers -//------------------------------------------------------------------------------ - -WindowAppImpl::Timer::Timer(const char * name, uint32_t timeoutInMs, Callback callback, void * context) : - WindowApp::Timer(name, timeoutInMs, callback, context) -{ - mHandler = xTimerCreate(name, // Just a text name, not used by the RTOS kernel - pdMS_TO_TICKS(timeoutInMs), // == default timer period - false, // no timer reload (==one-shot) - (void *) this, // init timer id = app task obj context - TimerCallback // timer callback handler - ); - if (mHandler == NULL) - { - SILABS_LOG("Timer create failed"); - appError(CHIP_ERROR_INTERNAL); - } -} - -void WindowAppImpl::Timer::Start() -{ - if (xTimerIsTimerActive(mHandler)) - { - Stop(); - } - - // Timer is not active - if (xTimerStart(mHandler, pdMS_TO_TICKS(100)) != pdPASS) - { - SILABS_LOG("Timer start() failed"); - appError(CHIP_ERROR_INTERNAL); - } - - mIsActive = true; -} - -void WindowAppImpl::Timer::IsrStart() -{ - portBASE_TYPE taskWoken = pdFALSE; // For FreeRTOS timer (below). - // Start/restart the button debounce timer (Note ISR version of FreeRTOS - // api call here). - xTimerStartFromISR(mHandler, &taskWoken); - if (taskWoken != pdFALSE) - { - taskYIELD(); - } - mIsActive = true; -} - -void WindowAppImpl::Timer::Stop() -{ - mIsActive = false; - if (xTimerStop(mHandler, pdMS_TO_TICKS(0)) == pdFAIL) - { - SILABS_LOG("Timer stop() failed"); - appError(CHIP_ERROR_INTERNAL); - } -} - -void WindowAppImpl::Timer::TimerCallback(TimerHandle_t xTimer) -{ - Timer * timer = (Timer *) pvTimerGetTimerID(xTimer); - if (timer) - { - timer->Timeout(); - } -} - -//------------------------------------------------------------------------------ -// Main Task -//------------------------------------------------------------------------------ - -StackType_t sAppStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)]; -StaticTask_t sAppTaskStruct; - -uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(WindowApp::Event)]; -StaticQueue_t sAppEventQueueStruct; - -WindowAppImpl WindowAppImpl::sInstance; - -WindowApp & WindowApp::Instance() -{ - return WindowAppImpl::sInstance; -} - -#ifdef DISPLAY_ENABLED -WindowAppImpl::WindowAppImpl() : mIconTimer("Timer:icon", LCD_ICON_TIMEOUT, OnIconTimeout, this) {} -#else -WindowAppImpl::WindowAppImpl() {} -#endif - -void WindowAppImpl::OnTaskCallback(void * parameter) -{ -#ifdef SL_WIFI - /* - * Wait for the WiFi to be initialized - */ - SILABS_LOG("APP: Wait WiFi Init"); - while (!wfx_hw_ready()) - { - vTaskDelay(10); - } - SILABS_LOG("APP: Done WiFi Init"); - /* We will init server when we get IP */ - chip::DeviceLayer::PlatformMgr().LockChipStack(); - sWiFiNetworkCommissioningInstance.Init(); - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - /* added for commissioning with wifi */ -#endif - - sInstance.Run(); -} - -void WindowAppImpl::OnIconTimeout(WindowApp::Timer & timer) -{ -#ifdef DISPLAY_ENABLED - sInstance.mIcon = LcdIcon::None; - sInstance.UpdateLCD(); -#endif -} - -CHIP_ERROR WindowAppImpl::Init() -{ - chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(WindowAppImpl::ButtonEventHandler); - - WindowApp::Init(); - - // Initialize App Task - mHandle = xTaskCreateStatic(OnTaskCallback, APP_TASK_NAME, ArraySize(sAppStack), NULL, 1, sAppStack, &sAppTaskStruct); - if (NULL == mHandle) - { - SILABS_LOG("Failed to allocate app task"); - return CHIP_ERROR_NO_MEMORY; - } - - // Initialize App Queue - mQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(WindowApp::Event), sAppEventQueueBuffer, &sAppEventQueueStruct); - if (NULL == mQueue) - { - SILABS_LOG("Failed to allocate app event queue"); - return CHIP_ERROR_NO_MEMORY; - } - - // Initialize LEDs - - mStatusLED.Init(APP_STATE_LED); - mActionLED.Init(APP_ACTION_LED); - -#ifdef DISPLAY_ENABLED - slLCD.Init(); -#endif - -#ifndef QR_CODE_ENABLED - // Create buffer for QR code that can fit max size and null terminator. - char qrCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1]; - chip::MutableCharSpan QRCode(qrCodeBuffer); - - if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(QRCode) == CHIP_NO_ERROR) - { - PrintQrCodeURL(QRCode); - } - else - { - SILABS_LOG("Getting QR code failed!"); - } -#endif // QR_CODE_ENABLED - - mWindowAppInit = true; - - return CHIP_NO_ERROR; -} - -CHIP_ERROR WindowAppImpl::Start() -{ - SILABS_LOG("Starting FreeRTOS scheduler"); - vTaskStartScheduler(); - - return CHIP_NO_ERROR; -} - -void WindowAppImpl::Finish() -{ - WindowApp::Finish(); - chip::Platform::MemoryShutdown(); - // Should never get here. - SILABS_LOG("vTaskStartScheduler() failed"); - appError(CHIP_ERROR_INTERNAL); -} - -void WindowAppImpl::PostEvent(const WindowApp::Event & event) -{ - if (mQueue) - { - BaseType_t status; - if (xPortIsInsideInterrupt()) - { - BaseType_t higherPrioTaskWoken = pdFALSE; - status = xQueueSendFromISR(mQueue, &event, &higherPrioTaskWoken); - -#ifdef portYIELD_FROM_ISR - portYIELD_FROM_ISR(higherPrioTaskWoken); -#elif portEND_SWITCHING_ISR // portYIELD_FROM_ISR or portEND_SWITCHING_ISR - portEND_SWITCHING_ISR(higherPrioTaskWoken); -#else // portYIELD_FROM_ISR or portEND_SWITCHING_ISR -#error "Must have portYIELD_FROM_ISR or portEND_SWITCHING_ISR" -#endif // portYIELD_FROM_ISR or portEND_SWITCHING_ISR - } - else - { - status = xQueueSend(mQueue, &event, 1); - } - - if (!status) - { - SILABS_LOG("Failed to post event to app task event queue"); - } - } -} - -void WindowAppImpl::PostAttributeChange(chip::EndpointId endpoint, chip::AttributeId attributeId) -{ - Instance().PostEvent(WindowApp::Event(WindowApp::EventId::AttributeChange, endpoint, attributeId)); -} - -void WindowAppImpl::ProcessEvents() -{ - WindowApp::Event event = EventId::None; - - BaseType_t received = xQueueReceive(mQueue, &event, pdMS_TO_TICKS(10)); - while (pdTRUE == received) - { - DispatchEvent(event); - received = xQueueReceive(mQueue, &event, 0); - } -} - -WindowApp::Timer * WindowAppImpl::CreateTimer(const char * name, uint32_t timeoutInMs, WindowApp::Timer::Callback callback, - void * context) -{ - return new Timer(name, timeoutInMs, callback, context); -} - -WindowApp::Button * WindowAppImpl::CreateButton(WindowApp::Button::Id id, const char * name) -{ - return new Button(id, name); -} - -void WindowAppImpl::DispatchEventAttributeChange(chip::EndpointId endpoint, chip::AttributeId attribute) -{ - switch (attribute) - { - /* RO OperationalStatus */ - case Attributes::OperationalStatus::Id: - UpdateLEDs(); - break; - /* RO Type: not supposed to dynamically change -> Cycling Window Covering Demo */ - case Attributes::Type::Id: - /* ============= Positions for Position Aware ============= */ - case Attributes::CurrentPositionLiftPercent100ths::Id: - case Attributes::CurrentPositionTiltPercent100ths::Id: - UpdateLCD(); - break; - /* ### ATTRIBUTEs CHANGEs IGNORED ### */ - /* RO EndProductType: not supposed to dynamically change */ - case Attributes::EndProductType::Id: - /* RO ConfigStatus: set by WC server */ - case Attributes::ConfigStatus::Id: - /* RO SafetyStatus: set by WC server */ - case Attributes::SafetyStatus::Id: - /* RW Mode: User can change */ - case Attributes::Mode::Id: - default: - break; - } -} - -void WindowAppImpl::DispatchEvent(const WindowApp::Event & event) -{ - WindowApp::DispatchEvent(event); - switch (event.mId) - { - case EventId::AttributeChange: - DispatchEventAttributeChange(event.mEndpoint, event.mAttributeId); - break; - case EventId::ResetWarning: - SILABS_LOG("Factory Reset Triggered. Release button within %ums to cancel.", LONG_PRESS_TIMEOUT); - // Turn off all LEDs before starting blink to make sure blink is - // co-ordinated. - UpdateLEDs(); - break; - case EventId::ResetCanceled: - SILABS_LOG("Factory Reset has been Canceled"); - UpdateLEDs(); - break; - case EventId::ProvisionedStateChanged: - UpdateLEDs(); - UpdateLCD(); - break; - - case EventId::WinkOn: - case EventId::WinkOff: - mState.isWinking = (EventId::WinkOn == event.mId); - UpdateLEDs(); - break; - case EventId::ConnectivityStateChanged: - case EventId::BLEConnectionsChanged: - UpdateLEDs(); - break; -#ifdef DISPLAY_ENABLED - case EventId::CoverTypeChange: - UpdateLCD(); - break; - case EventId::CoverChange: - mIconTimer.Start(); - mIcon = (GetCover().mEndpoint == 1) ? LcdIcon::One : LcdIcon::Two; - UpdateLCD(); - break; - case EventId::TiltModeChange: - mIconTimer.Start(); - mIcon = mTiltMode ? LcdIcon::Tilt : LcdIcon::Lift; - UpdateLCD(); - break; -#endif - default: - break; - } -} - -void WindowAppImpl::UpdateLEDs() -{ - Cover & cover = GetCover(); - if (mResetWarning) - { - - mStatusLED.Set(false); - mStatusLED.Blink(500); - - mActionLED.Set(false); - mActionLED.Blink(500); - } - else - { - if (mState.isWinking) - { - - mStatusLED.Blink(200, 200); - } - else -#if CHIP_ENABLE_OPENTHREAD - if (mState.isThreadProvisioned && mState.isThreadEnabled) -#else - if (mState.isWiFiProvisioned && mState.isWiFiEnabled) -#endif - - { - - mStatusLED.Blink(950, 50); - } - else if (mState.haveBLEConnections) { mStatusLED.Blink(100, 100); } - else { mStatusLED.Blink(50, 950); } - - // Action LED - NPercent100ths current; - LimitStatus liftLimit = LimitStatus::Intermediate; - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - Attributes::CurrentPositionLiftPercent100ths::Get(cover.mEndpoint, current); - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - if (!current.IsNull()) - { - AbsoluteLimits limits = { .open = WC_PERCENT100THS_MIN_OPEN, .closed = WC_PERCENT100THS_MAX_CLOSED }; - liftLimit = CheckLimitState(current.Value(), limits); - } - - if (OperationalState::Stall != cover.mLiftOpState) - { - - mActionLED.Blink(100); - } - else if (LimitStatus::IsUpOrOpen == liftLimit) - { - - mActionLED.Set(true); - } - else if (LimitStatus::IsDownOrClose == liftLimit) - { - - mActionLED.Set(false); - } - else - { - - mActionLED.Blink(1000); - } - } -} - -void WindowAppImpl::UpdateLCD() -{ - // Update LCD -#ifdef DISPLAY_ENABLED -#if CHIP_ENABLE_OPENTHREAD - if (mState.isThreadProvisioned) -#else - if (mState.isWiFiProvisioned) -#endif // CHIP_ENABLE_OPENTHREAD - { - Cover & cover = GetCover(); - chip::app::DataModel::Nullable lift; - chip::app::DataModel::Nullable tilt; - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - Type type = TypeGet(cover.mEndpoint); - - Attributes::CurrentPositionLift::Get(cover.mEndpoint, lift); - Attributes::CurrentPositionTilt::Get(cover.mEndpoint, tilt); - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - -#ifdef DISPLAY_ENABLED - if (!tilt.IsNull() && !lift.IsNull()) - { - LcdPainter::Paint(slLCD, type, lift.Value(), tilt.Value(), mIcon); - } -#endif - } -#ifdef QR_CODE_ENABLED - else - { - chip::MutableCharSpan qrCode(mQRCodeBuffer); - if (GetQRCode(qrCode, chip::RendezvousInformationFlags(chip::RendezvousInformationFlag::kBLE)) == CHIP_NO_ERROR) - { - slLCD.SetQRCode((uint8_t *) qrCode.data(), qrCode.size()); - slLCD.ShowQRCode(true, true); - } - } -#endif // QR_CODE_ENABLED -#endif // DISPLAY_ENABLED -} - -void WindowAppImpl::OnMainLoop() -{ - - mStatusLED.Animate(); - mActionLED.Animate(); -} - -//------------------------------------------------------------------------------ -// Buttons -//------------------------------------------------------------------------------ -WindowAppImpl::Button::Button(WindowApp::Button::Id id, const char * name) : WindowApp::Button(id, name) {} - -void WindowAppImpl::OnButtonChange(uint8_t Btn, uint8_t btnAction) -{ - WindowApp::Button * btn = static_cast