From 6a66d79e70efdf679b7bfb6005998f6ac316e2e5 Mon Sep 17 00:00:00 2001 From: Jean-Francois Penven Date: Thu, 20 Jul 2023 15:55:38 -0400 Subject: [PATCH] Move Base Application --- .../silabs/{efr32 => }/BaseApplication.cpp | 5 + .../silabs/{efr32 => }/BaseApplication.h | 5 +- examples/platform/silabs/MatterConfig.cpp | 9 +- examples/platform/silabs/SiWx917/BUILD.gn | 4 +- .../silabs/SiWx917/BaseApplication.cpp | 637 ------------------ .../platform/silabs/SiWx917/BaseApplication.h | 205 ------ examples/platform/silabs/board_config.h | 2 +- examples/platform/silabs/efr32/BUILD.gn | 4 +- examples/platform/silabs/main.cpp | 2 +- .../silabs/platformAbstraction/GsdkSpam.cpp | 4 +- .../platformAbstraction/WiseMcuSpam.cpp | 4 +- src/test_driver/efr32/BUILD.gn | 1 - src/test_driver/efr32/src/main.cpp | 4 +- third_party/silabs/efr32_sdk.gni | 3 +- 14 files changed, 23 insertions(+), 866 deletions(-) rename examples/platform/silabs/{efr32 => }/BaseApplication.cpp (99%) rename examples/platform/silabs/{efr32 => }/BaseApplication.h (99%) delete mode 100644 examples/platform/silabs/SiWx917/BaseApplication.cpp delete mode 100644 examples/platform/silabs/SiWx917/BaseApplication.h diff --git a/examples/platform/silabs/efr32/BaseApplication.cpp b/examples/platform/silabs/BaseApplication.cpp similarity index 99% rename from examples/platform/silabs/efr32/BaseApplication.cpp rename to examples/platform/silabs/BaseApplication.cpp index 77a91236554ae5..b0d1dd0ea8a414 100644 --- a/examples/platform/silabs/efr32/BaseApplication.cpp +++ b/examples/platform/silabs/BaseApplication.cpp @@ -242,7 +242,12 @@ CHIP_ERROR BaseApplication::Init() } PlatformMgr().AddEventHandler(OnPlatformEvent, 0); +#ifdef SL_WIFI + sIsProvisioned = ConnectivityMgr().IsWiFiStationProvisioned(); +#endif /* SL_WIFI */ +#if CHIP_ENABLE_OPENTHREAD sIsProvisioned = ConnectivityMgr().IsThreadProvisioned(); +#endif return err; } diff --git a/examples/platform/silabs/efr32/BaseApplication.h b/examples/platform/silabs/BaseApplication.h similarity index 99% rename from examples/platform/silabs/efr32/BaseApplication.h rename to examples/platform/silabs/BaseApplication.h index f2bc073c4ee9b2..9e99580811293c 100644 --- a/examples/platform/silabs/efr32/BaseApplication.h +++ b/examples/platform/silabs/BaseApplication.h @@ -29,6 +29,7 @@ #include "AppEvent.h" #include "FreeRTOS.h" #include "timers.h" // provides FreeRTOS timer support +#include #include #include #include @@ -47,10 +48,6 @@ #endif // QR_CODE_ENABLED #endif // DISPLAY_ENABLED -#ifndef SL_STATUS_LED -#define SL_STATUS_LED 1 -#endif - /********************************************************** * Defines *********************************************************/ diff --git a/examples/platform/silabs/MatterConfig.cpp b/examples/platform/silabs/MatterConfig.cpp index 4d2d2b4cbcb3a9..b524e6c8e43ac1 100644 --- a/examples/platform/silabs/MatterConfig.cpp +++ b/examples/platform/silabs/MatterConfig.cpp @@ -166,10 +166,10 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName) // Init Chip memory management before the stack ReturnErrorOnFailure(chip::Platform::MemoryInit()); - // WiFi needs to be initialized after Memory Init for some reason - #ifdef SL_WIFI +// WiFi needs to be initialized after Memory Init for some reason +#ifdef SL_WIFI InitWiFi(); - #endif +#endif ReturnErrorOnFailure(PlatformMgr().InitChipStack()); @@ -260,8 +260,7 @@ void SilabsMatterConfig::InitWiFi(void) SILABS_LOG("RSI init failed"); return CHIP_ERROR_INTERNAL; } -#endif /* WF200_WIFI */ - +#endif /* WF200_WIFI */ } #endif // SL_WIFI diff --git a/examples/platform/silabs/SiWx917/BUILD.gn b/examples/platform/silabs/SiWx917/BUILD.gn index fa88190b96c954..3fd6164b576ea1 100644 --- a/examples/platform/silabs/SiWx917/BUILD.gn +++ b/examples/platform/silabs/SiWx917/BUILD.gn @@ -247,7 +247,9 @@ source_set("siwx917-common") { ] sources = [ + "${silabs_common_plat_dir}/BaseApplication.cpp", "${silabs_common_plat_dir}/LEDWidget.cpp", + "${silabs_common_plat_dir}/MatterConfig.cpp", "${silabs_common_plat_dir}/SoftwareFaultReports.cpp", "${silabs_common_plat_dir}/heap_4_silabs.c", "${silabs_common_plat_dir}/silabs_utils.cpp", @@ -256,10 +258,8 @@ source_set("siwx917-common") { "${wifi_sdk_dir}/ethernetif.cpp", "${wifi_sdk_dir}/lwip_netif.cpp", "${wifi_sdk_dir}/wfx_notify.cpp", - "BaseApplication.cpp", "SiWx917/rsi_if.c", "SiWx917/wfx_rsi_host.c", - "${silabs_common_plat_dir}/MatterConfig.cpp", ] if (chip_enable_pw_rpc || chip_build_libshell) { diff --git a/examples/platform/silabs/SiWx917/BaseApplication.cpp b/examples/platform/silabs/SiWx917/BaseApplication.cpp deleted file mode 100644 index feab970b95fe5b..00000000000000 --- a/examples/platform/silabs/SiWx917/BaseApplication.cpp +++ /dev/null @@ -1,637 +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. - */ - -/********************************************************** - * Includes - *********************************************************/ - -#include "AppConfig.h" -#include "AppEvent.h" -#include "AppTask.h" - -#include "LEDWidget.h" - -#ifdef DISPLAY_ENABLED -#include "lcd.h" -#ifdef QR_CODE_ENABLED -#include "qrcodegen.h" -#endif // QR_CODE_ENABLED -#endif // DISPLAY_ENABLED - -#include "SilabsDeviceDataProvider.h" -#include "rsi_board.h" -#include "rsi_chip.h" -#include "silabs_utils.h" -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#ifdef SL_WIFI -#include "wfx_host_events.h" -#include -#include -#endif // SL_WIFI - -/********************************************************** - * Defines and Constants - *********************************************************/ - -#define FACTORY_RESET_TRIGGER_TIMEOUT 7000 -#define FACTORY_RESET_CANCEL_WINDOW_TIMEOUT 3000 -#define FACTORY_RESET_LOOP_COUNT 5 -#ifndef APP_TASK_STACK_SIZE -#define APP_TASK_STACK_SIZE (4096) -#endif -#define APP_TASK_PRIORITY 2 -#define APP_EVENT_QUEUE_SIZE 10 -#define EXAMPLE_VENDOR_ID 0xcafe -#define APP_STATE_LED 0 - -using namespace chip; -using namespace chip::app; -using namespace ::chip::DeviceLayer; -using namespace ::chip::DeviceLayer::Silabs; - -namespace { - -/********************************************************** - * Variable declarations - *********************************************************/ - -TimerHandle_t sFunctionTimer; // FreeRTOS app sw timer. -TimerHandle_t sLightTimer; - -TaskHandle_t sAppTaskHandle; -QueueHandle_t sAppEventQueue; - -LEDWidget sStatusLED; - -#ifdef SL_WIFI -app::Clusters::NetworkCommissioning::Instance - sWiFiNetworkCommissioningInstance(0 /* Endpoint Id */, &(NetworkCommissioning::SlWiFiDriver::GetInstance())); -#endif /* SL_WIFI */ - -#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) - -bool sIsProvisioned = false; -bool sIsEnabled = false; -bool sIsAttached = false; -bool sHaveBLEConnections = false; - -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER - -uint8_t sAppEventQueueBuffer[APP_EVENT_QUEUE_SIZE * sizeof(AppEvent)]; -StaticQueue_t sAppEventQueueStruct; - -StackType_t appStack[APP_TASK_STACK_SIZE / sizeof(StackType_t)]; -StaticTask_t appTaskStruct; - -BaseApplication::Function_t mFunction; -bool mFunctionTimerActive; - -#ifdef DISPLAY_ENABLED -SilabsLCD slLCD; -#endif - -#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER -Clusters::Identify::EffectIdentifierEnum sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect; - -Identify gIdentify = { - chip::EndpointId{ 1 }, - BaseApplication::OnIdentifyStart, - BaseApplication::OnIdentifyStop, - Clusters::Identify::IdentifyTypeEnum::kVisibleIndicator, - BaseApplication::OnTriggerIdentifyEffect, -}; - -#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER -} // namespace - -/********************************************************** - * AppTask Definitions - *********************************************************/ - -CHIP_ERROR BaseApplication::StartAppTask(TaskFunction_t taskFunction) -{ - sAppEventQueue = xQueueCreateStatic(APP_EVENT_QUEUE_SIZE, sizeof(AppEvent), sAppEventQueueBuffer, &sAppEventQueueStruct); - if (sAppEventQueue == NULL) - { - SILABS_LOG("Failed to allocate app event queue"); - appError(APP_ERROR_EVENT_QUEUE_FAILED); - } - - // Start App task. - sAppTaskHandle = - xTaskCreateStatic(taskFunction, APP_TASK_NAME, ArraySize(appStack), &sAppEventQueue, 1, appStack, &appTaskStruct); - if (sAppTaskHandle == nullptr) - { - SILABS_LOG("Failed to create app task"); - appError(APP_ERROR_CREATE_TASK_FAILED); - } - return CHIP_NO_ERROR; -} - -CHIP_ERROR BaseApplication::Init() -{ - CHIP_ERROR err = CHIP_NO_ERROR; - -#ifdef SL_WIFI - /* - * Wait for the WiFi to be initialized - */ - SILABS_LOG("APP: Wait WiFi Init"); - while (!wfx_hw_ready()) - { - vTaskDelay(10); - } - SILABS_LOG("APP: Done WiFi Init"); - /* We will init server when we get IP */ - - chip::DeviceLayer::PlatformMgr().LockChipStack(); - sWiFiNetworkCommissioningInstance.Init(); - chip::DeviceLayer::PlatformMgr().UnlockChipStack(); - -#endif - - // Create FreeRTOS sw timer for Function Selection. - sFunctionTimer = xTimerCreate("FnTmr", // Just a text name, not used by the RTOS kernel - pdMS_TO_TICKS(1), // == default timer period - false, // no timer reload (==one-shot) - (void *) this, // init timer id = app task obj context - FunctionTimerEventHandler // timer callback handler - ); - if (sFunctionTimer == NULL) - { - SILABS_LOG("funct timer create failed"); - appError(APP_ERROR_CREATE_TIMER_FAILED); - } - - // Create FreeRTOS sw timer for LED Management. - sLightTimer = xTimerCreate("LightTmr", // Text Name - pdMS_TO_TICKS(10), // Default timer period - true, // reload timer - (void *) this, // Timer Id - LightTimerEventHandler // Timer callback handler - ); - if (sLightTimer == NULL) - { - SILABS_LOG("Light Timer create failed"); - appError(APP_ERROR_CREATE_TIMER_FAILED); - } - - SILABS_LOG("Current Software Version String: %s", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION_STRING); - SILABS_LOG("Current Software Version: %d", CHIP_DEVICE_CONFIG_DEVICE_SOFTWARE_VERSION); - - sStatusLED.Init(APP_STATE_LED); - - ConfigurationMgr().LogDeviceConfig(); - - // Create buffer for QR code that can fit max size and null terminator. - char qrCodeBuffer[chip::QRCodeBasicSetupPayloadGenerator::kMaxQRCodeBase38RepresentationLength + 1]; - chip::MutableCharSpan QRCode(qrCodeBuffer); - - if (Silabs::SilabsDeviceDataProvider::GetDeviceDataProvider().GetSetupPayload(QRCode) == CHIP_NO_ERROR) - { - // Print setup info on LCD if available -#ifdef QR_CODE_ENABLED - slLCD.SetQRCode((uint8_t *) QRCode.data(), QRCode.size()); - slLCD.ShowQRCode(true, true); -#else - PrintQrCodeURL(QRCode); -#endif // QR_CODE_ENABLED - } - else - { - SILABS_LOG("Getting QR code failed!"); - } - - return err; -} - -void BaseApplication::FunctionTimerEventHandler(TimerHandle_t xTimer) -{ - AppEvent event; - event.Type = AppEvent::kEventType_Timer; - event.TimerEvent.Context = (void *) xTimer; - event.Handler = FunctionEventHandler; - PostEvent(&event); -} - -void BaseApplication::FunctionEventHandler(AppEvent * aEvent) -{ - if (aEvent->Type != AppEvent::kEventType_Timer) - { - return; - } -} - -void BaseApplication::FunctionFactoryReset(void) -{ - SILABS_LOG("#################################################################"); - SILABS_LOG("################### Factory reset triggered #####################"); - SILABS_LOG("#################################################################"); - - // Actually trigger Factory Reset - mFunction = kFunction_NoneSelected; - -#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 - StopStatusLEDTimer(); -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER - - chip::Server::GetInstance().ScheduleFactoryReset(); -} - -bool BaseApplication::ActivateStatusLedPatterns() -{ - bool isPatternSet = false; -#if defined(ENABLE_WSTK_LEDS) && defined(SL_CATALOG_SIMPLE_LED_LED1_PRESENT) -#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER - if (gIdentify.mActive) - { - // Identify in progress - // Do a steady blink on the status led - sStatusLED.Blink(250, 250); - isPatternSet = true; - } - else if (sIdentifyEffect != Clusters::Identify::EffectIdentifierEnum::kStopEffect) - { - // Identify trigger effect received. Do some on/off patterns on the status led - if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kBlink) - { - // Fast blink - sStatusLED.Blink(50, 50); - } - else if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kBreathe) - { - // Slow blink - sStatusLED.Blink(1000, 1000); - } - else if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kOkay) - { - // Pulse effect - sStatusLED.Blink(300, 700); - } - else if (sIdentifyEffect == Clusters::Identify::EffectIdentifierEnum::kChannelChange) - { - // Alternate between Short and Long pulses effect - static uint64_t mLastChangeTimeMS = 0; - static bool alternatePattern = false; - uint32_t onTimeMS = alternatePattern ? 50 : 700; - uint32_t offTimeMS = alternatePattern ? 950 : 300; - - uint64_t nowMS = chip::System::SystemClock().GetMonotonicMilliseconds64().count(); - if (nowMS >= mLastChangeTimeMS + 1000) // each pattern is done over a 1 second period - { - mLastChangeTimeMS = nowMS; - alternatePattern = !alternatePattern; - sStatusLED.Blink(onTimeMS, offTimeMS); - } - } - isPatternSet = true; - } -#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER - -#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) - // Identify Patterns have priority over Status patterns - if (!isPatternSet) - { - // Apply different status feedbacks - if (sIsProvisioned && sIsEnabled) - { - if (sIsAttached) - { - sStatusLED.Set(true); - } - else - { - sStatusLED.Blink(950, 50); - } - } - else if (sHaveBLEConnections) - { - sStatusLED.Blink(100, 100); - } - else - { - sStatusLED.Blink(50, 950); - } - isPatternSet = true; - } -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER -#endif // ENABLE_WSTK_LEDS) && SL_CATALOG_SIMPLE_LED_LED1_PRESENT - return isPatternSet; -} - -void BaseApplication::LightEventHandler() -{ - // Collect connectivity and configuration state from the CHIP stack. Because - // the CHIP event loop is being run in a separate task, the stack must be - // locked while these values are queried. However we use a non-blocking - // lock request (TryLockCHIPStack()) to avoid blocking other UI activities - // when the CHIP task is busy (e.g. with a long crypto operation). -#if !(defined(CHIP_CONFIG_ENABLE_ICD_SERVER) && CHIP_CONFIG_ENABLE_ICD_SERVER) - if (PlatformMgr().TryLockChipStack()) - { -#ifdef SL_WIFI - sIsProvisioned = ConnectivityMgr().IsWiFiStationProvisioned(); - sIsEnabled = ConnectivityMgr().IsWiFiStationEnabled(); - sIsAttached = ConnectivityMgr().IsWiFiStationConnected(); -#endif /* SL_WIFI */ -#if CHIP_ENABLE_OPENTHREAD - sIsProvisioned = ConnectivityMgr().IsThreadProvisioned(); - sIsEnabled = ConnectivityMgr().IsThreadEnabled(); - sIsAttached = ConnectivityMgr().IsThreadAttached(); -#endif /* CHIP_ENABLE_OPENTHREAD */ - sHaveBLEConnections = (ConnectivityMgr().NumBLEConnections() != 0); - PlatformMgr().UnlockChipStack(); - } -#endif // CHIP_CONFIG_ENABLE_ICD_SERVER - - // Update the status LED if factory reset has not been initiated. - // - // If system has "full connectivity", keep the LED On constantly. - // - // If thread and service provisioned, but not attached to the thread network - // yet OR no connectivity to the service OR subscriptions are not fully - // established THEN blink the LED Off for a short period of time. - // - // If the system has ble connection(s) uptill the stage above, THEN blink - // the LEDs at an even rate of 100ms. - // - // Otherwise, blink the LED ON for a very short time. - if (mFunction != kFunction_FactoryReset) - { - ActivateStatusLedPatterns(); - } - sStatusLED.Animate(); -} - -void BaseApplication::ButtonHandler(AppEvent * aEvent) -{ - uint8_t count = FACTORY_RESET_LOOP_COUNT; - - // To trigger software update: press the APP_FUNCTION_BUTTON button briefly (< - // FACTORY_RESET_TRIGGER_TIMEOUT) To initiate factory reset: press the - // APP_FUNCTION_BUTTON for FACTORY_RESET_TRIGGER_TIMEOUT + - // FACTORY_RESET_CANCEL_WINDOW_TIMEOUT All LEDs start blinking after - // FACTORY_RESET_TRIGGER_TIMEOUT to signal factory reset has been initiated. - // To cancel factory reset: release the APP_FUNCTION_BUTTON once all LEDs - // start blinking within the FACTORY_RESET_CANCEL_WINDOW_TIMEOUT - if (aEvent->ButtonEvent.Action == static_cast(SilabsPlatform::ButtonAction::ButtonPressed)) - { - if ((!mFunctionTimerActive) && (mFunction == kFunction_NoneSelected)) - { - mFunction = kFunction_FactoryReset; - - // Wait for sometime to determine button is pressed for Factory reset - // other functionality - vTaskDelay(1000); // Delay of 1sec before we check the button status - } - } - - while (!(RSI_NPSSGPIO_GetPin(NPSS_GPIO_0))) - { - if (count == 0) - { - FunctionFactoryReset(); - break; - } - - // Turn off status LED before starting blink to make sure blink is - // co-ordinated. - sStatusLED.Set(false); - sStatusLED.Blink(500); - SILABS_LOG("Factory reset triggering in %d sec release button to cancel", count--); - - // Delay of 1sec before checking the button status again - vTaskDelay(1000); - } - - if (count > 0) - { - sStatusLED.Set(false); - SILABS_LOG("Factory Reset has been Canceled"); // button held past Timeout wait till button is released - } - - // If the button was released before factory reset got initiated, start BLE advertissement in fast mode - if (mFunction == kFunction_FactoryReset) - { - mFunction = kFunction_NoneSelected; - -#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 - StopStatusLEDTimer(); -#endif - - if (!ConnectivityMgr().IsWiFiStationProvisioned()) - { - // Enable BLE advertisements - ConnectivityMgr().SetBLEAdvertisingEnabled(true); - ConnectivityMgr().SetBLEAdvertisingMode(ConnectivityMgr().kFastAdvertising); - } - else - { - SILABS_LOG("Network is already provisioned, Ble advertissement not enabled"); - } - } -} - -void BaseApplication::CancelFunctionTimer() -{ - if (xTimerStop(sFunctionTimer, pdMS_TO_TICKS(0)) == pdFAIL) - { - SILABS_LOG("app timer stop() failed"); - appError(APP_ERROR_STOP_TIMER_FAILED); - } - - mFunctionTimerActive = false; -} - -void BaseApplication::StartFunctionTimer(uint32_t aTimeoutInMs) -{ - if (xTimerIsTimerActive(sFunctionTimer)) - { - SILABS_LOG("app timer already started!"); - CancelFunctionTimer(); - } - - // timer is not active, change its period to required value (== restart). - // FreeRTOS- Block for a maximum of 100 ms if the change period command - // cannot immediately be sent to the timer command queue. - if (xTimerChangePeriod(sFunctionTimer, pdMS_TO_TICKS(aTimeoutInMs), pdMS_TO_TICKS(100)) != pdPASS) - { - SILABS_LOG("app timer start() failed"); - appError(APP_ERROR_START_TIMER_FAILED); - } - - mFunctionTimerActive = true; -} - -void BaseApplication::StartStatusLEDTimer() -{ - if (pdPASS != xTimerStart(sLightTimer, pdMS_TO_TICKS(0))) - { - SILABS_LOG("Light Time start failed"); - appError(APP_ERROR_START_TIMER_FAILED); - } -} - -void BaseApplication::StopStatusLEDTimer() -{ - sStatusLED.Set(false); - - if (xTimerStop(sLightTimer, pdMS_TO_TICKS(100)) != pdPASS) - { - SILABS_LOG("Light Time start failed"); - appError(APP_ERROR_START_TIMER_FAILED); - } -} - -#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER -void BaseApplication::OnIdentifyStart(Identify * identify) -{ - ChipLogProgress(Zcl, "onIdentifyStart"); - -#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 - StartStatusLEDTimer(); -#endif -} - -void BaseApplication::OnIdentifyStop(Identify * identify) -{ - ChipLogProgress(Zcl, "onIdentifyStop"); - -#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 - StopStatusLEDTimer(); -#endif -} - -void BaseApplication::OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState) -{ - ChipLogProgress(Zcl, "Trigger Identify Complete"); - sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect; - -#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 - StopStatusLEDTimer(); -#endif -} - -void BaseApplication::OnTriggerIdentifyEffect(Identify * identify) -{ - sIdentifyEffect = identify->mCurrentEffectIdentifier; - - if (identify->mEffectVariant != Clusters::Identify::EffectVariantEnum::kDefault) - { - ChipLogDetail(AppServer, "Identify Effect Variant unsupported. Using default"); - } - -#if CHIP_CONFIG_ENABLE_ICD_SERVER == 1 - StartStatusLEDTimer(); -#endif - - switch (sIdentifyEffect) - { - case Clusters::Identify::EffectIdentifierEnum::kBlink: - case Clusters::Identify::EffectIdentifierEnum::kOkay: - (void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(5), OnTriggerIdentifyEffectCompleted, - identify); - break; - case Clusters::Identify::EffectIdentifierEnum::kBreathe: - case Clusters::Identify::EffectIdentifierEnum::kChannelChange: - (void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(10), OnTriggerIdentifyEffectCompleted, - identify); - break; - case Clusters::Identify::EffectIdentifierEnum::kFinishEffect: - (void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify); - (void) chip::DeviceLayer::SystemLayer().StartTimer(chip::System::Clock::Seconds16(1), OnTriggerIdentifyEffectCompleted, - identify); - break; - case Clusters::Identify::EffectIdentifierEnum::kStopEffect: - (void) chip::DeviceLayer::SystemLayer().CancelTimer(OnTriggerIdentifyEffectCompleted, identify); - break; - default: - sIdentifyEffect = Clusters::Identify::EffectIdentifierEnum::kStopEffect; - ChipLogProgress(Zcl, "No identifier effect"); - } -} -#endif // EMBER_AF_PLUGIN_IDENTIFY_SERVER - -void BaseApplication::LightTimerEventHandler(TimerHandle_t xTimer) -{ - LightEventHandler(); -} - -#ifdef DISPLAY_ENABLED -SilabsLCD & BaseApplication::GetLCD(void) -{ - return slLCD; -} -#endif - -void BaseApplication::PostEvent(const AppEvent * aEvent) -{ - if (sAppEventQueue != NULL) - { - BaseType_t status; - if (xPortIsInsideInterrupt()) - { - BaseType_t higherPrioTaskWoken = pdFALSE; - status = xQueueSendFromISR(sAppEventQueue, aEvent, &higherPrioTaskWoken); - -#ifdef portYIELD_FROM_ISR - portYIELD_FROM_ISR(higherPrioTaskWoken); -#elif portEND_SWITCHING_ISR // portYIELD_FROM_ISR or portEND_SWITCHING_ISR - portEND_SWITCHING_ISR(higherPrioTaskWoken); -#else // portYIELD_FROM_ISR or portEND_SWITCHING_ISR -#error "Must have portYIELD_FROM_ISR or portEND_SWITCHING_ISR" -#endif // portYIELD_FROM_ISR or portEND_SWITCHING_ISR - } - else - { - status = xQueueSend(sAppEventQueue, aEvent, 1); - } - - if (!status) - { - SILABS_LOG("Failed to post event to app task event queue"); - } - } - else - { - SILABS_LOG("Event Queue is NULL should never happen"); - } -} - -void BaseApplication::DispatchEvent(AppEvent * aEvent) -{ - if (aEvent->Handler) - { - aEvent->Handler(aEvent); - } - else - { - SILABS_LOG("Event received with no handler. Dropping event."); - } -} diff --git a/examples/platform/silabs/SiWx917/BaseApplication.h b/examples/platform/silabs/SiWx917/BaseApplication.h deleted file mode 100644 index badb42a84db54b..00000000000000 --- a/examples/platform/silabs/SiWx917/BaseApplication.h +++ /dev/null @@ -1,205 +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. - */ - -#pragma once - -/********************************************************** - * Includes - *********************************************************/ - -#include -#include - -#include "AppEvent.h" -#include "FreeRTOS.h" -#include "timers.h" // provides FreeRTOS timer support -#include -#include -#include -#include -#include - -#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER -#include -#endif - -#ifdef DISPLAY_ENABLED -#include "demo-ui.h" -#include "lcd.h" -#ifdef QR_CODE_ENABLED -#include "qrcodegen.h" -#endif // QR_CODE_ENABLED -#endif // DISPLAY_ENABLED - -/********************************************************** - * Defines - *********************************************************/ - -// Application-defined error codes in the CHIP_ERROR space. -#define APP_ERROR_EVENT_QUEUE_FAILED CHIP_APPLICATION_ERROR(0x01) -#define APP_ERROR_CREATE_TASK_FAILED CHIP_APPLICATION_ERROR(0x02) -#define APP_ERROR_UNHANDLED_EVENT CHIP_APPLICATION_ERROR(0x03) -#define APP_ERROR_CREATE_TIMER_FAILED CHIP_APPLICATION_ERROR(0x04) -#define APP_ERROR_START_TIMER_FAILED CHIP_APPLICATION_ERROR(0x05) -#define APP_ERROR_STOP_TIMER_FAILED CHIP_APPLICATION_ERROR(0x06) - -/********************************************************** - * BaseApplication Declaration - *********************************************************/ - -class BaseApplication -{ - -public: - BaseApplication() = default; - virtual ~BaseApplication(){}; - - /** - * @brief Create AppTask task and Event Queue - * If an error occurs during creation, application will hang after printing out error code - * - * @return CHIP_ERROR CHIP_NO_ERROR if no errors - */ - CHIP_ERROR StartAppTask(TaskFunction_t taskFunction); - - /** - * @brief PostEvent function that add event to AppTask queue for processing - * - * @param event AppEvent to post - */ - static void PostEvent(const AppEvent * event); - -#ifdef DISPLAY_ENABLED - /** - * @brief Return LCD object - */ - static SilabsLCD & GetLCD(void); -#endif - - /** - * @brief Function called to start the LED light timer - */ - static void StartStatusLEDTimer(void); - - /** - * @brief Function to stop LED light timer - * Turns off Status LED before stopping timer - */ - static void StopStatusLEDTimer(void); - -#ifdef EMBER_AF_PLUGIN_IDENTIFY_SERVER - // Idenfiy server command callbacks. - static void OnIdentifyStart(Identify * identify); - static void OnIdentifyStop(Identify * identify); - static void OnTriggerIdentifyEffectCompleted(chip::System::Layer * systemLayer, void * appState); - static void OnTriggerIdentifyEffect(Identify * identify); -#endif - - enum Function_t - { - kFunction_NoneSelected = 0, - kFunction_SoftwareUpdate = 0, - kFunction_StartBleAdv = 1, - kFunction_FactoryReset = 2, - - kFunction_Invalid - } Function; - -protected: - CHIP_ERROR Init(); - - /** - * @brief Function called to start the function timer - * - * @param aTimeoutMs timer duration in ms - */ - static void StartFunctionTimer(uint32_t aTimeoutMs); - - /** - * @brief Function to stop function timer - */ - static void CancelFunctionTimer(void); - - /** - * @brief Function call event callback function for processing - * - * @param event triggered event to be processed - */ - void DispatchEvent(AppEvent * event); - - /** - * @brief Function Timer finished callback function - * Post an FunctionEventHandler event - * - * @param xTimer timer that finished - */ - static void FunctionTimerEventHandler(TimerHandle_t xTimer); - - /** - * @brief Factory reset trigger function - * Trigger factory if called - * - */ - static void FunctionFactoryReset(void); - - /** - * @brief Timer Event processing function - * Trigger factory if Press and Hold duration is respected - * - * @param aEvent post event being processed - */ - static void FunctionEventHandler(AppEvent * aEvent); - - /** - * @brief PB0 Button event processing function - * Press and hold will trigger a factory reset timer start - * Press and release will restart BLEAdvertising if not commisionned - * - * @param aEvent button event being processed - */ - static void ButtonHandler(AppEvent * aEvent); - - /** - * @brief Light Timer finished callback function - * Calls LED processing function - * - * @param xTimer timer that finished - */ - static void LightTimerEventHandler(TimerHandle_t xTimer); - - /** - * @brief Activate a set of Led patterns of the Status led - * Identify patterns and Trigger effects have priority - * If no identification patterns are in progress, we provide - * commissioning status feedback. - * - * @return True if a Led pattern was set, otherwise, returns false. - */ - static bool ActivateStatusLedPatterns(); - - /** - * @brief Updates device LEDs - */ - static void LightEventHandler(); - - /********************************************************** - * Protected Attributes declaration - *********************************************************/ - bool mSyncClusterToButtonAction; -}; diff --git a/examples/platform/silabs/board_config.h b/examples/platform/silabs/board_config.h index 8fa195ca83b58f..fa6779f583afd1 100644 --- a/examples/platform/silabs/board_config.h +++ b/examples/platform/silabs/board_config.h @@ -28,7 +28,7 @@ /** * @file - * This file includes dev board compile-time configuration constants for efr32. + * This file includes dev board compile-time configuration constants for Silabs board. * */ diff --git a/examples/platform/silabs/efr32/BUILD.gn b/examples/platform/silabs/efr32/BUILD.gn index 7e2a15e63476f6..3a965cb01185b1 100644 --- a/examples/platform/silabs/efr32/BUILD.gn +++ b/examples/platform/silabs/efr32/BUILD.gn @@ -285,13 +285,13 @@ source_set("efr32-common") { include_dirs = [ "." ] sources = [ + "${silabs_common_plat_dir}/BaseApplication.cpp", "${silabs_common_plat_dir}/LEDWidget.cpp", + "${silabs_common_plat_dir}/MatterConfig.cpp", "${silabs_common_plat_dir}/SoftwareFaultReports.cpp", "${silabs_common_plat_dir}/heap_4_silabs.c", "${silabs_common_plat_dir}/silabs_utils.cpp", "${silabs_common_plat_dir}/syscalls_stubs.cpp", - "BaseApplication.cpp", - "${silabs_common_plat_dir}/MatterConfig.cpp", ] if (chip_enable_pw_rpc || chip_build_libshell || enable_openthread_cli) { diff --git a/examples/platform/silabs/main.cpp b/examples/platform/silabs/main.cpp index 8bec10caff13ee..03fb25b549db67 100644 --- a/examples/platform/silabs/main.cpp +++ b/examples/platform/silabs/main.cpp @@ -22,9 +22,9 @@ #include "AppConfig.h" #include +#include #include #include -#include #ifdef SILABS_ATTESTATION_CREDENTIALS #include #else diff --git a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp index 62292e331572c5..98eaa6f7114724 100644 --- a/src/platform/silabs/platformAbstraction/GsdkSpam.cpp +++ b/src/platform/silabs/platformAbstraction/GsdkSpam.cpp @@ -29,7 +29,6 @@ extern "C" { #include "sl_simple_button_instances.h" #endif - extern "C" { #include @@ -52,7 +51,6 @@ extern "C" { #if SL_SYSTEM_VIEW #include "SEGGER_SYSVIEW.h" #endif - } #if SILABS_LOG_ENABLED @@ -74,7 +72,7 @@ CHIP_ERROR SilabsPlatform::Init(void) #if CHIP_ENABLE_OPENTHREAD sl_ot_sys_init(); -#endif +#endif #if SL_SYSTEM_VIEW SEGGER_SYSVIEW_Conf(); diff --git a/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp b/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp index 20225fd420b1a1..f226caeaaa8395 100644 --- a/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp +++ b/src/platform/silabs/platformAbstraction/WiseMcuSpam.cpp @@ -39,9 +39,9 @@ CHIP_ERROR SilabsPlatform::Init(void) RSI_Wakeupsw_config(); RSI_Wakeupsw_config_gpio0(); - #if SILABS_LOG_ENABLED +#if SILABS_LOG_ENABLED silabsInitLog(); - #endif +#endif return CHIP_NO_ERROR; } diff --git a/src/test_driver/efr32/BUILD.gn b/src/test_driver/efr32/BUILD.gn index 08ff02dc0886fd..59df8e9d54f03d 100644 --- a/src/test_driver/efr32/BUILD.gn +++ b/src/test_driver/efr32/BUILD.gn @@ -73,7 +73,6 @@ silabs_executable("efr32_device_tests") { "${examples_common_plat_dir}/PigweedLogger.cpp", "${examples_common_plat_dir}/heap_4_silabs.c", "${examples_common_plat_dir}/syscalls_stubs.cpp", - "${examples_plat_dir}/init_efrPlatform.cpp", "${examples_plat_dir}/uart.cpp", "src/main.cpp", ] diff --git a/src/test_driver/efr32/src/main.cpp b/src/test_driver/efr32/src/main.cpp index befd974512b36f..533fb5f94c307e 100644 --- a/src/test_driver/efr32/src/main.cpp +++ b/src/test_driver/efr32/src/main.cpp @@ -20,7 +20,6 @@ #include #include #include -#include #include #include #include @@ -30,6 +29,7 @@ #include #include #include +#include #include #include @@ -181,7 +181,7 @@ void RunRpcService(void *) int main(void) { - chip::Platform::DeviceLayer::SilabsPlatform::Init(); + chip::DeviceLayer::Silabs::GetPlatform().Init(); PigweedLogger::init(); mbedtls_platform_set_calloc_free(CHIPPlatformMemoryCalloc, CHIPPlatformMemoryFree); diff --git a/third_party/silabs/efr32_sdk.gni b/third_party/silabs/efr32_sdk.gni index 0dc0bdfb2411f9..71fc3099380d5c 100644 --- a/third_party/silabs/efr32_sdk.gni +++ b/third_party/silabs/efr32_sdk.gni @@ -181,8 +181,9 @@ template("efr32_sdk") { "${efr32_sdk_root}/platform/driver/debug/inc", "${silabs_gen_folder}/config", "${silabs_gen_folder}/autogen", + # Headers needed for Init no function will be called if OT is not used - "${sl_ot_efr32_root}", + "${sl_ot_efr32_root}", ] if (silabs_family != "mgm24") {