[Telink] Lighting app build with disabled CONFIG_PWM (#35621)

* 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 <borys.nykytiuk@telink-semi.com>

* Restyled by whitespace

* Restyled by clang-format

* Override method linkLed inside lighting app

* Restyled by clang-format

---------

Signed-off-by: Borys Nykytiuk <borys.nykytiuk@telink-semi.com>
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Alex Tsitsiura <s07641069@gmail.com>
diff --git a/examples/lighting-app/telink/CMakeLists.txt b/examples/lighting-app/telink/CMakeLists.txt
index 9e29436..9593094 100644
--- a/examples/lighting-app/telink/CMakeLists.txt
+++ b/examples/lighting-app/telink/CMakeLists.txt
@@ -48,13 +48,17 @@
                ${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 c835c88..d3327d1 100644
--- a/examples/lighting-app/telink/include/AppTask.h
+++ b/examples/lighting-app/telink/include/AppTask.h
@@ -48,6 +48,7 @@
     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 f250de4..63a5cb7 100644
--- a/examples/lighting-app/telink/src/AppTask.cpp
+++ b/examples/lighting-app/telink/src/AppTask.cpp
@@ -20,6 +20,7 @@
 #include <app/server/Server.h>
 
 #include "ColorFormat.h"
+#include "LEDManager.h"
 #include "PWMManager.h"
 
 #include <app-common/zap-generated/attributes/Accessors.h>
@@ -130,16 +131,24 @@
         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 @@
     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 @@
     }
 }
 #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 d2ad2a6..8b67c40 100644
--- a/examples/platform/telink/common/src/AppTaskCommon.cpp
+++ b/examples/platform/telink/common/src/AppTaskCommon.cpp
@@ -407,9 +407,11 @@
 
 #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 @@
     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 852216d..717180a 100644
--- a/examples/platform/telink/util/include/PWMManager.h
+++ b/examples/platform/telink/util/include/PWMManager.h
@@ -130,7 +130,7 @@
     Ws2812Strip(){};
 };
 
-#else
+#elif CONFIG_PWM
 
 class PwmPool : public PwmBackend
 {
@@ -150,4 +150,24 @@
     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 987b665..aa74797 100644
--- a/examples/platform/telink/util/src/PWMManager.cpp
+++ b/examples/platform/telink/util/src/PWMManager.cpp
@@ -200,7 +200,7 @@
     LOG_WRN("WS2812 LED setPwmHWBreath not supported");
 }
 
-#else
+#elif CONFIG_PWM
 
 #include <zephyr_pwm_pool.h>
 
@@ -261,4 +261,40 @@
     }
 }
 
+#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