Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Telink] Lighting app build with disabled CONFIG_PWM #35621

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
16 changes: 15 additions & 1 deletion examples/lighting-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -58,7 +59,9 @@ CHIP_ERROR AppTask::Init(void)
{
SetExampleButtonCallbacks(LightingActionEventHandler);
InitCommonParts();

#if (!CONFIG_PWM)
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
LedManager::getInstance().linkLed(LedManager::EAppLed_App0, 1);
#endif
Protocols::InteractionModel::Status status;

app::DataModel::Nullable<uint8_t> brightness;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down
8 changes: 5 additions & 3 deletions examples/platform/telink/common/src/AppTaskCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
22 changes: 21 additions & 1 deletion examples/platform/telink/util/include/PWMManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Ws2812Strip : public PwmBackend
Ws2812Strip(){};
};

#else
#elif CONFIG_PWM

class PwmPool : public PwmBackend
{
Expand All @@ -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
38 changes: 37 additions & 1 deletion examples/platform/telink/util/src/PWMManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <zephyr_pwm_pool.h>

Expand Down Expand Up @@ -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
Loading