1 /*
2  * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _NVS_H
8 #define _NVS_H
9 
10 #include <stdio.h>
11 #include "nvs.h"
12 #include "nimble/storage_port.h"
13 
14 static int
nvs_open_custom(const char * namespace_name,open_mode_t open_mode,cache_handle_t * out_handle)15 nvs_open_custom(const char* namespace_name, open_mode_t open_mode, cache_handle_t *out_handle)
16 {
17     switch (open_mode) {
18     case READONLY:
19         return nvs_open(namespace_name, NVS_READONLY, out_handle);
20 
21     case READWRITE:
22         return nvs_open(namespace_name, NVS_READWRITE, out_handle);
23 
24     default:
25         return -1;
26     }
27 }
28 
29 struct cache_fn_mapping
link_storage_fn(void * storage_cb)30 link_storage_fn(void *storage_cb)
31 {
32     struct cache_fn_mapping cache_fn;
33     cache_fn.open = nvs_open_custom;
34     cache_fn.close = nvs_close;
35     cache_fn.erase_all = nvs_erase_all;
36     cache_fn.write = nvs_set_blob;
37     cache_fn.read = nvs_get_blob;
38     return cache_fn;
39 }
40 #endif
41