Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[silabs] [siwx917] enabled LED and Button support, updated BLE adv time and clock freq #24608

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -200,7 +200,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
51 changes: 6 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,10 @@
/**********************************************************
* 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
// Button specific defines for SiWx917
#define SL_SIMPLE_BUTTON_PRESSED 1U
#define SIWx917_BTN0 0
#define SIWx917_BTN1 1

// 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 +76,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
20 changes: 11 additions & 9 deletions examples/light-switch-app/silabs/SiWx917/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@

#define SYSTEM_STATE_LED &sl_led_led0

#define APP_FUNCTION_BUTTON &sl_button_btn0
#define APP_LIGHT_SWITCH &sl_button_btn1

namespace {

constexpr chip::EndpointId kLightSwitchEndpoint = 1;
Expand Down Expand Up @@ -258,14 +255,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)
{
VerifyOrReturn(buttonHandle != NULL);

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

button_event.Handler = SwitchActionEventHandler;
sAppTask.PostEvent(&button_event);
if (button == SIWx917_BTN1)
{
button_event.Handler = SwitchActionEventHandler;
sAppTask.PostEvent(&button_event);
}
else if (button == SIWx917_BTN0)
{
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 @@ -204,8 +204,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
14 changes: 14 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,10 @@
/**********************************************************
* Defines
*********************************************************/
// Button specific defines for SiWx917
#define SL_SIMPLE_BUTTON_PRESSED 1
#define SIWx917_BTN0 0
#define SIWx917_BTN1 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 +73,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
51 changes: 39 additions & 12 deletions examples/lighting-app/silabs/SiWx917/src/AppTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,20 @@

#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"
#define APP_ACTION_LED 1
#endif // ENABLE_WSTK_LEDS
jmartinez-silabs marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -128,16 +134,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 @@ -227,11 +236,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 == SIWx917_BTN1 && btnAction == SL_SIMPLE_BUTTON_PRESSED)
{
button_event.Handler = LightActionEventHandler;
sAppTask.PostEvent(&button_event);
}
else if (button == SIWx917_BTN0)
{
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 @@ -197,7 +197,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
49 changes: 5 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,10 @@
/**********************************************************
* 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
// Button specific defines for SiWx917
#define SL_SIMPLE_BUTTON_PRESSED 1
#define SIWx917_BTN0 0
#define SIWx917_BTN1 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 +89,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