diff --git a/examples/lighting-app/nxp/k32w/k32w1/main/AppTask.cpp b/examples/lighting-app/nxp/k32w/k32w1/main/AppTask.cpp index 96f5a5b96b3248..4c1d0875470ee4 100644 --- a/examples/lighting-app/nxp/k32w/k32w1/main/AppTask.cpp +++ b/examples/lighting-app/nxp/k32w/k32w1/main/AppTask.cpp @@ -236,7 +236,7 @@ void AppTask::InitServer(intptr_t arg) #endif #if defined(USE_SMU2_DYNAMIC) - VerifyOrDie(SMU2::Init(initParams.persistentStorageDelegate) == CHIP_NO_ERROR); + VerifyOrDie(SMU2::Init() == CHIP_NO_ERROR); #endif // Init ZCL Data Model and start server diff --git a/src/platform/nxp/k32w/k32w1/SMU2Manager.cpp b/src/platform/nxp/k32w/k32w1/SMU2Manager.cpp index f4e0216bb8955a..f7c54ea7c796b7 100644 --- a/src/platform/nxp/k32w/k32w1/SMU2Manager.cpp +++ b/src/platform/nxp/k32w/k32w1/SMU2Manager.cpp @@ -25,10 +25,13 @@ */ #include "SMU2Manager.h" + #include +#include using namespace chip::DeviceLayer; using namespace chip::DeviceLayer::Internal; +using namespace chip::DeviceLayer::PersistedStorage; namespace chip::SMU2 { namespace { @@ -39,8 +42,6 @@ static const uint32_t AREA_SIZE = (AREA_END - AREA_START); uint8_t mAreaId = 0; -PersistentStorageDelegate * mStorage = nullptr; - memAreaCfg_t mAreaDescriptor; bool mDeviceCommissioned = false; bool mUseAllocator = false; @@ -92,7 +93,7 @@ void EventHandler(const ChipDeviceEvent * event, intptr_t) if (mDeviceCommissioned) { mUseAllocator = true; - mStorage->SyncSetKeyValue(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, (uint16_t) sizeof(mUseAllocator)); + KeyValueStoreMgr().Put(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, (uint16_t) sizeof(mUseAllocator)); ResetBLEController(); RegisterArea(); } @@ -103,22 +104,20 @@ void EventHandler(const ChipDeviceEvent * event, intptr_t) } // anonymous namespace -CHIP_ERROR Init(PersistentStorageDelegate * storage) +CHIP_ERROR Init() { CHIP_ERROR err = CHIP_NO_ERROR; uint16_t size = (uint16_t) sizeof(mUseAllocator); - mStorage = storage; - - VerifyOrReturnError(storage != nullptr, CHIP_ERROR_INCORRECT_STATE); PlatformMgr().AddEventHandler(EventHandler, reinterpret_cast(nullptr)); - err = mStorage->SyncGetKeyValue(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size); + size_t bytesRead = 0; + err = KeyValueStoreMgr().Get(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size, &bytesRead); if (err == CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND) { mUseAllocator = false; - err = mStorage->SyncSetKeyValue(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size); + err = KeyValueStoreMgr().Put(GetSMU2AllocatorKey().KeyName(), (void *) &mUseAllocator, size); } ReturnErrorOnFailure(err); @@ -137,7 +136,7 @@ CHIP_ERROR Deactivate(void) if (mUseAllocator) { mUseAllocator = false; - err = mStorage->SyncDeleteKeyValue(GetSMU2AllocatorKey().KeyName()); + err = KeyValueStoreMgr().Delete(GetSMU2AllocatorKey().KeyName()); ReturnErrorOnFailure(err); UnregisterArea(); diff --git a/src/platform/nxp/k32w/k32w1/SMU2Manager.h b/src/platform/nxp/k32w/k32w1/SMU2Manager.h index 7044d452727476..141229b8e6a932 100644 --- a/src/platform/nxp/k32w/k32w1/SMU2Manager.h +++ b/src/platform/nxp/k32w/k32w1/SMU2Manager.h @@ -27,12 +27,11 @@ #pragma once #include "fsl_component_mem_manager.h" -#include #include namespace chip::SMU2 { -CHIP_ERROR Init(PersistentStorageDelegate * storage); +CHIP_ERROR Init(); CHIP_ERROR Deactivate(void); void * Allocate(size_t size);