Skip to content

Commit

Permalink
[Silabs] merge LEDWidget (#26222)
Browse files Browse the repository at this point in the history
* Silabs merge LEDWidget

* Fix CI
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Jul 22, 2023
1 parent bbdb3ff commit 1702492
Show file tree
Hide file tree
Showing 23 changed files with 61 additions and 311 deletions.
8 changes: 1 addition & 7 deletions examples/chef/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
#include "AppConfig.h"
#include "AppEvent.h"

#ifdef ENABLE_WSTK_LEDS
#include "LEDWidget.h"
#include "sl_simple_led_instances.h"
#endif // ENABLE_WSTK_LEDS

#ifdef DISPLAY_ENABLED
#include "lcd.h"
Expand All @@ -51,10 +48,7 @@

#include <platform/CHIPDeviceLayer.h>

#ifdef ENABLE_WSTK_LEDS
#define SYSTEM_STATE_LED &sl_led_led0
#endif // ENABLE_WSTK_LEDS

#define SYSTEM_STATE_LED 0
#define APP_FUNCTION_BUTTON &sl_button_btn0

using namespace chip;
Expand Down
2 changes: 0 additions & 2 deletions examples/light-switch-app/silabs/SiWx917/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#include "AppEvent.h"
#include "BindingHandler.h"

#ifdef ENABLE_WSTK_LEDS
#include "LEDWidget.h"
#endif // ENABLE_WSTK_LEDS

#include "LightSwitchMgr.h"

Expand Down
3 changes: 0 additions & 3 deletions examples/light-switch-app/silabs/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
#include "AppEvent.h"
#include "BindingHandler.h"

#ifdef ENABLE_WSTK_LEDS
#include "LEDWidget.h"
#include "sl_simple_led_instances.h"
#endif // ENABLE_WSTK_LEDS

#include "LightSwitchMgr.h"

Expand Down
6 changes: 0 additions & 6 deletions examples/lighting-app/silabs/SiWx917/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,15 @@

#include <platform/CHIPDeviceLayer.h>

#ifdef ENABLE_WSTK_LEDS
#include "LEDWidget.h"
#define APP_ACTION_LED 1
#endif // ENABLE_WSTK_LEDS

using namespace chip;
using namespace ::chip::DeviceLayer;

namespace {

#ifdef ENABLE_WSTK_LEDS
LEDWidget sLightLED;
#endif // ENABLE_WSTK_LEDS

EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;

Expand Down Expand Up @@ -143,10 +139,8 @@ CHIP_ERROR AppTask::Init()

LightMgr().SetCallbacks(ActionInitiated, ActionCompleted);

#ifdef ENABLE_WSTK_LEDS
sLightLED.Init(APP_ACTION_LED);
sLightLED.Set(LightMgr().IsLightOn());
#endif // ENABLE_WSTK_LEDS

return err;
}
Expand Down
15 changes: 2 additions & 13 deletions examples/lighting-app/silabs/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
#include "AppConfig.h"
#include "AppEvent.h"

#ifdef ENABLE_WSTK_LEDS
#include "LEDWidget.h"
#include "sl_simple_led_instances.h"
#endif // ENABLE_WSTK_LEDS

#include <app/clusters/identify-server/identify-server.h>
#include <app/clusters/on-off-server/on-off-server.h>
Expand All @@ -41,13 +38,11 @@

#include <platform/CHIPDeviceLayer.h>

#ifdef ENABLE_WSTK_LEDS
#if defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT)
#define LIGHT_LED &sl_led_led1
#define LIGHT_LED 1
#else
#define LIGHT_LED &sl_led_led0
#define LIGHT_LED 0
#endif
#endif // ENABLE_WSTK_LEDS

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT

Expand All @@ -60,9 +55,7 @@ using namespace ::chip::DeviceLayer;

namespace {

#ifdef ENABLE_WSTK_LEDS
LEDWidget sLightLED;
#endif // ENABLE_WSTK_LEDS

EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;

Expand Down Expand Up @@ -157,10 +150,8 @@ CHIP_ERROR AppTask::Init()

LightMgr().SetCallbacks(ActionInitiated, ActionCompleted);

#ifdef ENABLE_WSTK_LEDS
sLightLED.Init(LIGHT_LED);
sLightLED.Set(LightMgr().IsLightOn());
#endif // ENABLE_WSTK_LEDS

// Update the LCD with the Stored value. Show QR Code if not provisioned
#ifdef DISPLAY_ENABLED
Expand Down Expand Up @@ -298,9 +289,7 @@ void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
bool lightOn = aAction == LightingManager::ON_ACTION;
SILABS_LOG("Turning light %s", (lightOn) ? "On" : "Off")

#ifdef ENABLE_WSTK_LEDS
sLightLED.Set(lightOn);
#endif // ENABLE_WSTK_LEDS

#ifdef DISPLAY_ENABLED
sAppTask.GetLCD().WriteDemoUI(lightOn);
Expand Down
7 changes: 5 additions & 2 deletions examples/lighting-app/silabs/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <AppTask.h>

#include "AppConfig.h"
#include "init_efrPlatform.h"
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
#include "sl_simple_button_instances.h"
#endif
Expand All @@ -35,11 +34,14 @@
#include <credentials/examples/DeviceAttestationCredsExample.h>
#endif

#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

#define BLE_DEV_NAME "SiLabs-Light"
using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;
using namespace ::chip::Credentials;
using namespace chip::DeviceLayer::Silabs;

#define UNUSED_PARAMETER(a) (a = a)

Expand All @@ -51,7 +53,8 @@ static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider;
// ================================================================================
int main(void)
{
init_efrPlatform();
GetPlatform().Init();

if (SilabsMatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR)
appError(CHIP_ERROR_INTERNAL);

Expand Down
11 changes: 0 additions & 11 deletions examples/lock-app/silabs/SiWx917/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
#include "EventHandlerLibShell.h"
#endif // ENABLE_CHIP_SHELL

#ifdef ENABLE_WSTK_LEDS
#include "LEDWidget.h"
#endif // ENABLE_WSTK_LEDS

#ifdef DISPLAY_ENABLED
#include "lcd.h"
Expand All @@ -53,9 +51,7 @@

#include <platform/CHIPDeviceLayer.h>

#ifdef ENABLE_WSTK_LEDS
#define LOCK_STATE_LED 1
#endif // ENABLE_WSTK_LEDS

using chip::app::Clusters::DoorLock::DlLockState;
using chip::app::Clusters::DoorLock::OperationErrorEnum;
Expand All @@ -67,9 +63,7 @@ using namespace ::chip::DeviceLayer::Internal;
using namespace SI917DoorLock::LockInitParams;

namespace {
#ifdef ENABLE_WSTK_LEDS
LEDWidget sLockLED;
#endif // ENABLE_WSTK_LEDS

EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;
} // namespace
Expand Down Expand Up @@ -238,11 +232,8 @@ CHIP_ERROR AppTask::Init()

LockMgr().SetCallbacks(ActionInitiated, ActionCompleted);

#ifdef ENABLE_WSTK_LEDS
// Initialize LEDs
sLockLED.Init(LOCK_STATE_LED);
sLockLED.Set(state.Value() == DlLockState::kUnlocked);
#endif // ENABLE_WSTK_LEDS

chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));

Expand Down Expand Up @@ -371,9 +362,7 @@ void AppTask::ActionInitiated(LockManager::Action_t aAction, int32_t aActor)
{
bool locked = (aAction == LockManager::LOCK_ACTION);
SILABS_LOG("%s Action has been initiated", (locked) ? "Lock" : "Unlock");
#ifdef ENABLE_WSTK_LEDS
sLockLED.Set(!locked);
#endif // ENABLE_WSTK_LEDS

#ifdef DISPLAY_ENABLED
sAppTask.GetLCD().WriteDemoUI(locked);
Expand Down
17 changes: 2 additions & 15 deletions examples/lock-app/silabs/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
#include "EventHandlerLibShell.h"
#endif // ENABLE_CHIP_SHELL

#ifdef ENABLE_WSTK_LEDS
#include "LEDWidget.h"
#include "sl_simple_led_instances.h"
#endif // ENABLE_WSTK_LEDS

#ifdef DISPLAY_ENABLED
#include "lcd.h"
Expand All @@ -53,11 +50,8 @@
#include <lib/support/CodeUtils.h>

#include <platform/CHIPDeviceLayer.h>

#ifdef ENABLE_WSTK_LEDS
#define SYSTEM_STATE_LED &sl_led_led0
#define LOCK_STATE_LED &sl_led_led1
#endif // ENABLE_WSTK_LEDS
#define SYSTEM_STATE_LED 0
#define LOCK_STATE_LED 1

#define APP_FUNCTION_BUTTON &sl_button_btn0
#define APP_LOCK_SWITCH &sl_button_btn1
Expand All @@ -72,9 +66,7 @@ using namespace ::chip::DeviceLayer::Internal;
using namespace EFR32DoorLock::LockInitParams;

namespace {
#ifdef ENABLE_WSTK_LEDS
LEDWidget sLockLED;
#endif // ENABLE_WSTK_LEDS

EmberAfIdentifyEffectIdentifier sIdentifyEffect = EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT;
} // namespace
Expand Down Expand Up @@ -243,11 +235,8 @@ CHIP_ERROR AppTask::Init()

LockMgr().SetCallbacks(ActionInitiated, ActionCompleted);

#ifdef ENABLE_WSTK_LEDS
// Initialize LEDs
sLockLED.Init(LOCK_STATE_LED);
sLockLED.Set(state.Value() == DlLockState::kUnlocked);
#endif // ENABLE_WSTK_LEDS

// Update the LCD with the Stored value. Show QR Code if not provisioned
#ifdef DISPLAY_ENABLED
Expand Down Expand Up @@ -395,9 +384,7 @@ void AppTask::ActionInitiated(LockManager::Action_t aAction, int32_t aActor)
{
bool locked = (aAction == LockManager::LOCK_ACTION);
SILABS_LOG("%s Action has been initiated", (locked) ? "Lock" : "Unlock");
#ifdef ENABLE_WSTK_LEDS
sLockLED.Set(!locked);
#endif // ENABLE_WSTK_LEDS

#ifdef DISPLAY_ENABLED
sAppTask.GetLCD().WriteDemoUI(locked);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
#include "LEDWidget.h"

#include <platform/CHIPDeviceLayer.h>
#include <platform/silabs/platformAbstraction/SilabsPlatform.h>

using namespace ::chip::System;
using namespace chip::DeviceLayer::Silabs;

void LEDWidget::Init(int led)
void LEDWidget::InitGpio(void)
{
// Sets gpio pin mode for ALL board Leds.
GetPlatform().InitLed();
}

void LEDWidget::Init(const uint8_t led)
{
mLastChangeTimeMS = 0;
mBlinkOnTimeMS = 0;
Expand All @@ -36,14 +44,14 @@ void LEDWidget::Init(int led)

void LEDWidget::Invert(void)
{
RSI_Board_LED_Toggle(mLed);
GetPlatform().ToggleLed(mLed);
mLedStatus = !mLedStatus;
}

void LEDWidget::Set(bool state)
{
mLastChangeTimeMS = mBlinkOnTimeMS = mBlinkOffTimeMS = 0;
state ? RSI_Board_LED_Set(mLed, true) : RSI_Board_LED_Set(mLed, false);
GetPlatform().SetLed(state, mLed);
mLedStatus = state;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@

#pragma once

#include "sl_led.h"
#include <stdint.h>

class LEDWidget
{
public:
static void InitGpio(void);
void Init(const sl_led_t * led);
void Init(uint8_t led);
void Set(bool state);
void Invert(void);
void Blink(uint32_t changeRateMS);
Expand All @@ -37,5 +36,6 @@ class LEDWidget
uint64_t mLastChangeTimeMS;
uint32_t mBlinkOnTimeMS;
uint32_t mBlinkOffTimeMS;
const sl_led_t * mLed;
uint8_t mLed;
bool mLedStatus;
};
5 changes: 1 addition & 4 deletions examples/platform/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ source_set("siwx917-common") {
]

sources = [
"${silabs_common_plat_dir}/LEDWidget.cpp",
"${silabs_common_plat_dir}/heap_4_silabs.c",
"${wifi_sdk_dir}/dhcp_client.cpp",
"${wifi_sdk_dir}/ethernetif.cpp",
Expand All @@ -252,10 +253,6 @@ source_set("siwx917-common") {
sources += [ "BaseApplication.cpp" ]
}

if (use_wstk_leds) {
sources += [ "LEDWidget.cpp" ]
}

if (chip_enable_pw_rpc || chip_build_libshell) {
sources += [ "uart.cpp" ]
}
Expand Down
Loading

0 comments on commit 1702492

Please sign in to comment.