mirror of
https://github.com/0xFEEDC0DE64/arduino-esp32.git
synced 2025-07-27 17:27:15 +02:00
IDF release/v4.0 08219f3cf
This commit is contained in:
@ -17,6 +17,7 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include "esp_attr.h"
|
||||
#include "esp_err.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -26,7 +27,12 @@ extern "C" {
|
||||
/**
|
||||
* Opaque pointer type representing non-volatile storage handle
|
||||
*/
|
||||
typedef uint32_t nvs_handle;
|
||||
typedef uint32_t nvs_handle_t;
|
||||
|
||||
/*
|
||||
* Pre-IDF V4.0 uses nvs_handle, so leaving the original typedef here for compatibility.
|
||||
*/
|
||||
typedef nvs_handle_t nvs_handle IDF_DEPRECATED("Replace with nvs_handle_t");
|
||||
|
||||
#define ESP_ERR_NVS_BASE 0x1100 /*!< Starting number of error codes */
|
||||
#define ESP_ERR_NVS_NOT_INITIALIZED (ESP_ERR_NVS_BASE + 0x01) /*!< The storage driver is not initialized */
|
||||
@ -54,31 +60,56 @@ typedef uint32_t nvs_handle;
|
||||
#define ESP_ERR_NVS_KEYS_NOT_INITIALIZED (ESP_ERR_NVS_BASE + 0x16) /*!< NVS key partition is uninitialized */
|
||||
#define ESP_ERR_NVS_CORRUPT_KEY_PART (ESP_ERR_NVS_BASE + 0x17) /*!< NVS key partition is corrupt */
|
||||
|
||||
#define ESP_ERR_NVS_CONTENT_DIFFERS (ESP_ERR_NVS_BASE + 0x18) /*!< Internal error; never returned by nvs API functions. NVS key is different in comparison */
|
||||
|
||||
#define NVS_DEFAULT_PART_NAME "nvs" /*!< Default partition name of the NVS partition in the partition table */
|
||||
|
||||
/**
|
||||
* @brief Mode of opening the non-volatile storage
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
NVS_READONLY, /*!< Read only */
|
||||
NVS_READWRITE /*!< Read and write */
|
||||
} nvs_open_mode;
|
||||
} nvs_open_mode_t;
|
||||
|
||||
/*
|
||||
* Pre-IDF V4.0 uses nvs_open_mode, so leaving the original typedef here for compatibility.
|
||||
*/
|
||||
typedef nvs_open_mode_t nvs_open_mode IDF_DEPRECATED("Replace with nvs_open_mode_t");
|
||||
|
||||
|
||||
/**
|
||||
* @brief Types of variables
|
||||
*
|
||||
*/
|
||||
typedef enum {
|
||||
NVS_TYPE_U8 = 0x01,
|
||||
NVS_TYPE_I8 = 0x11,
|
||||
NVS_TYPE_U16 = 0x02,
|
||||
NVS_TYPE_I16 = 0x12,
|
||||
NVS_TYPE_U32 = 0x04,
|
||||
NVS_TYPE_I32 = 0x14,
|
||||
NVS_TYPE_U64 = 0x08,
|
||||
NVS_TYPE_I64 = 0x18,
|
||||
NVS_TYPE_STR = 0x21,
|
||||
NVS_TYPE_BLOB = 0x42,
|
||||
NVS_TYPE_ANY = 0xff // Must be last
|
||||
NVS_TYPE_U8 = 0x01, /*!< Type uint8_t */
|
||||
NVS_TYPE_I8 = 0x11, /*!< Type int8_t */
|
||||
NVS_TYPE_U16 = 0x02, /*!< Type uint16_t */
|
||||
NVS_TYPE_I16 = 0x12, /*!< Type int16_t */
|
||||
NVS_TYPE_U32 = 0x04, /*!< Type uint32_t */
|
||||
NVS_TYPE_I32 = 0x14, /*!< Type int32_t */
|
||||
NVS_TYPE_U64 = 0x08, /*!< Type uint64_t */
|
||||
NVS_TYPE_I64 = 0x18, /*!< Type int64_t */
|
||||
NVS_TYPE_STR = 0x21, /*!< Type string */
|
||||
NVS_TYPE_BLOB = 0x42, /*!< Type blob */
|
||||
NVS_TYPE_ANY = 0xff /*!< Must be last */
|
||||
} nvs_type_t;
|
||||
|
||||
/**
|
||||
* @brief information about entry obtained from nvs_entry_info function
|
||||
*/
|
||||
typedef struct {
|
||||
char namespace_name[16]; /*!< Namespace to which key-value belong */
|
||||
char key[16]; /*!< Key of stored key-value pair */
|
||||
nvs_type_t type; /*!< Type of stored key-value pair */
|
||||
} nvs_entry_info_t;
|
||||
|
||||
/**
|
||||
* Opaque pointer type representing iterator to nvs entries
|
||||
*/
|
||||
typedef struct nvs_opaque_iterator_t *nvs_iterator_t;
|
||||
|
||||
/**
|
||||
* @brief Open non-volatile storage with a given namespace from the default NVS partition
|
||||
*
|
||||
@ -93,7 +124,7 @@ typedef enum {
|
||||
* at least 15 characters. Shouldn't be empty.
|
||||
* @param[in] open_mode NVS_READWRITE or NVS_READONLY. If NVS_READONLY, will
|
||||
* open a handle for reading only. All write requests will
|
||||
* be rejected for this handle.
|
||||
* be rejected for this handle.
|
||||
* @param[out] out_handle If successful (return code is zero), handle will be
|
||||
* returned in this argument.
|
||||
*
|
||||
@ -106,7 +137,7 @@ typedef enum {
|
||||
* - ESP_ERR_NVS_INVALID_NAME if namespace name doesn't satisfy constraints
|
||||
* - other error codes from the underlying storage driver
|
||||
*/
|
||||
esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_handle);
|
||||
esp_err_t nvs_open(const char* name, nvs_open_mode_t open_mode, nvs_handle_t *out_handle);
|
||||
|
||||
/**
|
||||
* @brief Open non-volatile storage with a given namespace from specified partition
|
||||
@ -119,9 +150,9 @@ esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_ha
|
||||
* @param[in] name Namespace name. Maximal length is determined by the
|
||||
* underlying implementation, but is guaranteed to be
|
||||
* at least 15 characters. Shouldn't be empty.
|
||||
* @param[in] open_mode NVS_READWRITE or NVS_READONLY. If NVS_READONLY, will
|
||||
* open a handle for reading only. All write requests will
|
||||
* be rejected for this handle.
|
||||
* @param[in] open_mode NVS_READWRITE or NVS_READONLY. If NVS_READONLY, will
|
||||
* open a handle for reading only. All write requests will
|
||||
* be rejected for this handle.
|
||||
* @param[out] out_handle If successful (return code is zero), handle will be
|
||||
* returned in this argument.
|
||||
*
|
||||
@ -134,7 +165,7 @@ esp_err_t nvs_open(const char* name, nvs_open_mode open_mode, nvs_handle *out_ha
|
||||
* - ESP_ERR_NVS_INVALID_NAME if namespace name doesn't satisfy constraints
|
||||
* - other error codes from the underlying storage driver
|
||||
*/
|
||||
esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_open_mode open_mode, nvs_handle *out_handle);
|
||||
esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_open_mode_t open_mode, nvs_handle_t *out_handle);
|
||||
|
||||
/**@{*/
|
||||
/**
|
||||
@ -165,15 +196,15 @@ esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_o
|
||||
* flash operation doesn't fail again.
|
||||
* - ESP_ERR_NVS_VALUE_TOO_LONG if the string value is too long
|
||||
*/
|
||||
esp_err_t nvs_set_i8 (nvs_handle handle, const char* key, int8_t value);
|
||||
esp_err_t nvs_set_u8 (nvs_handle handle, const char* key, uint8_t value);
|
||||
esp_err_t nvs_set_i16 (nvs_handle handle, const char* key, int16_t value);
|
||||
esp_err_t nvs_set_u16 (nvs_handle handle, const char* key, uint16_t value);
|
||||
esp_err_t nvs_set_i32 (nvs_handle handle, const char* key, int32_t value);
|
||||
esp_err_t nvs_set_u32 (nvs_handle handle, const char* key, uint32_t value);
|
||||
esp_err_t nvs_set_i64 (nvs_handle handle, const char* key, int64_t value);
|
||||
esp_err_t nvs_set_u64 (nvs_handle handle, const char* key, uint64_t value);
|
||||
esp_err_t nvs_set_str (nvs_handle handle, const char* key, const char* value);
|
||||
esp_err_t nvs_set_i8 (nvs_handle_t handle, const char* key, int8_t value);
|
||||
esp_err_t nvs_set_u8 (nvs_handle_t handle, const char* key, uint8_t value);
|
||||
esp_err_t nvs_set_i16 (nvs_handle_t handle, const char* key, int16_t value);
|
||||
esp_err_t nvs_set_u16 (nvs_handle_t handle, const char* key, uint16_t value);
|
||||
esp_err_t nvs_set_i32 (nvs_handle_t handle, const char* key, int32_t value);
|
||||
esp_err_t nvs_set_u32 (nvs_handle_t handle, const char* key, uint32_t value);
|
||||
esp_err_t nvs_set_i64 (nvs_handle_t handle, const char* key, int64_t value);
|
||||
esp_err_t nvs_set_u64 (nvs_handle_t handle, const char* key, uint64_t value);
|
||||
esp_err_t nvs_set_str (nvs_handle_t handle, const char* key, const char* value);
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
@ -203,7 +234,7 @@ esp_err_t nvs_set_str (nvs_handle handle, const char* key, const char* value);
|
||||
* flash operation doesn't fail again.
|
||||
* - ESP_ERR_NVS_VALUE_TOO_LONG if the value is too long
|
||||
*/
|
||||
esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, size_t length);
|
||||
esp_err_t nvs_set_blob(nvs_handle_t handle, const char* key, const void* value, size_t length);
|
||||
|
||||
/**@{*/
|
||||
/**
|
||||
@ -243,14 +274,14 @@ esp_err_t nvs_set_blob(nvs_handle handle, const char* key, const void* value, si
|
||||
* - ESP_ERR_NVS_INVALID_NAME if key name doesn't satisfy constraints
|
||||
* - ESP_ERR_NVS_INVALID_LENGTH if length is not sufficient to store data
|
||||
*/
|
||||
esp_err_t nvs_get_i8 (nvs_handle handle, const char* key, int8_t* out_value);
|
||||
esp_err_t nvs_get_u8 (nvs_handle handle, const char* key, uint8_t* out_value);
|
||||
esp_err_t nvs_get_i16 (nvs_handle handle, const char* key, int16_t* out_value);
|
||||
esp_err_t nvs_get_u16 (nvs_handle handle, const char* key, uint16_t* out_value);
|
||||
esp_err_t nvs_get_i32 (nvs_handle handle, const char* key, int32_t* out_value);
|
||||
esp_err_t nvs_get_u32 (nvs_handle handle, const char* key, uint32_t* out_value);
|
||||
esp_err_t nvs_get_i64 (nvs_handle handle, const char* key, int64_t* out_value);
|
||||
esp_err_t nvs_get_u64 (nvs_handle handle, const char* key, uint64_t* out_value);
|
||||
esp_err_t nvs_get_i8 (nvs_handle_t handle, const char* key, int8_t* out_value);
|
||||
esp_err_t nvs_get_u8 (nvs_handle_t handle, const char* key, uint8_t* out_value);
|
||||
esp_err_t nvs_get_i16 (nvs_handle_t handle, const char* key, int16_t* out_value);
|
||||
esp_err_t nvs_get_u16 (nvs_handle_t handle, const char* key, uint16_t* out_value);
|
||||
esp_err_t nvs_get_i32 (nvs_handle_t handle, const char* key, int32_t* out_value);
|
||||
esp_err_t nvs_get_u32 (nvs_handle_t handle, const char* key, uint32_t* out_value);
|
||||
esp_err_t nvs_get_i64 (nvs_handle_t handle, const char* key, int64_t* out_value);
|
||||
esp_err_t nvs_get_u64 (nvs_handle_t handle, const char* key, uint64_t* out_value);
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
@ -264,7 +295,7 @@ esp_err_t nvs_get_u64 (nvs_handle handle, const char* key, uint64_t* out_value);
|
||||
*
|
||||
* All functions expect out_value to be a pointer to an already allocated variable
|
||||
* of the given type.
|
||||
*
|
||||
*
|
||||
* nvs_get_str and nvs_get_blob functions support WinAPI-style length queries.
|
||||
* To get the size necessary to store the value, call nvs_get_str or nvs_get_blob
|
||||
* with zero out_value and non-zero pointer to length. Variable pointed to
|
||||
@ -310,8 +341,8 @@ esp_err_t nvs_get_u64 (nvs_handle handle, const char* key, uint64_t* out_value);
|
||||
* - ESP_ERR_NVS_INVALID_LENGTH if length is not sufficient to store data
|
||||
*/
|
||||
/**@{*/
|
||||
esp_err_t nvs_get_str (nvs_handle handle, const char* key, char* out_value, size_t* length);
|
||||
esp_err_t nvs_get_blob(nvs_handle handle, const char* key, void* out_value, size_t* length);
|
||||
esp_err_t nvs_get_str (nvs_handle_t handle, const char* key, char* out_value, size_t* length);
|
||||
esp_err_t nvs_get_blob(nvs_handle_t handle, const char* key, void* out_value, size_t* length);
|
||||
/**@}*/
|
||||
|
||||
/**
|
||||
@ -333,7 +364,7 @@ esp_err_t nvs_get_blob(nvs_handle handle, const char* key, void* out_value, size
|
||||
* - ESP_ERR_NVS_NOT_FOUND if the requested key doesn't exist
|
||||
* - other error codes from the underlying storage driver
|
||||
*/
|
||||
esp_err_t nvs_erase_key(nvs_handle handle, const char* key);
|
||||
esp_err_t nvs_erase_key(nvs_handle_t handle, const char* key);
|
||||
|
||||
/**
|
||||
* @brief Erase all key-value pairs in a namespace
|
||||
@ -349,7 +380,7 @@ esp_err_t nvs_erase_key(nvs_handle handle, const char* key);
|
||||
* - ESP_ERR_NVS_READ_ONLY if handle was opened as read only
|
||||
* - other error codes from the underlying storage driver
|
||||
*/
|
||||
esp_err_t nvs_erase_all(nvs_handle handle);
|
||||
esp_err_t nvs_erase_all(nvs_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Write any pending changes to non-volatile storage
|
||||
@ -366,7 +397,7 @@ esp_err_t nvs_erase_all(nvs_handle handle);
|
||||
* - ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
|
||||
* - other error codes from the underlying storage driver
|
||||
*/
|
||||
esp_err_t nvs_commit(nvs_handle handle);
|
||||
esp_err_t nvs_commit(nvs_handle_t handle);
|
||||
|
||||
/**
|
||||
* @brief Close the storage handle and free any allocated resources
|
||||
@ -379,7 +410,7 @@ esp_err_t nvs_commit(nvs_handle handle);
|
||||
*
|
||||
* @param[in] handle Storage handle to close
|
||||
*/
|
||||
void nvs_close(nvs_handle handle);
|
||||
void nvs_close(nvs_handle_t handle);
|
||||
|
||||
/**
|
||||
* @note Info about storage space NVS.
|
||||
@ -424,7 +455,7 @@ typedef struct {
|
||||
* Return param nvs_stats will be filled not with correct values because
|
||||
* not all pages will be counted. Counting will be interrupted at the first INVALID page.
|
||||
*/
|
||||
esp_err_t nvs_get_stats(const char* part_name, nvs_stats_t* nvs_stats);
|
||||
esp_err_t nvs_get_stats(const char *part_name, nvs_stats_t *nvs_stats);
|
||||
|
||||
/**
|
||||
* @brief Calculate all entries in a namespace.
|
||||
@ -435,7 +466,7 @@ esp_err_t nvs_get_stats(const char* part_name, nvs_stats_t* nvs_stats);
|
||||
*
|
||||
* \code{c}
|
||||
* // Example of nvs_get_used_entry_count() to get amount of all key-value pairs in one namespace:
|
||||
* nvs_handle handle;
|
||||
* nvs_handle_t handle;
|
||||
* nvs_open("namespace1", NVS_READWRITE, &handle);
|
||||
* ...
|
||||
* size_t used_entries;
|
||||
@ -462,7 +493,70 @@ esp_err_t nvs_get_stats(const char* part_name, nvs_stats_t* nvs_stats);
|
||||
* - Other error codes from the underlying storage driver.
|
||||
* Return param used_entries will be filled 0.
|
||||
*/
|
||||
esp_err_t nvs_get_used_entry_count(nvs_handle handle, size_t* used_entries);
|
||||
esp_err_t nvs_get_used_entry_count(nvs_handle_t handle, size_t* used_entries);
|
||||
|
||||
/**
|
||||
* @brief Create an iterator to enumerate NVS entries based on one or more parameters
|
||||
*
|
||||
* \code{c}
|
||||
* // Example of listing all the key-value pairs of any type under specified partition and namespace
|
||||
* nvs_iterator_t it = nvs_entry_find(partition, namespace, NVS_TYPE_ANY);
|
||||
* while (it != NULL) {
|
||||
* nvs_entry_info_t info;
|
||||
* nvs_entry_info(it, &info);
|
||||
* it = nvs_entry_next(it);
|
||||
* printf("key '%s', type '%d' \n", info.key, info.type);
|
||||
* };
|
||||
* // Note: no need to release iterator obtained from nvs_entry_find function when
|
||||
* // nvs_entry_find or nvs_entry_next function return NULL, indicating no other
|
||||
* // element for specified criteria was found.
|
||||
* }
|
||||
* \endcode
|
||||
*
|
||||
* @param[in] part_name Partition name
|
||||
*
|
||||
* @param[in] namespace_name Set this value if looking for entries with
|
||||
* a specific namespace. Pass NULL otherwise.
|
||||
*
|
||||
* @param[in] type One of nvs_type_t values.
|
||||
*
|
||||
* @return
|
||||
* Iterator used to enumerate all the entries found,
|
||||
* or NULL if no entry satisfying criteria was found.
|
||||
* Iterator obtained through this function has to be released
|
||||
* using nvs_release_iterator when not used any more.
|
||||
*/
|
||||
nvs_iterator_t nvs_entry_find(const char *part_name, const char *namespace_name, nvs_type_t type);
|
||||
|
||||
/**
|
||||
* @brief Returns next item matching the iterator criteria, NULL if no such item exists.
|
||||
*
|
||||
* Note that any copies of the iterator will be invalid after this call.
|
||||
*
|
||||
* @param[in] iterator Iterator obtained from nvs_entry_find function. Must be non-NULL.
|
||||
*
|
||||
* @return
|
||||
* NULL if no entry was found, valid nvs_iterator_t otherwise.
|
||||
*/
|
||||
nvs_iterator_t nvs_entry_next(nvs_iterator_t iterator);
|
||||
|
||||
/**
|
||||
* @brief Fills nvs_entry_info_t structure with information about entry pointed to by the iterator.
|
||||
*
|
||||
* @param[in] iterator Iterator obtained from nvs_entry_find or nvs_entry_next function. Must be non-NULL.
|
||||
*
|
||||
* @param[out] out_info Structure to which entry information is copied.
|
||||
*/
|
||||
void nvs_entry_info(nvs_iterator_t iterator, nvs_entry_info_t *out_info);
|
||||
|
||||
/**
|
||||
* @brief Release iterator
|
||||
*
|
||||
* @param[in] iterator Release iterator obtained from nvs_entry_find function. NULL argument is allowed.
|
||||
*
|
||||
*/
|
||||
void nvs_release_iterator(nvs_iterator_t iterator);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
Reference in New Issue
Block a user