diff --git a/examples/chef/efr32/include/AppTask.h b/examples/chef/efr32/include/AppTask.h index a8e186083c23f6..afa323b2d277f1 100644 --- a/examples/chef/efr32/include/AppTask.h +++ b/examples/chef/efr32/include/AppTask.h @@ -77,7 +77,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) override; + static void ButtonEventHandler(uint8_t button, uint8_t btnAction) override; /** * @brief Callback called by the identify-server when an identify command is received diff --git a/examples/chef/efr32/src/AppTask.cpp b/examples/chef/efr32/src/AppTask.cpp index 397fab5d482f7d..04355d98fd2035 100644 --- a/examples/chef/efr32/src/AppTask.cpp +++ b/examples/chef/efr32/src/AppTask.cpp @@ -41,6 +41,8 @@ #include +#include + #include #include @@ -49,7 +51,7 @@ #include #define SYSTEM_STATE_LED 0 -#define APP_FUNCTION_BUTTON &sl_button_btn0 +#define APP_FUNCTION_BUTTON 0 using namespace chip; using namespace ::chip::DeviceLayer; @@ -123,6 +125,9 @@ AppTask AppTask::sAppTask; CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; +#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT + chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler); +#endif err = BaseApplication::Init(&gIdentify); if (err != CHIP_NO_ERROR) @@ -164,18 +169,13 @@ void AppTask::AppTaskMain(void * pvParameter) } } -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; - if (buttonHandle == APP_FUNCTION_BUTTON) + if (button == APP_FUNCTION_BUTTON) { button_event.Handler = BaseApplication::ButtonHandler; sAppTask.PostEvent(&button_event); diff --git a/examples/chef/efr32/src/main.cpp b/examples/chef/efr32/src/main.cpp deleted file mode 100644 index f1aa92f95935d8..00000000000000 --- a/examples/chef/efr32/src/main.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "AppConfig.h" -#include "init_efrPlatform.h" -#include "sl_simple_button_instances.h" -#include "sl_system_kernel.h" -#include -#include -#include -#include -#ifdef SILABS_ATTESTATION_CREDENTIALS -#include -#else -#include -#endif - -#define BLE_DEV_NAME "SiLabs-Chef-App" -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::DeviceLayer; -using namespace ::chip::Credentials; - -#define UNUSED_PARAMETER(a) (a = a) - -volatile int apperror_cnt; -static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; - -// ================================================================================ -// Main Code -// ================================================================================ -int main(void) -{ - init_efrPlatform(); - if (SilabsMatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); - chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Initialize device attestation config -#ifdef SILABS_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(EFR32::GetEFR32DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - SILABS_LOG("Starting App Task"); - if (AppTask::GetAppTask().StartAppTask() != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - SILABS_LOG("Starting FreeRTOS scheduler"); - sl_system_kernel_start(); - - // Should never get here. - chip::Platform::MemoryShutdown(); - SILABS_LOG("vTaskStartScheduler() failed"); - appError(CHIP_ERROR_INTERNAL); -} - -void sl_button_on_change(const sl_button_t * handle) -{ - AppTask::GetAppTask().ButtonEventHandler(handle, sl_button_get_state(handle)); -} diff --git a/examples/light-switch-app/silabs/SiWx917/BUILD.gn b/examples/light-switch-app/silabs/SiWx917/BUILD.gn index 2d41d77fc50ab6..62ddb969e9b594 100644 --- a/examples/light-switch-app/silabs/SiWx917/BUILD.gn +++ b/examples/light-switch-app/silabs/SiWx917/BUILD.gn @@ -73,9 +73,9 @@ silabs_executable("light_switch_app") { sources = [ "${chip_root}/examples/light-switch-app/silabs/common/BindingHandler.cpp", "${chip_root}/examples/light-switch-app/silabs/common/LightSwitchMgr.cpp", + "${examples_common_plat_dir}/main.cpp", "src/AppTask.cpp", "src/ZclCallbacks.cpp", - "src/main.cpp", ] deps = [ diff --git a/examples/light-switch-app/silabs/SiWx917/include/AppConfig.h b/examples/light-switch-app/silabs/SiWx917/include/AppConfig.h index a936fe1d8abaeb..b20cbf8fc20d55 100644 --- a/examples/light-switch-app/silabs/SiWx917/include/AppConfig.h +++ b/examples/light-switch-app/silabs/SiWx917/include/AppConfig.h @@ -23,6 +23,8 @@ #define APP_TASK_NAME "Lit" +#define BLE_DEV_NAME "SiLabs-Light-Switch" + // Time it takes in ms for the simulated actuator to move from one // state to another. #define ACTUATOR_MOVEMENT_PERIOS_MS 10 diff --git a/examples/light-switch-app/silabs/SiWx917/src/AppTask.cpp b/examples/light-switch-app/silabs/SiWx917/src/AppTask.cpp index d53505b3374775..3cf6d9a034cae7 100644 --- a/examples/light-switch-app/silabs/SiWx917/src/AppTask.cpp +++ b/examples/light-switch-app/silabs/SiWx917/src/AppTask.cpp @@ -52,6 +52,8 @@ #include +#include + /********************************************************** * Defines and Constants *********************************************************/ @@ -152,6 +154,9 @@ AppTask AppTask::sAppTask; CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; + + chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler); + #ifdef DISPLAY_ENABLED GetLCD().Init((uint8_t *) "Light Switch"); #endif diff --git a/examples/light-switch-app/silabs/SiWx917/src/main.cpp b/examples/light-switch-app/silabs/SiWx917/src/main.cpp deleted file mode 100644 index bdafdfbf61cb08..00000000000000 --- a/examples/light-switch-app/silabs/SiWx917/src/main.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "AppConfig.h" -#include "init_ccpPlatform.h" -#include -#include -#include -#include -#ifdef SILABS_ATTESTATION_CREDENTIALS -#include -#else -#include -#endif - -#define BLE_DEV_NAME "SiLabs-Light-Switch" - -extern "C" void sl_button_on_change(uint8_t btn, uint8_t btnAction); - -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::DeviceLayer; -using namespace ::chip::Credentials; - -#define UNUSED_PARAMETER(a) (a = a) - -volatile int apperror_cnt; -static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; - -// ================================================================================ -// Main Code -// ================================================================================ -int main(void) -{ - init_ccpPlatform(); - if (SilabsMatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) - { - appError(CHIP_ERROR_INTERNAL); - } - - gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); - chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Initialize device attestation config -#ifdef SILABS_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(SIWx917::GetSIWx917DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - SILABS_LOG("Starting App Task"); - if (AppTask::GetAppTask().StartAppTask() != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - SILABS_LOG("Starting FreeRTOS scheduler"); - vTaskStartScheduler(); - - // Should never get here. - chip::Platform::MemoryShutdown(); - SILABS_LOG("vTaskStartScheduler() failed"); - appError(CHIP_ERROR_INTERNAL); -} - -void sl_button_on_change(uint8_t btn, uint8_t btnAction) -{ - AppTask::GetAppTask().ButtonEventHandler(btn, btnAction); -} diff --git a/examples/light-switch-app/silabs/efr32/BUILD.gn b/examples/light-switch-app/silabs/efr32/BUILD.gn index a0e4d707e7c6cd..e989008ba0efb6 100644 --- a/examples/light-switch-app/silabs/efr32/BUILD.gn +++ b/examples/light-switch-app/silabs/efr32/BUILD.gn @@ -91,9 +91,9 @@ silabs_executable("light_switch_app") { sources = [ "${chip_root}/examples/light-switch-app/silabs/common/BindingHandler.cpp", "${chip_root}/examples/light-switch-app/silabs/common/LightSwitchMgr.cpp", + "${examples_common_plat_dir}/main.cpp", "src/AppTask.cpp", "src/ZclCallbacks.cpp", - "src/main.cpp", ] deps = [ diff --git a/examples/light-switch-app/silabs/efr32/include/AppConfig.h b/examples/light-switch-app/silabs/efr32/include/AppConfig.h index 5b0d0a461072d5..6d61bd11840cb6 100644 --- a/examples/light-switch-app/silabs/efr32/include/AppConfig.h +++ b/examples/light-switch-app/silabs/efr32/include/AppConfig.h @@ -23,6 +23,8 @@ #define APP_TASK_NAME "Lit" +#define BLE_DEV_NAME "SiLabs-Light-Switch" + // Time it takes in ms for the simulated actuator to move from one // state to another. #define ACTUATOR_MOVEMENT_PERIOS_MS 10 diff --git a/examples/light-switch-app/silabs/efr32/include/AppTask.h b/examples/light-switch-app/silabs/efr32/include/AppTask.h index a8e186083c23f6..20ced3fb49a323 100644 --- a/examples/light-switch-app/silabs/efr32/include/AppTask.h +++ b/examples/light-switch-app/silabs/efr32/include/AppTask.h @@ -77,7 +77,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) override; + static void ButtonEventHandler(uint8_t button, uint8_t btnAction); /** * @brief Callback called by the identify-server when an identify command is received diff --git a/examples/light-switch-app/silabs/efr32/src/AppTask.cpp b/examples/light-switch-app/silabs/efr32/src/AppTask.cpp index fab53ca052baf6..257104fb427568 100644 --- a/examples/light-switch-app/silabs/efr32/src/AppTask.cpp +++ b/examples/light-switch-app/silabs/efr32/src/AppTask.cpp @@ -48,14 +48,16 @@ #include +#include + /********************************************************** * Defines and Constants *********************************************************/ #define SYSTEM_STATE_LED &sl_led_led0 -#define APP_FUNCTION_BUTTON &sl_button_btn0 -#define APP_LIGHT_SWITCH &sl_button_btn1 +#define APP_FUNCTION_BUTTON 0 +#define APP_LIGHT_SWITCH 1 namespace { @@ -151,6 +153,10 @@ AppTask AppTask::sAppTask; CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; +#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT + chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler); +#endif + #ifdef DISPLAY_ENABLED GetLCD().Init((uint8_t *) "Light Switch"); #endif @@ -248,20 +254,18 @@ 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; - if (buttonHandle == APP_LIGHT_SWITCH) + if (button == APP_LIGHT_SWITCH) { button_event.Handler = SwitchActionEventHandler; sAppTask.PostEvent(&button_event); } - else if (buttonHandle == APP_FUNCTION_BUTTON) + else if (button == APP_FUNCTION_BUTTON) { button_event.Handler = BaseApplication::ButtonHandler; sAppTask.PostEvent(&button_event); diff --git a/examples/light-switch-app/silabs/efr32/src/main.cpp b/examples/light-switch-app/silabs/efr32/src/main.cpp deleted file mode 100644 index cd16d5f31b0ac2..00000000000000 --- a/examples/light-switch-app/silabs/efr32/src/main.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "AppConfig.h" -#include "init_efrPlatform.h" -#include "sl_simple_button_instances.h" -#include "sl_system_kernel.h" -#include -#include -#include -#include -#ifdef SILABS_ATTESTATION_CREDENTIALS -#include -#else -#include -#endif - -#define BLE_DEV_NAME "SiLabs-Light-Switch" -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::DeviceLayer; -using namespace ::chip::Credentials; - -#define UNUSED_PARAMETER(a) (a = a) - -volatile int apperror_cnt; -static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; - -// ================================================================================ -// Main Code -// ================================================================================ -int main(void) -{ - init_efrPlatform(); - if (SilabsMatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); - chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Initialize device attestation config -#ifdef SILABS_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(Silabs::GetSilabsDacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - SILABS_LOG("Starting App Task"); - if (AppTask::GetAppTask().StartAppTask() != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - SILABS_LOG("Starting FreeRTOS scheduler"); - sl_system_kernel_start(); - - // Should never get here. - chip::Platform::MemoryShutdown(); - SILABS_LOG("vTaskStartScheduler() failed"); - appError(CHIP_ERROR_INTERNAL); -} - -void sl_button_on_change(const sl_button_t * handle) -{ - AppTask::GetAppTask().ButtonEventHandler(handle, sl_button_get_state(handle)); -} diff --git a/examples/lighting-app/silabs/SiWx917/BUILD.gn b/examples/lighting-app/silabs/SiWx917/BUILD.gn index 05c1caaa3e72e6..b0bcf56032f81a 100644 --- a/examples/lighting-app/silabs/SiWx917/BUILD.gn +++ b/examples/lighting-app/silabs/SiWx917/BUILD.gn @@ -70,10 +70,10 @@ silabs_executable("lighting_app") { defines = [] sources = [ + "${examples_common_plat_dir}/main.cpp", "src/AppTask.cpp", "src/LightingManager.cpp", "src/ZclCallbacks.cpp", - "src/main.cpp", ] deps = [ diff --git a/examples/lighting-app/silabs/SiWx917/include/AppConfig.h b/examples/lighting-app/silabs/SiWx917/include/AppConfig.h index b86af8b22c2213..0b916a32f8452c 100644 --- a/examples/lighting-app/silabs/SiWx917/include/AppConfig.h +++ b/examples/lighting-app/silabs/SiWx917/include/AppConfig.h @@ -25,6 +25,8 @@ #define APP_TASK_NAME "Lit" +#define BLE_DEV_NAME "SiLabs-Light" + // Time it takes in ms for the simulated actuator to move from one // state to another. #define ACTUATOR_MOVEMENT_PERIOS_MS 10 diff --git a/examples/lighting-app/silabs/efr32/BUILD.gn b/examples/lighting-app/silabs/efr32/BUILD.gn index 5656bbf53db9ab..391226a9fc7bb9 100644 --- a/examples/lighting-app/silabs/efr32/BUILD.gn +++ b/examples/lighting-app/silabs/efr32/BUILD.gn @@ -107,10 +107,10 @@ silabs_executable("lighting_app") { } sources = [ + "${examples_common_plat_dir}/main.cpp", "src/AppTask.cpp", "src/LightingManager.cpp", "src/ZclCallbacks.cpp", - "src/main.cpp", ] deps = [ diff --git a/examples/lighting-app/silabs/efr32/include/AppConfig.h b/examples/lighting-app/silabs/efr32/include/AppConfig.h index 349f28d7c466d6..1cb27c78ae654c 100644 --- a/examples/lighting-app/silabs/efr32/include/AppConfig.h +++ b/examples/lighting-app/silabs/efr32/include/AppConfig.h @@ -25,6 +25,8 @@ #define APP_TASK_NAME "Lit" +#define BLE_DEV_NAME "SiLabs-Light" + // Time it takes in ms for the simulated actuator to move from one // state to another. #define ACTUATOR_MOVEMENT_PERIOS_MS 10 diff --git a/examples/lighting-app/silabs/efr32/include/AppTask.h b/examples/lighting-app/silabs/efr32/include/AppTask.h index cc76b02e8b293d..e80d6bf75a9276 100644 --- a/examples/lighting-app/silabs/efr32/include/AppTask.h +++ b/examples/lighting-app/silabs/efr32/include/AppTask.h @@ -80,7 +80,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) override; + static void ButtonEventHandler(uint8_t button, uint8_t btnAction); #endif /** * @brief Callback called by the identify-server when an identify command is received diff --git a/examples/lighting-app/silabs/efr32/src/AppTask.cpp b/examples/lighting-app/silabs/efr32/src/AppTask.cpp index 58197087f4b2cb..a1fc21b66fa4a1 100755 --- a/examples/lighting-app/silabs/efr32/src/AppTask.cpp +++ b/examples/lighting-app/silabs/efr32/src/AppTask.cpp @@ -31,6 +31,8 @@ #include +#include + #include #include @@ -46,8 +48,8 @@ #ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT -#define APP_FUNCTION_BUTTON &sl_button_btn0 -#define APP_LIGHT_SWITCH &sl_button_btn1 +#define APP_FUNCTION_BUTTON 0 +#define APP_LIGHT_SWITCH 1 #endif using namespace chip; @@ -130,6 +132,10 @@ AppTask AppTask::sAppTask; CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; +#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT + chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler); +#endif + #ifdef DISPLAY_ENABLED GetLCD().Init((uint8_t *) "Lighting-App"); #endif @@ -258,26 +264,21 @@ void AppTask::LightActionEventHandler(AppEvent * aEvent) } } #ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT -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; - if (buttonHandle == APP_LIGHT_SWITCH && btnAction == SL_SIMPLE_BUTTON_PRESSED) + if (button == APP_LIGHT_SWITCH && btnAction == SL_SIMPLE_BUTTON_PRESSED) { button_event.Handler = LightActionEventHandler; - sAppTask.PostEvent(&button_event); + AppTask::GetAppTask().PostEvent(&button_event); } - else if (buttonHandle == APP_FUNCTION_BUTTON) + else if (button == APP_FUNCTION_BUTTON) { button_event.Handler = BaseApplication::ButtonHandler; - sAppTask.PostEvent(&button_event); + AppTask::GetAppTask().PostEvent(&button_event); } } diff --git a/examples/lighting-app/silabs/efr32/src/main.cpp b/examples/lighting-app/silabs/efr32/src/main.cpp deleted file mode 100644 index 7bfae98d5b397f..00000000000000 --- a/examples/lighting-app/silabs/efr32/src/main.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "AppConfig.h" -#ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT -#include "sl_simple_button_instances.h" -#endif -#include "sl_system_kernel.h" -#include -#include -#include -#include -#ifdef SILABS_ATTESTATION_CREDENTIALS -#include -#else -#include -#endif - -#include - -#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) - -volatile int apperror_cnt; -static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; - -// ================================================================================ -// Main Code -// ================================================================================ -int main(void) -{ - GetPlatform().Init(); - - if (SilabsMatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); - chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Initialize device attestation config -#ifdef SILABS_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(Silabs::GetSilabsDacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - SILABS_LOG("Starting App Task"); - if (AppTask::GetAppTask().StartAppTask() != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - SILABS_LOG("Starting FreeRTOS scheduler"); - sl_system_kernel_start(); - - // Should never get here. - chip::Platform::MemoryShutdown(); - SILABS_LOG("vTaskStartScheduler() failed"); - 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 diff --git a/examples/lock-app/silabs/SiWx917/BUILD.gn b/examples/lock-app/silabs/SiWx917/BUILD.gn index 0d6bdcd9781be9..8c531d0ee62608 100644 --- a/examples/lock-app/silabs/SiWx917/BUILD.gn +++ b/examples/lock-app/silabs/SiWx917/BUILD.gn @@ -70,10 +70,10 @@ silabs_executable("lock_app") { defines = [] sources = [ + "${examples_common_plat_dir}/main.cpp", "src/AppTask.cpp", "src/LockManager.cpp", "src/ZclCallbacks.cpp", - "src/main.cpp", ] if (chip_build_libshell) { diff --git a/examples/lock-app/silabs/SiWx917/include/AppConfig.h b/examples/lock-app/silabs/SiWx917/include/AppConfig.h index 3014c5be66479c..f6985596d8993e 100644 --- a/examples/lock-app/silabs/SiWx917/include/AppConfig.h +++ b/examples/lock-app/silabs/SiWx917/include/AppConfig.h @@ -23,6 +23,8 @@ #define APP_TASK_NAME "Lock" +#define BLE_DEV_NAME "SiLabs-Door-Lock" + // Time it takes in ms for the simulated actuator to move from one // state to another. #define ACTUATOR_MOVEMENT_PERIOS_MS 10 diff --git a/examples/lock-app/silabs/SiWx917/src/AppTask.cpp b/examples/lock-app/silabs/SiWx917/src/AppTask.cpp index a85ac491927d3f..fe1d267e465f02 100644 --- a/examples/lock-app/silabs/SiWx917/src/AppTask.cpp +++ b/examples/lock-app/silabs/SiWx917/src/AppTask.cpp @@ -49,6 +49,8 @@ #include +#include + #include #define LOCK_STATE_LED 1 @@ -138,6 +140,8 @@ CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; + chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler); + #ifdef DISPLAY_ENABLED GetLCD().Init((uint8_t *) "Lock-App", true); #endif diff --git a/examples/lock-app/silabs/SiWx917/src/main.cpp b/examples/lock-app/silabs/SiWx917/src/main.cpp deleted file mode 100644 index d28689ff99cfb5..00000000000000 --- a/examples/lock-app/silabs/SiWx917/src/main.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "AppConfig.h" -#include "init_ccpPlatform.h" -#include -#include -#include -#include -#ifdef SILABS_ATTESTATION_CREDENTIALS -#include -#else -#include -#endif - -#define BLE_DEV_NAME "SiLabs-Door-Lock" -extern "C" void sl_button_on_change(uint8_t btn, uint8_t btnAction); - -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::DeviceLayer; -using namespace ::chip::Credentials; - -#define UNUSED_PARAMETER(a) (a = a) - -volatile int apperror_cnt; -static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; - -// ================================================================================ -// Main Code -// ================================================================================ -int main(void) -{ - init_ccpPlatform(); - - if (SilabsMatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); - chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Initialize device attestation config -#ifdef SILABS_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(SI917::GetSI917DacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - SILABS_LOG("Starting App Task"); - if (AppTask::GetAppTask().StartAppTask() != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - SILABS_LOG("Starting FreeRTOS scheduler"); - vTaskStartScheduler(); - - // Should never get here. - chip::Platform::MemoryShutdown(); - SILABS_LOG("vTaskStartScheduler() failed"); - appError(CHIP_ERROR_INTERNAL); -} - -void sl_button_on_change(uint8_t btn, uint8_t btnAction) -{ - AppTask::GetAppTask().ButtonEventHandler(btn, btnAction); -} diff --git a/examples/lock-app/silabs/efr32/BUILD.gn b/examples/lock-app/silabs/efr32/BUILD.gn index 10ecbfc88f8181..d70726b29d1b70 100644 --- a/examples/lock-app/silabs/efr32/BUILD.gn +++ b/examples/lock-app/silabs/efr32/BUILD.gn @@ -89,10 +89,10 @@ silabs_executable("lock_app") { defines = [] sources = [ + "${examples_common_plat_dir}/main.cpp", "src/AppTask.cpp", "src/LockManager.cpp", "src/ZclCallbacks.cpp", - "src/main.cpp", ] if (chip_build_libshell) { diff --git a/examples/lock-app/silabs/efr32/include/AppConfig.h b/examples/lock-app/silabs/efr32/include/AppConfig.h index 36856b8cb38ed8..405bb4691ad8e5 100644 --- a/examples/lock-app/silabs/efr32/include/AppConfig.h +++ b/examples/lock-app/silabs/efr32/include/AppConfig.h @@ -23,6 +23,8 @@ #define APP_TASK_NAME "Lock" +#define BLE_DEV_NAME "SiLabs-Door-Lock" + // Time it takes in ms for the simulated actuator to move from one // state to another. #define ACTUATOR_MOVEMENT_PERIOS_MS 10 diff --git a/examples/lock-app/silabs/efr32/include/AppTask.h b/examples/lock-app/silabs/efr32/include/AppTask.h index 0c7723475772be..4205a9b891f2a3 100644 --- a/examples/lock-app/silabs/efr32/include/AppTask.h +++ b/examples/lock-app/silabs/efr32/include/AppTask.h @@ -86,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) override; + static void ButtonEventHandler(uint8_t button, uint8_t btnAction); /** * @brief Callback called by the identify-server when an identify command is received diff --git a/examples/lock-app/silabs/efr32/src/AppTask.cpp b/examples/lock-app/silabs/efr32/src/AppTask.cpp index ed1b51df6831d4..93757638519773 100644 --- a/examples/lock-app/silabs/efr32/src/AppTask.cpp +++ b/examples/lock-app/silabs/efr32/src/AppTask.cpp @@ -49,12 +49,14 @@ #include +#include + #include #define SYSTEM_STATE_LED 0 #define LOCK_STATE_LED 1 -#define APP_FUNCTION_BUTTON &sl_button_btn0 -#define APP_LOCK_SWITCH &sl_button_btn1 +#define APP_FUNCTION_BUTTON 0 +#define APP_LOCK_SWITCH 1 using chip::app::Clusters::DoorLock::DlLockState; using chip::app::Clusters::DoorLock::OperationErrorEnum; @@ -141,6 +143,8 @@ CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; + chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler); + #ifdef DISPLAY_ENABLED GetLCD().Init((uint8_t *) "Lock-App", true); #endif @@ -355,23 +359,18 @@ void AppTask::LockActionEventHandler(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; - if (buttonHandle == APP_LOCK_SWITCH && btnAction == SL_SIMPLE_BUTTON_PRESSED) + if (button == APP_LOCK_SWITCH && btnAction == SL_SIMPLE_BUTTON_PRESSED) { button_event.Handler = LockActionEventHandler; sAppTask.PostEvent(&button_event); } - else if (buttonHandle == APP_FUNCTION_BUTTON) + else if (button == APP_FUNCTION_BUTTON) { button_event.Handler = BaseApplication::ButtonHandler; sAppTask.PostEvent(&button_event); diff --git a/examples/lock-app/silabs/efr32/src/main.cpp b/examples/lock-app/silabs/efr32/src/main.cpp deleted file mode 100644 index aef9ed112eb164..00000000000000 --- a/examples/lock-app/silabs/efr32/src/main.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "AppConfig.h" -#include "init_efrPlatform.h" -#include "sl_simple_button_instances.h" -#include "sl_system_kernel.h" -#include -#include -#include -#include -#ifdef SILABS_ATTESTATION_CREDENTIALS -#include -#else -#include -#endif - -#define BLE_DEV_NAME "SiLabs-Door-Lock" -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::DeviceLayer; -using namespace ::chip::Credentials; - -#define UNUSED_PARAMETER(a) (a = a) - -volatile int apperror_cnt; -static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; - -// ================================================================================ -// Main Code -// ================================================================================ -int main(void) -{ - init_efrPlatform(); - if (SilabsMatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); - chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Initialize device attestation config -#ifdef SILABS_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(Silabs::GetSilabsDacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - SILABS_LOG("Starting App Task"); - if (AppTask::GetAppTask().StartAppTask() != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - SILABS_LOG("Starting FreeRTOS scheduler"); - sl_system_kernel_start(); - - // Should never get here. - chip::Platform::MemoryShutdown(); - SILABS_LOG("vTaskStartScheduler() failed"); - appError(CHIP_ERROR_INTERNAL); -} - -void sl_button_on_change(const sl_button_t * handle) -{ - AppTask::GetAppTask().ButtonEventHandler(handle, sl_button_get_state(handle)); -} diff --git a/examples/platform/silabs/Rpc.cpp b/examples/platform/silabs/Rpc.cpp index e3c1fed77ecf84..5c3462bece6f0e 100644 --- a/examples/platform/silabs/Rpc.cpp +++ b/examples/platform/silabs/Rpc.cpp @@ -82,7 +82,7 @@ class Efr32Button final : public Button public: pw::Status Event(const chip_rpc_ButtonEvent & request, pw_protobuf_Empty & response) override { - AppTask::GetAppTask().ButtonEventHandler(SL_SIMPLE_BUTTON_INSTANCE(request.idx) /* PB 0 or PB 1 */, request.pushed); + AppTask::GetAppTask().ButtonEventHandler(request.idx /* PB 0 or PB 1 */, request.pushed); return pw::OkStatus(); } }; diff --git a/examples/platform/silabs/efr32/BaseApplication.cpp b/examples/platform/silabs/efr32/BaseApplication.cpp index 8d088bd4de3e13..9d096f23353cab 100644 --- a/examples/platform/silabs/efr32/BaseApplication.cpp +++ b/examples/platform/silabs/efr32/BaseApplication.cpp @@ -76,7 +76,7 @@ #define SYSTEM_STATE_LED 0 #endif // ENABLE_WSTK_LEDS #ifdef SL_CATALOG_SIMPLE_BUTTON_PRESENT -#define APP_FUNCTION_BUTTON &sl_button_btn0 +#define APP_FUNCTION_BUTTON 0 #endif using namespace chip; diff --git a/examples/platform/silabs/efr32/BaseApplication.h b/examples/platform/silabs/efr32/BaseApplication.h index eeb49702099993..191fcba4aaf3f3 100644 --- a/examples/platform/silabs/efr32/BaseApplication.h +++ b/examples/platform/silabs/efr32/BaseApplication.h @@ -93,18 +93,6 @@ class BaseApplication * @brief Return LCD object */ 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 - * - * @param buttonHandle APP_LIGHT_SWITCH or APP_FUNCTION_BUTTON - * @param btnAction button action - SL_SIMPLE_BUTTON_PRESSED, - * SL_SIMPLE_BUTTON_RELEASED or SL_SIMPLE_BUTTON_DISABLED - */ - virtual void ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction) = 0; - #endif /** diff --git a/examples/lighting-app/silabs/SiWx917/src/main.cpp b/examples/platform/silabs/main.cpp similarity index 81% rename from examples/lighting-app/silabs/SiWx917/src/main.cpp rename to examples/platform/silabs/main.cpp index ce2ae970887a40..a94696ef08374e 100644 --- a/examples/lighting-app/silabs/SiWx917/src/main.cpp +++ b/examples/platform/silabs/main.cpp @@ -20,7 +20,6 @@ #include #include "AppConfig.h" -#include "init_ccpPlatform.h" #include #include @@ -32,16 +31,12 @@ #include #endif -#define BLE_DEV_NAME "SiLabs-Light" - -extern "C" void sl_button_on_change(uint8_t btn, uint8_t btnAction); +#include using namespace ::chip; -using namespace ::chip::Inet; using namespace ::chip::DeviceLayer; using namespace ::chip::Credentials; - -#define UNUSED_PARAMETER(a) (a = a) +using namespace chip::DeviceLayer::Silabs; volatile int apperror_cnt; static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; @@ -51,11 +46,10 @@ static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; // ================================================================================ int main(void) { - init_ccpPlatform(); + GetPlatform().Init(); + if (SilabsMatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) - { appError(CHIP_ERROR_INTERNAL); - } gExampleDeviceInfoProvider.SetStorageDelegate(&chip::Server::GetInstance().GetPersistentStorage()); chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); @@ -63,7 +57,7 @@ int main(void) chip::DeviceLayer::PlatformMgr().LockChipStack(); // Initialize device attestation config #ifdef SILABS_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(Silabs::GetSilabsDacProvider()); + SetDeviceAttestationCredentialsProvider(Credentials::Silabs::GetSilabsDacProvider()); #else SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); #endif @@ -71,20 +65,13 @@ int main(void) SILABS_LOG("Starting App Task"); if (AppTask::GetAppTask().StartAppTask() != CHIP_NO_ERROR) - { appError(CHIP_ERROR_INTERNAL); - } - SILABS_LOG("Starting FreeRTOS scheduler"); - vTaskStartScheduler(); + SILABS_LOG("Starting scheduler"); + GetPlatform().StartScheduler(); // Should never get here. chip::Platform::MemoryShutdown(); SILABS_LOG("vTaskStartScheduler() failed"); appError(CHIP_ERROR_INTERNAL); } - -void sl_button_on_change(uint8_t btn, uint8_t btnAction) -{ - AppTask::GetAppTask().ButtonEventHandler(btn, btnAction); -} diff --git a/examples/thermostat/silabs/efr32/BUILD.gn b/examples/thermostat/silabs/efr32/BUILD.gn index ac33e5624e5987..31485ed1bcdc29 100644 --- a/examples/thermostat/silabs/efr32/BUILD.gn +++ b/examples/thermostat/silabs/efr32/BUILD.gn @@ -105,11 +105,11 @@ silabs_executable("thermostat_app") { defines = [] sources = [ + "${examples_common_plat_dir}/main.cpp", "src/AppTask.cpp", "src/SensorManager.cpp", "src/TemperatureManager.cpp", "src/ZclCallbacks.cpp", - "src/main.cpp", ] if (use_temp_sensor) { diff --git a/examples/thermostat/silabs/efr32/include/AppConfig.h b/examples/thermostat/silabs/efr32/include/AppConfig.h index ed3c7592aa6020..a1561de487da01 100644 --- a/examples/thermostat/silabs/efr32/include/AppConfig.h +++ b/examples/thermostat/silabs/efr32/include/AppConfig.h @@ -23,6 +23,8 @@ #define APP_TASK_NAME "Lit" +#define BLE_DEV_NAME "SiLabs-Thermostat" + // Time it takes in ms for the simulated actuator to move from one // state to another. #define ACTUATOR_MOVEMENT_PERIOS_MS 10 diff --git a/examples/thermostat/silabs/efr32/include/AppTask.h b/examples/thermostat/silabs/efr32/include/AppTask.h index ce4fa6f0fef43c..8e0458d8a6fdf1 100644 --- a/examples/thermostat/silabs/efr32/include/AppTask.h +++ b/examples/thermostat/silabs/efr32/include/AppTask.h @@ -88,7 +88,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) override; + static void ButtonEventHandler(uint8_t button, uint8_t btnAction); /** * @brief Callback called by the identify-server when an identify command is received diff --git a/examples/thermostat/silabs/efr32/src/AppTask.cpp b/examples/thermostat/silabs/efr32/src/AppTask.cpp index 21cee0c90cc122..f3f8fdecf2e5a2 100644 --- a/examples/thermostat/silabs/efr32/src/AppTask.cpp +++ b/examples/thermostat/silabs/efr32/src/AppTask.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -53,8 +54,8 @@ * Defines and Constants *********************************************************/ -#define APP_FUNCTION_BUTTON &sl_button_btn0 -#define APP_THERMOSTAT &sl_button_btn1 +#define APP_FUNCTION_BUTTON 0 +#define APP_THERMOSTAT 1 #define MODE_TIMER 1000 // 1s timer period @@ -142,6 +143,8 @@ CHIP_ERROR AppTask::Init() { CHIP_ERROR err = CHIP_NO_ERROR; + chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(AppTask::ButtonEventHandler); + #ifdef DISPLAY_ENABLED GetLCD().Init((uint8_t *) "Thermostat-App"); GetLCD().SetCustomUI(ThermostatUI::DrawUI); @@ -242,18 +245,13 @@ void AppTask::UpdateThermoStatUI() #endif // DISPLAY_ENABLED } -void AppTask::ButtonEventHandler(const sl_button_t * buttonHandle, uint8_t btnAction) +void AppTask::ButtonEventHandler(uint8_t button, uint8_t btnAction) { - if (buttonHandle == nullptr) - { - return; - } - AppEvent aEvent = {}; aEvent.Type = AppEvent::kEventType_Button; aEvent.ButtonEvent.Action = btnAction; - if (buttonHandle == APP_FUNCTION_BUTTON) + if (button == APP_FUNCTION_BUTTON) { aEvent.Handler = BaseApplication::ButtonHandler; sAppTask.PostEvent(&aEvent); diff --git a/examples/thermostat/silabs/efr32/src/main.cpp b/examples/thermostat/silabs/efr32/src/main.cpp deleted file mode 100644 index 0af7a99a6a8dd9..00000000000000 --- a/examples/thermostat/silabs/efr32/src/main.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - * - * Copyright (c) 2020 Project CHIP Authors - * Copyright (c) 2019 Google LLC. - * All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "AppConfig.h" -#include "init_efrPlatform.h" -#include "sl_simple_button_instances.h" -#include "sl_system_kernel.h" -#include -#include -#include -#include -#ifdef SILABS_ATTESTATION_CREDENTIALS -#include -#else -#include -#endif - -#define BLE_DEV_NAME "SiLabs-Thermostat" -using namespace ::chip; -using namespace ::chip::Inet; -using namespace ::chip::DeviceLayer; -using namespace ::chip::Credentials; - -#define UNUSED_PARAMETER(a) (a = a) - -volatile int apperror_cnt; -static chip::DeviceLayer::DeviceInfoProviderImpl gExampleDeviceInfoProvider; - -// ================================================================================ -// Main Code -// ================================================================================ -int main(void) -{ - init_efrPlatform(); - if (SilabsMatterConfig::InitMatter(BLE_DEV_NAME) != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - gExampleDeviceInfoProvider.SetStorageDelegate(&Server::GetInstance().GetPersistentStorage()); - chip::DeviceLayer::SetDeviceInfoProvider(&gExampleDeviceInfoProvider); - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - // Initialize device attestation config -#ifdef SILABS_ATTESTATION_CREDENTIALS - SetDeviceAttestationCredentialsProvider(Silabs::GetSilabsDacProvider()); -#else - SetDeviceAttestationCredentialsProvider(Examples::GetExampleDACProvider()); -#endif - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - - SILABS_LOG("Starting App Task"); - if (AppTask::GetAppTask().StartAppTask() != CHIP_NO_ERROR) - appError(CHIP_ERROR_INTERNAL); - - SILABS_LOG("Starting FreeRTOS scheduler"); - sl_system_kernel_start(); - - // Should never get here. - chip::Platform::MemoryShutdown(); - SILABS_LOG("vTaskStartScheduler() failed"); - appError(CHIP_ERROR_INTERNAL); -} - -void sl_button_on_change(const sl_button_t * handle) -{ - AppTask::GetAppTask().ButtonEventHandler(handle, sl_button_get_state(handle)); -} diff --git a/examples/window-app/silabs/efr32/include/WindowAppImpl.h b/examples/window-app/silabs/efr32/include/WindowAppImpl.h index 27a26dba9a4399..86444574ba0088 100644 --- a/examples/window-app/silabs/efr32/include/WindowAppImpl.h +++ b/examples/window-app/silabs/efr32/include/WindowAppImpl.h @@ -43,7 +43,8 @@ class WindowAppImpl : public WindowApp void Finish() override; void PostEvent(const WindowApp::Event & event) override; void PostAttributeChange(chip::EndpointId endpoint, chip::AttributeId attributeId) override; - friend void sl_button_on_change(const sl_button_t * handle); + static void ButtonEventHandler(uint8_t button, uint8_t btnAction); + void OnButtonChange(uint8_t button, uint8_t btnAction); protected: struct Timer : public WindowApp::Timer @@ -67,7 +68,6 @@ class WindowAppImpl : public WindowApp WindowApp::Timer * CreateTimer(const char * name, uint32_t timeoutInMs, WindowApp::Timer::Callback callback, void * context) override; WindowApp::Button * CreateButton(WindowApp::Button::Id id, const char * name) override; - void OnButtonChange(const sl_button_t * handle); void ProcessEvents(); void DispatchEvent(const WindowApp::Event & event) override; void UpdateLEDs(); diff --git a/examples/window-app/silabs/efr32/src/WindowAppImpl.cpp b/examples/window-app/silabs/efr32/src/WindowAppImpl.cpp index e2032125538076..5358344b58ebe7 100644 --- a/examples/window-app/silabs/efr32/src/WindowAppImpl.cpp +++ b/examples/window-app/silabs/efr32/src/WindowAppImpl.cpp @@ -46,6 +46,8 @@ SilabsLCD slLCD; #endif +#include + #define APP_TASK_STACK_SIZE (4096) #define APP_TASK_PRIORITY 2 #define APP_EVENT_QUEUE_SIZE 10 @@ -187,6 +189,8 @@ void WindowAppImpl::OnIconTimeout(WindowApp::Timer & timer) CHIP_ERROR WindowAppImpl::Init() { + chip::DeviceLayer::Silabs::GetPlatform().SetButtonsCb(WindowAppImpl::ButtonEventHandler); + WindowApp::Init(); // Initialize App Task @@ -510,11 +514,11 @@ void WindowAppImpl::OnMainLoop() //------------------------------------------------------------------------------ WindowAppImpl::Button::Button(WindowApp::Button::Id id, const char * name) : WindowApp::Button(id, name) {} -void WindowAppImpl::OnButtonChange(const sl_button_t * handle) +void WindowAppImpl::OnButtonChange(uint8_t button, uint8_t btnAction) { - WindowApp::Button * btn = static_cast