Skip to content

Commit c184104

Browse files
committed
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>
1 parent 514e810 commit c184104

File tree

5 files changed

+83
-7
lines changed

5 files changed

+83
-7
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/src/AppTask.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "ColorFormat.h"
2323
#include "PWMManager.h"
24+
#include "LEDManager.h"
2425

2526
#include <app-common/zap-generated/attributes/Accessors.h>
2627

@@ -58,7 +59,9 @@ CHIP_ERROR AppTask::Init(void)
5859
{
5960
SetExampleButtonCallbacks(LightingActionEventHandler);
6061
InitCommonParts();
61-
62+
#if (!CONFIG_PWM)
63+
LedManager::getInstance().linkLed(LedManager::EAppLed_App0, 1);
64+
#endif
6265
Protocols::InteractionModel::Status status;
6366

6467
app::DataModel::Nullable<uint8_t> brightness;
@@ -130,16 +133,24 @@ void AppTask::SetInitiateAction(Fixture_Action aAction, int32_t aActor, uint8_t
130133
if (aAction == ON_ACTION)
131134
{
132135
sfixture_on = true;
136+
#ifdef CONFIG_PWM
133137
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (((uint32_t) sLedRgb.r * 1000) / UINT8_MAX));
134138
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (((uint32_t) sLedRgb.g * 1000) / UINT8_MAX));
135139
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (((uint32_t) sLedRgb.b * 1000) / UINT8_MAX));
140+
#else
141+
LedManager::getInstance().setLed(LedManager::EAppLed_App0, true);
142+
#endif
136143
}
137144
else
138145
{
139146
sfixture_on = false;
147+
#ifdef CONFIG_PWM
140148
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, false);
141149
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, false);
142150
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, false);
151+
#else
152+
LedManager::getInstance().setLed(LedManager::EAppLed_App0, false);
153+
#endif
143154
}
144155
}
145156
else if (aAction == LEVEL_ACTION)
@@ -217,6 +228,9 @@ void AppTask::PowerOnFactoryResetEventHandler(AppEvent * aEvent)
217228
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Red, (bool) (sPowerOnFactoryResetTimerCnt % 2));
218229
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Green, (bool) (sPowerOnFactoryResetTimerCnt % 2));
219230
PwmManager::getInstance().setPwm(PwmManager::EAppPwm_Blue, (bool) (sPowerOnFactoryResetTimerCnt % 2));
231+
#if !CONFIG_PWM
232+
LedManager::getInstance().setLed(LedManager::EAppLed_App0, (bool) (sPowerOnFactoryResetTimerCnt % 2));
233+
#endif
220234
k_timer_init(&sPowerOnFactoryResetTimer, PowerOnFactoryResetTimerEvent, nullptr);
221235
k_timer_start(&sPowerOnFactoryResetTimer, K_MSEC(kPowerOnFactoryResetIndicationTimeMs),
222236
K_MSEC(kPowerOnFactoryResetIndicationTimeMs));

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)