summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
authorDan Halbert <halbert@halwitz.org>2020-11-18 20:44:34 -0500
committerDan Halbert <halbert@halwitz.org>2020-11-19 00:23:27 -0500
commit682054a2169c108ad69e84acdb53fdd26405077e (patch)
treefd3ca900764489ab312657a0ca168daf5b4b5af3 /shared-bindings
parentffff02c053ff7975dc6a6c5ef5b5f424f0b04dad (diff)
WIP: redo API; not compiled yet
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/alarm/ResetReason.c (renamed from shared-bindings/sleep/ResetReason.c)18
-rw-r--r--shared-bindings/alarm/ResetReason.h (renamed from shared-bindings/sleep/ResetReason.h)9
-rw-r--r--shared-bindings/alarm/__init__.c130
-rw-r--r--shared-bindings/alarm/__init__.h35
-rw-r--r--shared-bindings/alarm/pin/PinAlarm.c116
-rw-r--r--shared-bindings/alarm/pin/PinAlarm.h (renamed from shared-bindings/alarm_time/Time.h)22
-rw-r--r--shared-bindings/alarm/time/DurationAlarm.c91
-rw-r--r--shared-bindings/alarm/time/DurationAlarm.h34
-rw-r--r--shared-bindings/alarm_io/__init__.c53
-rw-r--r--shared-bindings/alarm_io/__init__.h17
-rw-r--r--shared-bindings/alarm_time/Time.c76
-rw-r--r--shared-bindings/alarm_time/__init__.c76
-rw-r--r--shared-bindings/alarm_time/__init__.h15
-rw-r--r--shared-bindings/microcontroller/__init__.c1
-rw-r--r--shared-bindings/sleep/__init__.c112
-rw-r--r--shared-bindings/sleep/__init__.h9
16 files changed, 429 insertions, 385 deletions
diff --git a/shared-bindings/sleep/ResetReason.c b/shared-bindings/alarm/ResetReason.c
index cce55a81a..456715a08 100644
--- a/shared-bindings/sleep/ResetReason.c
+++ b/shared-bindings/alarm/ResetReason.c
@@ -26,12 +26,12 @@
#include "py/enum.h"
-#include "shared-bindings/sleep/ResetReason.h"
+#include "shared-bindings/alarm/ResetReason.h"
-MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_VALID);
-MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE);
-MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM);
-MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EXTERNAL);
+MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_VALID);
+MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE);
+MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM);
+MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EXTERNAL);
//| class ResetReason:
//| """The reason the chip was last reset"""
@@ -48,14 +48,14 @@ MAKE_ENUM_VALUE(sleep_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EX
//| EXTERNAL: object
//| """The chip was reset by an external input such as a button."""
//|
-MAKE_ENUM_MAP(sleep_reset_reason) {
+MAKE_ENUM_MAP(alarm_reset_reason) {
MAKE_ENUM_MAP_ENTRY(reset_reason, POWER_VALID),
MAKE_ENUM_MAP_ENTRY(reset_reason, SOFTWARE),
MAKE_ENUM_MAP_ENTRY(reset_reason, DEEP_SLEEP_ALARM),
MAKE_ENUM_MAP_ENTRY(reset_reason, EXTERNAL),
};
-STATIC MP_DEFINE_CONST_DICT(sleep_reset_reason_locals_dict, sleep_reset_reason_locals_table);
+STATIC MP_DEFINE_CONST_DICT(alarm_reset_reason_locals_dict, alarm_reset_reason_locals_table);
-MAKE_PRINTER(sleep, sleep_reset_reason);
+MAKE_PRINTER(alarm, alarm_reset_reason);
-MAKE_ENUM_TYPE(sleep, ResetReason, sleep_reset_reason);
+MAKE_ENUM_TYPE(alarm, ResetReason, alarm_reset_reason);
diff --git a/shared-bindings/sleep/ResetReason.h b/shared-bindings/alarm/ResetReason.h
index 2b312bb89..6fe7a4bd3 100644
--- a/shared-bindings/sleep/ResetReason.h
+++ b/shared-bindings/alarm/ResetReason.h
@@ -24,13 +24,16 @@
* THE SOFTWARE.
*/
-#pragma once
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
typedef enum {
RESET_REASON_POWER_APPLIED,
RESET_REASON_SOFTWARE,
RESET_REASON_DEEP_SLEEP_ALARM,
RESET_REASON_BUTTON,
-} sleep_reset_reason_t;
+} alarm_reset_reason_t;
-extern const mp_obj_type_t sleep_reset_reason_type;
+extern const mp_obj_type_t alarm_reset_reason_type;
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
diff --git a/shared-bindings/alarm/__init__.c b/shared-bindings/alarm/__init__.c
new file mode 100644
index 000000000..20535e156
--- /dev/null
+++ b/shared-bindings/alarm/__init__.c
@@ -0,0 +1,130 @@
+//| """Power-saving light and deep sleep. Alarms can be set to wake up from sleep.
+//|
+//| The `alarm` module provides sleep related functionality. There are two supported levels of
+//| sleep, light and deep.
+//|
+//| Light sleep leaves the CPU and RAM powered so that CircuitPython can resume where it left off
+//| after being woken up. CircuitPython automatically goes into a light sleep when `time.sleep()` is
+//| called. To light sleep until a non-time alarm use `alarm.sleep_until_alarm()`. Any active
+//| peripherals, such as I2C, are left on.
+//|
+//| Deep sleep shuts down power to nearly all of the chip including the CPU and RAM. This can save
+//| a more significant amount of power, but CircuitPython must start ``code.py`` from the beginning when woken
+//| up. CircuitPython will enter deep sleep automatically when the current program exits without error
+//| or calls `sys.exit(0)`.
+//| If an error causes CircuitPython to exit, error LED error flashes will be done periodically.
+//| An error includes an uncaught exception, or sys.exit called with a non-zero argumetn.
+//| To set alarms for deep sleep use `alarm.reload_on_alarm()` they will apply to next deep sleep only."""
+//|
+
+//| wake_alarm: Alarm
+//| """The most recent alarm to wake us up from a sleep (light or deep.)"""
+//|
+
+//| reset_reason: ResetReason
+//| """The reason the chip started up from reset state. This can may be power up or due to an alarm."""
+//|
+
+//| def sleep(alarm: Alarm, ...) -> Alarm:
+//| """Performs a light sleep until woken by one of the alarms. The alarm that triggers the wake
+//| is returned, and is also available as `alarm.wake_alarm`
+//| ...
+//|
+
+#include "py/obj.h"
+#include "py/runtime.h"
+
+#include "shared-bindings/alarm/pin/__init__.h"
+#include "shared-bindings/alarm/time/__init__.h"
+
+STATIC mp_obj_t alarm_sleep_until_alarm(size_t n_args, const mp_obj_t *args) {
+ // TODO
+}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_sleep_until_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, alarm_sleep_until_alarm);
+
+//| def restart_on_alarm(alarm: Alarm, ...) -> None:
+//| """Set one or more alarms to wake up from a deep sleep.
+//| When awakened, ``code.py`` will restart from the beginning.
+//| The last alarm to wake us up is available as `wake_alarm`.
+//| """
+//| ...
+//|
+STATIC mp_obj_t alarm_restart_on_alarm(size_t n_args, const mp_obj_t *args) {
+ // TODO
+}
+MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(alarm_restart_on_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, alarm_restart_on_alarm);
+
+//| """The `alarm.pin` module contains alarm attributes and classes related to pins
+//| """
+//|
+mp_map_elem_t alarm_pin_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_pin) },
+
+ { MP_ROM_QSTR(MP_QSTR_PinAlarm), MP_ROM_PTR(&alarm_pin_pin_alarm_type) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(alarm_pin_globals, alarm_pin_globals_table);
+
+const mp_obj_module_t alarm_pin_module = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&alarm_pinn_globals,
+};
+
+//| """The `alarm.time` module contains alarm attributes and classes related to time-keeping.
+//| """
+//|
+mp_map_elem_t alarm_time_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_time) },
+
+ { MP_ROM_QSTR(MP_QSTR_DurationAlarm), MP_ROM_PTR(&alarm_time_duration_alarm_type) },
+};
+
+STATIC MP_DEFINE_CONST_DICT(alarm_time_globals, alarm_time_globals_table);
+
+const mp_obj_module_t alarm_time_module = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&alarm_time_globals,
+};
+
+mp_map_elem_t alarm_module_globals_table[] = {
+ { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm) },
+
+ // wake_alarm and reset_reason are mutable attributes.
+ { MP_ROM_QSTR(MP_QSTR_wake_alarm), mp_const_none },
+ { MP_ROM_QSTR(MP_QSTR_reset_reason), mp_const_none },
+
+ { MP_ROM_QSTR(MP_QSTR_sleep_until_alarm), MP_ROM_PTR(&alarm_sleep_until_alarm_obj) },
+ { MP_ROM_QSTR(MP_QSTR_restart_on_alarm), MP_ROM_PTR(&alarm_restart_on_alarm_obj) },
+
+ { MP_ROM_QSTR(MP_QSTR_pin), MP_ROM_PTR(&alarm_pin_module) },
+ { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&alarm_time_module) }
+
+};
+STATIC MP_DEFINE_MUTABLE_DICT(alarm_module_globals, alarm_module_globals_table);
+
+// These are called from common_hal code to set the current wake alarm.
+void common_hal_alarm_set_wake_alarm(mp_obj_t alarm) {
+ // Equivalent of:
+ // alarm.wake_alarm = alarm
+ mp_map_elem_t *elem =
+ mp_map_lookup(&alarm_module_globals_table, MP_ROM_QSTR(MP_QSTR_wake_alarm), MP_MAP_LOOKUP);
+ if (elem) {
+ elem->value = alarm;
+ }
+}
+
+// These are called from common hal code to set the current wake alarm.
+void common_hal_alarm_set_reset_reason(mp_obj_t reset_reason) {
+ // Equivalent of:
+ // alarm.reset_reason = reset_reason
+ mp_map_elem_t *elem =
+ mp_map_lookup(&alarm_module_globals_table, MP_ROM_QSTR(MP_QSTR_reset_reason), MP_MAP_LOOKUP);
+ if (elem) {
+ elem->value = reset_reason;
+ }
+}
+
+const mp_obj_module_t alarm_module = {
+ .base = { &mp_type_module },
+ .globals = (mp_obj_dict_t*)&alarm_module_globals,
+};
diff --git a/shared-bindings/alarm/__init__.h b/shared-bindings/alarm/__init__.h
new file mode 100644
index 000000000..ce9cc79f4
--- /dev/null
+++ b/shared-bindings/alarm/__init__.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Dan Halbert for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM___INIT___H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM___INIT___H
+
+#include "py/obj.h"
+
+extern void common_hal_alarm_set_wake_alarm(mp_obj_t alarm);
+extern void common_hal_alarm_set_reset_reason(mp_obj_t reset_reason);
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM___INIT___H
diff --git a/shared-bindings/alarm/pin/PinAlarm.c b/shared-bindings/alarm/pin/PinAlarm.c
new file mode 100644
index 000000000..1404fa3f4
--- /dev/null
+++ b/shared-bindings/alarm/pin/PinAlarm.c
@@ -0,0 +1,116 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Dan Halbert for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "shared-bindings/board/__init__.h"
+#include "shared-bindings/microcontroller/__init__.h"
+#include "shared-bindings/microcontroller/Pin.h"
+
+#include "py/nlr.h"
+#include "py/obj.h"
+#include "py/runtime.h"
+#include "supervisor/shared/translate.h"
+
+//| class PinAlarm:
+//| """Trigger an alarm when a pin changes state.
+//|
+//| def __init__(self, pin: microcontroller.Pin, level: bool, *, edge: bool = False, pull: bool = False) -> None:
+//| """Create an alarm triggered by a `~microcontroller.Pin` level. The alarm is not active
+//| until it is listed in an `alarm`-enabling function, such as `alarm.sleep()` or
+//| `alarm.wake_after_exit()`.
+
+//| :param ~microcontroller.Pin pin: The pin to monitor. On some ports, the choice of pin
+//| may be limited due to hardware restrictions, particularly for deep-sleep alarms.
+//| :param bool level: When active, trigger when the level is high (``True``) or low (``False``).
+//| On some ports, multiple `PinAlarm` objects may need to have coordinated levels
+//| for deep-sleep alarms
+//| :param bool edge: If ``True``, trigger only when there is a transition to the specified
+//| value of `level`. If ``True``, if the alarm becomes active when the pin level already
+//| matches `level`, the alarm is not triggered: the pin must transition from ``not level``
+//| to ``level`` to trigger the alarm. On some ports, edge-triggering may not be available,
+//| particularly for deep-sleep alarms.
+//| :param bool pull: Enable a pull-up or pull-down which pulls the pin to level opposite
+//| opposite that of `level`. For instance, if `level` is set to ``True``, setting `pull`
+//| to ``True`` will enable a pull-down, to hold the pin low normally until an outside signal
+//| pulls it high.
+//| """
+//| ...
+//|
+STATIC mp_obj_t alarm_pin_pin_alarm_make_new(const mp_obj_type_t *type,
+ mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+ alarm_pin_pin_alarm_obj_t *self = m_new_obj(alarm_pin_pin_alarm_obj_t);
+ self->base.type = &alarm_pin_pin_alarm_type;
+ enum { ARG_pin, ARG_level, ARG_edge, ARG_pull };
+ static const mp_arg_t allowed_args[] = {
+ { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ },
+ { MP_QSTR_level, MP_ARG_REQUIRED | MP_ARG_BOOL },
+ { MP_QSTR_edge, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
+ { MP_QSTR_pull, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
+ };
+ mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
+ mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
+
+ const mcu_pin_obj_t* pin = validate_obj_is_free_pin(args[ARG_pin].u_obj);
+
+ common_hal_alarm_pin_pin_pin_alarm_construct(
+ self, pin, args[ARG_level].u_bool, args[ARG_edge].u_bool, args[ARG_pull].u_bool);
+
+ return MP_OBJ_FROM_PTR(self);
+}
+
+//| def __eq__(self, other: object) -> bool:
+//| """Two PinAlarm objects are equal if their durations are the same if their pin,
+//| level, edge, and pull attributes are all the same."""
+//| ...
+//|
+STATIC mp_obj_t alarm_pin_pin_alarm_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+ switch (op) {
+ case MP_BINARY_OP_EQUAL:
+ if (MP_OBJ_IS_TYPE(rhs_in, &alarm_pin_pin_alarm_type)) {
+ // Pins are singletons, so we can compare them directly.
+ return mp_obj_new_bool(
+ common_hal_pin_pin_alarm_get_pin(lhs_in) == common_hal_pin_pin_alarm_get_pin(rhs_in) &&
+ common_hal_pin_pin_alarm_get_level(lhs_in) == common_hal_pin_pin_alarm_get_level(rhs_in) &&
+ common_hal_pin_pin_alarm_get_edge(lhs_in) == common_hal_pin_pin_alarm_get_edge(rhs_in) &&
+ common_hal_pin_pin_alarm_get_pull(lhs_in) == common_hal_pin_pin_alarm_get_pull(rhs_in))
+ }
+ return mp_const_false;
+
+ default:
+ return MP_OBJ_NULL; // op not supported
+ }
+}
+
+STATIC const mp_rom_map_elem_t alarm_pin_pin_alarm_locals_dict_table[] = {
+};
+
+STATIC MP_DEFINE_CONST_DICT(alarm_pin_pin_alarm_locals, alarm_pin_pin_alarm_locals_dict);
+
+const mp_obj_type_t alarm_pin_pin_alarm_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_PinAlarm,
+ .make_new = alarm_pin_pin_alarm_make_new,
+ .locals_dict = (mp_obj_t)&alarm_pin_pin_alarm_locals,
+};
diff --git a/shared-bindings/alarm_time/Time.h b/shared-bindings/alarm/pin/PinAlarm.h
index 9962c26f2..e38c7f620 100644
--- a/shared-bindings/alarm_time/Time.h
+++ b/shared-bindings/alarm/pin/PinAlarm.h
@@ -1,9 +1,9 @@
/*
- * This file is part of the Micro Python project, http://micropython.org/
+ * This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
- * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries
+ * Copyright (c) 2020 Dan Halbert for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -24,19 +24,13 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_TIME_H
-#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_TIME_H
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H
-#include "py/runtime.h"
+#include "py/obj.h"
-typedef struct {
- mp_obj_base_t base;
- uint64_t time_to_alarm;
-} alarm_time_time_obj_t;
+extern const mp_obj_type_t alarm_pin_pin_alarm_type;
-extern const mp_obj_type_t alarm_time_time_type;
+extern void common_hal_alarm_pin_pin_pin_alarm_construct(alarm_pin_pin_alarm_obj_t *self, const mcu_pin_obj_t *pin, bool level, bool edge, bool pull);
-void common_hal_alarm_time_time_construct(alarm_time_time_obj_t* self,
- uint64_t ticks_ms);
-
-#endif //MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_TIME_H
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H
diff --git a/shared-bindings/alarm/time/DurationAlarm.c b/shared-bindings/alarm/time/DurationAlarm.c
new file mode 100644
index 000000000..c30c7f326
--- /dev/null
+++ b/shared-bindings/alarm/time/DurationAlarm.c
@@ -0,0 +1,91 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Dan Halbert for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "shared-bindings/board/__init__.h"
+#include "shared-bindings/microcontroller/__init__.h"
+#include "shared-bindings/microcontroller/Pin.h"
+
+#include "py/nlr.h"
+#include "py/obj.h"
+#include "py/runtime.h"
+#include "supervisor/shared/translate.h"
+
+//| class DurationAlarm:
+//| """Trigger an alarm at a specified interval from now.
+//|
+//| def __init__(self, secs: float) -> None:
+//| """Create an alarm that will be triggered in `secs` seconds **from the time
+//| the alarm is created**. The alarm is not active until it is listed in an
+//| `alarm`-enabling function, such as `alarm.sleep()` or
+//| `alarm.wake_after_exit()`. But the interval starts immediately upon
+//| instantiation.
+//| """
+//| ...
+//|
+STATIC mp_obj_t alarm_time_duration_alarm_make_new(const mp_obj_type_t *type,
+ mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) {
+ mp_arg_check_num(n_args, kw_args, 1, 1, false);
+
+ alarm_pin_duration_alarm_obj_t *self = m_new_obj(alarm_pin_duration_alarm_obj_t);
+ self->base.type = &alarm_pin_pin_alarm_type;
+
+ mp_float_t secs = mp_obj_get_float(args[0]);
+
+ common_hal_alarm_time_duration_alarm_construct(self, secs);
+
+ return MP_OBJ_FROM_PTR(self);
+}
+
+//| def __eq__(self, other: object) -> bool:
+//| """Two DurationAlarm objects are equal if their durations are the same."""
+//| ...
+//|
+STATIC mp_obj_t alarm_time_duration_alarm_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
+ switch (op) {
+ case MP_BINARY_OP_EQUAL:
+ if (MP_OBJ_IS_TYPE(rhs_in, &alarm_time_duration_alarm_type)) {
+ return mp_obj_new_bool(
+ common_hal_alarm_time_duration_alarm_get_duration(lhs_in) ==
+ common_hal_alarm_time_duration_alarm_get_duration(rhs_in));
+ }
+ return mp_const_false;
+
+ default:
+ return MP_OBJ_NULL; // op not supported
+ }
+}
+
+STATIC const mp_rom_map_elem_t alarm_time_duration_alarm_locals_dict_table[] = {
+};
+
+STATIC MP_DEFINE_CONST_DICT(alarm_time_duration_alarm_locals_dict, alarm_time_duration_alarm_locals_dict_table);
+
+const mp_obj_type_t alarm_time_duration_alarm_type = {
+ { &mp_type_type },
+ .name = MP_QSTR_DurationAlarm,
+ .make_new = alarm_time_duration_alarm_make_new,
+ .locals_dict = (mp_obj_t)&alarm_time_duration_alarm_locals,
+};
diff --git a/shared-bindings/alarm/time/DurationAlarm.h b/shared-bindings/alarm/time/DurationAlarm.h
new file mode 100644
index 000000000..1e4db6ac5
--- /dev/null
+++ b/shared-bindings/alarm/time/DurationAlarm.h
@@ -0,0 +1,34 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Dan Halbert for Adafruit Industries
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_DURATION_ALARM_H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_DURATION_ALARM_H
+
+#include "py/obj.h"
+
+extern const mp_obj_type_t alarm_time_duration_alarm_type;
+
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_DURATION_ALARM_H
diff --git a/shared-bindings/alarm_io/__init__.c b/shared-bindings/alarm_io/__init__.c
deleted file mode 100644
index 4e42f9a2e..000000000
--- a/shared-bindings/alarm_io/__init__.c
+++ /dev/null
@@ -1,53 +0,0 @@
-#include "py/obj.h"
-
-#include "shared-bindings/alarm_io/__init__.h"
-#include "shared-bindings/microcontroller/Pin.h"
-
-//| """alarm_io module
-//|
-//| The `alarm_io` module implements deep sleep."""
-
-STATIC mp_obj_t alarm_io_pin_state(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
- enum { ARG_level, ARG_pull };
- static const mp_arg_t allowed_args[] = {
- { MP_QSTR_level, MP_ARG_INT | MP_ARG_KW_ONLY | MP_ARG_REQUIRED },
- { MP_QSTR_pull, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_bool = false} },
- };
-
- mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
- mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args);
-
- mcu_pin_obj_t *pin = validate_obj_is_pin(pos_args[0]);
- alarm_io_obj_t *self = m_new_obj(alarm_io_obj_t);
-
- self->base.type = &alarm_io_type;
- self->gpio = pin->number;
- self->level = args[ARG_level].u_int;
- self->pull = args[ARG_pull].u_bool;
-
- return common_hal_alarm_io_pin_state(self);
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_KW(alarm_io_pin_state_obj, 1, alarm_io_pin_state);
-
-STATIC mp_obj_t alarm_io_disable(void) {
- common_hal_alarm_io_disable();
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_io_disable_obj, alarm_io_disable);
-
-STATIC const mp_rom_map_elem_t alarm_io_module_globals_table[] = {
- { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm_io) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_PinState), MP_ROM_PTR(&alarm_io_pin_state_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_io_disable_obj) },
-};
-STATIC MP_DEFINE_CONST_DICT(alarm_io_module_globals, alarm_io_module_globals_table);
-
-const mp_obj_module_t alarm_io_module = {
- .base = { &mp_type_module },
- .globals = (mp_obj_dict_t*)&alarm_io_module_globals,
-};
-
-const mp_obj_type_t alarm_io_type = {
- { &mp_type_type },
- .name = MP_QSTR_ioAlarm,
-};
diff --git a/shared-bindings/alarm_io/__init__.h b/shared-bindings/alarm_io/__init__.h
deleted file mode 100644
index 0a53497c0..000000000
--- a/shared-bindings/alarm_io/__init__.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_IO___INIT___H
-#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_IO___INIT___H
-
-#include "py/runtime.h"
-
-typedef struct {
- mp_obj_base_t base;
- uint8_t gpio, level;
- bool pull;
-} alarm_io_obj_t;
-
-extern const mp_obj_type_t alarm_io_type;
-
-extern mp_obj_t common_hal_alarm_io_pin_state (alarm_io_obj_t *self_in);
-extern void common_hal_alarm_io_disable (void);
-
-#endif //MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_IO___INIT___H
diff --git a/shared-bindings/alarm_time/Time.c b/shared-bindings/alarm_time/Time.c
deleted file mode 100644
index 904bf522e..000000000
--- a/shared-bindings/alarm_time/Time.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Scott Shawcroft
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "py/obj.h"
-#include "shared-bindings/alarm_time/__init__.h"
-
-//| """alarm_time module
-//|
-//| The `alarm_time` module implements deep sleep."""
-
-STATIC mp_obj_t alarm_time_duration(mp_obj_t seconds_o) {
- #if MICROPY_PY_BUILTINS_FLOAT
- mp_float_t seconds = mp_obj_get_float(seconds_o);
- mp_float_t msecs = 1000.0f * seconds + 0.5f;
- #else
- mp_int_t seconds = mp_obj_get_int(seconds_o);
- mp_int_t msecs = 1000 * seconds;
- #endif
-
- if (seconds < 0) {
- mp_raise_ValueError(translate("sleep length must be non-negative"));
- }
- common_hal_alarm_time_duration(msecs);
-
- alarm_time_obj_t *self = m_new_obj(alarm_time_obj_t);
- self->base.type = &alarm_time_type;
-
- return self;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(alarm_time_duration_obj, alarm_time_duration);
-
-STATIC mp_obj_t alarm_time_disable(void) {
- common_hal_alarm_time_disable();
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_time_disable_obj, alarm_time_disable);
-
-STATIC const mp_rom_map_elem_t alarm_time_module_globals_table[] = {
- { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm_time) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Duration), MP_ROM_PTR(&alarm_time_duration_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_time_disable_obj) },
-};
-STATIC MP_DEFINE_CONST_DICT(alarm_time_module_globals, alarm_time_module_globals_table);
-
-const mp_obj_module_t alarm_time_module = {
- .base = { &mp_type_module },
- .globals = (mp_obj_dict_t*)&alarm_time_module_globals,
-};
-
-const mp_obj_type_t alarm_time_type = {
- { &mp_type_type },
- .name = MP_QSTR_timeAlarm,
-};
diff --git a/shared-bindings/alarm_time/__init__.c b/shared-bindings/alarm_time/__init__.c
deleted file mode 100644
index 904bf522e..000000000
--- a/shared-bindings/alarm_time/__init__.c
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Scott Shawcroft
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "py/obj.h"
-#include "shared-bindings/alarm_time/__init__.h"
-
-//| """alarm_time module
-//|
-//| The `alarm_time` module implements deep sleep."""
-
-STATIC mp_obj_t alarm_time_duration(mp_obj_t seconds_o) {
- #if MICROPY_PY_BUILTINS_FLOAT
- mp_float_t seconds = mp_obj_get_float(seconds_o);
- mp_float_t msecs = 1000.0f * seconds + 0.5f;
- #else
- mp_int_t seconds = mp_obj_get_int(seconds_o);
- mp_int_t msecs = 1000 * seconds;
- #endif
-
- if (seconds < 0) {
- mp_raise_ValueError(translate("sleep length must be non-negative"));
- }
- common_hal_alarm_time_duration(msecs);
-
- alarm_time_obj_t *self = m_new_obj(alarm_time_obj_t);
- self->base.type = &alarm_time_type;
-
- return self;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_1(alarm_time_duration_obj, alarm_time_duration);
-
-STATIC mp_obj_t alarm_time_disable(void) {
- common_hal_alarm_time_disable();
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(alarm_time_disable_obj, alarm_time_disable);
-
-STATIC const mp_rom_map_elem_t alarm_time_module_globals_table[] = {
- { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_alarm_time) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Duration), MP_ROM_PTR(&alarm_time_duration_obj) },
- { MP_OBJ_NEW_QSTR(MP_QSTR_Disable), MP_ROM_PTR(&alarm_time_disable_obj) },
-};
-STATIC MP_DEFINE_CONST_DICT(alarm_time_module_globals, alarm_time_module_globals_table);
-
-const mp_obj_module_t alarm_time_module = {
- .base = { &mp_type_module },
- .globals = (mp_obj_dict_t*)&alarm_time_module_globals,
-};
-
-const mp_obj_type_t alarm_time_type = {
- { &mp_type_type },
- .name = MP_QSTR_timeAlarm,
-};
diff --git a/shared-bindings/alarm_time/__init__.h b/shared-bindings/alarm_time/__init__.h
deleted file mode 100644
index a96383069..000000000
--- a/shared-bindings/alarm_time/__init__.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME___INIT___H
-#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME___INIT___H
-
-#include "py/runtime.h"
-
-typedef struct {
- mp_obj_base_t base;
-} alarm_time_obj_t;
-
-extern const mp_obj_type_t alarm_time_type;
-
-extern void common_hal_alarm_time_duration (uint32_t);
-extern void common_hal_alarm_time_disable (void);
-
-#endif //MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME___INIT___H
diff --git a/shared-bindings/microcontroller/__init__.c b/shared-bindings/microcontroller/__init__.c
index bbc1640f7..bfeb812d6 100644
--- a/shared-bindings/microcontroller/__init__.c
+++ b/shared-bindings/microcontroller/__init__.c
@@ -160,7 +160,6 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_sleep_obj, mcu_sleep);
//|
//| .. module:: microcontroller.pin
//| :synopsis: Microcontroller pin names
-//| :platform: SAMD21
//|
//| References to pins as named by the microcontroller"""
//|
diff --git a/shared-bindings/sleep/__init__.c b/shared-bindings/sleep/__init__.c
deleted file mode 100644
index a714e0021..000000000
--- a/shared-bindings/sleep/__init__.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * This file is part of the MicroPython project, http://micropython.org/
- *
- * The MIT License (MIT)
- *
- * Copyright (c) 2020 Scott Shawcroft
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-
-#include "shared-bindings/alarm/__init__.h"
-
-//| """Light and deep sleep used to save power
-//|
-//| The `sleep` module provides sleep related functionality. There are two supported levels of
-//| sleep, light and deep.
-//|
-//| Light sleep leaves the CPU and RAM powered so that CircuitPython can resume where it left off
-//| after being woken up. Light sleep is automatically done by CircuitPython when `time.sleep()` is
-//| called. To light sleep until a non-time alarm use `sleep.sleep_until_alarm()`. Any active
-//| peripherals, such as I2C, are left on.
-//|
-//| Deep sleep shuts down power to nearly all of the chip including the CPU and RAM. This can save
-//| a more significant amount of power, but CircuitPython must start code.py from the beginning when woken
-//| up. CircuitPython will enter deep sleep automatically when the current program exits without error
-//| or calls `sys.exit(0)`.
-//| If an error causes CircuitPython to exit, error LED error flashes will be done periodically.
-//| An error includes an uncaught exception, or sys.exit called with a non-zero argumetn.
-//| To set alarms for deep sleep use `sleep.restart_on_alarm()` they will apply to next deep sleep only."""
-//|
-
-//| wake_alarm: Alarm
-//| """The most recent alarm to wake us up from a sleep (light or deep.)"""
-//|
-
-//| reset_reason: ResetReason
-//| """The reason the chip started up from reset state. This can may be power up or due to an alarm."""
-//|
-
-//| def sleep_until_alarm(alarm: Alarm, ...) -> Alarm:
-//| """Performs a light sleep until woken by one of the alarms. The alarm that woke us up is
-//| returned."""
-//| ...
-//|
-
-STATIC mp_obj_t sleep_sleep_until_alarm(size_t n_args, const mp_obj_t *args) {
-}
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(sleep_sleep_until_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, sleep_sleep_until_alarm);
-
-//| def restart_on_alarm(alarm: Alarm, ...) -> None:
-//| """Set one or more alarms to wake up from a deep sleep. When awakened, ``code.py`` will restart
-//| from the beginning. The last alarm to wake us up is available as `wake_alarm`. """
-//| ...
-//|
-STATIC mp_obj_t sleep_restart_on_alarm(size_t n_args, const mp_obj_t *args) {
-}
-MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(sleep_restart_on_alarm_obj, 1, MP_OBJ_FUN_ARGS_MAX, sleep_restart_on_alarm);
-
-
-mp_map_elem_t sleep_module_globals_table[] = {
- { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sleep) },
-
- { MP_ROM_QSTR(MP_QSTR_wake_alarm), mp_const_none },
- { MP_ROM_QSTR(MP_QSTR_reset_reason), mp_const_none },
-
- { MP_ROM_QSTR(MP_QSTR_sleep_until_alarm), sleep_sleep_until_alarm_obj },
- { MP_ROM_QSTR(MP_QSTR_restart_on_alarm), sleep_restart_on_alarm_obj },
-};
-STATIC MP_DEFINE_MUTABLE_DICT(sleep_module_globals, sleep_module_globals_table);
-
-// These are called from common hal code to set the current wake alarm.
-void common_hal_sleep_set_wake_alarm(mp_obj_t alarm) {
- // Equivalent of:
- // sleep.wake_alarm = alarm
- mp_map_elem_t *elem =
- mp_map_lookup(&sleep_module_globals_table, MP_ROM_QSTR(MP_QSTR_wake_alarm), MP_MAP_LOOKUP);
- if (elem) {
- elem->value = alarm;
- }
-}
-
-// These are called from common hal code to set the current wake alarm.
-void common_hal_sleep_set_reset_reason(mp_obj_t reset_reason) {
- // Equivalent of:
- // sleep.reset_reason = reset_reason
- mp_map_elem_t *elem =
- mp_map_lookup(&sleep_module_globals_table, MP_ROM_QSTR(MP_QSTR_reset_reason), MP_MAP_LOOKUP);
- if (elem) {
- elem->value = reset_reason;
- }
-}
-
-const mp_obj_module_t sleep_module = {
- .base = { &mp_type_module },
- .globals = (mp_obj_dict_t*)&sleep_module_globals,
-};
diff --git a/shared-bindings/sleep/__init__.h b/shared-bindings/sleep/__init__.h
deleted file mode 100644
index cd23ba5e4..000000000
--- a/shared-bindings/sleep/__init__.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_SLEEP___INIT___H
-#define MICROPY_INCLUDED_SHARED_BINDINGS_SLEEP___INIT___H
-
-#include "py/obj.h"
-
-extern mp_obj_t common_hal_sleep_get_wake_alarm(void);
-extern sleep_reset_reason_t common_hal_sleep_get_reset_reason(void);
-
-#endif // MICROPY_INCLUDED_SHARED_BINDINGS_SLEEPxs___INIT___H