From 9b9ed65a808a3ffed984ebe695479a93c2cca67b Mon Sep 17 00:00:00 2001 From: Alex Tsitsiura Date: Fri, 5 Apr 2024 16:34:02 +0300 Subject: [PATCH] [Telink] Peripheral modules optimization & Update builds to docker version 46 (#32754) * [telink] Rename config option according to zephyr. * [telink] Link application buttons from .dts. * [telink] Fix Lock application building. * [telink] Fix Window application building. * [telink] Link application LEDs from .dts. * [telink] Add pwm pool. * [Telink] Add boards pwm overlays. * [telink] Add led strip. * [telink] Fix b92 builds. * [Telink] Update Zephyr to specific revision * [telink] Fix github builds. * [Telink] Fix builds * [Telink] Update builds to docker version 44 * Restyled by whitespace * Restyled by clang-format * [Telink] Update copyrights * [Telink] Update builds to docker version 46 --------- Co-authored-by: Andrii Bilynskyi Co-authored-by: Restyled.io --- .github/workflows/bloat_check.yaml | 2 +- .github/workflows/build.yaml | 10 +- .github/workflows/chef.yaml | 10 +- .github/workflows/cirque.yaml | 2 +- .github/workflows/doxygen.yaml | 2 +- .github/workflows/examples-ameba.yaml | 2 +- .github/workflows/examples-asr.yaml | 2 +- .github/workflows/examples-bouffalolab.yaml | 2 +- .github/workflows/examples-efr32.yaml | 2 +- .github/workflows/examples-esp32.yaml | 4 +- .github/workflows/examples-infineon.yaml | 2 +- .github/workflows/examples-linux-arm.yaml | 2 +- .github/workflows/examples-linux-imx.yaml | 2 +- .../workflows/examples-linux-standalone.yaml | 2 +- .github/workflows/examples-mbed.yaml | 2 +- .github/workflows/examples-mw320.yaml | 2 +- .github/workflows/examples-nrfconnect.yaml | 2 +- .github/workflows/examples-nxp.yaml | 2 +- .github/workflows/examples-openiotsdk.yaml | 2 +- .github/workflows/examples-qpg.yaml | 2 +- .github/workflows/examples-rw61x.yaml | 2 +- .github/workflows/examples-stm32.yaml | 2 +- .github/workflows/examples-telink.yaml | 4 +- .github/workflows/examples-tizen.yaml | 2 +- .github/workflows/full-android.yaml | 2 +- .github/workflows/fuzzing-build.yaml | 2 +- .github/workflows/java-tests.yaml | 2 +- .github/workflows/lint.yml | 2 +- .github/workflows/minimal-build.yaml | 2 +- .github/workflows/qemu.yaml | 4 +- .github/workflows/release_artifacts.yaml | 4 +- .github/workflows/smoketest-android.yaml | 2 +- .github/workflows/tests.yaml | 4 +- .github/workflows/unit_integration_test.yaml | 2 +- .github/workflows/zap_regeneration.yaml | 2 +- .github/workflows/zap_templates.yaml | 2 +- config/telink/chip-module/Kconfig.defaults | 4 +- .../telink/CMakeLists.txt | 17 +- .../telink/include/AppConfig.h | 6 - .../telink/src/AppTask.cpp | 2 - examples/all-clusters-app/ameba/README.md | 4 +- .../all-clusters-app/telink/CMakeLists.txt | 14 +- .../telink/include/AppConfig.h | 6 - .../all-clusters-minimal-app/ameba/README.md | 4 +- .../telink/CMakeLists.txt | 15 +- .../telink/include/AppConfig.h | 3 - examples/bridge-app/telink/CMakeLists.txt | 15 +- .../bridge-app/telink/include/AppConfig.h | 6 - examples/bridge-app/telink/include/AppTask.h | 15 +- examples/bridge-app/telink/src/AppTask.cpp | 97 ++---- .../bridge-app/telink/src/ZclCallbacks.cpp | 58 --- examples/chef/telink/CMakeLists.txt | 11 +- examples/chef/telink/include/AppConfig.h | 3 - examples/chef/telink/include/AppTask.h | 3 + examples/chef/telink/src/AppTask.cpp | 8 + .../contact-sensor-app/telink/CMakeLists.txt | 14 +- .../telink/include/AppConfig.h | 6 - .../telink/include/AppTask.h | 1 + .../contact-sensor-app/telink/src/AppTask.cpp | 35 +- examples/light-switch-app/ameba/README.md | 4 +- .../light-switch-app/telink/CMakeLists.txt | 14 +- .../telink/include/AppConfig.h | 6 - .../light-switch-app/telink/src/AppTask.cpp | 2 - examples/lighting-app/ameba/README.md | 4 +- examples/lighting-app/telink/CMakeLists.txt | 17 +- examples/lighting-app/telink/README.md | 24 -- .../lighting-app/telink/include/AppConfig.h | 9 - .../lighting-app/telink/include/AppTask.h | 36 +- examples/lighting-app/telink/src/AppTask.cpp | 311 ++++------------- .../lighting-app/telink/src/ZclCallbacks.cpp | 39 +-- examples/lock-app/telink/CMakeLists.txt | 14 +- examples/lock-app/telink/include/AppConfig.h | 6 - examples/lock-app/telink/include/AppTask.h | 2 + examples/lock-app/telink/src/AppTask.cpp | 68 ++-- examples/ota-requestor-app/ameba/README.md | 4 +- .../ota-requestor-app/telink/CMakeLists.txt | 14 +- .../telink/include/AppConfig.h | 6 - examples/pigweed-app/ameba/README.md | 4 +- .../telink/common/include/AppTaskCommon.h | 42 +-- .../common/include/SensorManagerCommon.h | 1 - .../telink/common/src/AppTaskCommon.cpp | 240 ++++--------- .../telink/common/src/SensorManagerCommon.cpp | 16 +- .../telink/util/include/ButtonManager.h | 140 ++++++-- .../platform/telink/util/include/LEDManager.h | 119 +++++++ .../platform/telink/util/include/LEDWidget.h | 48 --- .../platform/telink/util/include/PWMDevice.h | 96 ----- .../platform/telink/util/include/PWMManager.h | 153 ++++++++ .../telink/util/include/WS2812Device.h | 57 --- .../telink/util/src/ButtonManager.cpp | 222 ++++-------- .../platform/telink/util/src/LEDManager.cpp | 154 ++++++++ .../platform/telink/util/src/LEDWidget.cpp | 124 ------- .../platform/telink/util/src/PWMDevice.cpp | 298 ---------------- .../platform/telink/util/src/PWMManager.cpp | 264 ++++++++++++++ .../platform/telink/util/src/WS2812Device.cpp | 85 ----- .../telink/zephyr_ext/zephyr_key_matrix.c | 139 ++++++++ .../telink/zephyr_ext/zephyr_key_matrix.h | 88 +++++ .../telink/zephyr_ext/zephyr_key_pool.c | 194 +++++++++++ .../telink/zephyr_ext/zephyr_key_pool.h | 75 ++++ .../telink/zephyr_ext/zephyr_led_pool.c | 202 +++++++++++ .../telink/zephyr_ext/zephyr_led_pool.h | 75 ++++ .../telink/zephyr_ext/zephyr_pwm_pool.c | 329 ++++++++++++++++++ .../telink/zephyr_ext/zephyr_pwm_pool.h | 88 +++++ .../telink/zephyr_ext/zephyr_ws2812.c | 112 ++++++ .../telink/zephyr_ext/zephyr_ws2812.h | 85 +++++ examples/pump-app/telink/CMakeLists.txt | 14 +- examples/pump-app/telink/include/AppConfig.h | 6 - examples/pump-app/telink/include/AppTask.h | 3 + examples/pump-app/telink/src/AppTask.cpp | 34 +- .../pump-controller-app/telink/CMakeLists.txt | 14 +- .../telink/include/AppConfig.h | 6 - .../telink/include/AppTask.h | 3 + .../telink/src/AppTask.cpp | 34 +- .../smoke-co-alarm-app/telink/CMakeLists.txt | 14 +- .../telink/include/AppConfig.h | 6 - .../smoke-co-alarm-app/telink/src/AppTask.cpp | 2 - .../telink/CMakeLists.txt | 16 +- .../telink/include/AppConfig.h | 3 - examples/thermostat/telink/CMakeLists.txt | 15 +- .../thermostat/telink/include/AppConfig.h | 6 - examples/window-app/telink/CMakeLists.txt | 14 +- .../window-app/telink/include/AppConfig.h | 5 - examples/window-app/telink/include/AppTask.h | 1 + .../telink/include/WindowCovering.h | 17 +- examples/window-app/telink/src/AppTask.cpp | 34 +- .../window-app/telink/src/WindowCovering.cpp | 29 +- .../window-app/telink/src/ZclCallbacks.cpp | 1 - integrations/cloudbuild/chef.yaml | 8 +- integrations/cloudbuild/smoke-test.yaml | 14 +- src/platform/telink/tlsr9258a.overlay | 31 -- .../telink/tlsr9258a_retention.overlay | 31 -- src/platform/telink/tlsr9518adk80d.overlay | 101 +++--- .../telink/tlsr9518adk80d_mars.overlay | 68 +--- .../telink/tlsr9518adk80d_retention.overlay | 31 ++ .../telink/tlsr9518adk80d_usb.overlay | 92 ++--- src/platform/telink/tlsr9528a.overlay | 100 +++--- .../telink/tlsr9528a_retention.overlay | 56 +-- src/test_driver/tizen/README.md | 4 +- 137 files changed, 3020 insertions(+), 2268 deletions(-) delete mode 100644 examples/bridge-app/telink/src/ZclCallbacks.cpp create mode 100644 examples/platform/telink/util/include/LEDManager.h delete mode 100644 examples/platform/telink/util/include/LEDWidget.h delete mode 100644 examples/platform/telink/util/include/PWMDevice.h create mode 100644 examples/platform/telink/util/include/PWMManager.h delete mode 100644 examples/platform/telink/util/include/WS2812Device.h create mode 100644 examples/platform/telink/util/src/LEDManager.cpp delete mode 100644 examples/platform/telink/util/src/LEDWidget.cpp delete mode 100644 examples/platform/telink/util/src/PWMDevice.cpp create mode 100644 examples/platform/telink/util/src/PWMManager.cpp delete mode 100644 examples/platform/telink/util/src/WS2812Device.cpp create mode 100644 examples/platform/telink/zephyr_ext/zephyr_key_matrix.c create mode 100644 examples/platform/telink/zephyr_ext/zephyr_key_matrix.h create mode 100644 examples/platform/telink/zephyr_ext/zephyr_key_pool.c create mode 100644 examples/platform/telink/zephyr_ext/zephyr_key_pool.h create mode 100644 examples/platform/telink/zephyr_ext/zephyr_led_pool.c create mode 100644 examples/platform/telink/zephyr_ext/zephyr_led_pool.h create mode 100644 examples/platform/telink/zephyr_ext/zephyr_pwm_pool.c create mode 100644 examples/platform/telink/zephyr_ext/zephyr_pwm_pool.h create mode 100644 examples/platform/telink/zephyr_ext/zephyr_ws2812.c create mode 100644 examples/platform/telink/zephyr_ext/zephyr_ws2812.h create mode 100644 src/platform/telink/tlsr9518adk80d_retention.overlay diff --git a/.github/workflows/bloat_check.yaml b/.github/workflows/bloat_check.yaml index 148426d99ccd6b..7b97c51ca8be31 100644 --- a/.github/workflows/bloat_check.yaml +++ b/.github/workflows/bloat_check.yaml @@ -34,7 +34,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 steps: - name: Checkout diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1da7dd09665706..f6abbd7315128d 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -40,7 +40,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/:/runner-root-volume" - "/tmp/log_output:/tmp/test_logs" @@ -136,7 +136,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/:/runner-root-volume" - "/tmp/log_output:/tmp/test_logs" @@ -279,7 +279,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/:/runner-root-volume" - "/tmp/log_output:/tmp/test_logs" @@ -340,7 +340,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/:/runner-root-volume" - "/tmp/log_output:/tmp/test_logs" @@ -449,7 +449,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/:/runner-root-volume" - "/tmp/log_output:/tmp/test_logs" diff --git a/.github/workflows/chef.yaml b/.github/workflows/chef.yaml index c2c4a777bde7d3..862ada5236f96f 100644 --- a/.github/workflows/chef.yaml +++ b/.github/workflows/chef.yaml @@ -33,7 +33,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 options: --user root steps: @@ -54,7 +54,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-esp32:41 + image: ghcr.io/project-chip/chip-build-esp32:46 options: --user root steps: @@ -75,7 +75,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-nrf-platform:41 + image: ghcr.io/project-chip/chip-build-nrf-platform:46 options: --user root steps: @@ -96,7 +96,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-telink:41 + image: ghcr.io/project-chip/chip-build-telink:46 options: --user root steps: @@ -108,7 +108,7 @@ jobs: platform: telink # - name: Update Zephyr to specific revision (for developers purpose) # shell: bash - # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py b5c8028ec94f3efa69decff3a09f0d6f8a21fd6d" + # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 65dc1812431bf946dfc110682298acf83d63e27a" - name: CI Examples Telink shell: bash run: | diff --git a/.github/workflows/cirque.yaml b/.github/workflows/cirque.yaml index 919085ac77ee0f..a82750e546278d 100644 --- a/.github/workflows/cirque.yaml +++ b/.github/workflows/cirque.yaml @@ -40,7 +40,7 @@ jobs: # need to run with privilege, which isn't supported by job.XXX.contaner # https://github.com/actions/container-action/issues/2 # container: - # image: ghcr.io/project-chip/chip-build-cirque:41 + # image: ghcr.io/project-chip/chip-build-cirque:46 # volumes: # - "/tmp:/tmp" # - "/dev/pts:/dev/pts" diff --git a/.github/workflows/doxygen.yaml b/.github/workflows/doxygen.yaml index cc93947c2c0937..e94296b45be733 100644 --- a/.github/workflows/doxygen.yaml +++ b/.github/workflows/doxygen.yaml @@ -81,7 +81,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/project-chip/chip-build-doxygen:41 + image: ghcr.io/project-chip/chip-build-doxygen:46 if: github.actor != 'restyled-io[bot]' diff --git a/.github/workflows/examples-ameba.yaml b/.github/workflows/examples-ameba.yaml index 1d4d478d0c00b6..16cfb4c17e0419 100644 --- a/.github/workflows/examples-ameba.yaml +++ b/.github/workflows/examples-ameba.yaml @@ -36,7 +36,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-ameba:42 + image: ghcr.io/project-chip/chip-build-ameba:46 options: --user root steps: diff --git a/.github/workflows/examples-asr.yaml b/.github/workflows/examples-asr.yaml index 52c63eda8fbbd0..6e9d4a8b13527b 100644 --- a/.github/workflows/examples-asr.yaml +++ b/.github/workflows/examples-asr.yaml @@ -34,7 +34,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-asr:41 + image: ghcr.io/project-chip/chip-build-asr:46 options: --user root steps: diff --git a/.github/workflows/examples-bouffalolab.yaml b/.github/workflows/examples-bouffalolab.yaml index 8d12696dcd8f89..ce38acdc0d5165 100644 --- a/.github/workflows/examples-bouffalolab.yaml +++ b/.github/workflows/examples-bouffalolab.yaml @@ -35,7 +35,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-bouffalolab:41 + image: ghcr.io/project-chip/chip-build-bouffalolab:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" steps: diff --git a/.github/workflows/examples-efr32.yaml b/.github/workflows/examples-efr32.yaml index c4af320b990074..0ec8a540c2311f 100644 --- a/.github/workflows/examples-efr32.yaml +++ b/.github/workflows/examples-efr32.yaml @@ -38,7 +38,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-efr32:41 + image: ghcr.io/project-chip/chip-build-efr32:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" steps: diff --git a/.github/workflows/examples-esp32.yaml b/.github/workflows/examples-esp32.yaml index d262bd789c687b..09eca99abad026 100644 --- a/.github/workflows/examples-esp32.yaml +++ b/.github/workflows/examples-esp32.yaml @@ -34,7 +34,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-esp32:41 + image: ghcr.io/project-chip/chip-build-esp32:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" @@ -124,7 +124,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-esp32:41 + image: ghcr.io/project-chip/chip-build-esp32:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" diff --git a/.github/workflows/examples-infineon.yaml b/.github/workflows/examples-infineon.yaml index 0f94ce1a2da631..9aba6a2ec6e1fc 100644 --- a/.github/workflows/examples-infineon.yaml +++ b/.github/workflows/examples-infineon.yaml @@ -35,7 +35,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-infineon:41 + image: ghcr.io/project-chip/chip-build-infineon:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" steps: diff --git a/.github/workflows/examples-linux-arm.yaml b/.github/workflows/examples-linux-arm.yaml index 562279a0d35375..6dc80615c426ac 100644 --- a/.github/workflows/examples-linux-arm.yaml +++ b/.github/workflows/examples-linux-arm.yaml @@ -34,7 +34,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-crosscompile:41 + image: ghcr.io/project-chip/chip-build-crosscompile:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" diff --git a/.github/workflows/examples-linux-imx.yaml b/.github/workflows/examples-linux-imx.yaml index 843e76b9b14c41..27a997db1bf5cf 100644 --- a/.github/workflows/examples-linux-imx.yaml +++ b/.github/workflows/examples-linux-imx.yaml @@ -34,7 +34,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-imx:41 + image: ghcr.io/project-chip/chip-build-imx:46 steps: - name: Checkout diff --git a/.github/workflows/examples-linux-standalone.yaml b/.github/workflows/examples-linux-standalone.yaml index ea60e6adbcb022..ffec5dad8cb1a9 100644 --- a/.github/workflows/examples-linux-standalone.yaml +++ b/.github/workflows/examples-linux-standalone.yaml @@ -34,7 +34,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" diff --git a/.github/workflows/examples-mbed.yaml b/.github/workflows/examples-mbed.yaml index 4b5748b4d0abe7..3744047406009a 100644 --- a/.github/workflows/examples-mbed.yaml +++ b/.github/workflows/examples-mbed.yaml @@ -40,7 +40,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-mbed-os:41 + image: ghcr.io/project-chip/chip-build-mbed-os:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" diff --git a/.github/workflows/examples-mw320.yaml b/.github/workflows/examples-mw320.yaml index a16ea66c148aca..1f2940af4c576f 100644 --- a/.github/workflows/examples-mw320.yaml +++ b/.github/workflows/examples-mw320.yaml @@ -37,7 +37,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" steps: diff --git a/.github/workflows/examples-nrfconnect.yaml b/.github/workflows/examples-nrfconnect.yaml index eb62c69299fc85..d305ebf05e4717 100644 --- a/.github/workflows/examples-nrfconnect.yaml +++ b/.github/workflows/examples-nrfconnect.yaml @@ -37,7 +37,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-nrf-platform:41 + image: ghcr.io/project-chip/chip-build-nrf-platform:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" diff --git a/.github/workflows/examples-nxp.yaml b/.github/workflows/examples-nxp.yaml index 9a8a7b8968bdc1..01ff636753d4b1 100644 --- a/.github/workflows/examples-nxp.yaml +++ b/.github/workflows/examples-nxp.yaml @@ -37,7 +37,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-k32w:38 + image: ghcr.io/project-chip/chip-build-k32w:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" steps: diff --git a/.github/workflows/examples-openiotsdk.yaml b/.github/workflows/examples-openiotsdk.yaml index b6f69791d2270a..fead4424f712a1 100644 --- a/.github/workflows/examples-openiotsdk.yaml +++ b/.github/workflows/examples-openiotsdk.yaml @@ -38,7 +38,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-openiotsdk:41 + image: ghcr.io/project-chip/chip-build-openiotsdk:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" options: --privileged diff --git a/.github/workflows/examples-qpg.yaml b/.github/workflows/examples-qpg.yaml index b0af5ab2141ef0..b67ef067ed1caf 100644 --- a/.github/workflows/examples-qpg.yaml +++ b/.github/workflows/examples-qpg.yaml @@ -37,7 +37,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" steps: diff --git a/.github/workflows/examples-rw61x.yaml b/.github/workflows/examples-rw61x.yaml index 42df03382b9249..7c13186dcaf7dc 100644 --- a/.github/workflows/examples-rw61x.yaml +++ b/.github/workflows/examples-rw61x.yaml @@ -37,7 +37,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-rw61x:37 + image: ghcr.io/project-chip/chip-build-rw61x:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" steps: diff --git a/.github/workflows/examples-stm32.yaml b/.github/workflows/examples-stm32.yaml index 9a30af500112ce..57d0c3115ca01b 100644 --- a/.github/workflows/examples-stm32.yaml +++ b/.github/workflows/examples-stm32.yaml @@ -38,7 +38,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" steps: diff --git a/.github/workflows/examples-telink.yaml b/.github/workflows/examples-telink.yaml index 285ba96aceda07..a21d4970730703 100644 --- a/.github/workflows/examples-telink.yaml +++ b/.github/workflows/examples-telink.yaml @@ -36,7 +36,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-telink:41 + image: ghcr.io/project-chip/chip-build-telink:46 volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" @@ -55,7 +55,7 @@ jobs: gh-context: ${{ toJson(github) }} # - name: Update Zephyr to specific revision (for developers purpose) - # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py b5c8028ec94f3efa69decff3a09f0d6f8a21fd6d" + # run: scripts/run_in_build_env.sh "python3 scripts/tools/telink/update_zephyr.py 65dc1812431bf946dfc110682298acf83d63e27a" - name: Build example Telink (B92 retention) Air Quality Sensor App run: | diff --git a/.github/workflows/examples-tizen.yaml b/.github/workflows/examples-tizen.yaml index 65c15e5ea4114d..f89c2d259490cc 100644 --- a/.github/workflows/examples-tizen.yaml +++ b/.github/workflows/examples-tizen.yaml @@ -34,7 +34,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-tizen:41 + image: ghcr.io/project-chip/chip-build-tizen:46 options: --user root volumes: - "/tmp/bloat_reports:/tmp/bloat_reports" diff --git a/.github/workflows/full-android.yaml b/.github/workflows/full-android.yaml index 81a277d906d786..48f0af185c268e 100644 --- a/.github/workflows/full-android.yaml +++ b/.github/workflows/full-android.yaml @@ -36,7 +36,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-android:41 + image: ghcr.io/project-chip/chip-build-android:46 volumes: - "/tmp/log_output:/tmp/test_logs" diff --git a/.github/workflows/fuzzing-build.yaml b/.github/workflows/fuzzing-build.yaml index f354ce369c27fd..4ba9c49d744aa0 100644 --- a/.github/workflows/fuzzing-build.yaml +++ b/.github/workflows/fuzzing-build.yaml @@ -33,7 +33,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/tmp/log_output:/tmp/test_logs" diff --git a/.github/workflows/java-tests.yaml b/.github/workflows/java-tests.yaml index 4356924024c9fe..b609ad79fc9d56 100644 --- a/.github/workflows/java-tests.yaml +++ b/.github/workflows/java-tests.yaml @@ -40,7 +40,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/project-chip/chip-build-java:41 + image: ghcr.io/project-chip/chip-build-java:46 options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=0 net.ipv6.conf.all.forwarding=0" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 36a5a0b996e41b..1968718809124a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -29,7 +29,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 steps: - name: Checkout diff --git a/.github/workflows/minimal-build.yaml b/.github/workflows/minimal-build.yaml index 029f3d759771fc..3320dab5a0b59c 100644 --- a/.github/workflows/minimal-build.yaml +++ b/.github/workflows/minimal-build.yaml @@ -31,7 +31,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/project-chip/chip-build-minimal:41 + image: ghcr.io/project-chip/chip-build-minimal:46 steps: - name: Checkout diff --git a/.github/workflows/qemu.yaml b/.github/workflows/qemu.yaml index dc356586b4dd96..9b6c85592d8755 100644 --- a/.github/workflows/qemu.yaml +++ b/.github/workflows/qemu.yaml @@ -38,7 +38,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-esp32-qemu:41 + image: ghcr.io/project-chip/chip-build-esp32-qemu:46 volumes: - "/tmp/log_output:/tmp/test_logs" @@ -78,7 +78,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-tizen-qemu:41 + image: ghcr.io/project-chip/chip-build-tizen-qemu:46 volumes: - "/tmp/log_output:/tmp/test_logs" diff --git a/.github/workflows/release_artifacts.yaml b/.github/workflows/release_artifacts.yaml index 57a1ce7b325dc3..78b50ad8033cad 100644 --- a/.github/workflows/release_artifacts.yaml +++ b/.github/workflows/release_artifacts.yaml @@ -32,7 +32,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/project-chip/chip-build-esp32:41 + image: ghcr.io/project-chip/chip-build-esp32:46 steps: - name: Checkout @@ -64,7 +64,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/project-chip/chip-build-efr32:41 + image: ghcr.io/project-chip/chip-build-efr32:46 steps: - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/smoketest-android.yaml b/.github/workflows/smoketest-android.yaml index d1dd509fd5aa63..d9d81abca4644f 100644 --- a/.github/workflows/smoketest-android.yaml +++ b/.github/workflows/smoketest-android.yaml @@ -37,7 +37,7 @@ jobs: if: github.actor != 'restyled-io[bot]' container: - image: ghcr.io/project-chip/chip-build-android:41 + image: ghcr.io/project-chip/chip-build-android:46 volumes: - "/:/runner-root-volume" - "/tmp/log_output:/tmp/test_logs" diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 2907a4a89711ea..e024d1668f396b 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -47,7 +47,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=1 net.ipv6.conf.all.forwarding=1" @@ -437,7 +437,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 options: --privileged --sysctl "net.ipv6.conf.all.disable_ipv6=0 net.ipv4.conf.all.forwarding=0 net.ipv6.conf.all.forwarding=0" diff --git a/.github/workflows/unit_integration_test.yaml b/.github/workflows/unit_integration_test.yaml index 478d347be25ab9..480e9ec74362be 100644 --- a/.github/workflows/unit_integration_test.yaml +++ b/.github/workflows/unit_integration_test.yaml @@ -37,7 +37,7 @@ jobs: runs-on: ubuntu-latest container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 volumes: - "/:/runner-root-volume" - "/tmp/log_output:/tmp/test_logs" diff --git a/.github/workflows/zap_regeneration.yaml b/.github/workflows/zap_regeneration.yaml index 4488e23258cd65..93b966fc314b34 100644 --- a/.github/workflows/zap_regeneration.yaml +++ b/.github/workflows/zap_regeneration.yaml @@ -30,7 +30,7 @@ jobs: runs-on: ubuntu-20.04 container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 defaults: run: shell: sh diff --git a/.github/workflows/zap_templates.yaml b/.github/workflows/zap_templates.yaml index f14b914ae7f88a..ea8c72ae349ba7 100644 --- a/.github/workflows/zap_templates.yaml +++ b/.github/workflows/zap_templates.yaml @@ -32,7 +32,7 @@ jobs: runs-on: ubuntu-20.04 container: - image: ghcr.io/project-chip/chip-build:41 + image: ghcr.io/project-chip/chip-build:46 defaults: run: shell: sh diff --git a/config/telink/chip-module/Kconfig.defaults b/config/telink/chip-module/Kconfig.defaults index 964b08547bb0b5..5e21bb752402ba 100644 --- a/config/telink/chip-module/Kconfig.defaults +++ b/config/telink/chip-module/Kconfig.defaults @@ -158,8 +158,8 @@ choice B9X_BLE_CTRL_MAC_TYPE endchoice # Board retention config -if BOARD_TLSR9528A_RETENTION || BOARD_TLSR9258A_RETENTION || BOARD_TLSR9518ADK80D_RETENTION -config BOARD_TLSR9X_NON_RETENTION_RAM_CODE +if BOARD_TLSR9528A_RETENTION || BOARD_TLSR9258A_RETENTION || BOARD_TLSR9518ADK80D_RETENTION +config SOC_SERIES_RISCV_TELINK_B9X_NON_RETENTION_RAM_CODE default y if PM config TELINK_B9x_MATTER_RETENTION_LAYOUT diff --git a/examples/air-quality-sensor-app/telink/CMakeLists.txt b/examples/air-quality-sensor-app/telink/CMakeLists.txt index 5ed8c314f1b334..a27ab91c186b44 100644 --- a/examples/air-quality-sensor-app/telink/CMakeLists.txt +++ b/examples/air-quality-sensor-app/telink/CMakeLists.txt @@ -76,7 +76,7 @@ project(chip-telink-air-quality-sensor-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE include @@ -84,7 +84,8 @@ target_include_directories(app PRIVATE ${GEN_DIR}/air-quality-sensor-app ${TELINK_COMMON}/common/include ${TELINK_COMMON}/util/include - ${CHIP_ROOT}/examples/air-quality-sensor-app/air-quality-sensor-common/include) + ${CHIP_ROOT}/examples/air-quality-sensor-app/air-quality-sensor-common/include + ${TELINK_COMMON}/zephyr_ext) target_sources(app PRIVATE src/AppTask.cpp @@ -92,12 +93,16 @@ target_sources(app PRIVATE ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp ${TELINK_COMMON}/common/src/SensorManagerCommon.cpp - ${TELINK_COMMON}/util/src/LEDWidget.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp ${TELINK_COMMON}/util/src/ThreadUtil.cpp - ${TELINK_COMMON}/util/src/PWMDevice.cpp - ${TELINK_COMMON}/util/src/WS2812Device.cpp - ${CHIP_ROOT}/examples/air-quality-sensor-app/air-quality-sensor-common/src/air-quality-sensor-manager.cpp) + ${TELINK_COMMON}/util/src/PWMManager.cpp + ${CHIP_ROOT}/examples/air-quality-sensor-app/air-quality-sensor-common/src/air-quality-sensor-manager.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c) chip_configure_data_model(app INCLUDE_SERVER diff --git a/examples/air-quality-sensor-app/telink/include/AppConfig.h b/examples/air-quality-sensor-app/telink/include/AppConfig.h index 7513ed3771b961..0888260c26a7f1 100644 --- a/examples/air-quality-sensor-app/telink/include/AppConfig.h +++ b/examples/air-quality-sensor-app/telink/include/AppConfig.h @@ -20,11 +20,5 @@ // ---- Air Quality Example App Config ---- -#define APP_USE_EXAMPLE_START_BUTTON 1 -#define APP_USE_BLE_START_BUTTON 0 -#define APP_USE_THREAD_START_BUTTON 0 #define APP_SET_DEVICE_INFO_PROVIDER 1 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0 -#if defined(CONFIG_BOARD_TLSR9518ADK80D) || defined(CONFIG_BOARD_TLSR9528A) -#define APP_USE_IDENTIFY_PWM 1 -#endif diff --git a/examples/air-quality-sensor-app/telink/src/AppTask.cpp b/examples/air-quality-sensor-app/telink/src/AppTask.cpp index ac2f61b3c06f52..da0f80ec9c15f7 100644 --- a/examples/air-quality-sensor-app/telink/src/AppTask.cpp +++ b/examples/air-quality-sensor-app/telink/src/AppTask.cpp @@ -37,9 +37,7 @@ CHIP_ERROR AppTask::Init(void) { CHIP_ERROR err; -#if APP_USE_EXAMPLE_START_BUTTON SetExampleButtonCallbacks(AirQualitySensorUpdateTimerEventHandler); -#endif InitCommonParts(); err = SensorMgr().Init(); diff --git a/examples/all-clusters-app/ameba/README.md b/examples/all-clusters-app/ameba/README.md index 3450d27befe551..f54a5344020ac7 100644 --- a/examples/all-clusters-app/ameba/README.md +++ b/examples/all-clusters-app/ameba/README.md @@ -27,11 +27,11 @@ The CHIP demo application is supported on - Pull docker image: - $ docker pull ghcr.io/project-chip/chip-build-ameba:42 + $ docker pull ghcr.io/project-chip/chip-build-ameba:46 - Run docker container: - $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:42 + $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:46 - Setup build environment: diff --git a/examples/all-clusters-app/telink/CMakeLists.txt b/examples/all-clusters-app/telink/CMakeLists.txt index 2c59e658a7e6dc..7787f423e28a50 100644 --- a/examples/all-clusters-app/telink/CMakeLists.txt +++ b/examples/all-clusters-app/telink/CMakeLists.txt @@ -61,7 +61,7 @@ project(chip-telink-all-clusters-app-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE include @@ -70,7 +70,8 @@ target_include_directories(app PRIVATE ${GEN_DIR}/app-common ${GEN_DIR}/all-clusters-app ${TELINK_COMMON}/common/include - ${TELINK_COMMON}/util/include) + ${TELINK_COMMON}/util/include + ${TELINK_COMMON}/zephyr_ext) target_sources(app PRIVATE src/AppTask.cpp @@ -92,10 +93,15 @@ target_sources(app PRIVATE ${ENERGY_MANAGEMENT_COMMON_DIR}/src/DeviceEnergyManagementManager.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp - ${TELINK_COMMON}/util/src/LEDWidget.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp ${TELINK_COMMON}/util/src/ThreadUtil.cpp - ${TELINK_COMMON}/util/src/PWMDevice.cpp) + ${TELINK_COMMON}/util/src/PWMManager.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c) chip_configure_data_model(app INCLUDE_SERVER diff --git a/examples/all-clusters-app/telink/include/AppConfig.h b/examples/all-clusters-app/telink/include/AppConfig.h index 68263bbda460db..602aa6065313a5 100644 --- a/examples/all-clusters-app/telink/include/AppConfig.h +++ b/examples/all-clusters-app/telink/include/AppConfig.h @@ -19,11 +19,5 @@ #pragma once // ---- All Clusters Application example config ---- -#define APP_USE_EXAMPLE_START_BUTTON 0 -#define APP_USE_BLE_START_BUTTON 0 -#define APP_USE_THREAD_START_BUTTON 1 #define APP_SET_DEVICE_INFO_PROVIDER 1 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 1 -#if defined(CONFIG_BOARD_TLSR9518ADK80D) || defined(CONFIG_BOARD_TLSR9528A) -#define APP_USE_IDENTIFY_PWM 1 -#endif diff --git a/examples/all-clusters-minimal-app/ameba/README.md b/examples/all-clusters-minimal-app/ameba/README.md index 693b06cbaa80e4..6daa6820ff9cdb 100644 --- a/examples/all-clusters-minimal-app/ameba/README.md +++ b/examples/all-clusters-minimal-app/ameba/README.md @@ -27,13 +27,13 @@ The CHIP demo application is supported on - Pull docker image: ``` - $ docker pull ghcr.io/project-chip/chip-build-ameba:35 + $ docker pull ghcr.io/project-chip/chip-build-ameba:46 ``` - Run docker container: ``` - $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:35 + $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:46 ``` - Setup build environment: diff --git a/examples/all-clusters-minimal-app/telink/CMakeLists.txt b/examples/all-clusters-minimal-app/telink/CMakeLists.txt index a68471e379a842..ee47129b514a1c 100644 --- a/examples/all-clusters-minimal-app/telink/CMakeLists.txt +++ b/examples/all-clusters-minimal-app/telink/CMakeLists.txt @@ -60,7 +60,7 @@ project(chip-telink-all-clusters-minimal-app-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE include @@ -68,7 +68,8 @@ target_include_directories(app PRIVATE ${GEN_DIR}/app-common ${GEN_DIR}/all-clusters-minimal-app ${TELINK_COMMON}/common/include - ${TELINK_COMMON}/util/include) + ${TELINK_COMMON}/util/include + ${TELINK_COMMON}/zephyr_ext) target_sources(app PRIVATE src/AppTask.cpp @@ -78,9 +79,15 @@ target_sources(app PRIVATE ${ALL_CLUSTERS_COMMON_DIR}/src/binding-handler.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp - ${TELINK_COMMON}/util/src/LEDWidget.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp + ${TELINK_COMMON}/util/src/PWMManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp - ${TELINK_COMMON}/util/src/ThreadUtil.cpp) + ${TELINK_COMMON}/util/src/ThreadUtil.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c) chip_configure_data_model(app INCLUDE_SERVER diff --git a/examples/all-clusters-minimal-app/telink/include/AppConfig.h b/examples/all-clusters-minimal-app/telink/include/AppConfig.h index 5ef62e04203e1b..38bbe54833078b 100644 --- a/examples/all-clusters-minimal-app/telink/include/AppConfig.h +++ b/examples/all-clusters-minimal-app/telink/include/AppConfig.h @@ -20,8 +20,5 @@ // ---- All Clusters Minimal Application example config ---- -#define APP_USE_EXAMPLE_START_BUTTON 0 -#define APP_USE_BLE_START_BUTTON 0 -#define APP_USE_THREAD_START_BUTTON 0 #define APP_SET_DEVICE_INFO_PROVIDER 0 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 1 diff --git a/examples/bridge-app/telink/CMakeLists.txt b/examples/bridge-app/telink/CMakeLists.txt index f4da959953def8..d4e78b101d90a4 100644 --- a/examples/bridge-app/telink/CMakeLists.txt +++ b/examples/bridge-app/telink/CMakeLists.txt @@ -59,7 +59,7 @@ project(chip-telink-bridge-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE include @@ -67,19 +67,24 @@ target_include_directories(app PRIVATE ${GEN_DIR}/bridge-app ${TELINK_COMMON}/common/include ${TELINK_COMMON}/util/include - ${TELINK_COMMON}/app/include) + ${TELINK_COMMON}/app/include + ${TELINK_COMMON}/zephyr_ext) target_sources(app PRIVATE src/AppTask.cpp - src/ZclCallbacks.cpp src/Device.cpp src/DeviceCallbacks.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp - ${TELINK_COMMON}/util/src/LEDWidget.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp ${TELINK_COMMON}/util/src/ThreadUtil.cpp - ${TELINK_COMMON}/util/src/PWMDevice.cpp) + ${TELINK_COMMON}/util/src/PWMManager.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c) chip_configure_data_model(app INCLUDE_SERVER diff --git a/examples/bridge-app/telink/include/AppConfig.h b/examples/bridge-app/telink/include/AppConfig.h index e5e26efb2871d1..e4af6138744261 100644 --- a/examples/bridge-app/telink/include/AppConfig.h +++ b/examples/bridge-app/telink/include/AppConfig.h @@ -20,11 +20,5 @@ // ---- Bridge App Example Config ---- -#define APP_USE_EXAMPLE_START_BUTTON 1 -#define APP_USE_BLE_START_BUTTON 0 -#define APP_USE_THREAD_START_BUTTON 1 #define APP_SET_DEVICE_INFO_PROVIDER 1 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0 -#if defined(CONFIG_BOARD_TLSR9518ADK80D) || defined(CONFIG_BOARD_TLSR9528A) -#define APP_USE_IDENTIFY_PWM 1 -#endif diff --git a/examples/bridge-app/telink/include/AppTask.h b/examples/bridge-app/telink/include/AppTask.h index 6b8a60df890dbf..18275849c015a4 100644 --- a/examples/bridge-app/telink/include/AppTask.h +++ b/examples/bridge-app/telink/include/AppTask.h @@ -19,14 +19,20 @@ #pragma once #include "AppTaskCommon.h" -#include "PWMDevice.h" class AppTask : public AppTaskCommon { public: + enum Action_t : uint8_t + { + ON_ACTION = 0, + OFF_ACTION, + LEVEL_ACTION, + INVALID_ACTION + }; + void UpdateClusterState(void); static void InitServer(intptr_t context); - PWMDevice & GetPWMDevice(void) { return mPwmRgbBlueLed; } private: friend AppTask & GetAppTask(void); @@ -34,13 +40,8 @@ class AppTask : public AppTaskCommon CHIP_ERROR Init(void); - static void ActionInitiated(PWMDevice::Action_t aAction, int32_t aActor); - static void ActionCompleted(PWMDevice::Action_t aAction, int32_t aActor); - static void LightingActionEventHandler(AppEvent * aEvent); - PWMDevice mPwmRgbBlueLed; - static AppTask sAppTask; }; diff --git a/examples/bridge-app/telink/src/AppTask.cpp b/examples/bridge-app/telink/src/AppTask.cpp index d70f9c078e3027..76a59c4de5e293 100644 --- a/examples/bridge-app/telink/src/AppTask.cpp +++ b/examples/bridge-app/telink/src/AppTask.cpp @@ -18,6 +18,7 @@ #include "AppTask.h" #include "Device.h" +#include "PWMManager.h" #include #include @@ -27,7 +28,8 @@ LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); namespace { -const struct pwm_dt_spec sPwmRgbSpecBlueLed = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0)); +bool sTurnedOn; +uint8_t sLevel; } // namespace AppTask AppTask::sAppTask; @@ -395,29 +397,32 @@ bool emberAfActionsClusterInstantActionCallback(app::CommandHandler * commandObj CHIP_ERROR AppTask::Init(void) { - // Init lighting manager - uint8_t minLightLevel = kDefaultMinLevel; - Clusters::LevelControl::Attributes::MinLevel::Get(kExampleEndpointId, &minLightLevel); + SetExampleButtonCallbacks(LightingActionEventHandler); + InitCommonParts(); - uint8_t maxLightLevel = kDefaultMaxLevel; - Clusters::LevelControl::Attributes::MaxLevel::Get(kExampleEndpointId, &maxLightLevel); + Protocols::InteractionModel::Status status; - // Initialize PWM LED - CHIP_ERROR err = sAppTask.mPwmRgbBlueLed.Init(&sPwmRgbSpecBlueLed, minLightLevel, maxLightLevel, maxLightLevel); - if (err != CHIP_NO_ERROR) + app::DataModel::Nullable level; + // Read brightness value + status = Clusters::LevelControl::Attributes::CurrentLevel::Get(kExampleEndpointId, level); + if (status == Protocols::InteractionModel::Status::Success && !level.IsNull()) { - LOG_ERR("Blue RGB PWM Device Init fail"); - return err; + sLevel = level.Value(); } - sAppTask.mPwmRgbBlueLed.SetCallbacks(ActionInitiated, ActionCompleted, nullptr); - -#if APP_USE_EXAMPLE_START_BUTTON - SetExampleButtonCallbacks(LightingActionEventHandler); -#endif - InitCommonParts(); + bool isOn; + // Read storedValue on/off value + status = Clusters::OnOff::Attributes::OnOff::Get(1, &isOn); + if (status == Protocols::InteractionModel::Status::Success) + { + sTurnedOn = isOn; + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, sTurnedOn); + } - memset(gDevices, 0, sizeof(gDevices)); + for (size_t i = 0; i < CHIP_DEVICE_CONFIG_DYNAMIC_ENDPOINT_COUNT; i++) + { + gDevices[i] = nullptr; + } gLight1.SetReachable(true); gLight2.SetReachable(true); @@ -531,66 +536,26 @@ Protocols::InteractionModel::Status HandleReadTempMeasurementAttribute(DeviceTem void AppTask::LightingActionEventHandler(AppEvent * aEvent) { - PWMDevice::Action_t action = PWMDevice::INVALID_ACTION; - int32_t actor = 0; + Action_t action = INVALID_ACTION; + int32_t actor = 0; if (aEvent->Type == AppEvent::kEventType_Lighting) { - action = static_cast(aEvent->LightingEvent.Action); + action = static_cast(aEvent->LightingEvent.Action); actor = aEvent->LightingEvent.Actor; } else if (aEvent->Type == AppEvent::kEventType_Button) { - action = sAppTask.mPwmRgbBlueLed.IsTurnedOn() ? PWMDevice::OFF_ACTION : PWMDevice::ON_ACTION; - actor = AppEvent::kEventType_Button; - } - - if (action != PWMDevice::INVALID_ACTION && (!sAppTask.mPwmRgbBlueLed.InitiateAction(action, actor, NULL))) - { - LOG_INF("Action is in progress or active"); - } -} - -void AppTask::ActionInitiated(PWMDevice::Action_t aAction, int32_t aActor) -{ - if (aAction == PWMDevice::ON_ACTION) - { - LOG_DBG("ON_ACTION initiated"); - } - else if (aAction == PWMDevice::OFF_ACTION) - { - LOG_DBG("OFF_ACTION initiated"); - } - else if (aAction == PWMDevice::LEVEL_ACTION) - { - LOG_DBG("LEVEL_ACTION initiated"); - } -} - -void AppTask::ActionCompleted(PWMDevice::Action_t aAction, int32_t aActor) -{ - if (aAction == PWMDevice::ON_ACTION) - { - LOG_DBG("ON_ACTION completed"); - } - else if (aAction == PWMDevice::OFF_ACTION) - { - LOG_DBG("OFF_ACTION completed"); - } - else if (aAction == PWMDevice::LEVEL_ACTION) - { - LOG_DBG("LEVEL_ACTION completed"); - } + sTurnedOn = !sTurnedOn; - if (aActor == AppEvent::kEventType_Button) - { - sAppTask.UpdateClusterState(); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, sTurnedOn); + GetAppTask().UpdateClusterState(); } } void AppTask::UpdateClusterState(void) { - bool isTurnedOn = sAppTask.mPwmRgbBlueLed.IsTurnedOn(); + bool isTurnedOn = sTurnedOn; // write the new on/off value Protocols::InteractionModel::Status status = Clusters::OnOff::Attributes::OnOff::Set(kExampleEndpointId, isTurnedOn); @@ -599,7 +564,7 @@ void AppTask::UpdateClusterState(void) { LOG_ERR("Update OnOff fail: %x", to_underlying(status)); } - uint8_t setLevel = sAppTask.mPwmRgbBlueLed.GetLevel(); + uint8_t setLevel = sLevel; status = Clusters::LevelControl::Attributes::CurrentLevel::Set(kExampleEndpointId, setLevel); if (status != Protocols::InteractionModel::Status::Success) { diff --git a/examples/bridge-app/telink/src/ZclCallbacks.cpp b/examples/bridge-app/telink/src/ZclCallbacks.cpp deleted file mode 100644 index e83993165acb51..00000000000000 --- a/examples/bridge-app/telink/src/ZclCallbacks.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * - * Copyright (c) 2023 Project CHIP Authors - * 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 "AppTask.h" -#include "ColorFormat.h" -#include "PWMDevice.h" - -#include -#include -#include -#include -#include - -LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); - -using namespace chip; -using namespace chip::app::Clusters; -using namespace chip::app::Clusters::OnOff; - -/** @brief OnOff Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfOnOffClusterInitCallback(EndpointId endpoint) -{ - Protocols::InteractionModel::Status status; - bool storedValue; - - // Read storedValue on/off value - status = Attributes::OnOff::Get(1, &storedValue); - if (status == Protocols::InteractionModel::Status::Success) - { - // Set actual state to stored before reboot - GetAppTask().GetPWMDevice().Set(storedValue); - } - - GetAppTask().UpdateClusterState(); -} diff --git a/examples/chef/telink/CMakeLists.txt b/examples/chef/telink/CMakeLists.txt index 71f0c549e6ed79..8538e2a9e9fc60 100755 --- a/examples/chef/telink/CMakeLists.txt +++ b/examples/chef/telink/CMakeLists.txt @@ -64,7 +64,7 @@ project(chip-telink-chef-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} @@ -78,6 +78,7 @@ target_include_directories(app PRIVATE ${TELINK_COMMON}/common/include ${TELINK_COMMON}/util/include ${TELINK_COMMON}/app/include + ${TELINK_COMMON}/zephyr_ext ) if (CONFIG_CHIP_LIB_SHELL) @@ -96,9 +97,15 @@ target_sources(app PRIVATE src/AppTask.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp - ${TELINK_COMMON}/util/src/PWMDevice.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp ${TELINK_COMMON}/util/src/ThreadUtil.cpp + ${TELINK_COMMON}/util/src/PWMManager.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c ${CHEF}/common/stubs.cpp ) diff --git a/examples/chef/telink/include/AppConfig.h b/examples/chef/telink/include/AppConfig.h index b3092856c49902..b5c1335abf1774 100644 --- a/examples/chef/telink/include/AppConfig.h +++ b/examples/chef/telink/include/AppConfig.h @@ -20,8 +20,5 @@ // ---- Chef Example App Config ---- -#define APP_USE_EXAMPLE_START_BUTTON 0 -#define APP_USE_BLE_START_BUTTON 1 -#define APP_USE_THREAD_START_BUTTON 1 #define APP_SET_DEVICE_INFO_PROVIDER 1 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0 diff --git a/examples/chef/telink/include/AppTask.h b/examples/chef/telink/include/AppTask.h index 3b91e9a3733786..13ede39ec8cfdb 100644 --- a/examples/chef/telink/include/AppTask.h +++ b/examples/chef/telink/include/AppTask.h @@ -20,6 +20,8 @@ #include "AppTaskCommon.h" +class ButtonManager; + class AppTask : public AppTaskCommon { public: @@ -28,6 +30,7 @@ class AppTask : public AppTaskCommon friend class AppTaskCommon; CHIP_ERROR Init(void); + void LinkButtons(ButtonManager & buttonManager); static AppTask sAppTask; }; diff --git a/examples/chef/telink/src/AppTask.cpp b/examples/chef/telink/src/AppTask.cpp index a9683f0d8c3610..4b3116d4fd675c 100644 --- a/examples/chef/telink/src/AppTask.cpp +++ b/examples/chef/telink/src/AppTask.cpp @@ -17,6 +17,7 @@ */ #include "AppTask.h" +#include "ButtonManager.h" #include LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); @@ -49,3 +50,10 @@ CHIP_ERROR AppTask::Init(void) return CHIP_NO_ERROR; } + +void AppTask::LinkButtons(ButtonManager & buttonManager) +{ + buttonManager.addCallback(FactoryResetButtonEventHandler, 0, true); + buttonManager.addCallback(ExampleActionButtonEventHandler, 1, true); + buttonManager.addCallback(StartBleAdvButtonEventHandler, 2, true); +} diff --git a/examples/contact-sensor-app/telink/CMakeLists.txt b/examples/contact-sensor-app/telink/CMakeLists.txt index c29ef949914036..379a1f09f13d4b 100755 --- a/examples/contact-sensor-app/telink/CMakeLists.txt +++ b/examples/contact-sensor-app/telink/CMakeLists.txt @@ -59,14 +59,15 @@ project(chip-telink-contact-sensor-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE include ${GEN_DIR}/app-common ${GEN_DIR}/contact-sensor-app ${TELINK_COMMON}/common/include - ${TELINK_COMMON}/util/include) + ${TELINK_COMMON}/util/include + ${TELINK_COMMON}/zephyr_ext) target_sources(app PRIVATE src/AppTask.cpp @@ -74,10 +75,15 @@ target_sources(app PRIVATE src/ZclCallbacks.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp - ${TELINK_COMMON}/util/src/LEDWidget.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp ${TELINK_COMMON}/util/src/ThreadUtil.cpp - ${TELINK_COMMON}/util/src/PWMDevice.cpp) + ${TELINK_COMMON}/util/src/PWMManager.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c) chip_configure_data_model(app INCLUDE_SERVER diff --git a/examples/contact-sensor-app/telink/include/AppConfig.h b/examples/contact-sensor-app/telink/include/AppConfig.h index feb2b82d7417fc..ecde0f2317eb92 100644 --- a/examples/contact-sensor-app/telink/include/AppConfig.h +++ b/examples/contact-sensor-app/telink/include/AppConfig.h @@ -19,11 +19,5 @@ #pragma once // ---- All Clusters Application example config ---- -#define APP_USE_EXAMPLE_START_BUTTON 1 -#define APP_USE_BLE_START_BUTTON 0 -#define APP_USE_THREAD_START_BUTTON 0 #define APP_SET_DEVICE_INFO_PROVIDER 1 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0 -#if defined(CONFIG_BOARD_TLSR9518ADK80D) || defined(CONFIG_BOARD_TLSR9528A) -#define APP_USE_IDENTIFY_PWM 1 -#endif diff --git a/examples/contact-sensor-app/telink/include/AppTask.h b/examples/contact-sensor-app/telink/include/AppTask.h index 3ac0028c78e3bb..8d888daa25a6de 100644 --- a/examples/contact-sensor-app/telink/include/AppTask.h +++ b/examples/contact-sensor-app/telink/include/AppTask.h @@ -39,6 +39,7 @@ class AppTask : public AppTaskCommon friend class AppTaskCommon; CHIP_ERROR Init(void); + void LinkLeds(LedManager & ledManager); static void OnStateChanged(ContactSensorManager::State aState); diff --git a/examples/contact-sensor-app/telink/src/AppTask.cpp b/examples/contact-sensor-app/telink/src/AppTask.cpp index dbcf9e1ce48405..8ddb43d7b7f084 100644 --- a/examples/contact-sensor-app/telink/src/AppTask.cpp +++ b/examples/contact-sensor-app/telink/src/AppTask.cpp @@ -17,6 +17,7 @@ */ #include "AppTask.h" +#include "LEDManager.h" #include @@ -25,25 +26,14 @@ LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); -namespace { -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED -LEDWidget sContactSensorLED; -#endif -} // namespace - AppTask AppTask::sAppTask; CHIP_ERROR AppTask::Init(void) { -#if APP_USE_EXAMPLE_START_BUTTON SetExampleButtonCallbacks(ContactActionEventHandler); -#endif InitCommonParts(); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sContactSensorLED.Init(GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios)); - sContactSensorLED.Set(ContactSensorMgr().IsContactClosed()); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, ContactSensorMgr().IsContactClosed()); UpdateDeviceState(); @@ -60,16 +50,12 @@ void AppTask::OnStateChanged(ContactSensorManager::State aState) if (ContactSensorManager::State::kContactClosed == aState) { LOG_INF("Contact state changed to CLOSED"); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sContactSensorLED.Set(true); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, true); } else if (ContactSensorManager::State::kContactOpened == aState) { LOG_INF("Contact state changed to OPEN"); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sContactSensorLED.Set(false); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, false); } if (sAppTask.IsSyncClusterToButtonAction()) @@ -155,8 +141,15 @@ void AppTask::UpdateDeviceStateInternal(intptr_t arg) /* get boolean state attribute value */ (void) app::Clusters::BooleanState::Attributes::StateValue::Get(1, &stateValueAttrValue); - ChipLogProgress(NotSpecified, "StateValue::Get : %d", stateValueAttrValue); + LedManager::getInstance().setLed(LedManager::EAppLed_App0, stateValueAttrValue); +} + +void AppTask::LinkLeds(LedManager & ledManager) +{ #if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sContactSensorLED.Set(stateValueAttrValue); -#endif + ledManager.linkLed(LedManager::EAppLed_Status, 0); + ledManager.linkLed(LedManager::EAppLed_App0, 1); +#else + ledManager.linkLed(LedManager::EAppLed_App0, 0); +#endif // CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED } diff --git a/examples/light-switch-app/ameba/README.md b/examples/light-switch-app/ameba/README.md index bc7953a87f8da2..4437e4c27e9245 100644 --- a/examples/light-switch-app/ameba/README.md +++ b/examples/light-switch-app/ameba/README.md @@ -26,11 +26,11 @@ The CHIP demo application is supported on - Pull docker image: - $ docker pull ghcr.io/project-chip/chip-build-ameba:42 + $ docker pull ghcr.io/project-chip/chip-build-ameba:46 - Run docker container: - $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:42 + $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:46 - Setup build environment: diff --git a/examples/light-switch-app/telink/CMakeLists.txt b/examples/light-switch-app/telink/CMakeLists.txt index 451727b9fe20ae..f634efa958df10 100755 --- a/examples/light-switch-app/telink/CMakeLists.txt +++ b/examples/light-switch-app/telink/CMakeLists.txt @@ -59,7 +59,7 @@ project(chip-telink-light-switch-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE include @@ -67,7 +67,8 @@ target_include_directories(app PRIVATE ${GEN_DIR}/light-switch-app ${TELINK_COMMON}/common/include ${TELINK_COMMON}/util/include - ${TELINK_COMMON}/app/include) + ${TELINK_COMMON}/app/include + ${TELINK_COMMON}/zephyr_ext) target_sources(app PRIVATE src/AppTask.cpp @@ -75,10 +76,15 @@ target_sources(app PRIVATE src/binding-handler.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp - ${TELINK_COMMON}/util/src/LEDWidget.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp ${TELINK_COMMON}/util/src/ThreadUtil.cpp - ${TELINK_COMMON}/util/src/PWMDevice.cpp) + ${TELINK_COMMON}/util/src/PWMManager.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c) chip_configure_data_model(app INCLUDE_SERVER diff --git a/examples/light-switch-app/telink/include/AppConfig.h b/examples/light-switch-app/telink/include/AppConfig.h index 8258f39573039c..15715b0e8a0a27 100644 --- a/examples/light-switch-app/telink/include/AppConfig.h +++ b/examples/light-switch-app/telink/include/AppConfig.h @@ -20,11 +20,5 @@ // ---- Light Switch Example App Config ---- -#define APP_USE_EXAMPLE_START_BUTTON 1 -#define APP_USE_BLE_START_BUTTON 0 -#define APP_USE_THREAD_START_BUTTON 0 #define APP_SET_DEVICE_INFO_PROVIDER 1 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0 -#if defined(CONFIG_BOARD_TLSR9518ADK80D) || defined(CONFIG_BOARD_TLSR9528A) -#define APP_USE_IDENTIFY_PWM 1 -#endif diff --git a/examples/light-switch-app/telink/src/AppTask.cpp b/examples/light-switch-app/telink/src/AppTask.cpp index 39b92cca42519d..96dcdd0b43ca48 100644 --- a/examples/light-switch-app/telink/src/AppTask.cpp +++ b/examples/light-switch-app/telink/src/AppTask.cpp @@ -25,9 +25,7 @@ AppTask AppTask::sAppTask; CHIP_ERROR AppTask::Init(void) { -#if APP_USE_EXAMPLE_START_BUTTON SetExampleButtonCallbacks(SwitchActionEventHandler); -#endif InitCommonParts(); // Configure Bindings diff --git a/examples/lighting-app/ameba/README.md b/examples/lighting-app/ameba/README.md index 44bc04a0811dc4..36fbe0f9d3c600 100644 --- a/examples/lighting-app/ameba/README.md +++ b/examples/lighting-app/ameba/README.md @@ -23,11 +23,11 @@ The CHIP demo application is supported on - Pull docker image: - $ docker pull ghcr.io/project-chip/chip-build-ameba:42 + $ docker pull ghcr.io/project-chip/chip-build-ameba:46 - Run docker container: - $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:42 + $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:46 - Setup build environment: diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt index 9620a00e1127e5..d0b0da7fa0a8e0 100644 --- a/examples/lighting-app/telink/CMakeLists.txt +++ b/examples/lighting-app/telink/CMakeLists.txt @@ -91,7 +91,7 @@ project(chip-telink-lighting-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE include @@ -99,19 +99,24 @@ target_include_directories(app PRIVATE ${GEN_DIR}/lighting-app ${TELINK_COMMON}/common/include ${TELINK_COMMON}/util/include - ${TELINK_COMMON}/app/include) + ${TELINK_COMMON}/app/include + ${TELINK_COMMON}/zephyr_ext) target_sources(app PRIVATE src/AppTask.cpp src/ZclCallbacks.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp - ${TELINK_COMMON}/util/src/LEDWidget.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp ${TELINK_COMMON}/util/src/ThreadUtil.cpp - ${TELINK_COMMON}/util/src/PWMDevice.cpp - ${TELINK_COMMON}/util/src/WS2812Device.cpp - ${TELINK_COMMON}/util/src/ColorFormat.cpp) + ${TELINK_COMMON}/util/src/PWMManager.cpp + ${TELINK_COMMON}/util/src/ColorFormat.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c) chip_configure_data_model(app INCLUDE_SERVER diff --git a/examples/lighting-app/telink/README.md b/examples/lighting-app/telink/README.md index 2f696170f3cca2..f4dfefe2b9795e 100644 --- a/examples/lighting-app/telink/README.md +++ b/examples/lighting-app/telink/README.md @@ -98,30 +98,6 @@ be used to specify the the effect. It is able to be in following effects: | Blinks (950 ms on/50 ms off) | Finish ( `Clusters::Identify::EffectIdentifierEnum::kFinishEffect`) | | LED off | Stop (`Clusters::Identify::EffectIdentifierEnum::kStopEffect`) | -#### Indicate current state of lightbulb - -By default, only **Blue** LED is used to show current state of lightbulb (only -for lightning-app). - -To enable RGB functionality in Your application set this config: - -In Matter examples/lighting-app/telink/include/**AppConfig.h**, set the define -`USE_RGB_PWM`: - -```bash - define USE_RGB_PWM 1 -``` - -To get current state of lightbulb in RGB mode, connect 3-color LED module to -following pins: - -| Name | Pin | -| :---: | :-----------------: | -| Red | PE2 (pin 8 of J34) | -| Green | PE0 (pin 5 of J34) | -| Blue | PB4 (pin 20 of J34) | -| GND | GND (pin 24 of J50) | - ### CHIP tool commands 1. Build diff --git a/examples/lighting-app/telink/include/AppConfig.h b/examples/lighting-app/telink/include/AppConfig.h index b616746393ff03..a3639efb3183af 100644 --- a/examples/lighting-app/telink/include/AppConfig.h +++ b/examples/lighting-app/telink/include/AppConfig.h @@ -20,14 +20,5 @@ // ---- Lighting Example App Config ---- -#define APP_USE_EXAMPLE_START_BUTTON 1 -#define APP_USE_BLE_START_BUTTON 1 -#define APP_USE_THREAD_START_BUTTON 1 #define APP_SET_DEVICE_INFO_PROVIDER 1 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0 -#if defined(CONFIG_BOARD_TLSR9518ADK80D) || defined(CONFIG_BOARD_TLSR9528A) -#define APP_USE_IDENTIFY_PWM 1 -#endif - -// Lighting LED config -#define USE_RGB_PWM 0 diff --git a/examples/lighting-app/telink/include/AppTask.h b/examples/lighting-app/telink/include/AppTask.h index 67b69ef84e2e45..c835c88e097c11 100644 --- a/examples/lighting-app/telink/include/AppTask.h +++ b/examples/lighting-app/telink/include/AppTask.h @@ -19,22 +19,29 @@ #pragma once #include "AppTaskCommon.h" -#include "PWMDevice.h" class AppTask : public AppTaskCommon { public: + enum Fixture_Action : uint8_t + { + ON_ACTION = 0, + OFF_ACTION, + LEVEL_ACTION, + COLOR_ACTION_XY, + COLOR_ACTION_HSV, + COLOR_ACTION_CT, + + INVALID_ACTION + }; + #ifdef CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET void PowerOnFactoryReset(void); #endif /* CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET */ - void SetInitiateAction(PWMDevice::Action_t aAction, int32_t aActor, uint8_t * value); - void UpdateClusterState(void); -#ifdef CONFIG_WS2812_STRIP - WS2812Device & GetLightingDevice(void) { return mWS2812Device; } -#else - PWMDevice & GetLightingDevice(void) { return mPwmRgbBlueLed; } -#endif /* CONFIG_WS2812_STRIP */ + bool IsTurnedOn() const; + void SetInitiateAction(Fixture_Action aAction, int32_t aActor, uint8_t * value); + void UpdateClusterState(void); private: friend AppTask & GetAppTask(void); @@ -42,9 +49,6 @@ class AppTask : public AppTaskCommon CHIP_ERROR Init(void); - static void ActionInitiated(PWMDevice::Action_t aAction, int32_t aActor); - static void ActionCompleted(PWMDevice::Action_t aAction, int32_t aActor); - static void LightingActionEventHandler(AppEvent * aEvent); #ifdef CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET static void PowerOnFactoryResetEventHandler(AppEvent * aEvent); @@ -54,16 +58,6 @@ class AppTask : public AppTaskCommon static k_timer sPowerOnFactoryResetTimer; #endif /* CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET */ -#ifdef CONFIG_WS2812_STRIP - WS2812Device mWS2812Device; -#else - PWMDevice mPwmRgbBlueLed; -#if USE_RGB_PWM - PWMDevice mPwmRgbGreenLed; - PWMDevice mPwmRgbRedLed; -#endif -#endif /* CONFIG_WS2812_STRIP */ - static AppTask sAppTask; }; diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp index 54dd2703c16ce9..bb4dc4150db2be 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -20,34 +20,29 @@ #include #include "ColorFormat.h" -#include "PWMDevice.h" +#include "PWMManager.h" #include LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); namespace { -#ifdef CONFIG_WS2812_STRIP -const struct device * const ws2812_dev = DEVICE_DT_GET(DT_ALIAS(led_strip)); -#else -const struct pwm_dt_spec sPwmRgbSpecBlueLed = PWM_DT_SPEC_GET_OR(DT_ALIAS(pwm_led0), {}); -#if USE_RGB_PWM -const struct pwm_dt_spec sPwmRgbSpecGreenLed = PWM_DT_SPEC_GET_OR(DT_ALIAS(pwm_led1), {}); -const struct pwm_dt_spec sPwmRgbSpecRedLed = PWM_DT_SPEC_GET_OR(DT_ALIAS(pwm_led2), {}); -#endif -#endif // CONFIG_WS2812_STRIP - -#if defined(CONFIG_WS2812_STRIP) || USE_RGB_PWM +bool sfixture_on; uint8_t sBrightness; -PWMDevice::Action_t sColorAction = PWMDevice::INVALID_ACTION; +AppTask::Fixture_Action sColorAction = AppTask::INVALID_ACTION; XyColor_t sXY; HsvColor_t sHSV; CtColor_t sCT; -#endif // CONFIG_WS2812_STRIP || USE_RGB_PWM +RgbColor_t sLedRgb; } // namespace AppTask AppTask::sAppTask; +bool AppTask::IsTurnedOn() const +{ + return sfixture_on; +} + #ifdef CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET void AppTask::PowerOnFactoryReset(void) { @@ -61,143 +56,47 @@ void AppTask::PowerOnFactoryReset(void) CHIP_ERROR AppTask::Init(void) { - CHIP_ERROR err; - - // Init lighting manager - uint8_t minLightLevel = kDefaultMinLevel; - Clusters::LevelControl::Attributes::MinLevel::Get(kExampleEndpointId, &minLightLevel); + SetExampleButtonCallbacks(LightingActionEventHandler); + InitCommonParts(); - uint8_t maxLightLevel = kDefaultMaxLevel; - Clusters::LevelControl::Attributes::MaxLevel::Get(kExampleEndpointId, &maxLightLevel); + Protocols::InteractionModel::Status status; -#ifdef CONFIG_WS2812_STRIP - err = sAppTask.mWS2812Device.Init(ws2812_dev, STRIP_NUM_PIXELS(led_strip)); - if (err != CHIP_NO_ERROR) + app::DataModel::Nullable brightness; + // Read brightness value + status = Clusters::LevelControl::Attributes::CurrentLevel::Get(kExampleEndpointId, brightness); + if (status == Protocols::InteractionModel::Status::Success && !brightness.IsNull()) { - LOG_ERR("WS2812 Device Init fail"); - return err; - } -#else - err = sAppTask.mPwmRgbBlueLed.Init(&sPwmRgbSpecBlueLed, minLightLevel, maxLightLevel, maxLightLevel); - if (err != CHIP_NO_ERROR) - { - LOG_ERR("Blue RGB PWM Device Init fail"); - return err; - } -#if USE_RGB_PWM - err = sAppTask.mPwmRgbRedLed.Init(&sPwmRgbSpecRedLed, minLightLevel, maxLightLevel, maxLightLevel); - if (err != CHIP_NO_ERROR) - { - LOG_ERR("Red RGB PWM Device Init fail"); - return err; + sBrightness = brightness.Value(); } - err = sAppTask.mPwmRgbGreenLed.Init(&sPwmRgbSpecGreenLed, minLightLevel, maxLightLevel, maxLightLevel); - if (err != CHIP_NO_ERROR) + memset(&sLedRgb, sBrightness, sizeof(RgbColor_t)); + + bool storedValue; + // Read storedValue on/off value + status = Clusters::OnOff::Attributes::OnOff::Get(1, &storedValue); + if (status == Protocols::InteractionModel::Status::Success) { - LOG_ERR("Green RGB PWM Device Init fail"); - return err; + // Set actual state to stored before reboot + SetInitiateAction(storedValue ? ON_ACTION : OFF_ACTION, static_cast(AppEvent::kEventType_Lighting), nullptr); } -#endif - sAppTask.mPwmRgbBlueLed.SetCallbacks(ActionInitiated, ActionCompleted, nullptr); -#endif // CONFIG_WS2812_STRIP - -#if APP_USE_EXAMPLE_START_BUTTON - SetExampleButtonCallbacks(LightingActionEventHandler); -#endif - InitCommonParts(); return CHIP_NO_ERROR; } void AppTask::LightingActionEventHandler(AppEvent * aEvent) { -#ifdef CONFIG_WS2812_STRIP - if (aEvent->Type == AppEvent::kEventType_Button) - { - if (sAppTask.mWS2812Device.IsTurnedOn()) - { - sAppTask.mWS2812Device.Set(SET_RGB_TURN_OFF); - } - else - { - sAppTask.mWS2812Device.Set(SET_RGB_TURN_ON); - } - - sAppTask.UpdateClusterState(); - } -#else - PWMDevice::Action_t action = PWMDevice::INVALID_ACTION; - int32_t actor = 0; + Fixture_Action action = INVALID_ACTION; + int32_t actor = 0; if (aEvent->Type == AppEvent::kEventType_Lighting) { - action = static_cast(aEvent->LightingEvent.Action); + action = static_cast(aEvent->LightingEvent.Action); actor = aEvent->LightingEvent.Actor; } else if (aEvent->Type == AppEvent::kEventType_Button) { -#if USE_RGB_PWM - if (sAppTask.mPwmRgbRedLed.IsTurnedOn() || sAppTask.mPwmRgbGreenLed.IsTurnedOn() || sAppTask.mPwmRgbBlueLed.IsTurnedOn()) - { - action = PWMDevice::OFF_ACTION; - } - else - { - action = PWMDevice::ON_ACTION; - } -#else - action = sAppTask.mPwmRgbBlueLed.IsTurnedOn() ? PWMDevice::OFF_ACTION : PWMDevice::ON_ACTION; -#endif - actor = AppEvent::kEventType_Button; - } - - if (action != PWMDevice::INVALID_ACTION && - ( -#if USE_RGB_PWM - !sAppTask.mPwmRgbRedLed.InitiateAction(action, actor, NULL) || - !sAppTask.mPwmRgbGreenLed.InitiateAction(action, actor, NULL) || -#endif - !sAppTask.mPwmRgbBlueLed.InitiateAction(action, actor, NULL))) - { - LOG_INF("Action is in progress or active"); - } -#endif // CONFIG_WS2812_STRIP -} - -void AppTask::ActionInitiated(PWMDevice::Action_t aAction, int32_t aActor) -{ - if (aAction == PWMDevice::ON_ACTION) - { - LOG_DBG("ON_ACTION initiated"); - } - else if (aAction == PWMDevice::OFF_ACTION) - { - LOG_DBG("OFF_ACTION initiated"); - } - else if (aAction == PWMDevice::LEVEL_ACTION) - { - LOG_DBG("LEVEL_ACTION initiated"); - } -} + sfixture_on = !sfixture_on; -void AppTask::ActionCompleted(PWMDevice::Action_t aAction, int32_t aActor) -{ - if (aAction == PWMDevice::ON_ACTION) - { - LOG_DBG("ON_ACTION completed"); - } - else if (aAction == PWMDevice::OFF_ACTION) - { - LOG_DBG("OFF_ACTION completed"); - } - else if (aAction == PWMDevice::LEVEL_ACTION) - { - LOG_DBG("LEVEL_ACTION completed"); - } - - if (aActor == AppEvent::kEventType_Button) - { sAppTask.UpdateClusterState(); } } @@ -205,38 +104,8 @@ void AppTask::ActionCompleted(PWMDevice::Action_t aAction, int32_t aActor) void AppTask::UpdateClusterState(void) { Protocols::InteractionModel::Status status; - bool isTurnedOn; - uint8_t setLevel; - -#if defined(CONFIG_WS2812_STRIP) || USE_RGB_PWM -#ifdef CONFIG_WS2812_STRIP - isTurnedOn = sAppTask.mWS2812Device.IsTurnedOn(); -#else - isTurnedOn = - sAppTask.mPwmRgbRedLed.IsTurnedOn() || sAppTask.mPwmRgbGreenLed.IsTurnedOn() || sAppTask.mPwmRgbBlueLed.IsTurnedOn(); -#endif // CONFIG_WS2812_STRIP - - if (sColorAction == PWMDevice::COLOR_ACTION_XY || sColorAction == PWMDevice::COLOR_ACTION_HSV || - sColorAction == PWMDevice::COLOR_ACTION_CT) - { - setLevel = sBrightness; - } - else - { -#ifdef CONFIG_WS2812_STRIP - setLevel = sAppTask.mWS2812Device.GetBlueLevel(); - if (setLevel > kDefaultMaxLevel) - { - setLevel = kDefaultMaxLevel; - } -#else - setLevel = sAppTask.mPwmRgbBlueLed.GetLevel(); -#endif // CONFIG_WS2812_STRIP - } -#else - isTurnedOn = sAppTask.mPwmRgbBlueLed.IsTurnedOn(); - setLevel = sAppTask.mPwmRgbBlueLed.GetLevel(); -#endif // CONFIG_WS2812_STRIP || USE_RGB_PWM + bool isTurnedOn = sfixture_on; + uint8_t setLevel = sBrightness; // write the new on/off value status = Clusters::OnOff::Attributes::OnOff::Set(kExampleEndpointId, isTurnedOn); @@ -252,100 +121,86 @@ void AppTask::UpdateClusterState(void) } } -void AppTask::SetInitiateAction(PWMDevice::Action_t aAction, int32_t aActor, uint8_t * value) +void AppTask::SetInitiateAction(Fixture_Action aAction, int32_t aActor, uint8_t * value) { -#if defined(CONFIG_WS2812_STRIP) || USE_RGB_PWM bool setRgbAction = false; - RgbColor_t rgb; -#endif // CONFIG_WS2812_STRIP || USE_RGB_PWM - if (aAction == PWMDevice::ON_ACTION || aAction == PWMDevice::OFF_ACTION) + if (aAction == ON_ACTION || aAction == OFF_ACTION) { -#ifdef CONFIG_WS2812_STRIP - if (aAction == PWMDevice::ON_ACTION) + if (aAction == ON_ACTION) { - sAppTask.mWS2812Device.Set(SET_RGB_TURN_ON); + sfixture_on = true; + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (((uint32_t) sLedRgb.r * 1000) / UINT8_MAX)); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (((uint32_t) sLedRgb.g * 1000) / UINT8_MAX)); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (((uint32_t) sLedRgb.b * 1000) / UINT8_MAX)); } - else if (aAction == PWMDevice::OFF_ACTION) + else { - sAppTask.mWS2812Device.Set(SET_RGB_TURN_OFF); + sfixture_on = false; + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, false); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, false); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, false); } -#else - sAppTask.mPwmRgbBlueLed.InitiateAction(aAction, aActor, value); -#if USE_RGB_PWM - sAppTask.mPwmRgbRedLed.InitiateAction(aAction, aActor, value); - sAppTask.mPwmRgbGreenLed.InitiateAction(aAction, aActor, value); -#endif -#endif // CONFIG_WS2812_STRIP } - else if (aAction == PWMDevice::LEVEL_ACTION) + else if (aAction == LEVEL_ACTION) { -#if defined(CONFIG_WS2812_STRIP) || USE_RGB_PWM // Save a new brightness for ColorControl sBrightness = *value; - if (sColorAction == PWMDevice::COLOR_ACTION_XY) + if (sColorAction == COLOR_ACTION_XY) { - rgb = XYToRgb(sBrightness, sXY.x, sXY.y); + sLedRgb = XYToRgb(sBrightness, sXY.x, sXY.y); } - else if (sColorAction == PWMDevice::COLOR_ACTION_HSV) + else if (sColorAction == COLOR_ACTION_HSV) { - sHSV.v = sBrightness; - rgb = HsvToRgb(sHSV); + sHSV.v = sBrightness; + sLedRgb = HsvToRgb(sHSV); } else { - memset(&rgb, sBrightness, sizeof(RgbColor_t)); + memset(&sLedRgb, sBrightness, sizeof(RgbColor_t)); } - ChipLogProgress(Zcl, "New brightness: %u | R: %u, G: %u, B: %u", sBrightness, rgb.r, rgb.g, rgb.b); + ChipLogProgress(Zcl, "New brightness: %u | R: %u, G: %u, B: %u", sBrightness, sLedRgb.r, sLedRgb.g, sLedRgb.b); setRgbAction = true; -#else - sAppTask.mPwmRgbBlueLed.InitiateAction(aAction, aActor, value); -#endif // CONFIG_WS2812_STRIP || USE_RGB_PWM } -#if defined(CONFIG_WS2812_STRIP) || USE_RGB_PWM - else if (aAction == PWMDevice::COLOR_ACTION_XY) + else if (aAction == COLOR_ACTION_XY) { - sXY = *reinterpret_cast(value); - rgb = XYToRgb(sBrightness, sXY.x, sXY.y); - ChipLogProgress(Zcl, "XY to RGB: X: %u, Y: %u, Level: %u | R: %u, G: %u, B: %u", sXY.x, sXY.y, sBrightness, rgb.r, rgb.g, - rgb.b); + sXY = *reinterpret_cast(value); + sLedRgb = XYToRgb(sBrightness, sXY.x, sXY.y); + ChipLogProgress(Zcl, "XY to RGB: X: %u, Y: %u, Level: %u | R: %u, G: %u, B: %u", sXY.x, sXY.y, sBrightness, sLedRgb.r, + sLedRgb.g, sLedRgb.b); setRgbAction = true; - sColorAction = PWMDevice::COLOR_ACTION_XY; + sColorAction = COLOR_ACTION_XY; } - else if (aAction == PWMDevice::COLOR_ACTION_HSV) + else if (aAction == COLOR_ACTION_HSV) { - sHSV = *reinterpret_cast(value); - sHSV.v = sBrightness; - rgb = HsvToRgb(sHSV); - ChipLogProgress(Zcl, "HSV to RGB: H: %u, S: %u, V: %u | R: %u, G: %u, B: %u", sHSV.h, sHSV.s, sHSV.v, rgb.r, rgb.g, rgb.b); + sHSV = *reinterpret_cast(value); + sHSV.v = sBrightness; + sLedRgb = HsvToRgb(sHSV); + ChipLogProgress(Zcl, "HSV to RGB: H: %u, S: %u, V: %u | R: %u, G: %u, B: %u", sHSV.h, sHSV.s, sHSV.v, sLedRgb.r, sLedRgb.g, + sLedRgb.b); setRgbAction = true; - sColorAction = PWMDevice::COLOR_ACTION_HSV; + sColorAction = COLOR_ACTION_HSV; } - else if (aAction == PWMDevice::COLOR_ACTION_CT) + else if (aAction == COLOR_ACTION_CT) { sCT = *reinterpret_cast(value); if (sCT.ctMireds) { - rgb = CTToRgb(sCT); - ChipLogProgress(Zcl, "ColorTemp to RGB: CT: %u | R: %u, G: %u, B: %u", sCT.ctMireds, rgb.r, rgb.g, rgb.b); + sLedRgb = CTToRgb(sCT); + ChipLogProgress(Zcl, "ColorTemp to RGB: CT: %u | R: %u, G: %u, B: %u", sCT.ctMireds, sLedRgb.r, sLedRgb.g, sLedRgb.b); setRgbAction = true; - sColorAction = PWMDevice::COLOR_ACTION_CT; + sColorAction = COLOR_ACTION_CT; } } if (setRgbAction) { -#ifdef CONFIG_WS2812_STRIP - sAppTask.mWS2812Device.SetLevel(&rgb); -#else - sAppTask.mPwmRgbRedLed.InitiateAction(aAction, aActor, &rgb.r); - sAppTask.mPwmRgbGreenLed.InitiateAction(aAction, aActor, &rgb.g); - sAppTask.mPwmRgbBlueLed.InitiateAction(aAction, aActor, &rgb.b); -#endif // CONFIG_WS2812_STRIP + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (((uint32_t) sLedRgb.r * 1000) / UINT8_MAX)); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (((uint32_t) sLedRgb.g * 1000) / UINT8_MAX)); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (((uint32_t) sLedRgb.b * 1000) / UINT8_MAX)); } -#endif // CONFIG_WS2812_STRIP || USE_RGB_PWM } #ifdef CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET @@ -359,15 +214,9 @@ void AppTask::PowerOnFactoryResetEventHandler(AppEvent * aEvent) { LOG_INF("Lighting App Power On Factory Reset Handler"); sPowerOnFactoryResetTimerCnt = 1; -#ifdef CONFIG_WS2812_STRIP - sAppTask.mWS2812Device.Set(sPowerOnFactoryResetTimerCnt % 2); -#else - sAppTask.mPwmRgbBlueLed.Set(sPowerOnFactoryResetTimerCnt % 2); -#if USE_RGB_PWM - sAppTask.mPwmRgbRedLed.Set(sPowerOnFactoryResetTimerCnt % 2); - sAppTask.mPwmRgbGreenLed.Set(sPowerOnFactoryResetTimerCnt % 2); -#endif -#endif // CONFIG_WS2812_STRIP + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (bool) (sPowerOnFactoryResetTimerCnt % 2)); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (bool) (sPowerOnFactoryResetTimerCnt % 2)); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (bool) (sPowerOnFactoryResetTimerCnt % 2)); k_timer_init(&sPowerOnFactoryResetTimer, PowerOnFactoryResetTimerEvent, nullptr); k_timer_start(&sPowerOnFactoryResetTimer, K_MSEC(kPowerOnFactoryResetIndicationTimeMs), K_MSEC(kPowerOnFactoryResetIndicationTimeMs)); @@ -377,15 +226,9 @@ void AppTask::PowerOnFactoryResetTimerEvent(struct k_timer * timer) { sPowerOnFactoryResetTimerCnt++; LOG_INF("Lighting App Power On Factory Reset Handler %u", sPowerOnFactoryResetTimerCnt); -#ifdef CONFIG_WS2812_STRIP - sAppTask.mWS2812Device.Set(sPowerOnFactoryResetTimerCnt % 2); -#else - sAppTask.mPwmRgbBlueLed.Set(sPowerOnFactoryResetTimerCnt % 2); -#if USE_RGB_PWM - sAppTask.mPwmRgbRedLed.Set(sPowerOnFactoryResetTimerCnt % 2); - sAppTask.mPwmRgbGreenLed.Set(sPowerOnFactoryResetTimerCnt % 2); -#endif -#endif // CONFIG_WS2812_STRIP + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (bool) (sPowerOnFactoryResetTimerCnt % 2)); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (bool) (sPowerOnFactoryResetTimerCnt % 2)); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (bool) (sPowerOnFactoryResetTimerCnt % 2)); if (sPowerOnFactoryResetTimerCnt > kPowerOnFactoryResetIndicationMax) { k_timer_stop(timer); diff --git a/examples/lighting-app/telink/src/ZclCallbacks.cpp b/examples/lighting-app/telink/src/ZclCallbacks.cpp index 7aebb1ba69bae1..75b43f7c39eee1 100644 --- a/examples/lighting-app/telink/src/ZclCallbacks.cpp +++ b/examples/lighting-app/telink/src/ZclCallbacks.cpp @@ -18,7 +18,6 @@ #include "AppTask.h" #include "ColorFormat.h" -#include "PWMDevice.h" #include #include @@ -30,7 +29,6 @@ LOG_MODULE_DECLARE(app, CONFIG_CHIP_APP_LOG_LEVEL); using namespace chip; using namespace chip::app::Clusters; -using namespace chip::app::Clusters::OnOff; void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & attributePath, uint8_t type, uint16_t size, uint8_t * value) @@ -43,15 +41,15 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & if (clusterId == OnOff::Id && attributeId == OnOff::Attributes::OnOff::Id) { ChipLogDetail(Zcl, "Cluster OnOff: attribute OnOff set to %u", *value); - GetAppTask().SetInitiateAction(*value ? PWMDevice::ON_ACTION : PWMDevice::OFF_ACTION, + GetAppTask().SetInitiateAction(*value ? AppTask::ON_ACTION : AppTask::OFF_ACTION, static_cast(AppEvent::kEventType_Lighting), value); } else if (clusterId == LevelControl::Id && attributeId == LevelControl::Attributes::CurrentLevel::Id) { - if (GetAppTask().GetLightingDevice().IsTurnedOn()) + if (GetAppTask().IsTurnedOn()) { ChipLogDetail(Zcl, "Cluster LevelControl: attribute CurrentLevel set to %u", *value); - GetAppTask().SetInitiateAction(PWMDevice::LEVEL_ACTION, static_cast(AppEvent::kEventType_Lighting), value); + GetAppTask().SetInitiateAction(AppTask::LEVEL_ACTION, static_cast(AppEvent::kEventType_Lighting), value); } else { @@ -81,7 +79,7 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & } ChipLogDetail(Zcl, "New XY color: %u|%u", xy.x, xy.y); - GetAppTask().SetInitiateAction(PWMDevice::COLOR_ACTION_XY, static_cast(AppEvent::kEventType_Lighting), + GetAppTask().SetInitiateAction(AppTask::COLOR_ACTION_XY, static_cast(AppEvent::kEventType_Lighting), (uint8_t *) &xy); } /* HSV color space */ @@ -103,14 +101,14 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & hsv.s = *value; } ChipLogDetail(Zcl, "New HSV color: hue = %u| saturation = %u", hsv.h, hsv.s); - GetAppTask().SetInitiateAction(PWMDevice::COLOR_ACTION_HSV, static_cast(AppEvent::kEventType_Lighting), + GetAppTask().SetInitiateAction(AppTask::COLOR_ACTION_HSV, static_cast(AppEvent::kEventType_Lighting), (uint8_t *) &hsv); } /* Temperature Mireds color space */ else if (attributeId == ColorControl::Attributes::ColorTemperatureMireds::Id) { ChipLogDetail(Zcl, "New Temperature Mireds color = %u", *(uint16_t *) value); - GetAppTask().SetInitiateAction(PWMDevice::COLOR_ACTION_CT, static_cast(AppEvent::kEventType_Lighting), value); + GetAppTask().SetInitiateAction(AppTask::COLOR_ACTION_CT, static_cast(AppEvent::kEventType_Lighting), value); } else { @@ -118,28 +116,3 @@ void MatterPostAttributeChangeCallback(const chip::app::ConcreteAttributePath & } } } - -/** @brief OnOff Cluster Init - * - * This function is called when a specific cluster is initialized. It gives the - * application an opportunity to take care of cluster initialization procedures. - * It is called exactly once for each endpoint where cluster is present. - * - * @param endpoint Ver.: always - * - */ -void emberAfOnOffClusterInitCallback(EndpointId endpoint) -{ - Protocols::InteractionModel::Status status; - bool storedValue; - - // Read storedValue on/off value - status = Attributes::OnOff::Get(1, &storedValue); - if (status == Protocols::InteractionModel::Status::Success) - { - // Set actual state to stored before reboot - GetAppTask().GetLightingDevice().Set(storedValue); - } - - GetAppTask().UpdateClusterState(); -} diff --git a/examples/lock-app/telink/CMakeLists.txt b/examples/lock-app/telink/CMakeLists.txt index 58a9e4fb5bab8f..003dcc649db44d 100755 --- a/examples/lock-app/telink/CMakeLists.txt +++ b/examples/lock-app/telink/CMakeLists.txt @@ -59,7 +59,7 @@ project(chip-telink-lock-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE include @@ -67,7 +67,8 @@ target_include_directories(app PRIVATE ${GEN_DIR}/lock-app ${TELINK_COMMON}/common/include ${TELINK_COMMON}/util/include - ${TELINK_COMMON}/app/include) + ${TELINK_COMMON}/app/include + ${TELINK_COMMON}/zephyr_ext) target_sources(app PRIVATE src/AppTask.cpp @@ -76,10 +77,15 @@ target_sources(app PRIVATE src/LockSettingsStorage.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp - ${TELINK_COMMON}/util/src/LEDWidget.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp ${TELINK_COMMON}/util/src/ThreadUtil.cpp - ${TELINK_COMMON}/util/src/PWMDevice.cpp) + ${TELINK_COMMON}/util/src/PWMManager.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c) chip_configure_data_model(app INCLUDE_SERVER diff --git a/examples/lock-app/telink/include/AppConfig.h b/examples/lock-app/telink/include/AppConfig.h index cb4b0c2b488d86..756ff5b3bfa15f 100644 --- a/examples/lock-app/telink/include/AppConfig.h +++ b/examples/lock-app/telink/include/AppConfig.h @@ -37,11 +37,5 @@ #define APP_DEFAULT_YEARDAY_SCHEDULE_PER_USER_COUNT 5 #define APP_DEFAULT_HOLYDAY_SCHEDULE_PER_USER_COUNT 5 -#define APP_USE_EXAMPLE_START_BUTTON 1 -#define APP_USE_BLE_START_BUTTON 0 -#define APP_USE_THREAD_START_BUTTON 0 #define APP_SET_DEVICE_INFO_PROVIDER 1 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 0 -#if defined(CONFIG_BOARD_TLSR9518ADK80D) || defined(CONFIG_BOARD_TLSR9528A) -#define APP_USE_IDENTIFY_PWM 1 -#endif diff --git a/examples/lock-app/telink/include/AppTask.h b/examples/lock-app/telink/include/AppTask.h index fb0f4113d4af9f..cec70dd8bb6c8f 100644 --- a/examples/lock-app/telink/include/AppTask.h +++ b/examples/lock-app/telink/include/AppTask.h @@ -37,6 +37,8 @@ class AppTask : public AppTaskCommon friend class AppTaskCommon; CHIP_ERROR Init(void); + void LinkButtons(ButtonManager & buttonManager); + void LinkLeds(LedManager & ledManager); static void LockActionEventHandler(AppEvent * event); static void LockStateChanged(LockManager::State_t state); diff --git a/examples/lock-app/telink/src/AppTask.cpp b/examples/lock-app/telink/src/AppTask.cpp index 19748544f8d15d..46e34db66710e5 100644 --- a/examples/lock-app/telink/src/AppTask.cpp +++ b/examples/lock-app/telink/src/AppTask.cpp @@ -18,6 +18,7 @@ #include "AppTask.h" #include "ButtonManager.h" +#include "LEDManager.h" #include #include #include @@ -33,33 +34,14 @@ using namespace ::chip::DeviceLayer; using namespace ::chip::DeviceLayer::Internal; using namespace TelinkDoorLock::LockInitParams; -namespace { -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED -LEDWidget sLockLED; -#endif -} // namespace - AppTask AppTask::sAppTask; -static const struct gpio_dt_spec sLockJammedInputDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_5), gpios); -static const struct gpio_dt_spec sLockStatusInputDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_6), gpios); -Button sLockJammedAction; -Button sLockStatusChangedAction; CHIP_ERROR AppTask::Init(void) { -#if APP_USE_EXAMPLE_START_BUTTON SetExampleButtonCallbacks(LockActionEventHandler); -#endif - sLockJammedAction.Configure(&sLockJammedInputDt, LockJammedEventHandler); - sLockStatusChangedAction.Configure(&sLockStatusInputDt, LockStateEventHandler); - ButtonManagerInst().AddButton(sLockJammedAction); - ButtonManagerInst().AddButton(sLockStatusChangedAction); InitCommonParts(); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sLockLED.Init(GPIO_DT_SPEC_GET(DT_ALIAS(led2), gpios)); - sLockLED.Set(LockMgr().IsLocked()); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, LockMgr().IsLocked()); chip::app::DataModel::Nullable state; chip::EndpointId endpointId{ kExampleEndpointId }; @@ -167,45 +149,31 @@ void AppTask::LockStateChanged(LockManager::State_t state) { case LockManager::State_t::kState_LockInitiated: LOG_INF("Callback: Lock action initiated"); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sLockLED.Blink(50, 50); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, 50, 50); break; case LockManager::State_t::kState_LockCompleted: LOG_INF("Callback: Lock action completed"); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sLockLED.Set(true); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, true); break; case LockManager::State_t::kState_UnlockInitiated: LOG_INF("Callback: Unlock action initiated"); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sLockLED.Blink(50, 50); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, 50, 50); break; case LockManager::State_t::kState_UnlockCompleted: LOG_INF("Callback: Unlock action completed"); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sLockLED.Set(false); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, false); break; case LockManager::State_t::kState_UnlatchInitiated: LOG_INF("Callback: Unbolt action initiated"); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sLockLED.Blink(75, 25); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, 75, 25); break; case LockManager::State_t::kState_UnlatchCompleted: LOG_INF("Callback: Unbolt action completed"); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sLockLED.Blink(25, 75); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, 25, 75); break; case LockManager::State_t::kState_NotFulyLocked: LOG_INF("Callback: Lock not fully locked. Unexpected state"); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - sLockLED.Blink(10, 90); -#endif + LedManager::getInstance().setLed(LedManager::EAppLed_App0, 10, 90); break; } } @@ -257,3 +225,21 @@ void AppTask::LockStateActionHandler(AppEvent * aEvent) /* Generating Door Lock Status event */ DoorLockServer::Instance().SetDoorState(kExampleEndpointId, mDoorState); } + +void AppTask::LinkButtons(ButtonManager & buttonManager) +{ + buttonManager.addCallback(FactoryResetButtonEventHandler, 0, true); + buttonManager.addCallback(ExampleActionButtonEventHandler, 1, true); + buttonManager.addCallback(LockJammedEventHandler, 2, true); + buttonManager.addCallback(LockStateEventHandler, 3, true); +} + +void AppTask::LinkLeds(LedManager & ledManager) +{ +#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED + ledManager.linkLed(LedManager::EAppLed_Status, 0); + ledManager.linkLed(LedManager::EAppLed_App0, 1); +#else + ledManager.linkLed(LedManager::EAppLed_App0, 0); +#endif // CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED +} diff --git a/examples/ota-requestor-app/ameba/README.md b/examples/ota-requestor-app/ameba/README.md index 7c10b157e4f8db..260c41fc4c5ed7 100644 --- a/examples/ota-requestor-app/ameba/README.md +++ b/examples/ota-requestor-app/ameba/README.md @@ -6,11 +6,11 @@ A prototype application that demonstrates OTA Requestor capabilities. - Pull docker image: - $ docker pull ghcr.io/project-chip/chip-build-ameba:42 + $ docker pull ghcr.io/project-chip/chip-build-ameba:46 - Run docker container: - $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:42 + $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:46 - Setup build environment: diff --git a/examples/ota-requestor-app/telink/CMakeLists.txt b/examples/ota-requestor-app/telink/CMakeLists.txt index 31be460d8a346c..b1010d7c3997b3 100644 --- a/examples/ota-requestor-app/telink/CMakeLists.txt +++ b/examples/ota-requestor-app/telink/CMakeLists.txt @@ -59,7 +59,7 @@ project(chip-telink-ota-requestor-example) include(${CHIP_ROOT}/config/telink/app/enable-gnu-std.cmake) include(${CHIP_ROOT}/src/app/chip_data_model.cmake) -target_compile_options(app PRIVATE -fpermissive) +target_compile_options(app PRIVATE $<$:-fpermissive>) target_include_directories(app PRIVATE include @@ -67,17 +67,23 @@ target_include_directories(app PRIVATE ${GEN_DIR}/ota-requestor-app ${TELINK_COMMON}/common/include ${TELINK_COMMON}/util/include - ${TELINK_COMMON}/app/include) + ${TELINK_COMMON}/app/include + ${TELINK_COMMON}/zephyr_ext) target_sources(app PRIVATE src/AppTask.cpp src/ZclCallbacks.cpp ${TELINK_COMMON}/common/src/mainCommon.cpp ${TELINK_COMMON}/common/src/AppTaskCommon.cpp - ${TELINK_COMMON}/util/src/LEDWidget.cpp + ${TELINK_COMMON}/util/src/LEDManager.cpp ${TELINK_COMMON}/util/src/ButtonManager.cpp ${TELINK_COMMON}/util/src/ThreadUtil.cpp - ${TELINK_COMMON}/util/src/PWMDevice.cpp) + ${TELINK_COMMON}/util/src/PWMManager.cpp + ${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c + ${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c + ${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c) chip_configure_data_model(app INCLUDE_SERVER diff --git a/examples/ota-requestor-app/telink/include/AppConfig.h b/examples/ota-requestor-app/telink/include/AppConfig.h index 05e62e8b612725..70d3394a96d697 100644 --- a/examples/ota-requestor-app/telink/include/AppConfig.h +++ b/examples/ota-requestor-app/telink/include/AppConfig.h @@ -20,11 +20,5 @@ // ---- OTA Requestor Example App Config ---- -#define APP_USE_EXAMPLE_START_BUTTON 0 -#define APP_USE_BLE_START_BUTTON 0 -#define APP_USE_THREAD_START_BUTTON 1 #define APP_SET_DEVICE_INFO_PROVIDER 1 #define APP_SET_NETWORK_COMM_ENDPOINT_SEC 1 -#if defined(CONFIG_BOARD_TLSR9518ADK80D) || defined(CONFIG_BOARD_TLSR9528A) -#define APP_USE_IDENTIFY_PWM 1 -#endif diff --git a/examples/pigweed-app/ameba/README.md b/examples/pigweed-app/ameba/README.md index c9bd9f82ce7a35..ebd350d5bda1d6 100644 --- a/examples/pigweed-app/ameba/README.md +++ b/examples/pigweed-app/ameba/README.md @@ -31,11 +31,11 @@ following features are available: - Pull docker image: - $ docker pull ghcr.io/project-chip/chip-build-ameba:42 + $ docker pull ghcr.io/project-chip/chip-build-ameba:46 - Run docker container: - $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:42 + $ docker run -it -v ${CHIP_DIR}:/root/chip ghcr.io/project-chip/chip-build-ameba:46 - Setup build environment: diff --git a/examples/platform/telink/common/include/AppTaskCommon.h b/examples/platform/telink/common/include/AppTaskCommon.h index 7bacaeb4377ee4..09b776d6e16a17 100644 --- a/examples/platform/telink/common/include/AppTaskCommon.h +++ b/examples/platform/telink/common/include/AppTaskCommon.h @@ -21,18 +21,6 @@ #include "AppConfig.h" #include "AppEventCommon.h" -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED -#include "LEDWidget.h" -#endif - -#ifdef APP_USE_IDENTIFY_PWM -#include "PWMDevice.h" -#endif - -#ifdef CONFIG_WS2812_STRIP -#include "WS2812Device.h" -#endif - #include #include #include @@ -64,6 +52,10 @@ inline constexpr uint8_t kButtonPushEvent = 1; inline constexpr uint8_t kButtonReleaseEvent = 0; } // namespace +class LedManager; +class PwmManager; +class ButtonManager; + class AppTaskCommon { public: @@ -80,12 +72,8 @@ class AppTaskCommon { kButtonId_ExampleAction = 1, kButtonId_FactoryReset, -#if APP_USE_THREAD_START_BUTTON kButtonId_StartThread, -#endif -#if APP_USE_BLE_START_BUTTON kButtonId_StartBleAdv -#endif } ButtonId; #endif @@ -95,44 +83,34 @@ class AppTaskCommon void DispatchEvent(AppEvent * event); void GetEvent(AppEvent * aEvent); + void InitLeds(); + virtual void LinkLeds(LedManager & ledManager); + void InitPwms(); + virtual void LinkPwms(PwmManager & pwmManager); void InitButtons(void); + virtual void LinkButtons(ButtonManager & buttonManager); static void FactoryResetTimerTimeoutCallback(k_timer * timer); static void FactoryResetTimerEventHandler(AppEvent * aEvent); static void FactoryResetButtonEventHandler(void); static void FactoryResetHandler(AppEvent * aEvent); -#if APP_USE_BLE_START_BUTTON static void StartBleAdvButtonEventHandler(void); static void StartBleAdvHandler(AppEvent * aEvent); -#endif -#if APP_USE_THREAD_START_BUTTON || !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE static void StartThreadButtonEventHandler(void); static void StartThreadHandler(AppEvent * aEvent); #endif -#if APP_USE_EXAMPLE_START_BUTTON static void ExampleActionButtonEventHandler(void); void SetExampleButtonCallbacks(EventHandler aAction_CB); EventHandler ExampleActionEventHandler; -#endif static void ChipEventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg); -#ifdef APP_USE_IDENTIFY_PWM - PWMDevice mPwmIdentifyLed; - - static void ActionIdentifyStateUpdateHandler(k_timer * timer); - static void UpdateIdentifyStateEventHandler(AppEvent * aEvent); -#endif - -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - static void UpdateLedStateEventHandler(AppEvent * aEvent); - static void LEDStateUpdateHandler(LEDWidget * ledWidget); static void UpdateStatusLED(void); -#endif #if CONFIG_CHIP_FACTORY_DATA chip::DeviceLayer::FactoryDataProvider mFactoryDataProvider; diff --git a/examples/platform/telink/common/include/SensorManagerCommon.h b/examples/platform/telink/common/include/SensorManagerCommon.h index 7181f8212a944c..25e800b078e021 100644 --- a/examples/platform/telink/common/include/SensorManagerCommon.h +++ b/examples/platform/telink/common/include/SensorManagerCommon.h @@ -46,7 +46,6 @@ class SensorManager static void SensorBanForNextMeasurTimerTimeoutCallback(k_timer * timer); #ifdef USE_COLOR_TEMPERATURE_LIGHT - WS2812Device mWS2812Device; void SetColorTemperatureLight(int8_t temp); #endif // USE_COLOR_TEMPERATURE_LIGHT diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index 3d93aa3ed5d07f..759e70bf625292 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -21,6 +21,8 @@ #include "BLEManagerImpl.h" #include "ButtonManager.h" +#include "LEDManager.h" +#include "PWMManager.h" #include "ThreadUtil.h" @@ -51,25 +53,6 @@ constexpr int kFactoryResetCalcTimeout = 3000; constexpr int kFactoryResetTriggerCntr = 3; constexpr int kAppEventQueueSize = 10; -#if CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE -const struct gpio_dt_spec sFactoryResetButtonDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_1), gpios); -#if APP_USE_BLE_START_BUTTON -const struct gpio_dt_spec sBleStartButtonDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_2), gpios); -#endif -#if APP_USE_THREAD_START_BUTTON -const struct gpio_dt_spec sThreadStartButtonDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_3), gpios); -#endif -#if APP_USE_EXAMPLE_START_BUTTON -const struct gpio_dt_spec sExampleActionButtonDt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_4), gpios); -#endif -#else -const struct gpio_dt_spec sButtonCol1Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_col1), gpios); -const struct gpio_dt_spec sButtonCol2Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_col2), gpios); -const struct gpio_dt_spec sButtonRow1Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_row1), gpios); -const struct gpio_dt_spec sButtonRow2Dt = GPIO_DT_SPEC_GET(DT_NODELABEL(key_matrix_row2), gpios); -#endif - -#ifdef APP_USE_IDENTIFY_PWM constexpr uint32_t kIdentifyBlinkRateMs = 200; constexpr uint32_t kIdentifyOkayOnRateMs = 50; constexpr uint32_t kIdentifyOkayOffRateMs = 950; @@ -78,30 +61,12 @@ constexpr uint32_t kIdentifyFinishOffRateMs = 50; constexpr uint32_t kIdentifyChannelChangeRateMs = 1000; constexpr uint32_t kIdentifyBreatheRateMs = 1000; -const struct pwm_dt_spec sPwmIdentifySpecGreenLed = PWM_DT_SPEC_GET(DT_ALIAS(pwm_led3)); -#endif - #if APP_SET_NETWORK_COMM_ENDPOINT_SEC constexpr EndpointId kNetworkCommissioningEndpointSecondary = 0xFFFE; #endif K_MSGQ_DEFINE(sAppEventQueue, sizeof(AppEvent), kAppEventQueueSize, alignof(AppEvent)); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED -LEDWidget sStatusLED; -#endif - -Button sFactoryResetButton; -#if APP_USE_BLE_START_BUTTON -Button sBleAdvStartButton; -#endif -#if APP_USE_EXAMPLE_START_BUTTON -Button sExampleActionButton; -#endif -#if APP_USE_THREAD_START_BUTTON -Button sThreadStartButton; -#endif - k_timer sFactoryResetTimer; uint8_t sFactoryResetCntr = 0; @@ -115,7 +80,8 @@ bool sHaveBLEConnections = false; chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; #endif -#ifdef APP_USE_IDENTIFY_PWM +#ifndef IDENTIFY_CLUSTER_DISABLED + void OnIdentifyTriggerEffect(Identify * identify) { AppTaskCommon::IdentifyEffectHandler(identify->mCurrentEffectIdentifier); @@ -128,6 +94,7 @@ Identify sIdentify = { Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator, OnIdentifyTriggerEffect, }; + #endif #if CONFIG_CHIP_FACTORY_DATA @@ -271,13 +238,10 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) CHIP_ERROR err; LOG_INF("SW Version: %u, %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION, CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); - // Initialize status LED -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED - LEDWidget::SetStateUpdateCallback(LEDStateUpdateHandler); - sStatusLED.Init(GPIO_DT_SPEC_GET_OR(DT_ALIAS(system_state_led), gpios, {})); - + InitLeds(); UpdateStatusLED(); -#endif + + InitPwms(); InitButtons(); @@ -285,18 +249,6 @@ CHIP_ERROR AppTaskCommon::InitCommonParts(void) k_timer_init(&sFactoryResetTimer, &AppTask::FactoryResetTimerTimeoutCallback, nullptr); k_timer_user_data_set(&sFactoryResetTimer, this); -#ifdef APP_USE_IDENTIFY_PWM - // Initialize PWM Identify led - err = GetAppTask().mPwmIdentifyLed.Init(&sPwmIdentifySpecGreenLed, kDefaultMinLevel, kDefaultMaxLevel, kDefaultMaxLevel); - if (err != CHIP_NO_ERROR) - { - LOG_ERR("Green IDENTIFY PWM Device Init fail"); - return err; - } - - GetAppTask().mPwmIdentifyLed.SetCallbacks(nullptr, nullptr, ActionIdentifyStateUpdateHandler); -#endif - // Initialize CHIP server #if CONFIG_CHIP_FACTORY_DATA ReturnErrorOnFailure(mFactoryDataProvider.Init()); @@ -370,91 +322,88 @@ void AppTaskCommon::ButtonEventHandler(ButtonId_t btnId, bool btnPressed) switch (btnId) { -#if APP_USE_EXAMPLE_START_BUTTON case kButtonId_ExampleAction: ExampleActionButtonEventHandler(); break; -#endif case kButtonId_FactoryReset: FactoryResetButtonEventHandler(); break; -#if APP_USE_THREAD_START_BUTTON +#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE case kButtonId_StartThread: StartThreadButtonEventHandler(); break; #endif -#if APP_USE_BLE_START_BUTTON case kButtonId_StartBleAdv: StartBleAdvButtonEventHandler(); break; -#endif } } #endif -void AppTaskCommon::InitButtons(void) +void AppTaskCommon::InitLeds() { -#if CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE - sFactoryResetButton.Configure(&sFactoryResetButtonDt, FactoryResetButtonEventHandler); -#if APP_USE_BLE_START_BUTTON - sBleAdvStartButton.Configure(&sBleStartButtonDt, StartBleAdvButtonEventHandler); -#endif -#if APP_USE_EXAMPLE_START_BUTTON - if (ExampleActionEventHandler) - { - sExampleActionButton.Configure(&sExampleActionButtonDt, ExampleActionButtonEventHandler); - } -#endif -#if APP_USE_THREAD_START_BUTTON - sThreadStartButton.Configure(&sThreadStartButtonDt, StartThreadButtonEventHandler); -#endif -#else - sFactoryResetButton.Configure(&sButtonRow1Dt, &sButtonCol1Dt, FactoryResetButtonEventHandler); -#if APP_USE_BLE_START_BUTTON - sBleAdvStartButton.Configure(&sButtonRow2Dt, &sButtonCol2Dt, StartBleAdvButtonEventHandler); -#endif -#if APP_USE_EXAMPLE_START_BUTTON - if (ExampleActionEventHandler) - { - sExampleActionButton.Configure(&sButtonRow1Dt, &sButtonCol2Dt, ExampleActionButtonEventHandler); - } -#endif -#if APP_USE_THREAD_START_BUTTON - sThreadStartButton.Configure(&sButtonRow2Dt, &sButtonCol1Dt, StartThreadButtonEventHandler); -#endif -#endif + LedManager & ledManager = LedManager::getInstance(); - ButtonManagerInst().AddButton(sFactoryResetButton); -#if APP_USE_BLE_START_BUTTON - ButtonManagerInst().AddButton(sBleAdvStartButton); -#endif -#if APP_USE_THREAD_START_BUTTON - ButtonManagerInst().AddButton(sThreadStartButton); -#endif -#if APP_USE_EXAMPLE_START_BUTTON - if (ExampleActionEventHandler) - { - ButtonManagerInst().AddButton(sExampleActionButton); - } -#endif + LinkLeds(ledManager); + + ledManager.linkBackend(LedPool::getInstance()); } +void AppTaskCommon::LinkLeds(LedManager & ledManager) +{ #if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED -void AppTaskCommon::UpdateLedStateEventHandler(AppEvent * aEvent) + ledManager.linkLed(LedManager::EAppLed_Status, 0); +#endif // CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED +} + +void AppTaskCommon::InitPwms() { - if (aEvent->Type == AppEvent::kEventType_UpdateLedState) - { - aEvent->UpdateLedStateEvent.LedWidget->UpdateState(); - } + PwmManager & pwmManager = PwmManager::getInstance(); + + LinkPwms(pwmManager); + +#if CONFIG_WS2812_STRIP + pwmManager.linkBackend(Ws2812Strip::getInstance()); +#else + pwmManager.linkBackend(PwmPool::getInstance()); +#endif // CONFIG_WS2812_STRIP } -void AppTaskCommon::LEDStateUpdateHandler(LEDWidget * ledWidget) +void AppTaskCommon::LinkPwms(PwmManager & pwmManager) { - AppEvent event; - event.Type = AppEvent::kEventType_UpdateLedState; - event.Handler = UpdateLedStateEventHandler; - event.UpdateLedStateEvent.LedWidget = ledWidget; - GetAppTask().PostEvent(&event); +#if CONFIG_WS2812_STRIP + pwmManager.linkPwm(PwmManager::EAppPwm_Red, 0); + pwmManager.linkPwm(PwmManager::EAppPwm_Green, 1); + pwmManager.linkPwm(PwmManager::EAppPwm_Blue, 2); +#else + pwmManager.linkPwm(PwmManager::EAppPwm_Indication, 0); + pwmManager.linkPwm(PwmManager::EAppPwm_Red, 1); + pwmManager.linkPwm(PwmManager::EAppPwm_Green, 2); + pwmManager.linkPwm(PwmManager::EAppPwm_Blue, 3); +#endif // CONFIG_WS2812_STRIP +} + +void AppTaskCommon::InitButtons(void) +{ + ButtonManager & buttonManager = ButtonManager::getInstance(); + + LinkButtons(buttonManager); + +#if CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE + buttonManager.linkBackend(ButtonPool::getInstance()); +#else + buttonManager.linkBackend(ButtonMatrix::getInstance()); +#endif // CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE +} + +void AppTaskCommon::LinkButtons(ButtonManager & buttonManager) +{ + buttonManager.addCallback(FactoryResetButtonEventHandler, 0, true); + buttonManager.addCallback(ExampleActionButtonEventHandler, 1, true); + buttonManager.addCallback(StartBleAdvButtonEventHandler, 2, true); +#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE + buttonManager.addCallback(StartThreadButtonEventHandler, 3, true); +#endif } void AppTaskCommon::UpdateStatusLED() @@ -463,86 +412,54 @@ void AppTaskCommon::UpdateStatusLED() { if (sIsThreadAttached) { - sStatusLED.Blink(950, 50); + LedManager::getInstance().setLed(LedManager::EAppLed_Status, 950, 50); } else { - sStatusLED.Blink(100, 100); + LedManager::getInstance().setLed(LedManager::EAppLed_Status, 100, 100); } } else { - sStatusLED.Blink(50, 950); + LedManager::getInstance().setLed(LedManager::EAppLed_Status, 50, 950); } } -#endif - -#ifdef APP_USE_IDENTIFY_PWM -void AppTaskCommon::ActionIdentifyStateUpdateHandler(k_timer * timer) -{ - AppEvent event; - event.Type = AppEvent::kEventType_UpdateLedState; - event.Handler = UpdateIdentifyStateEventHandler; - GetAppTask().PostEvent(&event); -} - -void AppTaskCommon::UpdateIdentifyStateEventHandler(AppEvent * aEvent) -{ - GetAppTask().mPwmIdentifyLed.UpdateAction(); -} void AppTaskCommon::IdentifyEffectHandler(Clusters::Identify::EffectIdentifierEnum aEffect) { - AppEvent event; - event.Type = AppEvent::kEventType_IdentifyStart; - switch (aEffect) { case Clusters::Identify::EffectIdentifierEnum::kBlink: ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kBlink"); - event.Handler = [](AppEvent *) { - GetAppTask().mPwmIdentifyLed.InitiateBlinkAction(kIdentifyBlinkRateMs, kIdentifyBlinkRateMs); - }; + PwmManager::getInstance().setPwmBlink(PwmManager::EAppPwm_Indication, kIdentifyBlinkRateMs, kIdentifyBlinkRateMs); break; case Clusters::Identify::EffectIdentifierEnum::kBreathe: ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kBreathe"); - event.Handler = [](AppEvent *) { - GetAppTask().mPwmIdentifyLed.InitiateBreatheAction(PWMDevice::kBreatheType_Both, kIdentifyBreatheRateMs); - }; + PwmManager::getInstance().setPwmBreath(PwmManager::EAppPwm_Indication, kIdentifyBreatheRateMs); break; case Clusters::Identify::EffectIdentifierEnum::kOkay: ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kOkay"); - event.Handler = [](AppEvent *) { - GetAppTask().mPwmIdentifyLed.InitiateBlinkAction(kIdentifyOkayOnRateMs, kIdentifyOkayOffRateMs); - }; + PwmManager::getInstance().setPwmBlink(PwmManager::EAppPwm_Indication, kIdentifyOkayOnRateMs, kIdentifyOkayOffRateMs); break; case Clusters::Identify::EffectIdentifierEnum::kChannelChange: ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kChannelChange"); - event.Handler = [](AppEvent *) { - GetAppTask().mPwmIdentifyLed.InitiateBlinkAction(kIdentifyChannelChangeRateMs, kIdentifyChannelChangeRateMs); - }; + PwmManager::getInstance().setPwmBlink(PwmManager::EAppPwm_Indication, kIdentifyChannelChangeRateMs, + kIdentifyChannelChangeRateMs); break; case Clusters::Identify::EffectIdentifierEnum::kFinishEffect: ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kFinishEffect"); - event.Handler = [](AppEvent *) { - GetAppTask().mPwmIdentifyLed.InitiateBlinkAction(kIdentifyFinishOnRateMs, kIdentifyFinishOffRateMs); - }; + PwmManager::getInstance().setPwmBlink(PwmManager::EAppPwm_Indication, kIdentifyFinishOnRateMs, kIdentifyFinishOffRateMs); break; case Clusters::Identify::EffectIdentifierEnum::kStopEffect: ChipLogProgress(Zcl, "Clusters::Identify::EffectIdentifierEnum::kStopEffect"); - event.Handler = [](AppEvent *) { GetAppTask().mPwmIdentifyLed.StopAction(); }; - event.Type = AppEvent::kEventType_IdentifyStop; + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Indication, false); break; default: ChipLogProgress(Zcl, "No identifier effect"); return; } - - GetAppTask().PostEvent(&event); } -#endif -#if APP_USE_BLE_START_BUTTON void AppTaskCommon::StartBleAdvButtonEventHandler(void) { AppEvent event; @@ -575,7 +492,6 @@ void AppTaskCommon::StartBleAdvHandler(AppEvent * aEvent) LOG_ERR("OpenBasicCommissioningWindow fail"); } } -#endif void AppTaskCommon::FactoryResetButtonEventHandler(void) { @@ -630,7 +546,7 @@ void AppTaskCommon::FactoryResetTimerEventHandler(AppEvent * aEvent) LOG_INF("Factory Reset Trigger Counter is cleared"); } -#if APP_USE_THREAD_START_BUTTON || !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE +#if !CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE void AppTaskCommon::StartThreadButtonEventHandler(void) { AppEvent event; @@ -663,7 +579,6 @@ void AppTaskCommon::StartThreadHandler(AppEvent * aEvent) } #endif -#if APP_USE_EXAMPLE_START_BUTTON void AppTaskCommon::ExampleActionButtonEventHandler(void) { AppEvent event; @@ -683,7 +598,6 @@ void AppTaskCommon::SetExampleButtonCallbacks(EventHandler aAction_CB) { ExampleActionEventHandler = aAction_CB; } -#endif void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* arg */) { @@ -691,9 +605,7 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* { case DeviceEventType::kCHIPoBLEAdvertisingChange: sHaveBLEConnections = ConnectivityMgr().NumBLEConnections() != 0; -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED UpdateStatusLED(); -#endif #ifdef CONFIG_CHIP_NFC_COMMISSIONING if (event->CHIPoBLEAdvertisingChange.Result == kActivity_Started) { @@ -716,9 +628,7 @@ void AppTaskCommon::ChipEventHandler(const ChipDeviceEvent * event, intptr_t /* sIsThreadProvisioned = ConnectivityMgr().IsThreadProvisioned(); sIsThreadEnabled = ConnectivityMgr().IsThreadEnabled(); sIsThreadAttached = ConnectivityMgr().IsThreadAttached(); -#if CONFIG_CHIP_ENABLE_APPLICATION_STATUS_LED UpdateStatusLED(); -#endif break; case DeviceEventType::kDnssdInitialized: #if CONFIG_CHIP_OTA_REQUESTOR diff --git a/examples/platform/telink/common/src/SensorManagerCommon.cpp b/examples/platform/telink/common/src/SensorManagerCommon.cpp index 1c4d5f9990a0cb..0164749ce7167b 100644 --- a/examples/platform/telink/common/src/SensorManagerCommon.cpp +++ b/examples/platform/telink/common/src/SensorManagerCommon.cpp @@ -17,6 +17,7 @@ */ #include "SensorManagerCommon.h" +#include "PWMManager.h" #ifdef CONFIG_CHIP_USE_MARS_SENSOR #include #endif // CONFIG_CHIP_USE_MARS_SENSOR @@ -36,7 +37,6 @@ constexpr uint16_t kSensorBanForNextMeasurTimeout = 1000; // 1s timeout const struct device * const sht3xd_dev = DEVICE_DT_GET_ONE(sensirion_sht3xd); #ifdef USE_COLOR_TEMPERATURE_LIGHT -const struct device * const ws2812_dev = DEVICE_DT_GET(DT_ALIAS(led_strip)); #define TEMP_LOW_LIM 0 // °C #define TEMP_HIGH_LIM 40 // °C @@ -60,16 +60,6 @@ CHIP_ERROR SensorManager::Init() #ifdef USE_COLOR_TEMPERATURE_LIGHT RgbColor_t rgb = { 0 }; - - CHIP_ERROR err = sSensorManager.mWS2812Device.Init(ws2812_dev, STRIP_NUM_PIXELS(led_strip)); - if (err != CHIP_NO_ERROR) - { - LOG_ERR("WS2812 Device Init fail"); - return err; - } - - sSensorManager.mWS2812Device.SetLevel(&rgb); - sSensorManager.mWS2812Device.Set(SET_RGB_TURN_ON); #endif // USE_COLOR_TEMPERATURE_LIGHT // Initialise the timer to ban sensor measurement @@ -245,7 +235,9 @@ void SensorManager::SetColorTemperatureLight(int8_t temp) LOG_ERR("Couldn't set the Color Temperature Light"); } - sSensorManager.mWS2812Device.SetLevel(&rgb); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, ((uint32_t) rgb.r * 1000) / 0xff); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, ((uint32_t) rgb.g * 1000) / 0xff); + PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, ((uint32_t) rgb.b * 1000) / 0xff); } #endif // USE_COLOR_TEMPERATURE_LIGHT #endif // CONFIG_CHIP_USE_MARS_SENSOR diff --git a/examples/platform/telink/util/include/ButtonManager.h b/examples/platform/telink/util/include/ButtonManager.h index e9ea1b60b17816..c61f165dbca94e 100644 --- a/examples/platform/telink/util/include/ButtonManager.h +++ b/examples/platform/telink/util/include/ButtonManager.h @@ -17,53 +17,125 @@ #pragma once -#include -#include +#include +#include -#define STATE_HIGH 1 -#define STATE_LOW 0 +class ButtonBackend +{ +public: + virtual bool linkHW(void (*on_button_change)(size_t button, bool pressed, void * context), void * context) = 0; +}; -class Button +class ButtonManager { public: - void Configure(const gpio_dt_spec * input_button_dt, const gpio_dt_spec * output_button_dt, void (*callback)(void)); - void Configure(const gpio_dt_spec * input_button_dt, void (*callback)(void)); - void Poll(Button * previous); - void PollIRQ(const struct device * dev, uint32_t pins); - void SetCallback(void (*callback)(void)); + static ButtonManager & getInstance(); + void addCallback(void (*callback)(void), size_t button, bool pressed); + void rmCallback(void (*callback)(void)); + void rmCallback(size_t button, bool pressed); + void linkBackend(ButtonBackend & backend); + + ButtonManager(ButtonManager const &) = delete; + void operator=(ButtonManager const &) = delete; private: - int Init(void); - int Deinit(void); - - const struct gpio_dt_spec * mInput_button; - const struct gpio_dt_spec * mOutput_matrix_pin; - int mPreviousState = STATE_LOW; - struct gpio_callback mButton_cb_data; - void (*mCallback)(void) = NULL; + struct Event + { + size_t button; + bool pressed; + void (*callback)(void); + + friend bool operator<(const Event & lhs, const Event & rhs) + { + if (lhs.button < rhs.button) + { + return true; + } + else if (lhs.button > rhs.button) + { + return false; + } + else if (lhs.pressed < rhs.pressed) + { + return true; + } + else if (lhs.pressed > rhs.pressed) + { + return false; + } + else if (lhs.callback < rhs.callback) + { + return true; + } + else + { + return false; + } + } + friend bool operator>(const Event & lhs, const Event & rhs) + { + if (lhs.button > rhs.button) + { + return true; + } + else if (lhs.button < rhs.button) + { + return false; + } + else if (lhs.pressed > rhs.pressed) + { + return true; + } + else if (lhs.pressed < rhs.pressed) + { + return false; + } + else if (lhs.callback > rhs.callback) + { + return true; + } + else + { + return false; + } + } + }; + + ButtonManager(); + + static void onButton(size_t button, bool pressed, void * buttonMgr); + + std::set m_events; }; -class ButtonManager +#if CONFIG_CHIP_BUTTON_MANAGER_IRQ_MODE + +class ButtonPool : public ButtonBackend { public: - void Init(void); - void Poll(void); - void PollIRQ(const struct device * dev, uint32_t pins); - void AddButton(Button & button); - void SetCallback(unsigned int index, void (*callback)(void)); + static ButtonPool & getInstance(); + bool linkHW(void (*on_button_change)(size_t button, bool pressed, void * context), void * context); + + ButtonPool(ButtonPool const &) = delete; + void operator=(ButtonPool const &) = delete; private: - std::vector