Skip to content

Commit 682054a

Browse files
committed
WIP: redo API; not compiled yet
1 parent ffff02c commit 682054a

File tree

21 files changed

+445
-454
lines changed

21 files changed

+445
-454
lines changed

locale/circuitpython.pot

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PACKAGE VERSION\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2020-11-04 21:18+0530\n"
11+
"POT-Creation-Date: 2020-11-19 00:22-0500\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language-Team: LANGUAGE <[email protected]>\n"
@@ -303,7 +303,8 @@ msgstr ""
303303
msgid "All I2C peripherals are in use"
304304
msgstr ""
305305

306-
#: ports/esp32s2/peripherals/pcnt_handler.c
306+
#: ports/esp32s2/common-hal/countio/Counter.c
307+
#: ports/esp32s2/common-hal/rotaryio/IncrementalEncoder.c
307308
msgid "All PCNT units in use"
308309
msgstr ""
309310

@@ -3221,6 +3222,7 @@ msgstr ""
32213222
msgid "pow() with 3 arguments requires integers"
32223223
msgstr ""
32233224

3225+
#: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h
32243226
#: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h
32253227
#: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h
32263228
#: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h
@@ -3328,7 +3330,7 @@ msgstr ""
33283330
msgid "size is defined for ndarrays only"
33293331
msgstr ""
33303332

3331-
#: shared-bindings/alarm_time/__init__.c shared-bindings/time/__init__.c
3333+
#: shared-bindings/time/__init__.c
33323334
msgid "sleep length must be non-negative"
33333335
msgstr ""
33343336

ports/esp32s2/mpconfigport.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ LONGINT_IMPL = MPZ
1515
# These modules are implemented in ports/<port>/common-hal:
1616
CIRCUITPY_FULL_BUILD = 1
1717
CIRCUITPY_ALARM = 1
18-
CIRCUITPY_ALARM_IO = 1
19-
CIRCUITPY_ALARM_TIME = 1
20-
CIRCUITPY_ALARM_TOUCH = 1
2118
CIRCUITPY_AUDIOBUSIO = 0
2219
CIRCUITPY_AUDIOIO = 0
2320
CIRCUITPY_CANIO = 1

py/circuitpy_defns.mk

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,6 @@ endif
102102
ifeq ($(CIRCUITPY_ALARM),1)
103103
SRC_PATTERNS += alarm/%
104104
endif
105-
ifeq ($(CIRCUITPY_ALARM_IO),1)
106-
SRC_PATTERNS += alarm_io/%
107-
endif
108-
ifeq ($(CIRCUITPY_ALARM_TIME),1)
109-
SRC_PATTERNS += alarm_time/%
110-
endif
111-
ifeq ($(CIRCUITPY_ALARM_TOUCH),1)
112-
SRC_PATTERNS += alarm_touch/%
113-
endif
114105
ifeq ($(CIRCUITPY_ANALOGIO),1)
115106
SRC_PATTERNS += analogio/%
116107
endif
@@ -247,9 +238,6 @@ endif
247238
ifeq ($(CIRCUITPY_SHARPDISPLAY),1)
248239
SRC_PATTERNS += sharpdisplay/%
249240
endif
250-
ifeq ($(CIRCUITPY_SLEEP),1)
251-
SRC_PATTERNS += sleep/%
252-
endif
253241
ifeq ($(CIRCUITPY_SOCKETPOOL),1)
254242
SRC_PATTERNS += socketpool/%
255243
endif
@@ -314,9 +302,9 @@ SRC_COMMON_HAL_ALL = \
314302
_pew/PewPew.c \
315303
_pew/__init__.c \
316304
alarm/__init__.c \
317-
alarm_io/__init__.c \
318-
alarm_time/__init__.c \
319-
alarm_touch/__init__.c \
305+
alarm/pin/__init__.c \
306+
alarm/time/__init__.c \
307+
alarm/touch/__init__.c \
320308
analogio/AnalogIn.c \
321309
analogio/AnalogOut.c \
322310
analogio/__init__.c \
@@ -372,8 +360,8 @@ SRC_COMMON_HAL_ALL = \
372360
rtc/__init__.c \
373361
sdioio/SDCard.c \
374362
sdioio/__init__.c \
375-
sleep/__init__.c \
376-
sleep/ResetReason.c \
363+
sleepio/__init__.c \
364+
sleepio/ResetReason.c \
377365
socketpool/__init__.c \
378366
socketpool/SocketPool.c \
379367
socketpool/Socket.c \

py/circuitpy_mpconfig.h

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -250,27 +250,6 @@ extern const struct _mp_obj_module_t alarm_module;
250250
#define ALARM_MODULE
251251
#endif
252252

