3232 wakeup_cause /0 ,
3333 sleep_enable_ext0_wakeup /2 ,
3434 sleep_enable_ext1_wakeup /2 ,
35+ nvs_fetch_binary /2 ,
3536 nvs_get_binary /1 , nvs_get_binary /2 , nvs_get_binary /3 ,
3637 nvs_set_binary /2 , nvs_set_binary /3 ,
38+ nvs_put_binary /3 ,
3739 nvs_erase_key /1 , nvs_erase_key /2 ,
3840 nvs_erase_all /0 , nvs_erase_all /1 ,
3941 nvs_reformat /0 ,
4446 get_mac /1
4547]).
4648
49+ -deprecated ([
50+ {nvs_get_binary , 1 , next_version },
51+ {nvs_erase_key , 1 , next_version },
52+ {nvs_erase_all , 0 , next_version },
53+ {nvs_set_binary , 2 , next_version },
54+ {nvs_set_binary , 3 , next_version }
55+ ]).
56+
4757-type esp_reset_reason () ::
4858 esp_rst_unknown
4959 | esp_rst_poweron
@@ -132,8 +142,24 @@ sleep_enable_ext0_wakeup(_Pin, _Level) ->
132142sleep_enable_ext1_wakeup (_Mask , _Mode ) ->
133143 erlang :nif_error (undefined ).
134144
145+ % %-----------------------------------------------------------------------------
146+ % % @param Namespace NVS namespace
147+ % % @param Key NVS key
148+ % % @returns tagged tuple with binary value associated with this key in NV
149+ % % storage, {error, not_found} if there is no value associated with
150+ % % this key, or in general {error, Reason} for any other error.
151+ % % @doc Get the binary value associated with a key, or undefined, if
152+ % % there is no value associated with this key.
153+ % % @end
154+ % %-----------------------------------------------------------------------------
155+ -spec nvs_fetch_binary (Namespace :: atom (), Key :: atom ()) ->
156+ {ok , binary ()} | {error , not_found } | {error , atom ()}.
157+ nvs_fetch_binary (Namespace , Key ) when is_atom (Namespace ) andalso is_atom (Key ) ->
158+ erlang :nif_error (undefined ).
159+
135160% %-----------------------------------------------------------------------------
136161% % @doc Equivalent to nvs_get_binary(?ATOMVM_NVS_NS, Key).
162+ % % @deprecated Please do not use this function.
137163% % @end
138164% %-----------------------------------------------------------------------------
139165-spec nvs_get_binary (Key :: atom ()) -> binary () | undefined .
@@ -151,7 +177,11 @@ nvs_get_binary(Key) when is_atom(Key) ->
151177% %-----------------------------------------------------------------------------
152178-spec nvs_get_binary (Namespace :: atom (), Key :: atom ()) -> binary () | undefined .
153179nvs_get_binary (Namespace , Key ) when is_atom (Namespace ) andalso is_atom (Key ) ->
154- erlang :nif_error (undefined ).
180+ case nvs_fetch_binary (Namespace , Key ) of
181+ {ok , Result } -> Result ;
182+ {errror , not_found } -> undefined ;
183+ {error , OtherError } -> throw (OtherError )
184+ end .
155185
156186% %-----------------------------------------------------------------------------
157187% % @param Namespace NVS namespace
@@ -177,6 +207,7 @@ nvs_get_binary(Namespace, Key, Default) when
177207
178208% %-----------------------------------------------------------------------------
179209% % @doc Equivalent to nvs_set_binary(?ATOMVM_NVS_NS, Key, Value).
210+ % % @deprecated Please use nvs_put_binary instead.
180211% % @end
181212% %-----------------------------------------------------------------------------
182213-spec nvs_set_binary (Key :: atom (), Value :: binary ()) -> ok .
@@ -190,18 +221,35 @@ nvs_set_binary(Key, Value) when is_atom(Key) andalso is_binary(Value) ->
190221% % @returns ok
191222% % @doc Set an binary value associated with a key. If a value exists
192223% % for the specified key, it is over-written.
224+ % % @deprecated Please use nvs_put_binary instead.
193225% % @end
194226% %-----------------------------------------------------------------------------
195227-spec nvs_set_binary (Namespace :: atom (), Key :: atom (), Value :: binary ()) -> ok .
196228nvs_set_binary (Namespace , Key , Value ) when
197229 is_atom (Namespace ) andalso is_atom (Key ) andalso is_binary (Value )
230+ ->
231+ nvs_put_binary (Namespace , Key , Value ).
232+
233+ % %-----------------------------------------------------------------------------
234+ % % @param Namespace NVS namespace
235+ % % @param Key NVS key
236+ % % @param Value binary value
237+ % % @returns ok
238+ % % @doc Set an binary value associated with a key. If a value exists
239+ % % for the specified key, it is over-written.
240+ % % @end
241+ % %-----------------------------------------------------------------------------
242+ -spec nvs_put_binary (Namespace :: atom (), Key :: atom (), Value :: binary ()) -> ok .
243+ nvs_put_binary (Namespace , Key , Value ) when
244+ is_atom (Namespace ) andalso is_atom (Key ) andalso is_binary (Value )
198245->
199246 erlang :nif_error (undefined ).
200247
201248% %-----------------------------------------------------------------------------
202249% % @param Key NVS key
203250% % @returns ok
204251% % @doc Equivalent to nvs_erase_key(?ATOMVM_NVS_NS, Key).
252+ % % @deprecated Please do not use this function.
205253% % @end
206254% %-----------------------------------------------------------------------------
207255-spec nvs_erase_key (Key :: atom ()) -> ok .
@@ -222,6 +270,7 @@ nvs_erase_key(Namespace, Key) when is_atom(Namespace) andalso is_atom(Key) ->
222270
223271% %-----------------------------------------------------------------------------
224272% % @doc Equivalent to nvs_erase_all(?ATOMVM_NVS_NS).
273+ % % @deprecated Please do not use this function.
225274% % @end
226275% %-----------------------------------------------------------------------------
227276-spec nvs_erase_all () -> ok .
0 commit comments