WIP: redo API; not compiled yet

This commit is contained in:
Dan Halbert 2020-11-18 20:44:34 -05:00
parent ffff02c053
commit 682054a216
21 changed files with 445 additions and 454 deletions

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-11-04 21:18+0530\n"
"POT-Creation-Date: 2020-11-19 00:22-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -303,7 +303,8 @@ msgstr ""
msgid "All I2C peripherals are in use"
msgstr ""
#: ports/esp32s2/peripherals/pcnt_handler.c
#: ports/esp32s2/common-hal/countio/Counter.c
#: ports/esp32s2/common-hal/rotaryio/IncrementalEncoder.c
msgid "All PCNT units in use"
msgstr ""
@ -3221,6 +3222,7 @@ msgstr ""
msgid "pow() with 3 arguments requires integers"
msgstr ""
#: ports/esp32s2/boards/adafruit_magtag_2.9_grayscale/mpconfigboard.h
#: ports/esp32s2/boards/adafruit_metro_esp32s2/mpconfigboard.h
#: ports/esp32s2/boards/electroniccats_bastwifi/mpconfigboard.h
#: ports/esp32s2/boards/espressif_kaluga_1/mpconfigboard.h
@ -3328,7 +3330,7 @@ msgstr ""
msgid "size is defined for ndarrays only"
msgstr ""
#: shared-bindings/alarm_time/__init__.c shared-bindings/time/__init__.c
#: shared-bindings/time/__init__.c
msgid "sleep length must be non-negative"
msgstr ""

View File

@ -15,9 +15,6 @@ LONGINT_IMPL = MPZ
# These modules are implemented in ports/<port>/common-hal:
CIRCUITPY_FULL_BUILD = 1
CIRCUITPY_ALARM = 1
CIRCUITPY_ALARM_IO = 1
CIRCUITPY_ALARM_TIME = 1
CIRCUITPY_ALARM_TOUCH = 1
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_AUDIOIO = 0
CIRCUITPY_CANIO = 1

View File

@ -102,15 +102,6 @@ endif
ifeq ($(CIRCUITPY_ALARM),1)
SRC_PATTERNS += alarm/%
endif
ifeq ($(CIRCUITPY_ALARM_IO),1)
SRC_PATTERNS += alarm_io/%
endif
ifeq ($(CIRCUITPY_ALARM_TIME),1)
SRC_PATTERNS += alarm_time/%
endif
ifeq ($(CIRCUITPY_ALARM_TOUCH),1)
SRC_PATTERNS += alarm_touch/%
endif
ifeq ($(CIRCUITPY_ANALOGIO),1)
SRC_PATTERNS += analogio/%
endif
@ -247,9 +238,6 @@ endif
ifeq ($(CIRCUITPY_SHARPDISPLAY),1)
SRC_PATTERNS += sharpdisplay/%
endif
ifeq ($(CIRCUITPY_SLEEP),1)
SRC_PATTERNS += sleep/%
endif
ifeq ($(CIRCUITPY_SOCKETPOOL),1)
SRC_PATTERNS += socketpool/%
endif
@ -314,9 +302,9 @@ SRC_COMMON_HAL_ALL = \
_pew/PewPew.c \
_pew/__init__.c \
alarm/__init__.c \
alarm_io/__init__.c \
alarm_time/__init__.c \
alarm_touch/__init__.c \
alarm/pin/__init__.c \
alarm/time/__init__.c \
alarm/touch/__init__.c \
analogio/AnalogIn.c \
analogio/AnalogOut.c \
analogio/__init__.c \
@ -372,8 +360,8 @@ SRC_COMMON_HAL_ALL = \
rtc/__init__.c \
sdioio/SDCard.c \
sdioio/__init__.c \
sleep/__init__.c \
sleep/ResetReason.c \
sleepio/__init__.c \
sleepio/ResetReason.c \
socketpool/__init__.c \
socketpool/SocketPool.c \
socketpool/Socket.c \

View File

