Skip to content

Commit

Permalink
[siwx917] enabled LED and Button support, updated BLE adv time interv…
Browse files Browse the repository at this point in the history
…al and clock to 180MHz
  • Loading branch information
silabs-srishylam committed Jan 24, 2023
1 parent 8f926b8 commit 8b481c8
Show file tree
Hide file tree
Showing 24 changed files with 647 additions and 173 deletions.
2 changes: 1 addition & 1 deletion examples/light-switch-app/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ efr32_executable("light_switch_app") {
]

if (use_wstk_leds) {
#sources += [ "${examples_plat_dir}/LEDWidget.cpp" ]
sources += [ "${examples_plat_dir}/LEDWidget.cpp" ]
}

if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli ||
Expand Down
48 changes: 3 additions & 45 deletions examples/light-switch-app/silabs/SiWx917/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,49 +38,7 @@
/**********************************************************
* Defines
*********************************************************/

#define SL_SIMPLE_BUTTON_MODE_POLL 0U ///< BUTTON input capture using polling
#define SL_SIMPLE_BUTTON_MODE_POLL_AND_DEBOUNCE 1U ///< BUTTON input capture using polling and debouncing
#define SL_SIMPLE_BUTTON_MODE_INTERRUPT 2U ///< BUTTON input capture using interrupt

#define SL_SIMPLE_BUTTON_DISABLED 2U ///< BUTTON state is disabled
#define SL_SIMPLE_BUTTON_PRESSED 1U ///< BUTTON state is pressed
#define SL_SIMPLE_BUTTON_RELEASED 0U ///< BUTTON state is released

typedef uint8_t sl_button_mode_t; ///< BUTTON mode
typedef uint8_t sl_button_state_t; ///< BUTTON state
typedef struct sl_button sl_button_t;

/// A BUTTON instance
typedef struct sl_button
{
void * context; ///< The context for this BUTTON instance
void (*init)(const sl_button_t * handle); ///< Member function to initialize BUTTON instance
void (*poll)(const sl_button_t * handle); ///< Member function to poll BUTTON
void (*enable)(const sl_button_t * handle); ///< Member function to enable BUTTON
void (*disable)(const sl_button_t * handle); ///< Member function to disable BUTTON
sl_button_state_t (*get_state)(const sl_button_t * handle); ///< Member function to retrieve BUTTON state
} sl_button;

const sl_button_t sl_button_btn0 = {
.context = NULL,
.init = NULL,
.poll = NULL,
.enable = NULL,
.disable = NULL,
.get_state = NULL,
};
#define APP_FUNCTION_BUTTON &sl_button_btn0

const sl_button_t sl_button_btn1 = {
.context = NULL,
.init = NULL,
.poll = NULL,
.enable = NULL,
.disable = NULL,
.get_state = NULL,
};
#define APP_LIGHT_SWITCH &sl_button_btn1
#define SL_SIMPLE_BUTTON_PRESSED 1U

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
Expand Down Expand Up @@ -115,11 +73,11 @@ class AppTask : public BaseApplication
* @brief Event handler when a button is pressed
* Function posts an event for button processing
*
* @param buttonHandle APP_LIGHT_SWITCH or APP_FUNCTION_BUTTON
* @param button - btn0 or btn1
* @param btnAction button action - SL_SIMPLE_BUTTON_PRESSED,
* SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
*/
void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction);
void ButtonEventHandler(uint8_t button, uint8_t btnAction);

