Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
|
The hdw-nvs component is a convenience wrapper for the IDF's Non-volatile Storage Library. Non-volatile storage (NVS) library is designed to store key-value pairs in flash.
The goal is to make reading and writing integer and blob values easy and simple for Swadge modes. The component takes care of opening and closing handles and error checking.
There are no checks for key collisions between Swadge modes, so it's wise to use a mode-specific prefix for that mode's keys.
You don't need to call initNvs() or deinitNvs(). The system does this the appropriate time.
readNvs32() and writeNvs32() can be used to read and write 32 bit integer values.
readNvsBlob() and writeNvsBlob() can be used to read and write binary blobs.
eraseNvsKey() can be used to erase a key, both 32 bit integer or blob. eraseNvs() can be used to erase all keys. It's dangerous to use, so be careful.
readNvsStats() and readAllNvsEntryInfos() can be used to read metadata about NVS.
Go to the source code of this file.
Macros | |
#define | NVS_PART_NAME_MAX_SIZE 16 |
#define | NVS_KEY_NAME_MAX_SIZE 16 |
#define | NVS_NAMESPACE_NAME "storage" |
Functions | |
bool | initNvs (bool firstTry) |
Initialize the nonvolatile storage. | |
bool | deinitNvs (void) |
Deinitialize NVS. | |
bool | eraseNvs (void) |
Erase and re-initialize the nonvolatile storage. | |
bool | readNvs32 (const char *key, int32_t *outVal) |
Read a 32 bit value from NVS with a given string key. | |
bool | writeNvs32 (const char *key, int32_t val) |
Write a 32 bit value to NVS with a given string key. | |
bool | readNamespaceNvs32 (const char *namespace, const char *key, int32_t *outVal) |
Read a 32 bit value from NVS with a given string key. | |
bool | writeNamespaceNvs32 (const char *namespace, const char *key, int32_t val) |
Write a 32 bit value to NVS with a given string key. | |
bool | readNvsBlob (const char *key, void *out_value, size_t *length) |
Read a blob from NVS with a given string key. Typically, this should be called once with NULL passed for out_value, to get the value for length, then memory for out_value should be allocated, then this should be called again. | |
bool | writeNvsBlob (const char *key, const void *value, size_t length) |
Write a blob to NVS with a given string key. | |
bool | readNamespaceNvsBlob (const char *namespace, const char *key, void *out_value, size_t *length) |
Read a blob from NVS with a given string key. Typically, this should be called once with NULL passed for out_value, to get the value for length, then memory for out_value should be allocated, then this should be called again. | |
bool | writeNamespaceNvsBlob (const char *namespace, const char *key, const void *value, size_t length) |
Write a blob to NVS with a given string key. | |
bool | eraseNvsKey (const char *key) |
Delete the value with the given key from NVS. | |
bool | eraseNamespaceNvsKey (const char *namespace, const char *key) |
Delete the value with the given key from NVS. | |
bool | readNvsStats (nvs_stats_t *outStats) |
Read info about used memory in NVS. | |
bool | readAllNvsEntryInfos (nvs_stats_t *outStats, nvs_entry_info_t *outEntryInfos, size_t *numEntryInfos) |
Read info about each used entry in the default NVS namespace. Typically, this should be called once with NULL passed for outEntryInfos, to get the value for numEntryInfos, then memory for outEntryInfos should be allocated, then this should be called again. | |
bool | readNamespaceNvsEntryInfos (const char *namespace, nvs_stats_t *outStats, nvs_entry_info_t *outEntryInfos, size_t *numEntryInfos) |
Read info about each used entry in a specific NVS namespace. Typically, this should be called once with NULL passed for outEntryInfos, to get the value for numEntryInfos, then memory for outEntryInfos should be allocated, then this should be called again. | |
bool | nvsNamespaceInUse (const char *namespace) |
Quickly return whether or not any entries exist in a given NVS namespace. | |
#define NVS_PART_NAME_MAX_SIZE 16 |
maximum length of partition name (excluding null terminator)
#define NVS_KEY_NAME_MAX_SIZE 16 |
Maximal length of NVS key name (including null terminator)
#define NVS_NAMESPACE_NAME "storage" |
The default namespace used for NVS
bool initNvs | ( | bool | firstTry | ) |
Initialize the nonvolatile storage.
firstTry | true if this is the first time NVS is initialized this boot, false otherwise |
bool deinitNvs | ( | void | ) |
Deinitialize NVS.
bool eraseNvs | ( | void | ) |
Erase and re-initialize the nonvolatile storage.
bool readNvs32 | ( | const char * | key, |
int32_t * | outVal ) |
Read a 32 bit value from NVS with a given string key.
key | The key for the value to read |
outVal | The value that was read |
bool writeNvs32 | ( | const char * | key, |
int32_t | val ) |
Write a 32 bit value to NVS with a given string key.
key | The key for the value to write |
val | The value to write |
bool readNamespaceNvs32 | ( | const char * | namespace, |
const char * | key, | ||
int32_t * | outVal ) |
Read a 32 bit value from NVS with a given string key.
namespace | The NVS namespace to use |
key | The key for the value to read |
outVal | The value that was read |
bool writeNamespaceNvs32 | ( | const char * | namespace, |
const char * | key, | ||
int32_t | val ) |
Write a 32 bit value to NVS with a given string key.
namespace | The NVS namespace to use |
key | The key for the value to write |
val | The value to write |
bool readNvsBlob | ( | const char * | key, |
void * | out_value, | ||
size_t * | length ) |
Read a blob from NVS with a given string key. Typically, this should be called once with NULL passed for out_value, to get the value for length, then memory for out_value should be allocated, then this should be called again.
key | The key for the value to read |
out_value | The value will be written to this memory. It must be allocated before calling readNvsBlob() |
length | If out_value is NULL , this will be set to the length of the given key. Otherwise, it is the length of the blob to read. |
bool writeNvsBlob | ( | const char * | key, |
const void * | value, | ||
size_t | length ) |
Write a blob to NVS with a given string key.
key | The key for the value to write |
value | The blob value to write |
length | The length of the blob |
bool readNamespaceNvsBlob | ( | const char * | namespace, |
const char * | key, | ||
void * | out_value, | ||
size_t * | length ) |
Read a blob from NVS with a given string key. Typically, this should be called once with NULL passed for out_value, to get the value for length, then memory for out_value should be allocated, then this should be called again.
namespace | The NVS namespace to use |
key | The key for the value to read |
out_value | The value will be written to this memory. It must be allocated before calling readNvsBlob() |
length | If out_value is NULL , this will be set to the length of the given key. Otherwise, it is the length of the blob to read. |
bool writeNamespaceNvsBlob | ( | const char * | namespace, |
const char * | key, | ||
const void * | value, | ||
size_t | length ) |
Write a blob to NVS with a given string key.
namespace | The NVS namespace to use |
key | The key for the value to write |
value | The blob value to write |
length | The length of the blob |
bool eraseNvsKey | ( | const char * | key | ) |
Delete the value with the given key from NVS.
key | The NVS key to be deleted |
bool eraseNamespaceNvsKey | ( | const char * | namespace, |
const char * | key ) |
Delete the value with the given key from NVS.
namespace | The NVS namespace to use |
key | The NVS key to be deleted |
bool readNvsStats | ( | nvs_stats_t * | outStats | ) |
Read info about used memory in NVS.
outStats | The NVS stats struct will be written to this memory. It must be allocated before calling readNvsStats() |
bool readAllNvsEntryInfos | ( | nvs_stats_t * | outStats, |
nvs_entry_info_t * | outEntryInfos, | ||
size_t * | numEntryInfos ) |
Read info about each used entry in the default NVS namespace. Typically, this should be called once with NULL passed for outEntryInfos, to get the value for numEntryInfos, then memory for outEntryInfos should be allocated, then this should be called again.
outStats | If not NULL , the NVS stats struct will be written to this memory. It must be allocated before calling readAllNvsEntryInfos() |
outEntryInfos | A pointer to an array of NVS entry info structs will be written to this memory |
numEntryInfos | If outEntryInfos is NULL , this will be set to the length of the given key. Otherwise, it is the number of entry infos to read |
bool readNamespaceNvsEntryInfos | ( | const char * | namespace, |
nvs_stats_t * | outStats, | ||
nvs_entry_info_t * | outEntryInfos, | ||
size_t * | numEntryInfos ) |
Read info about each used entry in a specific NVS namespace. Typically, this should be called once with NULL passed for outEntryInfos, to get the value for numEntryInfos, then memory for outEntryInfos should be allocated, then this should be called again.
namespace | The name of the NVS namespace to use |
outStats | If not NULL , the NVS stats struct will be written to this memory. It must be allocated before calling readAllNvsEntryInfos() |
outEntryInfos | A pointer to an array of NVS entry info structs will be written to this memory |
numEntryInfos | If outEntryInfos is NULL , this will be set to the length of the given key. Otherwise, it is the number of entry infos to read |
bool nvsNamespaceInUse | ( | const char * | namespace | ) |
Quickly return whether or not any entries exist in a given NVS namespace.
namespace | The namespace to check for any entries |