@ -250,27 +250,6 @@ extern const struct _mp_obj_module_t alarm_module;
#define ALARM_MODULE
#endif
#if CIRCUITPY_ALARM_IO
extern const struct _mp_obj_module_t alarm_io_module;
#define ALARM_IO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_io), (mp_obj_t)&alarm_io_module },
#else
#define ALARM_IO_MODULE
#endif
#if CIRCUITPY_ALARM_TIME
extern const struct _mp_obj_module_t alarm_time_module;
#define ALARM_TIME_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_time), (mp_obj_t)&alarm_time_module },
#else
#define ALARM_TIME_MODULE
#endif
#if CIRCUITPY_ALARM_TOUCH
extern const struct _mp_obj_module_t alarm_touch_module;
#define ALARM_TOUCH_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_alarm_touch), (mp_obj_t)&alarm_touch_module },
#else
#define ALARM_TOUCH_MODULE
#endif
#if CIRCUITPY_ANALOGIO
#define ANALOGIO_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_analogio), (mp_obj_t)&analogio_module },
extern const struct _mp_obj_module_t analogio_module;
@ -642,13 +621,6 @@ extern const struct _mp_obj_module_t sharpdisplay_module;
#define SHARPDISPLAY_MODULE
#endif
#if CIRCUITPY_SLEEP
extern const struct _mp_obj_module_t sleep_module;
#define SLEEP_MODULE { MP_OBJ_NEW_QSTR(MP_QSTR_sleep),(mp_obj_t)&sleep_module },
#else
#define SLEEP_MODULE
#endif
#if CIRCUITPY_SOCKETPOOL
extern const struct _mp_obj_module_t socketpool_module;
#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;
#define MICROPY_PORT_BUILTIN_MODULES_STRONG_LINKS \
AESIO_MODULE \
ALARM_MODULE \
ALARM_IO_MODULE \
ALARM_TIME_MODULE \
ALARM_TOUCH_MODULE \
ANALOGIO_MODULE \
AUDIOBUSIO_MODULE \
AUDIOCORE_MODULE \
@ -862,7 +831,6 @@ extern const struct _mp_obj_module_t wifi_module;
SDCARDIO_MODULE \
SDIOIO_MODULE \
SHARPDISPLAY_MODULE \
SLEEP_MODULE \
SOCKETPOOL_MODULE \
SSL_MODULE \
STAGE_MODULE \

View File

@ -39,18 +39,15 @@ CFLAGS += -DMICROPY_PY_ASYNC_AWAIT=$(MICROPY_PY_ASYNC_AWAIT)
CIRCUITPY_AESIO ?= 0
CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO)
# TODO: CIRCUITPY_ALARM will gradually be added to
# as many ports as possible
# so make this 1 or CIRCUITPY_FULL_BUILD eventually
CIRCUITPY_SLEEPIO ?= 0
CFLAGS += -DCIRCUITPY_SLEEPIO=$(CIRCUITPY_SLEEPIO)
CIRCUITPY_ALARM ?= 0
CFLAGS += -DCIRCUITPY_ALARM=$(CIRCUITPY_ALARM)
CIRCUITPY_ALARM_IO ?= 0
CFLAGS += -DCIRCUITPY_ALARM_IO=$(CIRCUITPY_ALARM_IO)
CIRCUITPY_ALARM_TIME ?= 0
CFLAGS += -DCIRCUITPY_ALARM_TIME=$(CIRCUITPY_ALARM_TIME)
CIRCUITPY_ALARM_TOUCH ?= 0
CFLAGS += -DCIRCUITPY_ALARM_TOUCH=$(CIRCUITPY_ALARM_TOUCH)
CIRCUITPY_ANALOGIO ?= 1
CFLAGS += -DCIRCUITPY_ANALOGIO=$(CIRCUITPY_ANALOGIO)
@ -221,11 +218,6 @@ CFLAGS += -DCIRCUITPY_SDIOIO=$(CIRCUITPY_SDIOIO)
CIRCUITPY_SHARPDISPLAY ?= $(CIRCUITPY_FRAMEBUFFERIO)
CFLAGS += -DCIRCUITPY_SHARPDISPLAY=$(CIRCUITPY_SHARPDISPLAY)
# TODO: CIRCUITPY_SLEEP will gradually be added to all ports
# even if it doesn't actually sleep, so make this 1 eventually.
CIRCUITPY_SLEEP ?= 0
CFLAGS += -DCIRCUITPY_SLEEP=$(CIRCUITPY_SLEEP)
CIRCUITPY_SOCKETPOOL ?= $(CIRCUITPY_WIFI)
CFLAGS += -DCIRCUITPY_SOCKETPOOL=$(CIRCUITPY_SOCKETPOOL)

View File

@ -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);

View File

@ -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

View File

@ -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,
};

View File

@ -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

View File

@ -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,
};

View File

@ -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

View File

@ -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,
};

View File

@ -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

View File

@ -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,
};

View File

@ -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

View File

@ -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,
};

View File

@ -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,
};

View File

@ -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

View File

@ -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"""
//|

View File

@ -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,
};

View File

@ -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