Skip to content

Commit ab610ea

Browse files
BorysNykytiukrestyled-commitss07641069
authored andcommitted
[Telink] Lighting app build with disabled CONFIG_PWM (project-chip#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>
1 parent 148bc25 commit ab610ea

File tree

6 files changed

+88
-6
lines changed

6 files changed

+88
-6
lines changed

examples/lighting-app/telink/CMakeLists.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@ target_sources(app PRIVATE
4848
${TELINK_COMMON}/zephyr_ext/zephyr_key_matrix.c
4949
${TELINK_COMMON}/zephyr_ext/zephyr_key_pool.c
5050
${TELINK_COMMON}/zephyr_ext/zephyr_led_pool.c
51-
${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c
5251
${TELINK_COMMON}/zephyr_ext/zephyr_ws2812.c)
5352

5453
chip_configure_data_model(app
5554
ZAP_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../lighting-common/lighting-app.zap
5655
)
5756

57+
if(CONFIG_PWM)
58+
target_sources(app PRIVATE
59+
${TELINK_COMMON}/zephyr_ext/zephyr_pwm_pool.c)
60+
endif()
61+
5862
if(CONFIG_BOOTLOADER_MCUBOOT)
5963
target_sources(app PRIVATE ${TELINK_COMMON}/util/src/OTAUtil.cpp)
6064
endif()

examples/lighting-app/telink/include/AppTask.h

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class AppTask : public AppTaskCommon
4848
friend class AppTaskCommon;
4949

5050
CHIP_ERROR Init(void);
51+
void LinkLeds(LedManager & ledManager);
5152

5253
static void LightingActionEventHandler(AppEvent * aEvent);
5354
#ifdef CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET

examples/lighting-app/telink/src/AppTask.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <app/server/Server.h>
2121

2222
#include "ColorFormat.h"
23+
#include "LEDManager.h"
2324
#include "PWMManager.h"
2425

2526
#include <app-common/zap-generated/attributes/Accessors.h>
@@ -130,16 +131,24 @@ void AppTask::SetInitiateAction(Fixture_Action aAction, int32_t aActor, uint8_t
130131
if (aAction == ON_ACTION)
131132
{
132133
sfixture_on = true;
134+
#ifdef CONFIG_PWM
133135
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (((uint32_t) sLedRgb.r * 1000) / UINT8_MAX));
134136
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (((uint32_t) sLedRgb.g * 1000) / UINT8_MAX));
135137
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (((uint32_t) sLedRgb.b * 1000) / UINT8_MAX));
138+
#else
139+
LedManager::getInstance().setLed(LedManager::EAppLed_App0, true);
140+
#endif
136141
}
137142
else
138143
{
139144
sfixture_on = false;
145+
#ifdef CONFIG_PWM
140146
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, false);
141147
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, false);
142148
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, false);
149+
#else
150+
LedManager::getInstance().setLed(LedManager::EAppLed_App0, false);
151+
#endif
143152
}
144153
}
145154
else if (aAction == LEVEL_ACTION)
@@ -217,6 +226,9 @@ void AppTask::PowerOnFactoryResetEventHandler(AppEvent * aEvent)
217226
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (bool) (sPowerOnFactoryResetTimerCnt % 2));
218227
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (bool) (sPowerOnFactoryResetTimerCnt % 2));
219228
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (bool) (sPowerOnFactoryResetTimerCnt % 2));
229+
#if !CONFIG_PWM
230+
LedManager::getInstance().setLed(LedManager::EAppLed_App0, (bool) (sPowerOnFactoryResetTimerCnt % 2));
231+
#endif
220232
k_timer_init(&sPowerOnFactoryResetTimer, PowerOnFactoryResetTimerEvent, nullptr);
221233
k_timer_start(&sPowerOnFactoryResetTimer, K_MSEC(kPowerOnFactoryResetIndicationTimeMs),
222234
K_MSEC(kPowerOnFactoryResetIndicationTimeMs));
@@ -237,3 +249,10 @@ void AppTask::PowerOnFactoryResetTimerEvent(struct k_timer * timer)
237249
}
238250
}
239251
#endif /* CONFIG_CHIP_ENABLE_POWER_ON_FACTORY_RESET */
252+
253+
void AppTask::LinkLeds(LedManager & ledManager)
254+
{
255+
#if (!CONFIG_PWM)
256+
ledManager.linkLed(LedManager::EAppLed_App0, 0);
257+
#endif // !CONFIG_PWM
258+
}

