Skip to content

Commit

Permalink
Add initial board support (#24606)
Browse files Browse the repository at this point in the history
  • Loading branch information
jepenven-silabs authored and pull[bot] committed Aug 3, 2023
1 parent 761bdd1 commit 3986046
Show file tree
Hide file tree
Showing 12 changed files with 181 additions and 55 deletions.
7 changes: 6 additions & 1 deletion examples/lighting-app/silabs/efr32/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ if (chip_enable_wifi) {

# ThunderBoards, Explorer Kit and MGM240L do not support LCD (No LCD)
if (silabs_board == "BRD4166A" || silabs_board == "BRD2601B" ||
silabs_board == "BRD2703A" || silabs_board == "BRD4319A") {
silabs_board == "BRD2703A" || silabs_board == "BRD4319A" ||
silabs_board == "BRD2704A") {
show_qr_code = false
disable_lcd = true
}
Expand Down Expand Up @@ -208,6 +209,10 @@ efr32_executable("lighting_app") {
include_dirs = [ "include" ]
defines = []

if (silabs_board == "BRD2704A") {
defines += [ "SL_STATUS_LED=0" ]
}

sources = [
"${examples_common_plat_dir}/heap_4_silabs.c",
"${examples_plat_dir}/BaseApplication.cpp",
Expand Down
6 changes: 4 additions & 2 deletions examples/lighting-app/silabs/efr32/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "BaseApplication.h"
#include "FreeRTOS.h"
#include "LightingManager.h"
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
#include "sl_simple_button_instances.h"
#endif
#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/identify-server/identify-server.h>
#include <ble/BLEEndPoint.h>
Expand Down Expand Up @@ -69,7 +71,7 @@ class AppTask : public BaseApplication
static void AppTaskMain(void * pvParameter);

CHIP_ERROR StartAppTask();

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
/**
* @brief Event handler when a button is pressed
* Function posts an event for button processing
Expand All @@ -79,7 +81,7 @@ class AppTask : public BaseApplication
* SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
*/
void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction) override;

#endif
/**
* @brief Callback called by the identify-server when an identify command is received
*
Expand Down
20 changes: 16 additions & 4 deletions examples/lighting-app/silabs/efr32/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,18 @@
#include <platform/CHIPDeviceLayer.h>

#ifdef ENABLE_WSTK_LEDS
#define SYSTEM_STATE_LED &sl_led_led0
#if SL_STATUS_LED
#define LIGHT_LED &sl_led_led1
#else
#define LIGHT_LED &sl_led_led0
#endif
#endif // ENABLE_WSTK_LEDS

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT

#define APP_FUNCTION_BUTTON &sl_button_btn0
#define APP_LIGHT_SWITCH &sl_button_btn1
#endif

using namespace chip;
using namespace ::chip::DeviceLayer;
Expand Down Expand Up @@ -225,11 +231,13 @@ void AppTask::LightActionEventHandler(AppEvent * aEvent)
action = static_cast<LightingManager::Action_t>(aEvent->LightEvent.Action);
actor = aEvent->LightEvent.Actor;
}
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
else if (aEvent->Type == AppEvent::kEventType_Button)
{
action = (LightMgr().IsLightOn()) ? LightingManager::OFF_ACTION : LightingManager::ON_ACTION;
actor = AppEvent::kEventType_Button;
}
#endif
else
{
err = APP_ERROR_UNHANDLED_EVENT;
Expand All @@ -245,7 +253,7 @@ void AppTask::LightActionEventHandler(AppEvent * aEvent)
}
}
}

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
void AppTask::ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction)
{
if (buttonHandle == NULL)
Expand All @@ -269,6 +277,8 @@ void AppTask::ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAc
}
}

#endif

void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
{
// Action initiated, update the light led
Expand All @@ -282,11 +292,12 @@ void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
#ifdef DISPLAY_ENABLED
sAppTask.GetLCD().WriteDemoUI(lightOn);
#endif

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
if (aActor == AppEvent::kEventType_Button)
{
sAppTask.mSyncClusterToButtonAction = true;
}
#endif
}

void AppTask::ActionCompleted(LightingManager::Action_t aAction)
Expand All @@ -300,12 +311,13 @@ void AppTask::ActionCompleted(LightingManager::Action_t aAction)
{
SILABS_LOG("Light OFF")
}

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
if (sAppTask.mSyncClusterToButtonAction)
{
chip::DeviceLayer::PlatformMgr().ScheduleWork(UpdateClusterState, reinterpret_cast<intptr_t>(nullptr));
sAppTask.mSyncClusterToButtonAction = false;
}
#endif
}

void AppTask::PostLightActionRequest(int32_t aActor, LightingManager::Action_t aAction)
Expand Down
4 changes: 4 additions & 0 deletions examples/lighting-app/silabs/efr32/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@

#include "AppConfig.h"
#include "init_efrPlatform.h"
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
#include "sl_simple_button_instances.h"
#endif
#include "sl_system_kernel.h"
#include <DeviceInfoProviderImpl.h>
#include <app/server/Server.h>
Expand Down Expand Up @@ -78,7 +80,9 @@ int main(void)
appError(CHIP_ERROR_INTERNAL);
}

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
void sl_button_on_change(const sl_button_t * handle)
{
AppTask::GetAppTask().ButtonEventHandler(handle, sl_button_get_state(handle));
}
#endif
42 changes: 23 additions & 19 deletions examples/platform/silabs/efr32/BaseApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include "AppEvent.h"
#include "AppTask.h"

#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
#include "LEDWidget.h"
#include "sl_simple_led_instances.h"
#endif // ENABLE_WSTK_LEDS
Expand Down Expand Up @@ -74,11 +74,12 @@
#define APP_EVENT_QUEUE_SIZE 10
#define EXAMPLE_VENDOR_ID 0xcafe

#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
#define SYSTEM_STATE_LED &sl_led_led0
#endif // ENABLE_WSTK_LEDS

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
#define APP_FUNCTION_BUTTON &sl_button_btn0
#endif

using namespace chip;
using namespace ::chip::DeviceLayer;
Expand All @@ -95,7 +96,7 @@ TimerHandle_t sLightTimer;
TaskHandle_t sAppTaskHandle;
QueueHandle_t sAppEventQueue;

#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
LEDWidget sStatusLED;
#endif // ENABLE_WSTK_LEDS

Expand Down Expand Up @@ -211,7 +212,7 @@ CHIP_ERROR BaseApplication::Init(Identify * identifyObj)

SILABS_LOG("Current Software Version: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING);

#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
LEDWidget::InitGpio();
sStatusLED.Init(SYSTEM_STATE_LED);
#endif // ENABLE_WSTK_LEDS
Expand Down Expand Up @@ -272,7 +273,7 @@ void BaseApplication::FunctionEventHandler(AppEvent * aEvent)

mFunction = kFunction_FactoryReset;

#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
// Turn off all LEDs before starting blink to make sure blink is
// co-ordinated.
sStatusLED.Set(false);
Expand Down Expand Up @@ -333,27 +334,27 @@ void BaseApplication::LightEventHandler()
{
if ((gIdentifyptr != nullptr) && (gIdentifyptr->mActive))
{
#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Blink(250, 250);
#endif // ENABLE_WSTK_LEDS
}
else if (sIdentifyEffect != EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_STOP_EFFECT)
{
if (sIdentifyEffect == EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BLINK)
{
#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Blink(50, 50);
#endif // ENABLE_WSTK_LEDS
}
if (sIdentifyEffect == EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_BREATHE)
{
#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Blink(1000, 1000);
#endif // ENABLE_WSTK_LEDS
}
if (sIdentifyEffect == EMBER_ZCL_IDENTIFY_EFFECT_IDENTIFIER_OKAY)
{
#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Blink(300, 700);
#endif // ENABLE_WSTK_LEDS
}
Expand All @@ -363,37 +364,37 @@ void BaseApplication::LightEventHandler()
{
if (sIsAttached)
{
#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Set(true);
#endif // ENABLE_WSTK_LEDS
}
else
{
#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Blink(950, 50);
#endif
}
}
else if (sHaveBLEConnections)
{
#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Blink(100, 100);
#endif // ENABLE_WSTK_LEDS
}
else
{
#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Blink(50, 950);
#endif // ENABLE_WSTK_LEDS
}
#endif // CHIP_DEVICE_CONFIG_ENABLE_SED
}

#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Animate();
#endif // ENABLE_WSTK_LEDS
}

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
void BaseApplication::ButtonHandler(AppEvent * aEvent)
{
// To trigger software update: press the APP_FUNCTION_BUTTON button briefly (<
Expand Down Expand Up @@ -440,7 +441,10 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
SILABS_LOG("Failed to open the Basic Commissioning Window");
}
}
else { SILABS_LOG("Network is already provisioned, Ble advertissement not enabled"); }
else
{
SILABS_LOG("Network is already provisioned, Ble advertissement not enabled");
}
}
else if (mFunctionTimerActive && mFunction == kFunction_FactoryReset)
{
Expand All @@ -457,7 +461,7 @@ void BaseApplication::ButtonHandler(AppEvent * aEvent)
}
}
}

#endif
void BaseApplication::CancelFunctionTimer()
{
if (xTimerStop(sFunctionTimer, 0) == pdFAIL)
Expand Down Expand Up @@ -500,7 +504,7 @@ void BaseApplication::StartStatusLEDTimer()

void BaseApplication::StopStatusLEDTimer()
{
#ifdef ENABLE_WSTK_LEDS
#if defined(ENABLE_WSTK_LEDS) && SL_STATUS_LED
sStatusLED.Set(false);
#endif // ENABLE_WSTK_LEDS

Expand Down
14 changes: 11 additions & 3 deletions examples/platform/silabs/efr32/BaseApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

#include "AppEvent.h"
#include "FreeRTOS.h"
#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
#include "sl_simple_button_instances.h"
#endif
#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/identify-server/identify-server.h>
#include <ble/BLEEndPoint.h>
Expand All @@ -43,6 +45,10 @@
#endif // QR_CODE_ENABLED
#endif // DISPLAY_ENABLED

#ifndef SL_STATUS_LED
#define SL_STATUS_LED 1
#endif

/**********************************************************
* Defines
*********************************************************/
Expand Down Expand Up @@ -87,7 +93,7 @@ class BaseApplication
*/
static SilabsLCD & GetLCD(void);
#endif

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
/**
* @brief Event handler when a button is pressed
* Function posts an event for button processing
Expand All @@ -98,6 +104,8 @@ class BaseApplication
*/
virtual void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction) = 0;

#endif

/**
* @brief Function called to start the LED light timer
*/
Expand Down Expand Up @@ -156,7 +164,7 @@ class BaseApplication
* @param aEvent post event being processed
*/
static void FunctionEventHandler(AppEvent * aEvent);

#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT
/**
* @brief PB0 Button event processing function
* Press and hold will trigger a factory reset timer start
Expand All @@ -165,7 +173,7 @@ class BaseApplication
* @param aEvent button event being processed
*/
static void ButtonHandler(AppEvent * aEvent);

#endif
/**
* @brief Light Timer finished callback function
* Calls LED processing function
Expand Down
Loading

0 comments on commit 3986046

Please sign in to comment.