Skip to content

Commit b36fbbe

Browse files
committed
ESP32/NVS: use put rather than set
Right now there are `fetch` and `get` function, `put` name matches better current naming. Signed-off-by: Davide Bettio <[email protected]>
1 parent 2025e40 commit b36fbbe

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

doc/src/network-programming-guide.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,13 @@ If set in NVS storage, you may remove the corresponding `ssid` and `psk` paramet
231231

232232
You can set these credentials once, as follows:
233233

234-
esp:nvs_set_binary(atomvm, sta_ssid, <<"myssid">>).
235-
esp:nvs_set_binary(atomvm, sta_psk, <<"mypsk">>).
234+
esp:nvs_put_binary(atomvm, sta_ssid, <<"myssid">>).
235+
esp:nvs_put_binary(atomvm, sta_psk, <<"mypsk">>).
236236

237237
or
238238

239-
esp:nvs_set_binary(atomvm, ap_ssid, <<"myssid">>).
240-
esp:nvs_set_binary(atomvm, ap_psk, <<"mypsk">>).
239+
esp:nvs_put_binary(atomvm, ap_ssid, <<"myssid">>).
240+
esp:nvs_put_binary(atomvm, ap_psk, <<"mypsk">>).
241241

242242
With these settings, you can run ESP programs that initialize the network without configuring your SSID and PSK explicitly in source code.
243243

libs/eavmlib/src/esp.erl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
nvs_fetch_binary/2,
3636
nvs_get_binary/1, nvs_get_binary/2, nvs_get_binary/3,
3737
nvs_set_binary/2, nvs_set_binary/3,
38+
nvs_put_binary/3,
3839
nvs_erase_key/1, nvs_erase_key/2,
3940
nvs_erase_all/0, nvs_erase_all/1,
4041
nvs_reformat/0,
@@ -45,6 +46,8 @@
4546
get_mac/1
4647
]).
4748

49+
-deprecated([{nvs_set_binary, 2, next_version}, {nvs_set_binary, 3, next_version}]).
50+
4851
-type esp_reset_reason() ::
4952
esp_rst_unknown
5053
| esp_rst_poweron
@@ -197,6 +200,7 @@ nvs_get_binary(Namespace, Key, Default) when
197200

198201
%%-----------------------------------------------------------------------------
199202
%% @doc Equivalent to nvs_set_binary(?ATOMVM_NVS_NS, Key, Value).
203+
%% @deprecated Please use nvs_put_binary instead.
200204
%% @end
201205
%%-----------------------------------------------------------------------------
202206
-spec nvs_set_binary(Key :: atom(), Value :: binary()) -> ok.
@@ -210,11 +214,27 @@ nvs_set_binary(Key, Value) when is_atom(Key) andalso is_binary(Value) ->
210214
%% @returns ok
211215
%% @doc Set an binary value associated with a key. If a value exists
212216
%% for the specified key, it is over-written.
217+
%% @deprecated Please use nvs_put_binary instead.
213218
%% @end
214219
%%-----------------------------------------------------------------------------
215220
-spec nvs_set_binary(Namespace :: atom(), Key :: atom(), Value :: binary()) -> ok.
216221
nvs_set_binary(Namespace, Key, Value) when
217222
is_atom(Namespace) andalso is_atom(Key) andalso is_binary(Value)
223+
->
224+
nvs_put_binary(Namespace, Key, Value).
225+
226+
%%-----------------------------------------------------------------------------
227+
%% @param Namespace NVS namespace
228+
%% @param Key NVS key
229+
%% @param Value binary value
230+
%% @returns ok
231+
%% @doc Set an binary value associated with a key. If a value exists
232+
%% for the specified key, it is over-written.
233+
%% @end
234+
%%-----------------------------------------------------------------------------
235+
-spec nvs_put_binary(Namespace :: atom(), Key :: atom(), Value :: binary()) -> ok.
236+
nvs_put_binary(Namespace, Key, Value) when
237+
is_atom(Namespace) andalso is_atom(Key) andalso is_binary(Value)
218238
->
219239
erlang:nif_error(undefined).
220240

src/platforms/esp32/components/avm_builtins/nvs_nif.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static term nif_esp_nvs_get_binary(Context *ctx, int argc, term argv[])
121121
}
122122
}
123123

124-
static term nif_esp_nvs_set_binary(Context *ctx, int argc, term argv[])
124+
static term nif_esp_nvs_put_binary(Context *ctx, int argc, term argv[])
125125
{
126126
UNUSED(argc);
127127
VALIDATE_VALUE(argv[0], term_is_atom);
@@ -260,9 +260,9 @@ static const struct Nif esp_nvs_get_binary_nif = {
260260
.base.type = NIFFunctionType,
261261
.nif_ptr = nif_esp_nvs_get_binary
262262
};
263-
static const struct Nif esp_nvs_set_binary_nif = {
263+
static const struct Nif esp_nvs_put_binary_nif = {
264264
.base.type = NIFFunctionType,
265-
.nif_ptr = nif_esp_nvs_set_binary
265+
.nif_ptr = nif_esp_nvs_put_binary
266266
};
267267
static const struct Nif esp_nvs_erase_key_nif = {
268268
.base.type = NIFFunctionType,
@@ -294,9 +294,9 @@ const struct Nif *nvs_nif_get_nif(const char *nifname)
294294
TRACE("Resolved platform nif %s ...\n", nifname);
295295
return &esp_nvs_get_binary_nif;
296296
}
297-
if (strcmp("esp:nvs_set_binary/3", nifname) == 0) {
297+
if (strcmp("esp:nvs_put_binary/3", nifname) == 0) {
298298
TRACE("Resolved platform nif %s ...\n", nifname);
299-
return &esp_nvs_set_binary_nif;
299+
return &esp_nvs_put_binary_nif;
300300
}
301301
if (strcmp("esp:nvs_erase_key/2", nifname) == 0) {
302302
TRACE("Resolved platform nif %s ...\n", nifname);

0 commit comments

Comments
 (0)