examples/platform/telink/common/src/AppTaskCommon.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,11 @@ void AppTaskCommon::InitPwms()
407407

408408
#if CONFIG_WS2812_STRIP
409409
pwmManager.linkBackend(Ws2812Strip::getInstance());
410-
#else
410+
#elif CONFIG_PWM
411411
pwmManager.linkBackend(PwmPool::getInstance());
412-
#endif // CONFIG_WS2812_STRIP
412+
#else
413+
pwmManager.linkBackend(PwmDummy::getInstance());
414+
#endif
413415
}
414416

415417
void AppTaskCommon::LinkPwms(PwmManager & pwmManager)
@@ -420,7 +422,7 @@ void AppTaskCommon::LinkPwms(PwmManager & pwmManager)
420422
pwmManager.linkPwm(PwmManager::EAppPwm_Red, 0);
421423
pwmManager.linkPwm(PwmManager::EAppPwm_Green, 1);
422424
pwmManager.linkPwm(PwmManager::EAppPwm_Blue, 2);
423-
#else
425+
#elif CONFIG_PWM
424426
pwmManager.linkPwm(PwmManager::EAppPwm_Indication, 0);
425427
pwmManager.linkPwm(PwmManager::EAppPwm_Red, 1);
426428
pwmManager.linkPwm(PwmManager::EAppPwm_Green, 2);

examples/platform/telink/util/include/PWMManager.h

+21-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class Ws2812Strip : public PwmBackend
130130
Ws2812Strip(){};
131131
};
132132

133-
#else
133+
#elif CONFIG_PWM
134134

135135
class PwmPool : public PwmBackend
136136
{
@@ -150,4 +150,24 @@ class PwmPool : public PwmBackend
150150
PwmPool(){};
151151
};
152152

153+
#else
154+
155+
class PwmDummy : public PwmBackend
156+
{
157+
public:
158+
static PwmDummy & getInstance();
159+
bool linkHW();
160+
161+
void setPwmHW(size_t pwm, bool state);
162+
void setPwmHW(size_t pwm, uint32_t permille);
163+
void setPwmHWBlink(size_t pwm, size_t onMs, size_t offMs);
164+
void setPwmHWBreath(size_t pwm, size_t breathMs);
165+
166+
PwmDummy(PwmDummy const &) = delete;
167+
void operator=(PwmDummy const &) = delete;
168+
169+
private:
170+
PwmDummy(){};
171+
};
172+
153173
#endif // CONFIG_WS2812_STRIP

examples/platform/telink/util/src/PWMManager.cpp

+37-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void Ws2812Strip::setPwmHWBreath(size_t pwm, size_t breathMs)
200200
LOG_WRN("WS2812 LED setPwmHWBreath not supported");
201201
}
202202

203-
#else
203+
#elif CONFIG_PWM
204204

205205
#include <zephyr_pwm_pool.h>
206206

@@ -261,4 +261,40 @@ void PwmPool::setPwmHWBreath(size_t pwm, size_t breathMs)
261261
}
262262
}
263263

264+
#else
265+
// Dummy implementation
266+
PwmDummy & PwmDummy::getInstance()
267+
{
268+
static PwmDummy instance;
269+
270+
return instance;
271+
}
272+
273+
bool PwmDummy::linkHW()
274+
{
275+
LOG_INF("PWM Dummy inited");
276+
277+
return true;
278+
}
279+
280+
void PwmDummy::setPwmHW(size_t pwm, bool state)
281+
{
282+
LOG_INF("PWM Dummy %u turn %s", pwm, state ? "on" : "off");
283+
}
284+
285+
void PwmDummy::setPwmHW(size_t pwm, uint32_t permille)
286+
{
287+
LOG_INF("PWM Dummy %u set %u", pwm, permille);
288+
}
289+
290+
void PwmDummy::setPwmHWBlink(size_t pwm, size_t onMs, size_t offMs)
291+
{
292+
LOG_WRN("PWM Dummy setPwmHWBlink not supported");
293+
}
294+
295+
void PwmDummy::setPwmHWBreath(size_t pwm, size_t breathMs)
296+
{
297+
LOG_WRN("PWM Dummy setPwmHWBreath not supported");
298+
}
299+
264300
#endif // CONFIG_WS2812_STRIP

0 commit comments

Comments
 (0)