Skip to content

Commit

Permalink
add KVS configuration feature for esp32 platform (#21825)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jerry-ESP authored and pull[bot] committed Sep 22, 2022
1 parent afb6da5 commit 4714707
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
6 changes: 6 additions & 0 deletions config/esp32/components/chip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,12 @@ menu "CHIP Device Layer"
default "nvs"
help
Label of the partition to store key-values in the "chip-counters" namespace.

config CHIP_KVS_NAMESPACE_PARTITION_LABEL
string "chip-kvs namespace partition label"
default "nvs"
help
Label of the partition to store key-values in the "chip-kvs" namespace.

endmenu

Expand Down
1 change: 1 addition & 0 deletions src/platform/ESP32/CHIPDevicePlatformConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,5 @@
#define CHIP_DEVICE_CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION CONFIG_CHIP_FACTORY_NAMESPACE_PARTITION_LABEL
#define CHIP_DEVICE_CONFIG_CHIP_CONFIG_NAMESPACE_PARTITION CONFIG_CHIP_CONFIG_NAMESPACE_PARTITION_LABEL
#define CHIP_DEVICE_CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION_LABEL
#define CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION CONFIG_CHIP_KVS_NAMESPACE_PARTITION_LABEL
#define CHIP_DEVICE_CONFIG_ENABLE_DEVICE_INSTANCE_INFO_PROVIDER CONFIG_ENABLE_ESP32_DEVICE_INSTANCE_INFO_PROVIDER
2 changes: 2 additions & 0 deletions src/platform/ESP32/ConfigurationManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ CHIP_ERROR ConfigurationManagerImpl::Init()
SuccessOrExit(MapConfigError(esp_err));
esp_err = nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_COUNTERS_NAMESPACE_PARTITION);
SuccessOrExit(MapConfigError(esp_err));
esp_err = nvs_flash_init_partition(CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION);
SuccessOrExit(MapConfigError(esp_err));
#endif

// Force initialization of NVS namespaces if they doesn't already exist.
Expand Down
8 changes: 4 additions & 4 deletions src/platform/ESP32/KeyValueStoreManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Get(const char * key, void * value, size_t
VerifyOrReturnError(offset_bytes == 0, CHIP_ERROR_NOT_IMPLEMENTED);

Internal::ScopedNvsHandle handle;
ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READONLY));
ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READONLY, CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION));

char keyHash[NVS_KEY_NAME_MAX_SIZE];
VerifyOrDo(HashIfLongKey(key, keyHash) == false, key = keyHash);
Expand All @@ -95,7 +95,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Put(const char * key, const void * value,
VerifyOrReturnError(value, CHIP_ERROR_INVALID_ARGUMENT);

Internal::ScopedNvsHandle handle;
ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE));
ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE, CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION));

char keyHash[NVS_KEY_NAME_MAX_SIZE];
VerifyOrDo(HashIfLongKey(key, keyHash) == false, key = keyHash);
Expand All @@ -112,7 +112,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::_Delete(const char * key)
{
Internal::ScopedNvsHandle handle;

ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE));
ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE, CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION));

char keyHash[NVS_KEY_NAME_MAX_SIZE];
VerifyOrDo(HashIfLongKey(key, keyHash) == false, key = keyHash);
Expand All @@ -129,7 +129,7 @@ CHIP_ERROR KeyValueStoreManagerImpl::EraseAll(void)
{
Internal::ScopedNvsHandle handle;

ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE));
ReturnErrorOnFailure(handle.Open(kNamespace, NVS_READWRITE, CHIP_DEVICE_CONFIG_CHIP_KVS_NAMESPACE_PARTITION));
ReturnMappedErrorOnFailure(nvs_erase_all(handle));
ReturnMappedErrorOnFailure(nvs_commit(handle));

Expand Down

0 comments on commit 4714707

Please sign in to comment.