253-
#if CIRCUITPY_ALARM_IO
254-
extern const struct _mp_obj_module_t alarm_io_module;
255-
#define ALARM_IO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_io), (mp_obj_t)&alarm_io_module },
256-
#else
257-
#define ALARM_IO_MODULE
258-
#endif
259-
260-
#if CIRCUITPY_ALARM_TIME
261-
extern const struct _mp_obj_module_t alarm_time_module;
262-
#define ALARM_TIME_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_time), (mp_obj_t)&alarm_time_module },
263-
#else
264-
#define ALARM_TIME_MODULE
265-
#endif
266-
267-
#if CIRCUITPY_ALARM_TOUCH
268-
extern const struct _mp_obj_module_t alarm_touch_module;
269-
#define ALARM_TOUCH_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_touch), (mp_obj_t)&alarm_touch_module },
270-
#else
271-
#define ALARM_TOUCH_MODULE
272-
#endif
273-
274253
#if CIRCUITPY_ANALOGIO
275254
#define ANALOGIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module },
276255
extern const struct _mp_obj_module_t analogio_module;
@@ -642,13 +621,6 @@ extern const struct _mp_obj_module_t sharpdisplay_module;
642621
#define SHARPDISPLAY_MODULE
643622
#endif
644623

645-
#if CIRCUITPY_SLEEP
646-
extern const struct _mp_obj_module_t sleep_module;
647-
#define SLEEP_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_sleep),(mp_obj_t)&sleep_module },
648-
#else
649-
#define SLEEP_MODULE
650-
#endif
651-
652624
#if CIRCUITPY_SOCKETPOOL
653625
extern const struct _mp_obj_module_t socketpool_module;
654626
#define SOCKETPOOL_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_socketpool), (mp_obj_t)&socketpool_module },
@@ -807,9 +779,6 @@ extern const struct _mp_obj_module_t wifi_module;
807779
#define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \
808780
AESIO_MODULE \
809781
ALARM_MODULE \
810-
ALARM_IO_MODULE \
811-
ALARM_TIME_MODULE \
812-
ALARM_TOUCH_MODULE \
813782
ANALOGIO_MODULE \
814783
AUDIOBUSIO_MODULE \
815784
AUDIOCORE_MODULE \
@@ -862,7 +831,6 @@ extern const struct _mp_obj_module_t wifi_module;
862831
SDCARDIO_MODULE \
863832
SDIOIO_MODULE \
864833
SHARPDISPLAY_MODULE \
865-
SLEEP_MODULE \
866834
SOCKETPOOL_MODULE \
867835
SSL_MODULE \
868836
STAGE_MODULE \

py/circuitpy_mpconfig.mk

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,15 @@ CFLAGS += -DMICROPY_PY_ASYNC_AWAIT=$(MICROPY_PY_ASYNC_AWAIT)
3939
CIRCUITPY_AESIO ?= 0
4040
CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO)
4141

42+
# TODO: CIRCUITPY_ALARM will gradually be added to
43+
# as many ports as possible
44+
# so make this 1 or CIRCUITPY_FULL_BUILD eventually
45+
CIRCUITPY_SLEEPIO ?= 0
46+
CFLAGS += -DCIRCUITPY_SLEEPIO=$(CIRCUITPY_SLEEPIO)
47+
4248
CIRCUITPY_ALARM ?= 0
4349
CFLAGS += -DCIRCUITPY_ALARM=$(CIRCUITPY_ALARM)
4450

45-
CIRCUITPY_ALARM_IO ?= 0
46-
CFLAGS += -DCIRCUITPY_ALARM_IO=$(CIRCUITPY_ALARM_IO)
47-
48-
CIRCUITPY_ALARM_TIME ?= 0
49-
CFLAGS += -DCIRCUITPY_ALARM_TIME=$(CIRCUITPY_ALARM_TIME)
50-
51-
CIRCUITPY_ALARM_TOUCH ?= 0
52-
CFLAGS += -DCIRCUITPY_ALARM_TOUCH=$(CIRCUITPY_ALARM_TOUCH)
53-
5451
CIRCUITPY_ANALOGIO ?= 1
5552
CFLAGS += -DCIRCUITPY_ANALOGIO=$(CIRCUITPY_ANALOGIO)
5653

@@ -221,11 +218,6 @@ CFLAGS += -DCIRCUITPY_SDIOIO=$(CIRCUITPY_SDIOIO)
221218
CIRCUITPY_SHARPDISPLAY ?= $(CIRCUITPY_FRAMEBUFFERIO)
222219
CFLAGS += -DCIRCUITPY_SHARPDISPLAY=$(CIRCUITPY_SHARPDISPLAY)
223220