/**
* @brief Callback called by the identify-server when an identify command is received
Expand Down
23 changes: 11 additions & 12 deletions examples/light-switch-app/silabs/SiWx917/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@

#define SYSTEM_STATE_LED &sl_led_led0

#define APP_FUNCTION_BUTTON &sl_button_btn0
#define APP_LIGHT_SWITCH &sl_button_btn1

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

Expand Down Expand Up @@ -247,17 +244,19 @@ void AppTask::SwitchActionEventHandler(AppEvent * aEvent)
}
}

void AppTask::ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction)
void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
{
if (buttonHandle == NULL)
{
return;
}

AppEvent button_event = {};
button_event.Type = AppEvent::kEventType_Button;
button_event.ButtonEvent.Action = btnAction;

button_event.Handler = SwitchActionEventHandler;
sAppTask.PostEvent(&button_event);
if (button == 1)
{
button_event.Handler = SwitchActionEventHandler;
sAppTask.PostEvent(&button_event);
}
else if (button == 0)
{
button_event.Handler = BaseApplication::ButtonHandler;
sAppTask.PostEvent(&button_event);
}
}
6 changes: 3 additions & 3 deletions examples/light-switch-app/silabs/SiWx917/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#define BLE_DEV_NAME "SiLabs-Light-Switch"

extern "C" void sl_button_on_change();
extern "C" void sl_button_on_change(uint8_t btn, uint8_t btnAction);

using namespace ::chip;
using namespace ::chip::Inet;
Expand Down Expand Up @@ -81,7 +81,7 @@ int main(void)
appError(CHIP_ERROR_INTERNAL);
}

void sl_button_on_change()
void sl_button_on_change(uint8_t btn,uint8_t btnAction)
{
AppTask::GetAppTask().ButtonEventHandler(APP_LIGHT_SWITCH, SL_SIMPLE_BUTTON_PRESSED);
AppTask::GetAppTask().ButtonEventHandler(btn, btnAction);
}
3 changes: 1 addition & 2 deletions examples/lighting-app/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ efr32_executable("lighting_app") {
]

if (use_wstk_leds) {
# TODO: Commentting for CCP till the bring up of this is done
#sources += [ "${examples_plat_dir}/LEDWidget.cpp" ]
sources += [ "${examples_plat_dir}/LEDWidget.cpp" ]
}

if (chip_enable_pw_rpc || chip_build_libshell || use_rs911x) {
Expand Down
11 changes: 11 additions & 0 deletions examples/lighting-app/silabs/SiWx917/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
/**********************************************************
* Defines
*********************************************************/
#define SL_SIMPLE_BUTTON_PRESSED 1

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
Expand Down Expand Up @@ -69,6 +70,16 @@ class AppTask : public BaseApplication

CHIP_ERROR StartAppTask();

/**
* @brief Event handler when a button is pressed
* Function posts an event for button processing
*
* @param button - btn0 or btn1
* @param btnAction button action - SL_SIMPLE_BUTTON_PRESSED,
* SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
*/
void ButtonEventHandler(uint8_t button, uint8_t btnAction);

/**
* @brief Callback called by the identify-server when an identify command is received
*
Expand Down
54 changes: 42 additions & 12 deletions examples/lighting-app/silabs/SiWx917/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,23 @@

#include <platform/CHIPDeviceLayer.h>

#define APP_FUNCTION_BUTTON &sl_button_btn0
#define APP_LIGHT_SWITCH &sl_button_btn1
#ifdef ENABLE_WSTK_LEDS
#include "LEDWidget.h"
#endif // ENABLE_WSTK_LEDS

#ifdef ENABLE_WSTK_LEDS
#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 @@ -130,16 +139,19 @@ CHIP_ERROR AppTask::Init()
appError(err);
}

/* TODO
err = LightMgr().Init();
if (err != CHIP_NO_ERROR)
{
SILABS_LOG("LightMgr::Init() failed");
appError(err);
}
err = LightMgr().Init();
if (err != CHIP_NO_ERROR)
{
SILABS_LOG("LightMgr::Init() failed");
appError(err);
}

LightMgr().SetCallbacks(ActionInitiated, ActionCompleted);
*/
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 Expand Up @@ -229,11 +241,29 @@ void AppTask::LightActionEventHandler(AppEvent * aEvent)
}
}

void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction)
{
AppEvent button_event = {};
button_event.Type = AppEvent::kEventType_Button;
button_event.ButtonEvent.Action = btnAction;
if (button == 1 && btnAction == SL_SIMPLE_BUTTON_PRESSED)
{
button_event.Handler = LightActionEventHandler;
sAppTask.PostEvent(&button_event);
}
else if (button == 0)
{
button_event.Handler = BaseApplication::ButtonHandler;
sAppTask.PostEvent(&button_event);
}
}

