Skip to content

Commit 2802265

Browse files
s07641069serhiiSalamakharestyled-commitsinterfer
authored andcommitted
[Telink] Add lighting color feature & Move LightingManager into PWMDevice (#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>
1 parent 901715d commit 2802265

File tree

15 files changed

+642
-96
lines changed

15 files changed

+642
-96
lines changed

examples/all-clusters-app/telink/src/AppTask.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,23 @@
4343

4444
#include <zephyr/logging/log.h>
4545
#include <zephyr/zephyr.h>
46+
#if CONFIG_CHIP_LIB_SHELL
47+
#include <sys.h>
48+
#include <zephyr/shell/shell.h>
49+
50+
static int cmd_telink_reboot(const struct shell * shell, size_t argc, char ** argv)
51+
{
52+
ARG_UNUSED(argc);
53+
ARG_UNUSED(argv);
54+
55+
shell_print(shell, "Performing board reboot...");
56+
sys_reboot();
57+
}
58+
59+
SHELL_STATIC_SUBCMD_SET_CREATE(sub_telink, SHELL_CMD(reboot, NULL, "Reboot board command", cmd_telink_reboot),
60+
SHELL_SUBCMD_SET_END);
61+
SHELL_CMD_REGISTER(telink, &sub_telink, "Telink commands", NULL);
62+
#endif // CONFIG_CHIP_LIB_SHELL
4663

4764
LOG_MODULE_DECLARE(app);
4865

examples/all-clusters-minimal-app/telink/src/AppTask.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@
4141
#include <zephyr/logging/log.h>
4242
#include <zephyr/zephyr.h>
4343

44+
#if CONFIG_CHIP_LIB_SHELL
45+
#include <sys.h>
46+
#include <zephyr/shell/shell.h>
47+
48+
static int cmd_telink_reboot(const struct shell * shell, size_t argc, char ** argv)
49+
{
50+
ARG_UNUSED(argc);
51+
ARG_UNUSED(argv);
52+
53+
shell_print(shell, "Performing board reboot...");
54+
sys_reboot();
55+
}
56+
57+
SHELL_STATIC_SUBCMD_SET_CREATE(sub_telink, SHELL_CMD(reboot, NULL, "Reboot board command", cmd_telink_reboot),
58+
SHELL_SUBCMD_SET_END);
59+
SHELL_CMD_REGISTER(telink, &sub_telink, "Telink commands", NULL);
60+
#endif // CONFIG_CHIP_LIB_SHELL
61+
4462
LOG_MODULE_DECLARE(app);
4563

4664
namespace {

examples/light-switch-app/telink/src/AppTask.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@
4545

4646
#include <algorithm>
4747

48+
#if CONFIG_CHIP_LIB_SHELL
49+
#include <sys.h>
50+
#include <zephyr/shell/shell.h>
51+
52+
static int cmd_telink_reboot(const struct shell * shell, size_t argc, char ** argv)
53+
{
54+
ARG_UNUSED(argc);
55+
ARG_UNUSED(argv);
56+
57+
shell_print(shell, "Performing board reboot...");
58+
sys_reboot();
59+
}
60+
61+
SHELL_STATIC_SUBCMD_SET_CREATE(sub_telink, SHELL_CMD(reboot, NULL, "Reboot board command", cmd_telink_reboot),
62+
SHELL_SUBCMD_SET_END);
63+
SHELL_CMD_REGISTER(telink, &sub_telink, "Telink commands", NULL);
64+
#endif // CONFIG_CHIP_LIB_SHELL
65+
4866
LOG_MODULE_DECLARE(app);
4967

5068
using namespace ::chip;

examples/light-switch-app/telink/src/binding-handler.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
#include <app/clusters/bindings/bindings.h>
2727
#include <lib/support/CodeUtils.h>
2828

29-
#if defined(ENABLE_CHIP_SHELL)
29+
#if defined(CONFIG_CHIP_LIB_SHELL)
3030
#include "lib/shell/Engine.h"
3131
#include "lib/shell/commands/Help.h"
32-
#endif // ENABLE_CHIP_SHELL
32+
#endif // CONFIG_CHIP_LIB_SHELL
3333

3434
using namespace chip;
3535
using namespace chip::app;
3636

37-
#if defined(ENABLE_CHIP_SHELL)
37+
#if defined(CONFIG_CHIP_LIB_SHELL)
3838
using Shell::Engine;
3939
using Shell::shell_command_t;
4040
using Shell::streamer_get;
@@ -47,7 +47,7 @@ Engine sShellSwitchGroupsSubCommands;
4747
Engine sShellSwitchGroupsOnOffSubCommands;
4848

4949
Engine sShellSwitchBindingSubCommands;
50-
#endif // defined(ENABLE_CHIP_SHELL)
50+
#endif // defined(CONFIG_CHIP_LIB_SHELL)
5151

5252
namespace {
5353

@@ -140,7 +140,7 @@ void LightSwitchContextReleaseHandler(void * context)
140140
Platform::Delete(static_cast<BindingCommandData *>(context));
141141
}
142142

143-
#ifdef ENABLE_CHIP_SHELL
143+
#ifdef CONFIG_CHIP_LIB_SHELL
144144

145145
/********************************************************
146146
* Switch shell functions
@@ -384,7 +384,7 @@ static void RegisterSwitchCommands()
384384

385385
Engine::Root().RegisterCommands(&sSwitchCommand, 1);
386386
}
387-
#endif // ENABLE_CHIP_SHELL
387+
#endif // CONFIG_CHIP_LIB_SHELL
388388

389389
void InitBindingHandlerInternal(intptr_t arg)
390390
{
@@ -439,7 +439,7 @@ CHIP_ERROR InitBindingHandler()
439439
// so it requires the Server instance to be correctly initialized. Post the init function to
440440
// the event queue so that everything is ready when initialization is conducted.
441441
chip::DeviceLayer::PlatformMgr().ScheduleWork(InitBindingHandlerInternal);
442-
#if defined(ENABLE_CHIP_SHELL)
442+
#if defined(CONFIG_CHIP_LIB_SHELL)
443443
RegisterSwitchCommands();
444444
#endif
445445
return CHIP_NO_ERROR;

examples/lighting-app/telink/CMakeLists.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,13 @@ add_definitions(
4747

4848
target_sources(app PRIVATE
4949
src/AppTask.cpp
50-
src/LightingManager.cpp
5150
src/main.cpp
5251
src/ZclCallbacks.cpp
5352
${TELINK_COMMON}/util/src/LEDWidget.cpp
5453
${TELINK_COMMON}/util/src/ButtonManager.cpp
55-
${TELINK_COMMON}/util/src/ThreadUtil.cpp)
54+
${TELINK_COMMON}/util/src/ThreadUtil.cpp
55+
${TELINK_COMMON}/util/src/PWMDevice.cpp
56+
${TELINK_COMMON}/util/src/ColorFormat.cpp)
5657

5758
chip_configure_data_model(app
5859
INCLUDE_SERVER

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,10 @@
3434
#define SYSTEM_STATE_LED_PIN 7
3535

3636
// Lighting LED config
37-
#define LIGHTING_PWM_DEVICE DEVICE_DT_GET(DT_PWMS_CTLR(DT_ALIAS(pwm_led0)))
38-
#define LIGHTING_PWM_CHANNEL DT_PWMS_CHANNEL(DT_ALIAS(pwm_led0))
37+
#define USE_RGB_PWM 0
38+
39+
#define LIGHTING_PWM_SPEC_BLUE PWM_DT_SPEC_GET(DT_ALIAS(pwm_led0))
40+
#if USE_RGB_PWM
41+
#define LIGHTING_PWM_SPEC_GREEN PWM_DT_SPEC_GET(DT_ALIAS(pwm_led1))
42+
#define LIGHTING_PWM_SPEC_RED PWM_DT_SPEC_GET(DT_ALIAS(pwm_led2))
43+
#endif

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

+11-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include "AppEvent.h"
2222
#include "LEDWidget.h"
23-
#include "LightingManager.h"
23+
#include "PWMDevice.h"
2424
#include <platform/CHIPDeviceLayer.h>
2525

2626
#if CONFIG_CHIP_FACTORY_DATA
@@ -40,9 +40,10 @@ class AppTask
4040
public:
4141
CHIP_ERROR StartApp();
4242

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

4748
enum ButtonId_t
4849
{
@@ -59,8 +60,8 @@ class AppTask
5960
friend AppTask & GetAppTask(void);
6061
CHIP_ERROR Init();
6162

62-
static void ActionInitiated(LightingManager::Action_t aAction, int32_t aActor);
63-
static void ActionCompleted(LightingManager::Action_t aAction, int32_t aActor);
63+
static void ActionInitiated(PWMDevice::Action_t aAction, int32_t aActor);
64+
static void ActionCompleted(PWMDevice::Action_t aAction, int32_t aActor);
6465

6566
void DispatchEvent(AppEvent * event);
6667

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

9091
static AppTask sAppTask;
92+
PWMDevice mBluePwmLed;
93+
#if USE_RGB_PWM
94+
PWMDevice mGreenPwmLed;
95+
PWMDevice mRedPwmLed;
96+
#endif
9197

9298
#if CONFIG_CHIP_FACTORY_DATA
9399
// chip::DeviceLayer::FactoryDataProvider<chip::DeviceLayer::InternalFlashFactoryData> mFactoryDataProvider;

0 commit comments

Comments
 (0)