Skip to content

Commit

Permalink
[Telink] Add lighting color feature & Move LightingManager into PWMDe…
Browse files Browse the repository at this point in the history
…vice (#24378)

* [Telink] Moved LightingManager into PWMDevice

* Restyled by clang-format

* [Telink] Adding lighting color feature (#59)

* [Telink] Added lighting color feature

* [Telink] Added tlsr9518adk80d.overlay to lighting-app

* [Telink] Updated RGB functionality

* [Telink] Updated RGB PWM pins

Co-authored-by: Alex Tsitsiura <s07641069@gmail.com>

* Restyled by whitespace

* Restyled by clang-format

* [Telink] Minor changes

* [Telink] Add 'telink reboot' shell CLI command (#63)

* [Telink] Restyled

Co-authored-by: Serhii Salamakha <serhii.salamakha@gmail.com>
Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Dmytro Huz <75682372+interfer@users.noreply.github.com>
  • Loading branch information
4 people authored and pull[bot] committed Feb 19, 2024
1 parent 350e946 commit 7cbf6db
Show file tree
Hide file tree
Showing 15 changed files with 642 additions and 96 deletions.
17 changes: 17 additions & 0 deletions examples/all-clusters-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@

#include <zephyr/logging/log.h>
#include <zephyr/zephyr.h>
#if CONFIG_CHIP_LIB_SHELL
#include <sys.h>
#include <zephyr/shell/shell.h>

static int cmd_telink_reboot(const struct shell * shell, size_t argc, char ** argv)
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);

shell_print(shell, "Performing board reboot...");
sys_reboot();
}

SHELL_STATIC_SUBCMD_SET_CREATE(sub_telink, SHELL_CMD(reboot, NULL, "Reboot board command", cmd_telink_reboot),
SHELL_SUBCMD_SET_END);
SHELL_CMD_REGISTER(telink, &sub_telink, "Telink commands", NULL);
#endif // CONFIG_CHIP_LIB_SHELL

LOG_MODULE_DECLARE(app);

Expand Down
18 changes: 18 additions & 0 deletions examples/all-clusters-minimal-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@
#include <zephyr/logging/log.h>
#include <zephyr/zephyr.h>

#if CONFIG_CHIP_LIB_SHELL
#include <sys.h>
#include <zephyr/shell/shell.h>

static int cmd_telink_reboot(const struct shell * shell, size_t argc, char ** argv)
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);

shell_print(shell, "Performing board reboot...");
sys_reboot();
}

SHELL_STATIC_SUBCMD_SET_CREATE(sub_telink, SHELL_CMD(reboot, NULL, "Reboot board command", cmd_telink_reboot),
SHELL_SUBCMD_SET_END);
SHELL_CMD_REGISTER(telink, &sub_telink, "Telink commands", NULL);
#endif // CONFIG_CHIP_LIB_SHELL

LOG_MODULE_DECLARE(app);

namespace {
Expand Down
18 changes: 18 additions & 0 deletions examples/light-switch-app/telink/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@

#include <algorithm>

#if CONFIG_CHIP_LIB_SHELL
#include <sys.h>
#include <zephyr/shell/shell.h>

static int cmd_telink_reboot(const struct shell * shell, size_t argc, char ** argv)
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);

shell_print(shell, "Performing board reboot...");
sys_reboot();
}

SHELL_STATIC_SUBCMD_SET_CREATE(sub_telink, SHELL_CMD(reboot, NULL, "Reboot board command", cmd_telink_reboot),
SHELL_SUBCMD_SET_END);
SHELL_CMD_REGISTER(telink, &sub_telink, "Telink commands", NULL);
#endif // CONFIG_CHIP_LIB_SHELL

LOG_MODULE_DECLARE(app);

using namespace ::chip;
Expand Down
14 changes: 7 additions & 7 deletions examples/light-switch-app/telink/src/binding-handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
#include <app/clusters/bindings/bindings.h>
#include <lib/support/CodeUtils.h>

#if defined(ENABLE_CHIP_SHELL)
#if defined(CONFIG_CHIP_LIB_SHELL)
#include "lib/shell/Engine.h"
#include "lib/shell/commands/Help.h"
#endif // ENABLE_CHIP_SHELL
#endif // CONFIG_CHIP_LIB_SHELL

using namespace chip;
using namespace chip::app;

#if defined(ENABLE_CHIP_SHELL)
#if defined(CONFIG_CHIP_LIB_SHELL)
using Shell::Engine;
using Shell::shell_command_t;
using Shell::streamer_get;
Expand All @@ -47,7 +47,7 @@ Engine sShellSwitchGroupsSubCommands;
Engine sShellSwitchGroupsOnOffSubCommands;