void AppTask::ActionInitiated(LightingManager::Action_t aAction, int32_t aActor)
{
// Action initiated, update the light led
bool lightOn = aAction == LightingManager::ON_ACTION;
SILABS_LOG("Turning light %s", (lightOn) ? "On" : "Off")
SILABS_LOG("Turning light %s", (lightOn) ? "On" : "Off");
sLightLED.Set(lightOn);

#ifdef DISPLAY_ENABLED
sAppTask.GetLCD().WriteDemoUI(lightOn);
Expand Down
8 changes: 8 additions & 0 deletions examples/lighting-app/silabs/SiWx917/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
#endif

#define BLE_DEV_NAME "SiLabs-Light"

extern "C" void sl_button_on_change(uint8_t btn, uint8_t btnAction);

using namespace ::chip;
using namespace ::chip::Inet;
using namespace ::chip::DeviceLayer;
Expand Down Expand Up @@ -80,3 +83,8 @@ int main(void)
SILABS_LOG("vTaskStartScheduler() failed");
appError(CHIP_ERROR_INTERNAL);
}

void sl_button_on_change(uint8_t btn,uint8_t btnAction)
{
AppTask::GetAppTask().ButtonEventHandler(btn, btnAction);
}
2 changes: 1 addition & 1 deletion examples/lock-app/silabs/SiWx917/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ efr32_executable("lock_app") {
]

if (use_wstk_leds) {
#sources += [ "${examples_plat_dir}/LEDWidget.cpp" ]
sources += [ "${examples_plat_dir}/LEDWidget.cpp" ]
}

if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli ||
Expand Down
46 changes: 2 additions & 44 deletions examples/lock-app/silabs/SiWx917/include/AppTask.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include "BaseApplication.h"
#include "FreeRTOS.h"
#include "LockManager.h"
//#include "sl_simple_button_instances.h"
#include "timers.h" // provides FreeRTOS timer support
#include <app/clusters/identify-server/identify-server.h>
#include <ble/BLEEndPoint.h>
Expand All @@ -40,48 +39,7 @@
/**********************************************************
* Defines
*********************************************************/
#define SL_SIMPLE_BUTTON_MODE_POLL 0U ///< BUTTON input capture using polling
#define SL_SIMPLE_BUTTON_MODE_POLL_AND_DEBOUNCE 1U ///< BUTTON input capture using polling and debouncing
#define SL_SIMPLE_BUTTON_MODE_INTERRUPT 2U ///< BUTTON input capture using interrupt

#define SL_SIMPLE_BUTTON_DISABLED 2U ///< BUTTON state is disabled
#define SL_SIMPLE_BUTTON_PRESSED 1U ///< BUTTON state is pressed
#define SL_SIMPLE_BUTTON_RELEASED 0U ///< BUTTON state is released

typedef uint8_t sl_button_mode_t; ///< BUTTON mode
typedef uint8_t sl_button_state_t; ///< BUTTON state
typedef struct sl_button sl_button_t;

/// A BUTTON instance
typedef struct sl_button
{
void * context; ///< The context for this BUTTON instance
void (*init)(const sl_button_t * handle); ///< Member function to initialize BUTTON instance
void (*poll)(const sl_button_t * handle); ///< Member function to poll BUTTON
void (*enable)(const sl_button_t * handle); ///< Member function to enable BUTTON
void (*disable)(const sl_button_t * handle); ///< Member function to disable BUTTON
sl_button_state_t (*get_state)(const sl_button_t * handle); ///< Member function to retrieve BUTTON state
} sl_button;

const sl_button_t sl_button_btn0 = {
.context = NULL,
.init = NULL,
.poll = NULL,
.enable = NULL,
.disable = NULL,
.get_state = NULL,
};
#define APP_FUNCTION_BUTTON &sl_button_btn0

const sl_button_t sl_button_btn1 = {
.context = NULL,
.init = NULL,
.poll = NULL,
.enable = NULL,
.disable = NULL,
.get_state = NULL,
};
#define APP_LIGHT_SWITCH &sl_button_btn1
#define SL_SIMPLE_BUTTON_PRESSED 1

// Application-defined error codes in the CHIP_ERROR space.
#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01)
Expand Down Expand Up @@ -128,7 +86,7 @@ class AppTask : public BaseApplication
* @param btnAction button action - SL_SIMPLE_BUTTON_PRESSED,
* SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED
*/
void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction);
void ButtonEventHandler(uint8_t button, uint8_t btnAction);

/**
* @brief Callback called by the identify-server when an identify command is received
Expand Down
Loading

0 comments on commit 8b481c8

Please sign in to comment.