224-
# TODO: CIRCUITPY_SLEEP will gradually be added to all ports
225-
# even if it doesn't actually sleep, so make this 1 eventually.
226-
CIRCUITPY_SLEEP ?= 0
227-
CFLAGS += -DCIRCUITPY_SLEEP=$(CIRCUITPY_SLEEP)
228-
229221
CIRCUITPY_SOCKETPOOL ?= $(CIRCUITPY_WIFI)
230222
CFLAGS += -DCIRCUITPY_SOCKETPOOL=$(CIRCUITPY_SOCKETPOOL)
231223

shared-bindings/sleep/ResetReason.c renamed to shared-bindings/alarm/ResetReason.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
#include "py/enum.h"
2828

29-
#include "shared-bindings/sleep/ResetReason.h"
29+
#include "shared-bindings/alarm/ResetReason.h"
3030

31-
MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_VALID);
32-
MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE);
33-
MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM);
34-
MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EXTERNAL);
31+
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_VALID);
32+
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE);
33+
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM);
34+
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EXTERNAL);
3535

3636
//| class ResetReason:
3737
//| """The reason the chip was last reset"""
@@ -48,14 +48,14 @@ MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EX
4848
//| EXTERNAL: object
4949
//| """The chip was reset by an external input such as a button."""
5050
//|
51-
MAKE_ENUM_MAP(sleep_reset_reason) {
51+
MAKE_ENUM_MAP(alarm_reset_reason) {
5252
MAKE_ENUM_MAP_ENTRY(reset_reason, POWER_VALID),
5353
MAKE_ENUM_MAP_ENTRY(reset_reason, SOFTWARE),
5454
MAKE_ENUM_MAP_ENTRY(reset_reason, DEEP_SLEEP_ALARM),
5555
MAKE_ENUM_MAP_ENTRY(reset_reason, EXTERNAL),
5656
};
57-
STATIC MP_DEFINE_CONST_DICT(sleep_reset_reason_locals_dict, sleep_reset_reason_locals_table);
57+
STATIC MP_DEFINE_CONST_DICT(alarm_reset_reason_locals_dict, alarm_reset_reason_locals_table);
5858

59-
MAKE_PRINTER(sleep, sleep_reset_reason);
59+
MAKE_PRINTER(alarm, alarm_reset_reason);
6060

61-
MAKE_ENUM_TYPE(sleep, ResetReason, sleep_reset_reason);
61+
MAKE_ENUM_TYPE(alarm, ResetReason, alarm_reset_reason);

shared-bindings/sleep/ResetReason.h renamed to shared-bindings/alarm/ResetReason.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
* THE SOFTWARE.
2525
*/
2626

27-
#pragma once
27+
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
28+
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
2829

2930
typedef enum {
3031
RESET_REASON_POWER_APPLIED,
3132
RESET_REASON_SOFTWARE,
3233
RESET_REASON_DEEP_SLEEP_ALARM,
3334
RESET_REASON_BUTTON,
34-
} sleep_reset_reason_t;
35+
} alarm_reset_reason_t;
3536

36-
extern const mp_obj_type_t sleep_reset_reason_type;
37+
extern const mp_obj_type_t alarm_reset_reason_type;
38+
39+
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H

