VSF Documented
nvs.h
Go to the documentation of this file.
1/*============================ INCLUDES ======================================*/
2
3#ifndef __VSF_ESPIDF_NVS_H__
4#define __VSF_ESPIDF_NVS_H__
5
6#include <stdint.h>
7#include <stddef.h>
8#include <stdbool.h>
9#include "esp_err.h"
10
11#ifdef __cplusplus
12extern "C" {
13#endif
14
15/*============================ MACROS ========================================*/
16
17// ---------------------------------------------------------------------------
18// NVS-specific error codes (ESP_ERR_NVS_BASE = 0x1100)
19// ---------------------------------------------------------------------------
20
21#define ESP_ERR_NVS_BASE 0x1100
22#define ESP_ERR_NVS_NOT_INITIALIZED (ESP_ERR_NVS_BASE + 0x01)
23#define ESP_ERR_NVS_NOT_FOUND (ESP_ERR_NVS_BASE + 0x02)
24#define ESP_ERR_NVS_TYPE_MISMATCH (ESP_ERR_NVS_BASE + 0x03)
25#define ESP_ERR_NVS_READ_ONLY (ESP_ERR_NVS_BASE + 0x04)
26#define ESP_ERR_NVS_NOT_ENOUGH_SPACE (ESP_ERR_NVS_BASE + 0x05)
27#define ESP_ERR_NVS_INVALID_NAME (ESP_ERR_NVS_BASE + 0x06)
28#define ESP_ERR_NVS_INVALID_HANDLE (ESP_ERR_NVS_BASE + 0x07)
29#define ESP_ERR_NVS_REMOVE_FAILED (ESP_ERR_NVS_BASE + 0x08)
30#define ESP_ERR_NVS_KEY_TOO_LONG (ESP_ERR_NVS_BASE + 0x09)
31#define ESP_ERR_NVS_PAGE_FULL (ESP_ERR_NVS_BASE + 0x0a)
32#define ESP_ERR_NVS_INVALID_STATE (ESP_ERR_NVS_BASE + 0x0b)
33#define ESP_ERR_NVS_INVALID_LENGTH (ESP_ERR_NVS_BASE + 0x0c)
34#define ESP_ERR_NVS_NO_FREE_PAGES (ESP_ERR_NVS_BASE + 0x0d)
35#define ESP_ERR_NVS_VALUE_TOO_LONG (ESP_ERR_NVS_BASE + 0x0e)
36#define ESP_ERR_NVS_PART_NOT_FOUND (ESP_ERR_NVS_BASE + 0x0f)
37#define ESP_ERR_NVS_NEW_VERSION_FOUND (ESP_ERR_NVS_BASE + 0x10)
38#define ESP_ERR_NVS_XTS_ENCR_FAILED (ESP_ERR_NVS_BASE + 0x11)
39#define ESP_ERR_NVS_XTS_DECR_FAILED (ESP_ERR_NVS_BASE + 0x12)
40#define ESP_ERR_NVS_XTS_CFG_FAILED (ESP_ERR_NVS_BASE + 0x13)
41#define ESP_ERR_NVS_XTS_CFG_NOT_FOUND (ESP_ERR_NVS_BASE + 0x14)
42#define ESP_ERR_NVS_ENCR_NOT_SUPPORTED (ESP_ERR_NVS_BASE + 0x15)
43#define ESP_ERR_NVS_KEYS_NOT_INITIALIZED (ESP_ERR_NVS_BASE + 0x16)
44#define ESP_ERR_NVS_CORRUPT_KEY_PART (ESP_ERR_NVS_BASE + 0x17)
45#define ESP_ERR_NVS_CONTENT_DIFFERS (ESP_ERR_NVS_BASE + 0x18)
46#define ESP_ERR_NVS_WRONG_ENCRYPTION (ESP_ERR_NVS_BASE + 0x19)
47
48// ---------------------------------------------------------------------------
49// Constants
50// ---------------------------------------------------------------------------
51
52#define NVS_DEFAULT_PART_NAME "nvs"
53#define NVS_PART_NAME_MAX_SIZE 16
54#define NVS_KEY_NAME_MAX_SIZE 16
55#define NVS_NS_NAME_MAX_SIZE NVS_KEY_NAME_MAX_SIZE
56
57/*============================ MACROFIED FUNCTIONS ===========================*/
58/*============================ TYPES =========================================*/
59
60// ---------------------------------------------------------------------------
61// Handle
62// ---------------------------------------------------------------------------
63
65
66// ---------------------------------------------------------------------------
67// Open mode
68// ---------------------------------------------------------------------------
69
70typedef enum {
74
75// ---------------------------------------------------------------------------
76// Value types (encoding matches ESP-IDF v5.x)
77// ---------------------------------------------------------------------------
78
79typedef enum {
92
93// ---------------------------------------------------------------------------
94// Iterator entry info
95// ---------------------------------------------------------------------------
96
97typedef struct {
98 char namespace_name[NVS_NS_NAME_MAX_SIZE];
102
103// ---------------------------------------------------------------------------
104// Opaque iterator handle
105// ---------------------------------------------------------------------------
106
108
109// ---------------------------------------------------------------------------
110// NVS statistics
111// ---------------------------------------------------------------------------
112
113typedef struct {
119
120/*============================ GLOBAL VARIABLES ==============================*/
121/*============================ PROTOTYPES ====================================*/
122
123// ---------------------------------------------------------------------------
124// Open / close / commit
125// ---------------------------------------------------------------------------
126
127esp_err_t nvs_open(const char *namespace_name, nvs_open_mode_t open_mode,
128 nvs_handle_t *out_handle);
129esp_err_t nvs_open_from_partition(const char *part_name,
130 const char *namespace_name,
131 nvs_open_mode_t open_mode,
132 nvs_handle_t *out_handle);
133void nvs_close(nvs_handle_t handle);
135
136// ---------------------------------------------------------------------------
137// Setters (integer / string / blob)
138// ---------------------------------------------------------------------------
139
140esp_err_t nvs_set_i8 (nvs_handle_t handle, const char *key, int8_t value);
141esp_err_t nvs_set_u8 (nvs_handle_t handle, const char *key, uint8_t value);
148esp_err_t nvs_set_str (nvs_handle_t handle, const char *key,
149 const char *value);
150esp_err_t nvs_set_blob(nvs_handle_t handle, const char *key,
151 const void *value, size_t length);
152
153// ---------------------------------------------------------------------------
154// Getters (integer / string / blob)
155// For str/blob: if *length is 0, the actual required length is written back
156// to *length and the function returns ESP_OK with out_value untouched.
157// ---------------------------------------------------------------------------
158
159esp_err_t nvs_get_i8 (nvs_handle_t handle, const char *key, int8_t *out_value);
160esp_err_t nvs_get_u8 (nvs_handle_t handle, const char *key, uint8_t *out_value);
161esp_err_t nvs_get_i16(nvs_handle_t handle, const char *key, int16_t *out_value);
162esp_err_t nvs_get_u16(nvs_handle_t handle, const char *key, uint16_t *out_value);
163esp_err_t nvs_get_i32(nvs_handle_t handle, const char *key, int32_t *out_value);
164esp_err_t nvs_get_u32(nvs_handle_t handle, const char *key, uint32_t *out_value);
165esp_err_t nvs_get_i64(nvs_handle_t handle, const char *key, int64_t *out_value);
166esp_err_t nvs_get_u64(nvs_handle_t handle, const char *key, uint64_t *out_value);
167esp_err_t nvs_get_str (nvs_handle_t handle, const char *key,
168 char *out_value, size_t *length);
169esp_err_t nvs_get_blob(nvs_handle_t handle, const char *key,
170 void *out_value, size_t *length);
171
172// ---------------------------------------------------------------------------
173// Erase
174// ---------------------------------------------------------------------------
175
176esp_err_t nvs_erase_key(nvs_handle_t handle, const char *key);
178
179// ---------------------------------------------------------------------------
180// Stats / used-entry-count
181// ---------------------------------------------------------------------------
182
183esp_err_t nvs_get_stats(const char *part_name, nvs_stats_t *nvs_stats);
184esp_err_t nvs_get_used_entry_count(nvs_handle_t handle, size_t *used_entries);
185
186// ---------------------------------------------------------------------------
187// Iterator
188// ---------------------------------------------------------------------------
189
190esp_err_t nvs_entry_find(const char *part_name, const char *namespace_name,
191 nvs_type_t type, nvs_iterator_t *output_iterator);
194 nvs_entry_info_t *out_info);
196
197#ifdef __cplusplus
198}
199#endif
200
201#endif /* __VSF_ESPIDF_NVS_H__ */
int esp_err_t
Definition esp_err.h:41
nvs_open_mode_t
Definition nvs.h:70
@ NVS_READONLY
Definition nvs.h:71
@ NVS_READWRITE
Definition nvs.h:72
esp_err_t nvs_set_u8(nvs_handle_t handle, const char *key, uint8_t value)
esp_err_t nvs_entry_next(nvs_iterator_t *iterator)
Definition nvs_flash_port.c:882
esp_err_t nvs_erase_key(nvs_handle_t handle, const char *key)
Definition nvs_flash_port.c:760
uint32_t nvs_handle_t
Definition nvs.h:64
esp_err_t nvs_entry_find(const char *part_name, const char *namespace_name, nvs_type_t type, nvs_iterator_t *output_iterator)
Definition nvs_flash_port.c:853
esp_err_t nvs_open_from_partition(const char *part_name, const char *namespace_name, nvs_open_mode_t open_mode, nvs_handle_t *out_handle)
Definition nvs_flash_port.c:572
esp_err_t nvs_set_blob(nvs_handle_t handle, const char *key, const void *value, size_t length)
Definition nvs_flash_port.c:684
#define NVS_NS_NAME_MAX_SIZE
Definition nvs.h:55
void nvs_release_iterator(nvs_iterator_t iterator)
Definition nvs_flash_port.c:918
esp_err_t nvs_set_i32(nvs_handle_t handle, const char *key, int32_t value)
esp_err_t nvs_get_blob(nvs_handle_t handle, const char *key, void *out_value, size_t *length)
Definition nvs_flash_port.c:750
esp_err_t nvs_get_u16(nvs_handle_t handle, const char *key, uint16_t *out_value)
esp_err_t nvs_set_i64(nvs_handle_t handle, const char *key, int64_t value)
esp_err_t nvs_open(const char *namespace_name, nvs_open_mode_t open_mode, nvs_handle_t *out_handle)
Definition nvs_flash_port.c:565
esp_err_t nvs_get_i16(nvs_handle_t handle, const char *key, int16_t *out_value)
esp_err_t nvs_set_str(nvs_handle_t handle, const char *key, const char *value)
Definition nvs_flash_port.c:677
void nvs_close(nvs_handle_t handle)
Definition nvs_flash_port.c:601
esp_err_t nvs_set_i8(nvs_handle_t handle, const char *key, int8_t value)
#define NVS_KEY_NAME_MAX_SIZE
Definition nvs.h:54
esp_err_t nvs_get_i8(nvs_handle_t handle, const char *key, int8_t *out_value)
nvs_type_t
Definition nvs.h:79
@ NVS_TYPE_I32
Definition nvs.h:85
@ NVS_TYPE_U64
Definition nvs.h:86
@ NVS_TYPE_U8
Definition nvs.h:80
@ NVS_TYPE_STR
Definition nvs.h:88
@ NVS_TYPE_ANY
Definition nvs.h:90
@ NVS_TYPE_I8
Definition nvs.h:81
@ NVS_TYPE_I16
Definition nvs.h:83
@ NVS_TYPE_I64
Definition nvs.h:87
@ NVS_TYPE_BLOB
Definition nvs.h:89
@ NVS_TYPE_U32
Definition nvs.h:84
@ NVS_TYPE_U16
Definition nvs.h:82
esp_err_t nvs_set_u32(nvs_handle_t handle, const char *key, uint32_t value)
esp_err_t nvs_get_u32(nvs_handle_t handle, const char *key, uint32_t *out_value)
esp_err_t nvs_commit(nvs_handle_t handle)
Definition nvs_flash_port.c:607
esp_err_t nvs_erase_all(nvs_handle_t handle)
Definition nvs_flash_port.c:775
esp_err_t nvs_get_stats(const char *part_name, nvs_stats_t *nvs_stats)
Definition nvs_flash_port.c:799
esp_err_t nvs_get_i32(nvs_handle_t handle, const char *key, int32_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_str(nvs_handle_t handle, const char *key, char *out_value, size_t *length)
Definition nvs_flash_port.c:744
esp_err_t nvs_set_u64(nvs_handle_t handle, const char *key, uint64_t value)
esp_err_t nvs_get_u64(nvs_handle_t handle, const char *key, uint64_t *out_value)
struct nvs_opaque_iterator_t * nvs_iterator_t
Definition nvs.h:107
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_get_used_entry_count(nvs_handle_t handle, size_t *used_entries)
Definition nvs_flash_port.c:820
esp_err_t nvs_get_u8(nvs_handle_t handle, const char *key, uint8_t *out_value)
esp_err_t nvs_entry_info(const nvs_iterator_t iterator, nvs_entry_info_t *out_info)
Definition nvs_flash_port.c:902
unsigned short uint16_t
Definition stdint.h:7
unsigned uint32_t
Definition stdint.h:9
int int32_t
Definition stdint.h:8
long long int64_t
Definition stdint.h:10
short int16_t
Definition stdint.h:6
unsigned long long uint64_t
Definition stdint.h:11
unsigned char uint8_t
Definition stdint.h:5
signed char int8_t
Definition stdint.h:4
Definition nvs.h:97
nvs_type_t type
Definition nvs.h:100
Definition nvs_flash_port.c:141
Definition nvs.h:113
size_t used_entries
Definition nvs.h:114
size_t free_entries
Definition nvs.h:115
size_t namespace_count
Definition nvs.h:117
size_t total_entries
Definition nvs.h:116
vk_av_control_value_t value
Definition vsf_audio.h:171
vk_av_control_type_t type
Definition vsf_audio.h:170
uint_fast8_t length
Definition vsf_pbuf.c:38
Generated from commit: vsfteam/vsf@015f4d1