|
|
@@ -171,10 +171,10 @@ esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_o
|
|
|
|
|
|
/**@{*/
|
|
|
/**
|
|
|
- * @brief set value for given key
|
|
|
+ * @brief set int8_t value for given key
|
|
|
*
|
|
|
- * This family of functions set value for the key, given its name. Note that
|
|
|
- * actual storage will not be updated until nvs_commit function is called.
|
|
|
+ * Set value for the key, given its name. Note that the actual storage will not be updated
|
|
|
+ * until \c nvs_commit is called.
|
|
|
*
|
|
|
* @param[in] handle Handle obtained from nvs_open function.
|
|
|
* Handles that were opened read only cannot be used.
|
|
|
@@ -182,8 +182,6 @@ esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_o
|
|
|
* implementation, but is guaranteed to be at least
|
|
|
* 15 characters. Shouldn't be empty.
|
|
|
* @param[in] value The value to set.
|
|
|
- * For strings, the maximum length (including null character) is
|
|
|
- * 4000 bytes.
|
|
|
*
|
|
|
* @return
|
|
|
* - ESP_OK if value was set successfully
|
|
|
@@ -196,16 +194,85 @@ esp_err_t nvs_open_from_partition(const char *part_name, const char* name, nvs_o
|
|
|
* write operation has failed. The value was written however, and
|
|
|
* update will be finished after re-initialization of nvs, provided that
|
|
|
* 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_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_i8 (nvs_handle_t handle, const char* key, int8_t value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief set uint8_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_set_i8 except for the data type.
|
|
|
+ */
|
|
|
+esp_err_t nvs_set_u8 (nvs_handle_t handle, const char* key, uint8_t value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief set int16_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_set_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_set_i16 (nvs_handle_t handle, const char* key, int16_t value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief set uint16_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_set_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_set_u16 (nvs_handle_t handle, const char* key, uint16_t value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief set int32_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_set_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_set_i32 (nvs_handle_t handle, const char* key, int32_t value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief set uint32_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_set_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_set_u32 (nvs_handle_t handle, const char* key, uint32_t value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief set int64_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_set_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_set_i64 (nvs_handle_t handle, const char* key, int64_t value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief set uint64_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_set_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_set_u64 (nvs_handle_t handle, const char* key, uint64_t value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief set string for given key
|
|
|
+ *
|
|
|
+ * Set value for the key, given its name. Note that the actual storage will not be updated
|
|
|
+ * until \c nvs_commit is called.
|
|
|
+ *
|
|
|
+ * @param[in] handle Handle obtained from nvs_open function.
|
|
|
+ * Handles that were opened read only cannot be used.
|
|
|
+ * @param[in] key Key name. Maximal length is (NVS_KEY_NAME_MAX_SIZE-1) characters. Shouldn't be empty.
|
|
|
+ * @param[in] value The value to set.
|
|
|
+ * For strings, the maximum length (including null character) is
|
|
|
+ * 4000 bytes, if there is one complete page free for writing.
|
|
|
+ * This decreases, however, if the free space is fragmented.
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ * - ESP_OK if value was set successfully
|
|
|
+ * - ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
|
|
|
+ * - ESP_ERR_NVS_READ_ONLY if storage handle was opened as read only
|
|
|
+ * - ESP_ERR_NVS_INVALID_NAME if key name doesn't satisfy constraints
|
|
|
+ * - ESP_ERR_NVS_NOT_ENOUGH_SPACE if there is not enough space in the
|
|
|
+ * underlying storage to save the value
|
|
|
+ * - ESP_ERR_NVS_REMOVE_FAILED if the value wasn't updated because flash
|
|
|
+ * write operation has failed. The value was written however, and
|
|
|
+ * update will be finished after re-initialization of nvs, provided that
|
|
|
+ * flash operation doesn't fail again.
|
|
|
+ * - ESP_ERR_NVS_VALUE_TOO_LONG if the string value is too long
|
|
|
+ */
|
|
|
esp_err_t nvs_set_str (nvs_handle_t handle, const char* key, const char* value);
|
|
|
/**@}*/
|
|
|
|
|
|
@@ -240,16 +307,15 @@ esp_err_t nvs_set_blob(nvs_handle_t handle, const char* key, const void* value,
|
|
|
|
|
|
/**@{*/
|
|
|
/**
|
|
|
- * @brief get value for given key
|
|
|
+ * @brief get int8_t value for given key
|
|
|
*
|
|
|
- * These functions retrieve value for the key, given its name. If key does not
|
|
|
+ * These functions retrieve value for the key, given its name. If \c key does not
|
|
|
* exist, or the requested variable type doesn't match the type which was used
|
|
|
* when setting a value, an error is returned.
|
|
|
*
|
|
|
* In case of any error, out_value is not modified.
|
|
|
*
|
|
|
- * All functions expect out_value to be a pointer to an already allocated variable
|
|
|
- * of the given type.
|
|
|
+ * \c out_value has to be a pointer to an already allocated variable of the given type.
|
|
|
*
|
|
|
* \code{c}
|
|
|
* // Example of using nvs_get_i32:
|
|
|
@@ -276,18 +342,61 @@ esp_err_t nvs_set_blob(nvs_handle_t handle, const char* key, const void* value,
|
|
|
* - 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_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_i8 (nvs_handle_t handle, const char* key, int8_t* out_value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief get uint8_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_get_i8 except for the data type.
|
|
|
+ */
|
|
|
+esp_err_t nvs_get_u8 (nvs_handle_t handle, const char* key, uint8_t* out_value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief get int16_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_get_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_get_i16 (nvs_handle_t handle, const char* key, int16_t* out_value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief get uint16_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_get_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_get_u16 (nvs_handle_t handle, const char* key, uint16_t* out_value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief get int32_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_get_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_get_i32 (nvs_handle_t handle, const char* key, int32_t* out_value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief get uint32_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_get_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_get_u32 (nvs_handle_t handle, const char* key, uint32_t* out_value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief get int64_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_get_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_get_i64 (nvs_handle_t handle, const char* key, int64_t* out_value);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief get uint64_t value for given key
|
|
|
+ *
|
|
|
+ * This function is the same as \c nvs_get_i8 except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_get_u64 (nvs_handle_t handle, const char* key, uint64_t* out_value);
|
|
|
/**@}*/
|
|
|
|
|
|
+/**@{*/
|
|
|
/**
|
|
|
- * @brief get value for given key
|
|
|
+ * @brief get string value for given key
|
|
|
*
|
|
|
* These functions retrieve the data of an entry, given its key. If key does not
|
|
|
* exist, or the requested variable type doesn't match the type which was used
|
|
|
@@ -323,10 +432,8 @@ esp_err_t nvs_get_u64 (nvs_handle_t handle, const char* key, uint64_t* out_value
|
|
|
* \endcode
|
|
|
*
|
|
|
* @param[in] handle Handle obtained from nvs_open function.
|
|
|
- * @param[in] key Key name. Maximal length is determined by the underlying
|
|
|
- * implementation, but is guaranteed to be at least
|
|
|
- * 15 characters. Shouldn't be empty.
|
|
|
- * @param out_value Pointer to the output value.
|
|
|
+ * @param[in] key Key name. Maximal length is (NVS_KEY_NAME_MAX_SIZE-1) characters. Shouldn't be empty.
|
|
|
+ * @param[out] out_value Pointer to the output value.
|
|
|
* May be NULL for nvs_get_str and nvs_get_blob, in this
|
|
|
* case required length will be returned in length argument.
|
|
|
* @param[inout] length A non-zero pointer to the variable holding the length of out_value.
|
|
|
@@ -340,10 +447,15 @@ esp_err_t nvs_get_u64 (nvs_handle_t handle, const char* key, uint64_t* out_value
|
|
|
* - ESP_ERR_NVS_NOT_FOUND if the requested key doesn't exist
|
|
|
* - ESP_ERR_NVS_INVALID_HANDLE if handle has been closed or is NULL
|
|
|
* - 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_NVS_INVALID_LENGTH if \c length is not sufficient to store data
|
|
|
*/
|
|
|
-/**@{*/
|
|
|
esp_err_t nvs_get_str (nvs_handle_t handle, const char* key, char* out_value, size_t* length);
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief get blob value for given key
|
|
|
+ *
|
|
|
+ * This function behaves the same as \c nvs_get_str, except for the data type.
|
|
|
+ */
|
|
|
esp_err_t nvs_get_blob(nvs_handle_t handle, const char* key, void* out_value, size_t* length);
|
|
|
/**@}*/
|
|
|
|
|
|
@@ -462,7 +574,9 @@ esp_err_t nvs_get_stats(const char *part_name, nvs_stats_t *nvs_stats);
|
|
|
/**
|
|
|
* @brief Calculate all entries in a namespace.
|
|
|
*
|
|
|
- * Note that to find out the total number of records occupied by the namespace,
|
|
|
+ * An entry represents the smallest storage unit in NVS.
|
|
|
+ * Strings and blobs may occupy more than one entry.
|
|
|
+ * Note that to find out the total number of entries occupied by the namespace,
|
|
|
* add one to the returned value used_entries (if err is equal to ESP_OK).
|
|
|
* Because the name space entry takes one entry.
|
|
|
*
|
|
|
@@ -474,7 +588,7 @@ esp_err_t nvs_get_stats(const char *part_name, nvs_stats_t *nvs_stats);
|
|
|
* size_t used_entries;
|
|
|
* size_t total_entries_namespace;
|
|
|
* if(nvs_get_used_entry_count(handle, &used_entries) == ESP_OK){
|
|
|
- * // the total number of records occupied by the namespace
|
|
|
+ * // the total number of entries occupied by the namespace
|
|
|
* total_entries_namespace = used_entries + 1;
|
|
|
* }
|
|
|
* \endcode
|