shared-bindings/alarm/__init__.c

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
//| """Power-saving light and deep sleep. Alarms can be set to wake up from sleep.
2+
//|
3+
//| The `alarm` module provides sleep related functionality. There are two supported levels of
4+
//| sleep, light and deep.
5+
//|
6+
//| Light sleep leaves the CPU and RAM powered so that CircuitPython can resume where it left off
7+
//| after being woken up. CircuitPython automatically goes into a light sleep when `time.sleep()` is
8+
//| called. To light sleep until a non-time alarm use `alarm.sleep_until_alarm()`. Any active
9+
//| peripherals, such as I2C, are left on.
10+
//|
11+
//| Deep sleep shuts down power to nearly all of the chip including the CPU and RAM. This can save
12+
//| a more significant amount of power, but CircuitPython must start ``code.py`` from the beginning when woken
13+
//| up. CircuitPython will enter deep sleep automatically when the current program exits without error
14+
//| or calls `sys.exit(0)`.
15+
//| If an error causes CircuitPython to exit, error LED error flashes will be done periodically.
16+
//| An error includes an uncaught exception, or sys.exit called with a non-zero argumetn.
17+
//| To set alarms for deep sleep use `alarm.reload_on_alarm()` they will apply to next deep sleep only."""
18+
//|
19+
20+
//| wake_alarm: Alarm
21+
//| """The most recent alarm to wake us up from a sleep (light or deep.)"""
22+
//|
23+
24+
//| reset_reason: ResetReason
25+
//| """The reason the chip started up from reset state. This can may be power up or due to an alarm."""
26+
//|
27+
28+
//| def sleep(alarm: Alarm, ...) -> Alarm:
29+
//| """Performs a light sleep until woken by one of the alarms. The alarm that triggers the wake
30+
//| is returned, and is also available as `alarm.wake_alarm`
31+
//| ...
32+
//|
33+
34+
#include "py/obj.h"
35+
#include "py/runtime.h"
36+
37+
#include "shared-bindings/alarm/pin/__init__.h"
38+
#include "shared-bindings/alarm/time/__init__.h"
39+
40+
STATIC mp_obj_t alarm_sleep_until_alarm(size_t n_args, const mp_obj_t *args) {
41+
// TODO
42+
}
43+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_sleep_until_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, alarm_sleep_until_alarm);
44+
45+
//| def restart_on_alarm(alarm: Alarm, ...) -> None:
46+
//| """Set one or more alarms to wake up from a deep sleep.
47+
//| When awakened, ``code.py`` will restart from the beginning.
48+
//| The last alarm to wake us up is available as `wake_alarm`.
49+
//| """
50+
//| ...
51+
//|
52+
STATIC mp_obj_t alarm_restart_on_alarm(size_t n_args, const mp_obj_t *args) {
53+
// TODO
54+
}
55+
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_restart_on_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, alarm_restart_on_alarm);
56+
57+
//| """The `alarm.pin` module contains alarm attributes and classes related to pins
58+
//| """
59+
//|
60+
mp_map_elem_t alarm_pin_globals_table[] = {
61+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pin) },
62+
63+
{ MP_ROM_QSTR(MP_QSTR_PinAlarm), MP_ROM_PTR(&alarm_pin_pin_alarm_type) },
64+
};
65+
66+
STATIC MP_DEFINE_CONST_DICT(alarm_pin_globals, alarm_pin_globals_table);
67+
68+
const mp_obj_module_t alarm_pin_module = {
69+
.base = { &mp_type_module },
70+
.globals = (mp_obj_dict_t*)&alarm_pinn_globals,
71+
};
72+
73+
//| """The `alarm.time` module contains alarm attributes and classes related to time-keeping.
74+
//| """
75+
//|
76+
mp_map_elem_t alarm_time_globals_table[] = {
77+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_time) },
78+
79+
{ MP_ROM_QSTR(MP_QSTR_DurationAlarm), MP_ROM_PTR(&alarm_time_duration_alarm_type) },
80+
};
81+
82+
STATIC MP_DEFINE_CONST_DICT(alarm_time_globals, alarm_time_globals_table);
83+
84+
const mp_obj_module_t alarm_time_module = {
85+
.base = { &mp_type_module },
86+
.globals = (mp_obj_dict_t*)&alarm_time_globals,
87+
};
88+
89+
mp_map_elem_t alarm_module_globals_table[] = {
90+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm) },
91+
92+
// wake_alarm and reset_reason are mutable attributes.
93+
{ MP_ROM_QSTR(MP_QSTR_wake_alarm), mp_const_none },
94+
{ MP_ROM_QSTR(MP_QSTR_reset_reason), mp_const_none },
95+
96+
{ MP_ROM_QSTR(MP_QSTR_sleep_until_alarm), MP_ROM_PTR(&alarm_sleep_until_alarm_obj) },
97+
{ MP_ROM_QSTR(MP_QSTR_restart_on_alarm), MP_ROM_PTR(&alarm_restart_on_alarm_obj) },
98+
99+
{ MP_ROM_QSTR(MP_QSTR_pin), MP_ROM_PTR(&alarm_pin_module) },
100+
{ MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&alarm_time_module) }
101+
102+
};
103+
STATIC MP_DEFINE_MUTABLE_DICT(alarm_module_globals, alarm_module_globals_table);
104+
105+
// These are called from common_hal code to set the current wake alarm.
106+
void common_hal_alarm_set_wake_alarm(mp_obj_t alarm) {
107+
// Equivalent of:
108+
// alarm.wake_alarm = alarm
109+
mp_map_elem_t *elem =
110+
mp_map_lookup(&alarm_module_globals_table, MP_ROM_QSTR(MP_QSTR_wake_alarm), MP_MAP_LOOKUP);
111+
if (elem) {
112+
elem->value = alarm;
113+
}
114+
}
115+
116+
// These are called from common hal code to set the current wake alarm.
117+
void common_hal_alarm_set_reset_reason(mp_obj_t reset_reason) {
118+
// Equivalent of:
119+
// alarm.reset_reason = reset_reason
120+
mp_map_elem_t *elem =
121+
mp_map_lookup(&alarm_module_globals_table, MP_ROM_QSTR(MP_QSTR_reset_reason), MP_MAP_LOOKUP);
122+
if (elem) {
123+
elem->value = reset_reason;
124+
}
125+
}
126+
127+
const mp_obj_module_t alarm_module = {
128+
.base = { &mp_type_module },
129+
.globals = (mp_obj_dict_t*)&alarm_module_globals,
130+
};

0 commit comments

Comments
 (0)