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/include/AppTask.h b/examples/lighting-app/telink/include/AppTask.h index c835c88e097c11..d3327d1ed3f6b8 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 f250de450def21..63a5cb7d910e0c 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -20,6 +20,7 @@ #include #include "ColorFormat.h" +#include "LEDManager.h" #include "PWMManager.h" #include @@ -130,16 +131,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 +226,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)); @@ -237,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 +} diff --git a/examples/platform/telink/common/src/AppTaskCommon.cpp b/examples/platform/telink/common/src/AppTaskCommon.cpp index d2ad2a6fd83a00..8b67c403a8194c 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..717180a9fa4f01 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