Engine sShellSwitchBindingSubCommands;
#endif // defined(ENABLE_CHIP_SHELL)
#endif // defined(CONFIG_CHIP_LIB_SHELL)

namespace {

Expand Down Expand Up @@ -140,7 +140,7 @@ void LightSwitchContextReleaseHandler(void * context)
Platform::Delete(static_cast<BindingCommandData *>(context));
}

#ifdef ENABLE_CHIP_SHELL
#ifdef CONFIG_CHIP_LIB_SHELL

/********************************************************
* Switch shell functions
Expand Down Expand Up @@ -384,7 +384,7 @@ static void RegisterSwitchCommands()

Engine::Root().RegisterCommands(&sSwitchCommand, 1);
}
#endif // ENABLE_CHIP_SHELL
#endif // CONFIG_CHIP_LIB_SHELL

void InitBindingHandlerInternal(intptr_t arg)
{
Expand Down Expand Up @@ -439,7 +439,7 @@ CHIP_ERROR InitBindingHandler()
// so it requires the Server instance to be correctly initialized. Post the init function to
// the event queue so that everything is ready when initialization is conducted.
chip::DeviceLayer::PlatformMgr().ScheduleWork(InitBindingHandlerInternal);
#if defined(ENABLE_CHIP_SHELL)
#if defined(CONFIG_CHIP_LIB_SHELL)
RegisterSwitchCommands();
#endif
return CHIP_NO_ERROR;
Expand Down
5 changes: 3 additions & 2 deletions examples/lighting-app/telink/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ add_definitions(

target_sources(app PRIVATE
src/AppTask.cpp
src/LightingManager.cpp
src/main.cpp
src/ZclCallbacks.cpp
${TELINK_COMMON}/util/src/LEDWidget.cpp
${TELINK_COMMON}/util/src/ButtonManager.cpp
${TELINK_COMMON}/util/src/ThreadUtil.cpp)
${TELINK_COMMON}/util/src/ThreadUtil.cpp
${TELINK_COMMON}/util/src/PWMDevice.cpp
${TELINK_COMMON}/util/src/ColorFormat.cpp)

chip_configure_data_model(app
INCLUDE_SERVER
Expand Down
9 changes: 7 additions & 2 deletions examples/lighting-app/telink/include/AppConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,10 @@
#define SYSTEM_STATE_LED_PIN 7

// Lighting LED config
#define LIGHTING_PWM_DEVICE DEVICE_DT_GET(DT_PWMS_CTLR(DT_ALIAS(pwm_led0)))
#define LIGHTING_PWM_CHANNEL DT_PWMS_CHANNEL(DT_ALIAS(pwm_led0))
#define USE_RGB_PWM 0

#define LIGHTING_PWM_SPEC_BLUE PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0))
#if USE_RGB_PWM
#define LIGHTING_PWM_SPEC_GREEN PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1))
#define LIGHTING_PWM_SPEC_RED PWM_DT_SPEC_GET(DT_ALIAS(pwm_led2))
#endif
16 changes: 11 additions & 5 deletions examples/lighting-app/telink/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "AppEvent.h"
#include "LEDWidget.h"
#include "LightingManager.h"
#include "PWMDevice.h"
#include <platform/CHIPDeviceLayer.h>

#if CONFIG_CHIP_FACTORY_DATA
Expand All @@ -40,9 +40,10 @@ class AppTask
public:
CHIP_ERROR StartApp();

void PostLightingActionRequest(LightingManager::Action_t aAction);
void PostEvent(AppEvent * event);
void SetInitiateAction(PWMDevice::Action_t aAction, int32_t aActor, uint8_t * value);
void PostEvent(AppEvent * aEvent);
void UpdateClusterState();
PWMDevice & GetPWMDevice() { return mBluePwmLed; }

enum ButtonId_t
{
Expand All @@ -59,8 +60,8 @@ class AppTask
friend AppTask & GetAppTask(void);
CHIP_ERROR Init();

static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor);
static void ActionCompleted(LightingManager::Action_t aAction, int32_t aActor);
static void ActionInitiated(PWMDevice::Action_t aAction, int32_t aActor);
static void ActionCompleted(PWMDevice::Action_t aAction, int32_t aActor);

void DispatchEvent(AppEvent * event);

Expand Down Expand Up @@ -88,6 +89,11 @@ class AppTask
static void ThreadProvisioningHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg);

static AppTask sAppTask;
PWMDevice mBluePwmLed;
#if USE_RGB_PWM
PWMDevice mGreenPwmLed;
PWMDevice mRedPwmLed;
#endif

#if CONFIG_CHIP_FACTORY_DATA
// chip::DeviceLayer::FactoryDataProvider<chip::DeviceLayer::InternalFlashFactoryData> mFactoryDataProvider;
Expand Down
Loading

0 comments on commit 7cbf6db

Please sign in to comment.