From c184104f4f857b54319e7e2fab4a1513a91517e2 Mon Sep 17 00:00:00 2001 From: Borys Nykytiuk Date: Mon, 9 Sep 2024 11:13:04 +0300 Subject: [PATCH 1/5] soc: riscv: telink: Lighting app run without CONFIG_PWM Add Dummy backend to the PWM Manager Add option to execute Lightining app with LED Manager Signed-off-by: Borys Nykytiuk --- examples/lighting-app/telink/CMakeLists.txt | 6 ++- examples/lighting-app/telink/src/AppTask.cpp | 16 +++++++- .../telink/common/src/AppTaskCommon.cpp | 8 ++-- .../platform/telink/util/include/PWMManager.h | 22 ++++++++++- .../platform/telink/util/src/PWMManager.cpp | 38 ++++++++++++++++++- 5 files changed, 83 insertions(+), 7 deletions(-) diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt index 9e29436a05f5fa..95930946944237 100644 --- a/examples/lighting-app/telink/CMakeLists.txt +++ b/examples/lighting-app/telink/CMakeLists.txt @@ -48,13 +48,17 @@ target_sources(app PRIVATE ${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 ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../lighting-common/lighting-app.zap ) +if(CONFIG_PWM) + target_sources(app PRIVATE + ${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c) +endif() + if(CONFIG_BOOTLOADER_MCUBOOT) target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp) endif() diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp index f250de450def21..d2b209a3dff506 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -21,6 +21,7 @@ #include "ColorFormat.h" #include "PWMManager.h" +#include "LEDManager.h" #include @@ -58,7 +59,9 @@ CHIP_ERROR AppTask::Init(void) { SetExampleButtonCallbacks(LightingActionEventHandler); InitCommonParts(); - +#if (!CONFIG_PWM) + LedManager::getInstance().linkLed(LedManager::EAppLed_App0, 1); +#endif Protocols::InteractionModel::Status status; app::DataModel::Nullable brightness; @@ -130,16 +133,24 @@ void AppTask::SetInitiateAction(Fixture_Action aAction, int32_t aActor, uint8_t if (aAction == ON_ACTION) { sfixture_on = true; +#ifdef CONFIG_PWM 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 + LedManager::getInstance().setLed(LedManager::EAppLed_App0, true); +#endif } else { sfixture_on = false; +#ifdef CONFIG_PWM PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, false); PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, false); PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, false); +#else + LedManager::getInstance().setLed(LedManager::EAppLed_App0, false); +#endif } } else if (aAction == LEVEL_ACTION) @@ -217,6 +228,9 @@ void AppTask::PowerOnFactoryResetEventHandler(AppEvent * aEvent) 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 !CONFIG_PWM + LedManager::getInstance().setLed(LedManager::EAppLed_App0, (bool) (sPowerOnFactoryResetTimerCnt % 2)); +#endif k_timer_init(&sPowerOnFactoryResetTimer, PowerOnFactoryResetTimerEvent, nullptr); k_timer_start(&sPowerOnFactoryResetTimer, K_MSEC(kPowerOnFactoryResetIndicationTimeMs), K_MSEC(kPowerOnFactoryResetIndicationTimeMs)); diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index d2ad2a6fd83a00..e6e7b81a7b1b8f 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -407,9 +407,11 @@ void AppTaskCommon::InitPwms() #if CONFIG_WS2812_STRIP pwmManager.linkBackend(Ws2812Strip::getInstance()); -#else +#elif CONFIG_PWM pwmManager.linkBackend(PwmPool::getInstance()); -#endif // CONFIG_WS2812_STRIP +#else + pwmManager.linkBackend(PwmDummy::getInstance()); +#endif } void AppTaskCommon::LinkPwms(PwmManager & pwmManager) @@ -420,7 +422,7 @@ void AppTaskCommon::LinkPwms(PwmManager & pwmManager) pwmManager.linkPwm(PwmManager::EAppPwm_Red, 0); pwmManager.linkPwm(PwmManager::EAppPwm_Green, 1); pwmManager.linkPwm(PwmManager::EAppPwm_Blue, 2); -#else +#elif CONFIG_PWM pwmManager.linkPwm(PwmManager::EAppPwm_Indication, 0); pwmManager.linkPwm(PwmManager::EAppPwm_Red, 1); pwmManager.linkPwm(PwmManager::EAppPwm_Green, 2); diff --git a/examples/platform/telink/util/include/PWMManager.h b/examples/platform/telink/util/include/PWMManager.h index 852216d08b6d43..f650d301fb01ad 100644 --- a/examples/platform/telink/util/include/PWMManager.h +++ b/examples/platform/telink/util/include/PWMManager.h @@ -130,7 +130,7 @@ class Ws2812Strip : public PwmBackend Ws2812Strip(){}; }; -#else +#elif CONFIG_PWM class PwmPool : public PwmBackend { @@ -150,4 +150,24 @@ class PwmPool : public PwmBackend PwmPool(){}; }; +#else + +class PwmDummy : public PwmBackend +{ +public: + static PwmDummy & getInstance(); + bool linkHW(); + + void setPwmHW(size_t pwm, bool state); + void setPwmHW(size_t pwm, uint32_t permille); + void setPwmHWBlink(size_t pwm, size_t onMs, size_t offMs); + void setPwmHWBreath(size_t pwm, size_t breathMs); + + PwmDummy(PwmDummy const &) = delete; + void operator=(PwmDummy const &) = delete; + +private: + PwmDummy(){}; +}; + #endif // CONFIG_WS2812_STRIP diff --git a/examples/platform/telink/util/src/PWMManager.cpp b/examples/platform/telink/util/src/PWMManager.cpp index 987b66518d44ca..aa747974c93b31 100644 --- a/examples/platform/telink/util/src/PWMManager.cpp +++ b/examples/platform/telink/util/src/PWMManager.cpp @@ -200,7 +200,7 @@ void Ws2812Strip::setPwmHWBreath(size_t pwm, size_t breathMs) LOG_WRN("WS2812 LED setPwmHWBreath not supported"); } -#else +#elif CONFIG_PWM #include @@ -261,4 +261,40 @@ void PwmPool::setPwmHWBreath(size_t pwm, size_t breathMs) } } +#else +// Dummy implementation +PwmDummy & PwmDummy::getInstance() +{ + static PwmDummy instance; + + return instance; +} + +bool PwmDummy::linkHW() +{ + LOG_INF("PWM Dummy inited"); + + return true; +} + +void PwmDummy::setPwmHW(size_t pwm, bool state) +{ + LOG_INF("PWM Dummy %u turn %s", pwm, state ? "on" : "off"); +} + +void PwmDummy::setPwmHW(size_t pwm, uint32_t permille) +{ + LOG_INF("PWM Dummy %u set %u", pwm, permille); +} + +void PwmDummy::setPwmHWBlink(size_t pwm, size_t onMs, size_t offMs) +{ + LOG_WRN("PWM Dummy setPwmHWBlink not supported"); +} + +void PwmDummy::setPwmHWBreath(size_t pwm, size_t breathMs) +{ + LOG_WRN("PWM Dummy setPwmHWBreath not supported"); +} + #endif // CONFIG_WS2812_STRIP From 2f27101279ea9b708bf0661404e7ff9ea57c43ac Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 17 Sep 2024 11:59:43 +0000 Subject: [PATCH 2/5] Restyled by whitespace --- examples/lighting-app/telink/src/AppTask.cpp | 2 +- examples/platform/telink/common/src/AppTaskCommon.cpp | 2 +- examples/platform/telink/util/include/PWMManager.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp index d2b209a3dff506..8a01e1a9d2c0b0 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -59,7 +59,7 @@ CHIP_ERROR AppTask::Init(void) { SetExampleButtonCallbacks(LightingActionEventHandler); InitCommonParts(); -#if (!CONFIG_PWM) +#if (!CONFIG_PWM) LedManager::getInstance().linkLed(LedManager::EAppLed_App0, 1); #endif Protocols::InteractionModel::Status status; diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index e6e7b81a7b1b8f..8b67c403a8194c 100644 --- a/examples/platform/telink/common/src/AppTaskCommon.cpp +++ b/examples/platform/telink/common/src/AppTaskCommon.cpp @@ -422,7 +422,7 @@ void AppTaskCommon::LinkPwms(PwmManager & pwmManager) pwmManager.linkPwm(PwmManager::EAppPwm_Red, 0); pwmManager.linkPwm(PwmManager::EAppPwm_Green, 1); pwmManager.linkPwm(PwmManager::EAppPwm_Blue, 2); -#elif CONFIG_PWM +#elif CONFIG_PWM pwmManager.linkPwm(PwmManager::EAppPwm_Indication, 0); pwmManager.linkPwm(PwmManager::EAppPwm_Red, 1); pwmManager.linkPwm(PwmManager::EAppPwm_Green, 2); diff --git a/examples/platform/telink/util/include/PWMManager.h b/examples/platform/telink/util/include/PWMManager.h index f650d301fb01ad..005e3eb4122fd7 100644 --- a/examples/platform/telink/util/include/PWMManager.h +++ b/examples/platform/telink/util/include/PWMManager.h @@ -150,7 +150,7 @@ class PwmPool : public PwmBackend PwmPool(){}; }; -#else +#else class PwmDummy : public PwmBackend { From 20a74bfee3c0ef7687bb30c30b67c1eebbee3b41 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 17 Sep 2024 11:59:44 +0000 Subject: [PATCH 3/5] Restyled by clang-format --- examples/lighting-app/telink/src/AppTask.cpp | 4 ++-- examples/platform/telink/util/include/PWMManager.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp index 8a01e1a9d2c0b0..d981e6349a3a37 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -20,8 +20,8 @@ #include #include "ColorFormat.h" -#include "PWMManager.h" #include "LEDManager.h" +#include "PWMManager.h" #include @@ -60,7 +60,7 @@ CHIP_ERROR AppTask::Init(void) SetExampleButtonCallbacks(LightingActionEventHandler); InitCommonParts(); #if (!CONFIG_PWM) - LedManager::getInstance().linkLed(LedManager::EAppLed_App0, 1); + LedManager::getInstance().linkLed(LedManager::EAppLed_App0, 1); #endif Protocols::InteractionModel::Status status; diff --git a/examples/platform/telink/util/include/PWMManager.h b/examples/platform/telink/util/include/PWMManager.h index 005e3eb4122fd7..717180a9fa4f01 100644 --- a/examples/platform/telink/util/include/PWMManager.h +++ b/examples/platform/telink/util/include/PWMManager.h @@ -163,7 +163,7 @@ class PwmDummy : public PwmBackend void setPwmHWBlink(size_t pwm, size_t onMs, size_t offMs); void setPwmHWBreath(size_t pwm, size_t breathMs); - PwmDummy(PwmDummy const &) = delete; + PwmDummy(PwmDummy const &) = delete; void operator=(PwmDummy const &) = delete; private: From 870aef5a432526b33c96f6837440e187b5007cab Mon Sep 17 00:00:00 2001 From: Borys Nykytiuk Date: Tue, 17 Sep 2024 17:27:01 +0300 Subject: [PATCH 4/5] Override method linkLed inside lighting app --- examples/lighting-app/telink/include/AppTask.h | 1 + examples/lighting-app/telink/src/AppTask.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/lighting-app/telink/include/AppTask.h b/examples/lighting-app/telink/include/AppTask.h index c835c88e097c11..310453770deb0c 100644 --- a/examples/lighting-app/telink/include/AppTask.h +++ b/examples/lighting-app/telink/include/AppTask.h @@ -48,6 +48,7 @@ class AppTask : public AppTaskCommon friend class AppTaskCommon; CHIP_ERROR Init(void); + void LinkLeds(LedManager & ledManager); static void LightingActionEventHandler(AppEvent * aEvent); #ifdef CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp index d981e6349a3a37..63a5cb7d910e0c 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -59,9 +59,7 @@ CHIP_ERROR AppTask::Init(void) { SetExampleButtonCallbacks(LightingActionEventHandler); InitCommonParts(); -#if (!CONFIG_PWM) - LedManager::getInstance().linkLed(LedManager::EAppLed_App0, 1); -#endif + Protocols::InteractionModel::Status status; app::DataModel::Nullable brightness; @@ -251,3 +249,10 @@ void AppTask::PowerOnFactoryResetTimerEvent(struct k_timer * timer) } } #endif /* CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET */ + +void AppTask::LinkLeds(LedManager & ledManager) +{ +#if (!CONFIG_PWM) + ledManager.linkLed(LedManager::EAppLed_App0, 0); +#endif // !CONFIG_PWM +} From 8b810fb953b73935e34ce7e5e8cd04d987acb151 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Tue, 17 Sep 2024 14:27:26 +0000 Subject: [PATCH 5/5] Restyled by clang-format --- examples/lighting-app/telink/include/AppTask.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/lighting-app/telink/include/AppTask.h b/examples/lighting-app/telink/include/AppTask.h index 310453770deb0c..d3327d1ed3f6b8 100644 --- a/examples/lighting-app/telink/include/AppTask.h +++ b/examples/lighting-app/telink/include/AppTask.h @@ -48,7 +48,7 @@ class AppTask : public AppTaskCommon friend class AppTaskCommon; CHIP_ERROR Init(void); - void LinkLeds(LedManager & ledManager); + void LinkLeds(LedManager & ledManager); static void LightingActionEventHandler(AppEvent * aEvent); #ifdef CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET