Skip to content

Commit 246358e

Browse files
committed
Merge pull request atomvm#756 from pguyot/w32/add-more-missing-functions-s
Add more missing function stubs Add functions used by examples and more. Also fix name of `esp:sleep_get_wakeup_cause/0` These changes are made under both the "Apache 2.0" and the "GNU Lesser General Public License 2.1 or later" license terms (dual license). SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
2 parents 9fee649 + 30df02f commit 246358e

File tree

4 files changed

+109
-5
lines changed

4 files changed

+109
-5
lines changed

libs/eavmlib/src/esp.erl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@
2929
-export([
3030
restart/0,
3131
reset_reason/0,
32-
wakeup_cause/0,
32+
sleep_get_wakeup_cause/0,
3333
sleep_enable_ext0_wakeup/2,
3434
sleep_enable_ext1_wakeup/2,
35+
deep_sleep/1,
3536
nvs_fetch_binary/2,
3637
nvs_get_binary/1, nvs_get_binary/2, nvs_get_binary/3,
3738
nvs_set_binary/2, nvs_set_binary/3,
@@ -122,8 +123,8 @@ reset_reason() ->
122123
%% @doc Returns the cause for the wakeup
123124
%% @end
124125
%%-----------------------------------------------------------------------------
125-
-spec wakeup_cause() -> undefined | esp_wakeup_cause() | error.
126-
wakeup_cause() ->
126+
-spec sleep_get_wakeup_cause() -> undefined | esp_wakeup_cause() | error.
127+
sleep_get_wakeup_cause() ->
127128
erlang:nif_error(undefined).
128129

129130
%%-----------------------------------------------------------------------------
@@ -142,6 +143,18 @@ sleep_enable_ext0_wakeup(_Pin, _Level) ->
142143
sleep_enable_ext1_wakeup(_Mask, _Mode) ->
143144
erlang:nif_error(undefined).
144145

146+
%%-----------------------------------------------------------------------------
147+
%% @param SleepMS time to deep sleep in milliseconds
148+
%% @doc Put the esp32 into deep sleep.
149+
%% This function never returns. Program is restarted and wake up reason can be
150+
%% inspected to determine if the esp32 was woken by the timeout or by another
151+
%% cause.
152+
%% @end
153+
%%-----------------------------------------------------------------------------
154+
-spec deep_sleep(SleepMS :: non_neg_integer()) -> no_return().
155+
deep_sleep(_SleepMS) ->
156+
erlang:nif_error(undefined).
157+
145158
%%-----------------------------------------------------------------------------
146159
%% @param Namespace NVS namespace
147160
%% @param Key NVS key

libs/estdlib/src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ include(BuildErlang)
2424

2525
set(ERLANG_MODULES
2626
base64
27+
binary
2728
calendar
2829
crypto
2930
gen_event

libs/estdlib/src/binary.erl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
%
2+
% This file is part of AtomVM.
3+
%
4+
% Copyright 2023 Paul Guyot <pguyot@kallisys.net>
5+
%
6+
% Licensed under the Apache License, Version 2.0 (the "License");
7+
% you may not use this file except in compliance with the License.
8+
% You may obtain a copy of the License at
9+
%
10+
% http://www.apache.org/licenses/LICENSE-2.0
11+
%
12+
% Unless required by applicable law or agreed to in writing, software
13+
% distributed under the License is distributed on an "AS IS" BASIS,
14+
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
% See the License for the specific language governing permissions and
16+
% limitations under the License.
17+
%
18+
% SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
19+
%
20+
21+
%%-----------------------------------------------------------------------------
22+
%% @doc An implementation of a subset of the Erlang/OTP binary interface.
23+
%% @end
24+
%%-----------------------------------------------------------------------------
25+
-module(binary).
26+
27+
-export([at/2]).
28+
29+
%%-----------------------------------------------------------------------------
30+
%% @param Binary binary to get a byte from
31+
%% @param Index 0-based index of the byte to return
32+
%% @returns value of the byte from the binary
33+
%% @doc Get a byte from a binary by index.
34+
%% @end
35+
%%-----------------------------------------------------------------------------
36+
-spec at(Binary :: binary(), Index :: non_neg_integer()) -> byte().
37+
at(_Binary, _Index) ->
38+
erlang:nif_error(undefined).

libs/estdlib/src/erlang.erl

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,21 @@
7979
open_port/2,
8080
system_time/1,
8181
group_leader/0,
82+
group_leader/2,
8283
process_flag/2,
8384
get_module_info/1,
8485
get_module_info/2,
8586
processes/0,
8687
binary_to_term/1,
87-
term_to_binary/1
88+
term_to_binary/1,
89+
timestamp/0,
90+
universaltime/0,
91+
localtime/0
8892
]).
8993

9094
-export_type([
91-
time_unit/0
95+
time_unit/0,
96+
timestamp/0
9297
]).
9398

9499
%%
@@ -100,6 +105,9 @@
100105

101106
-type mem_type() :: binary().
102107
-type time_unit() :: second | millisecond | microsecond.
108+
-type timestamp() :: {
109+
MegaSecs :: non_neg_integer(), Secs :: non_neg_integer(), MicroSecs :: non_neg_integer
110+
}.
103111

104112
%%-----------------------------------------------------------------------------
105113
%% @param Time time in milliseconds after which to send the timeout message.
@@ -833,6 +841,17 @@ system_time(_Unit) ->
833841
group_leader() ->
834842
erlang:nif_error(undefined).
835843

844+
%%-----------------------------------------------------------------------------
845+
%% @param Leader pid of process to set as leader
846+
%% @param Pid pid of process to set a Leader
847+
%% @returns `true'
848+
%% @doc Set the group leader for a given process.
849+
%% @end
850+
%%-----------------------------------------------------------------------------
851+
-spec group_leader(Leader :: pid(), Pid :: pid()) -> true.
852+
group_leader(_Leader, _Pid) ->
853+
erlang:nif_error(undefined).
854+
836855
%%-----------------------------------------------------------------------------
837856
%% @param Flag flag to change
838857
%% @param Value new value of the flag
@@ -913,3 +932,36 @@ binary_to_term(_Binary) ->
913932
-spec term_to_binary(Term :: any()) -> binary().
914933
term_to_binary(_Term) ->
915934
erlang:nif_error(undefined).
935+
936+
%%-----------------------------------------------------------------------------
937+
%% @returns A tuple representing the current timestamp.
938+
%% @see monotonic_time/1
939+
%% @see system_time/1
940+
%% @doc Return the timestamp in `{MegaSec, Sec, MicroSec}' format.
941+
%% This the old format returned by `erlang:now/0'. Please note that the latter
942+
%% which is deprecated in Erlang/OTP is not implemented by AtomVM.
943+
%% @end
944+
%%-----------------------------------------------------------------------------
945+
-spec timestamp() -> erlang:timestamp().
946+
timestamp() ->
947+
erlang:nif_error(undefined).
948+
949+
%%-----------------------------------------------------------------------------
950+
%% @returns A tuple representing the current universal time.
951+
%% @see localtime/0
952+
%% @doc Return the current time and day for UTC.
953+
%% @end
954+
%%-----------------------------------------------------------------------------
955+
-spec universaltime() -> calendar:datetime().
956+
universaltime() ->
957+
erlang:nif_error(undefined).
958+
959+
%%-----------------------------------------------------------------------------
960+
%% @returns A tuple representing the current local time.
961+
%% @see universaltime/0
962+
%% @doc Return the current time and day for system local timezone.
963+
%% @end
964+
%%-----------------------------------------------------------------------------
965+
-spec localtime() -> calendar:datetime().
966+
localtime() ->
967+
erlang:nif_error(undefined).

0 commit comments

Comments
 (0)