summaryrefslogtreecommitdiff
path: root/shared-bindings
diff options
context:
space:
mode:
Diffstat (limited to 'shared-bindings')
-rw-r--r--shared-bindings/_typing/__init__.pyi11
-rw-r--r--shared-bindings/alarm/__init__.c74
-rw-r--r--shared-bindings/alarm/__init__.h6
-rw-r--r--shared-bindings/alarm/pin/PinAlarm.c28
-rw-r--r--shared-bindings/alarm/time/DurationAlarm.c11
-rw-r--r--shared-bindings/microcontroller/Processor.c18
-rw-r--r--shared-bindings/microcontroller/Processor.h3
-rw-r--r--shared-bindings/microcontroller/ResetReason.c (renamed from shared-bindings/alarm/ResetReason.c)41
-rw-r--r--shared-bindings/microcontroller/ResetReason.h (renamed from shared-bindings/alarm/ResetReason.h)18
-rw-r--r--shared-bindings/microcontroller/__init__.c9
-rw-r--r--shared-bindings/microcontroller/__init__.h4
-rw-r--r--shared-bindings/supervisor/RunReason.c38
-rw-r--r--shared-bindings/supervisor/RunReason.h4
-rwxr-xr-xshared-bindings/supervisor/Runtime.c10
14 files changed, 143 insertions, 132 deletions
diff --git a/shared-bindings/_typing/__init__.pyi b/shared-bindings/_typing/__init__.pyi
index 3b3f18cb9..02839ab47 100644
--- a/shared-bindings/_typing/__init__.pyi
+++ b/shared-bindings/_typing/__init__.pyi
@@ -54,13 +54,12 @@ FrameBuffer = Union[rgbmatrix.RGBMatrix]
"""
Alarm = Union[
- alarm_time.Time, alarm_pin.PinLevel, alarm_touch.PinTouch
+ alarm.pin.PinAlarm, alarm.time.DurationAlarm
]
-"""Classes that implement the audiosample protocol
+"""Classes that implement alarms for sleeping and asynchronous notification.
- - `alarm_time.Time`
- - `alarm_pin.PinLevel`
- - `alarm_touch.PinTouch`
+ - `alarm.pin.PinAlarm`
+ - `alarm.time.DurationAlarm`
- You can play use these alarms to wake from light or deep sleep.
+ You can use these alarms to wake from light or deep sleep.
"""
diff --git a/shared-bindings/alarm/__init__.c b/shared-bindings/alarm/__init__.c
index 771c8ff9b..934544216 100644
--- a/shared-bindings/alarm/__init__.c
+++ b/shared-bindings/alarm/__init__.c
@@ -1,3 +1,37 @@
+/*
+ * 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 "py/obj.h"
+#include "py/runtime.h"
+
+#include "shared-bindings/alarm/__init__.h"
+#include "shared-bindings/alarm/ResetReason.h"
+#include "shared-bindings/alarm/pin/PinAlarm.h"
+#include "shared-bindings/alarm/time/DurationAlarm.h"
+
//| """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
@@ -11,54 +45,43 @@
//| 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)`.
+//| 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."""
+//| To set alarms for deep sleep use `alarm.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(alarm: Alarm, ...) -> Alarm:
+//| def sleep_until_alarm(*alarms: 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/__init__.h"
-#include "shared-bindings/alarm/ResetReason.h"
-#include "shared-bindings/alarm/pin/PinAlarm.h"
-#include "shared-bindings/alarm/time/DurationAlarm.h"
-
STATIC mp_obj_t alarm_sleep_until_alarm(size_t n_args, const mp_obj_t *args) {
// TODO
+ common_hal_alarm_sleep_until_alarm(size_t n_args, const mp_obj_t *args);
return mp_const_none;
}
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:
+//| def restart_on_alarm(*alarms: 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`.
+//| The last alarm to wake us up is available as `alarm.wake_alarm`.
//| """
//| ...
//|
STATIC mp_obj_t alarm_restart_on_alarm(size_t n_args, const mp_obj_t *args) {
// TODO
+ common_hal_alarm_restart_on_alarm(size_t n_args, const mp_obj_t *args);
return mp_const_none;
}
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
+//| """The `alarm.pin` module contains alarm attributes and classes related to pins.
//| """
//|
STATIC const mp_map_elem_t alarm_pin_globals_table[] = {
@@ -95,7 +118,6 @@ STATIC mp_map_elem_t alarm_module_globals_table[] = {
// 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_OBJ_FROM_PTR(&reset_reason_INVALID_obj) },
{ MP_ROM_QSTR(MP_QSTR_sleep_until_alarm), MP_OBJ_FROM_PTR(&alarm_sleep_until_alarm_obj) },
{ MP_ROM_QSTR(MP_QSTR_restart_on_alarm), MP_OBJ_FROM_PTR(&alarm_restart_on_alarm_obj) },
@@ -116,16 +138,6 @@ void common_hal_alarm_set_wake_alarm(mp_obj_t 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.map, 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
index a0ee76e53..29be8716c 100644
--- a/shared-bindings/alarm/__init__.h
+++ b/shared-bindings/alarm/__init__.h
@@ -29,11 +29,9 @@
#include "py/obj.h"
-#include "shared-bindings/alarm/ResetReason.h"
-
extern void common_hal_alarm_set_wake_alarm(mp_obj_t alarm);
-extern alarm_reset_reason_t common_hal_alarm_get_reset_reason(void);
-extern void common_hal_alarm_set_reset_reason(mp_obj_t reset_reason);
+extern mp_obj_t common_hal_alarm_restart_on_alarm(size_t n_alarms, const mp_obj_t *alarms);
+extern mp_obj_t alarm_sleep_until_alarm(size_t n_alarms, const mp_obj_t *alarms);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM___INIT___H
diff --git a/shared-bindings/alarm/pin/PinAlarm.c b/shared-bindings/alarm/pin/PinAlarm.c
index fef1face7..835a5be5c 100644
--- a/shared-bindings/alarm/pin/PinAlarm.c
+++ b/shared-bindings/alarm/pin/PinAlarm.c
@@ -35,27 +35,27 @@
#include "supervisor/shared/translate.h"
//| class PinAlarm:
-//| """Trigger an alarm when a pin changes state.
+//| """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()`.
-
+//| until it is listed in an `alarm`-enabling function, such as `alarm.sleep_until_alarm()` or
+//| `alarm.restart_on_alarm()`.
+//|
//| :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.
+//| 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
+//| 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.
+//| 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.
+//| 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.
//| """
//| ...
//|
diff --git a/shared-bindings/alarm/time/DurationAlarm.c b/shared-bindings/alarm/time/DurationAlarm.c
index 5fb232f4a..c105bbebf 100644
--- a/shared-bindings/alarm/time/DurationAlarm.c
+++ b/shared-bindings/alarm/time/DurationAlarm.c
@@ -34,14 +34,13 @@
#include "supervisor/shared/translate.h"
//| class DurationAlarm:
-//| """Trigger an alarm at a specified interval from now.
+//| """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.
+//| """Create an alarm that will be triggered in `secs` seconds from the time
+//| sleep starts. The alarm is not active until it is listed in an
+//| `alarm`-enabling function, such as `alarm.sleep_until_alarm()` or
+//| `alarm.restart_on_alarm()`.
//| """
//| ...
//|
diff --git a/shared-bindings/microcontroller/Processor.c b/shared-bindings/microcontroller/Processor.c
index 8c703891d..b0ab842f4 100644
--- a/shared-bindings/microcontroller/Processor.c
+++ b/shared-bindings/microcontroller/Processor.c
@@ -67,6 +67,23 @@ const mp_obj_property_t mcu_processor_frequency_obj = {
},
};
+//| reset_reason: `microcontroller.ResetReason`
+//| """The reason the microcontroller started up from reset state."""
+//|
+STATIC mp_obj_t mcu_processor_get_reset_reason(mp_obj_t self) {
+ return cp_enum_find(&mcu_reset_reason_type, common_hal_mcu_processor_get_reset_reason());
+}
+
+MP_DEFINE_CONST_FUN_OBJ_1(mcu_processor_get_reset_reason_obj, mcu_processor_get_reset_reason);
+
+const mp_obj_property_t mcu_reset_reason_obj = {
+ .base.type = &mp_type_property,
+ .proxy = {(mp_obj_t)&mcu_processor_get_reason_reason_obj, // getter
+ (mp_obj_t)&mp_const_none_obj, // no setter
+ (mp_obj_t)&mp_const_none_obj, // no deleter
+ },
+};
+
//| temperature: Optional[float]
//| """The on-chip temperature, in Celsius, as a float. (read-only)
//|
@@ -128,6 +145,7 @@ const mp_obj_property_t mcu_processor_voltage_obj = {
STATIC const mp_rom_map_elem_t mcu_processor_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_frequency), MP_ROM_PTR(&mcu_processor_frequency_obj) },
+ { MP_ROM_QSTR(MP_QSTR_reset_reason), MP_ROM_PTR(&mcu_processor_reset_reason_obj) },
{ MP_ROM_QSTR(MP_QSTR_temperature), MP_ROM_PTR(&mcu_processor_temperature_obj) },
{ MP_ROM_QSTR(MP_QSTR_uid), MP_ROM_PTR(&mcu_processor_uid_obj) },
{ MP_ROM_QSTR(MP_QSTR_voltage), MP_ROM_PTR(&mcu_processor_voltage_obj) },
diff --git a/shared-bindings/microcontroller/Processor.h b/shared-bindings/microcontroller/Processor.h
index 0f520f940..a842e06f3 100644
--- a/shared-bindings/microcontroller/Processor.h
+++ b/shared-bindings/microcontroller/Processor.h
@@ -29,11 +29,12 @@
#include "py/obj.h"
-#include "common-hal/microcontroller/Processor.h"
+#include "shared-bindings/microcontroller/ResetReason.h"
extern const mp_obj_type_t mcu_processor_type;
uint32_t common_hal_mcu_processor_get_frequency(void);
+mcu_reset_reason_t common_hal_mcu_processor_get_reset_reason(void);
float common_hal_mcu_processor_get_temperature(void);
void common_hal_mcu_processor_get_uid(uint8_t raw_id[]);
float common_hal_mcu_processor_get_voltage(void);
diff --git a/shared-bindings/alarm/ResetReason.c b/shared-bindings/microcontroller/ResetReason.c
index 086562fc9..151fcf315 100644
--- a/shared-bindings/alarm/ResetReason.c
+++ b/shared-bindings/microcontroller/ResetReason.c
@@ -27,42 +27,37 @@
#include "py/obj.h"
#include "py/enum.h"
-#include "shared-bindings/alarm/ResetReason.h"
+#include "shared-bindings/microcontroller/ResetReason.h"
-MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, INVALID, RESET_REASON_INVALID);
-MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, POWER_ON, RESET_REASON_POWER_ON);
-MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, BROWNOUT, RESET_REASON_BROWNOUT);
-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, RESET_PIN, RESET_REASON_RESET_PIN);
-MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, WATCHDOG, RESET_REASON_WATCHDOG);
+MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, POWER_ON, RESET_REASON_POWER_ON);
+MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, BROWNOUT, RESET_REASON_BROWNOUT);
+MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE);
+MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM);
+MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, RESET_PIN, RESET_REASON_RESET_PIN);
+MAKE_ENUM_VALUE(mcu_reset_reason_type, reset_reason, WATCHDOG, RESET_REASON_WATCHDOG);
//| class ResetReason:
-//| """The reason the chip was last reset"""
-//|
-//| INVALID: object
-//| """Invalid reason: indicates an internal error."""
+//| """The reason the microntroller was last reset"""
//|
//| POWER_ON: object
-//| """The chip was started from power off."""
+//| """The microntroller was started from power off."""
//|
//| BROWNOUT: object
-//| """The chip was reset due to voltage brownout."""
+//| """The microntroller was reset due to too low a voltage."""
//|
//| SOFTWARE: object
-//| """The chip was reset from software."""
+//| """The microntroller was reset from software."""
//|
//| DEEP_SLEEP_ALARM: object
-//| """The chip was reset for deep sleep and restarted by an alarm."""
+//| """The microntroller was reset for deep sleep and restarted by an alarm."""
//|
//| RESET_PIN: object
-//| """The chip was reset by a signal on its reset pin. The pin might be connected to a reset buton."""
+//| """The microntroller was reset by a signal on its reset pin. The pin might be connected to a reset button."""
//|
//| WATCHDOG: object
-//| """The chip was reset by its watchdog timer."""
+//| """The chip microcontroller reset by its watchdog timer."""
//|
-MAKE_ENUM_MAP(alarm_reset_reason) {
- MAKE_ENUM_MAP_ENTRY(reset_reason, INVALID),
+MAKE_ENUM_MAP(mcu_reset_reason) {
MAKE_ENUM_MAP_ENTRY(reset_reason, POWER_ON),
MAKE_ENUM_MAP_ENTRY(reset_reason, BROWNOUT),
MAKE_ENUM_MAP_ENTRY(reset_reason, SOFTWARE),
@@ -70,8 +65,8 @@ MAKE_ENUM_MAP(alarm_reset_reason) {
MAKE_ENUM_MAP_ENTRY(reset_reason, RESET_PIN),
MAKE_ENUM_MAP_ENTRY(reset_reason, WATCHDOG),
};
-STATIC MP_DEFINE_CONST_DICT(alarm_reset_reason_locals_dict, alarm_reset_reason_locals_table);
+STATIC MP_DEFINE_CONST_DICT(mcu_reset_reason_locals_dict, mcu_reset_reason_locals_table);
-MAKE_PRINTER(alarm, alarm_reset_reason);
+MAKE_PRINTER(alarm, mcu_reset_reason);
-MAKE_ENUM_TYPE(alarm, ResetReason, alarm_reset_reason);
+MAKE_ENUM_TYPE(alarm, ResetReason, mcu_reset_reason);
diff --git a/shared-bindings/alarm/ResetReason.h b/shared-bindings/microcontroller/ResetReason.h
index 2d6b8bc0c..df1abf266 100644
--- a/shared-bindings/alarm/ResetReason.h
+++ b/shared-bindings/microcontroller/ResetReason.h
@@ -24,24 +24,28 @@
* THE SOFTWARE.
*/
-#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
-#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
+#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_MCU__RESET_REASON__H
+#define MICROPY_INCLUDED_SHARED_BINDINGS_MCU__RESET_REASON__H
#include "py/obj.h"
#include "py/enum.h"
typedef enum {
- RESET_REASON_INVALID,
RESET_REASON_POWER_ON,
RESET_REASON_BROWNOUT,
RESET_REASON_SOFTWARE,
RESET_REASON_DEEP_SLEEP_ALARM,
RESET_REASON_RESET_PIN,
RESET_REASON_WATCHDOG,
-} alarm_reset_reason_t;
+} mcu_reset_reason_t;
-extern const cp_enum_obj_t reset_reason_INVALID_obj;
+extern const cp_enum_obj_t reset_reason_POWER_ON_obj;
+extern const cp_enum_obj_t reset_reason_BROWNOUT_obj;
+extern const cp_enum_obj_t reset_reason_SOFTWARE_obj;
+extern const cp_enum_obj_t reset_reason_DEEP_SLEEP_ALARM_obj;
+extern const cp_enum_obj_t reset_reason_RESET_PIN_obj;
+extern const cp_enum_obj_t reset_reason_WATCHDOG_obj;
-extern const mp_obj_type_t alarm_reset_reason_type;
+extern const mp_obj_type_t mcu_reset_reason_type;
-#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
+#endif // MICROPY_INCLUDED_SHARED_BINDINGS_MCU__RESET_REASON__H
diff --git a/shared-bindings/microcontroller/__init__.c b/shared-bindings/microcontroller/__init__.c
index bfeb812d6..d09cf8f44 100644
--- a/shared-bindings/microcontroller/__init__.c
+++ b/shared-bindings/microcontroller/__init__.c
@@ -135,13 +135,6 @@ STATIC mp_obj_t mcu_reset(void) {
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_reset_obj, mcu_reset);
-STATIC mp_obj_t mcu_sleep(void) {
- common_hal_mcu_deep_sleep();
- // We won't actually get here because mcu is going into sleep.
- return mp_const_none;
-}
-STATIC MP_DEFINE_CONST_FUN_OBJ_0(mcu_sleep_obj, mcu_sleep);
-
//| nvm: Optional[ByteArray]
//| """Available non-volatile memory.
//| This object is the sole instance of `nvm.ByteArray` when available or ``None`` otherwise.
@@ -176,8 +169,6 @@ STATIC const mp_rom_map_elem_t mcu_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_enable_interrupts), MP_ROM_PTR(&mcu_enable_interrupts_obj) },
{ MP_ROM_QSTR(MP_QSTR_on_next_reset), MP_ROM_PTR(&mcu_on_next_reset_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&mcu_reset_obj) },
- //ToDo: Remove MP_QSTR_sleep when sleep on code.py exit implemented.
- { MP_ROM_QSTR(MP_QSTR_sleep), MP_ROM_PTR(&mcu_sleep_obj) },
#if CIRCUITPY_INTERNAL_NVM_SIZE > 0
{ MP_ROM_QSTR(MP_QSTR_nvm), MP_ROM_PTR(&common_hal_mcu_nvm_obj) },
#else
diff --git a/shared-bindings/microcontroller/__init__.h b/shared-bindings/microcontroller/__init__.h
index f5bcfaa08..ac71de424 100644
--- a/shared-bindings/microcontroller/__init__.h
+++ b/shared-bindings/microcontroller/__init__.h
@@ -32,7 +32,7 @@
#include "py/mpconfig.h"
#include "common-hal/microcontroller/Processor.h"
-
+#include "shared-bindings/microcontroller/ResetReason.h"
#include "shared-bindings/microcontroller/RunMode.h"
extern void common_hal_mcu_delay_us(uint32_t);
@@ -43,8 +43,6 @@ extern void common_hal_mcu_enable_interrupts(void);
extern void common_hal_mcu_on_next_reset(mcu_runmode_t runmode);
extern void common_hal_mcu_reset(void);
-extern void common_hal_mcu_deep_sleep(void);
-
extern const mp_obj_dict_t mcu_pin_globals;
extern const mcu_processor_obj_t common_hal_mcu_processor_obj;
diff --git a/shared-bindings/supervisor/RunReason.c b/shared-bindings/supervisor/RunReason.c
index 5233cf959..ee08f6d71 100644
--- a/shared-bindings/supervisor/RunReason.c
+++ b/shared-bindings/supervisor/RunReason.c
@@ -28,35 +28,35 @@
#include "shared-bindings/supervisor/RunReason.h"
-MAKE_ENUM_VALUE(canio_bus_state_type, run_reason, ERROR_ACTIVE, RUN_REASON_STARTUP);
-MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_PASSIVE, RUN_REASON_AUTORELOAD);
-MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, ERROR_WARNING, RUN_REASON_SUPERVISOR_RELOAD);
-MAKE_ENUM_VALUE(canio_bus_state_type, bus_state, BUS_OFF, RUN_REASON_RELOAD_HOTKEY);
+MAKE_ENUM_VALUE(supervisor_run_reason_type, run_reason, STARTUP, RUN_REASON_STARTUP);
+MAKE_ENUM_VALUE(supervisor_run_reason_type, run_reason, AUTORELOAD, RUN_REASON_AUTORELOAD);
+MAKE_ENUM_VALUE(supervisor_run_reason_type, run_reason, SUPERVISOR_RELOAD, RUN_REASON_SUPERVISOR_RELOAD);
+MAKE_ENUM_VALUE(supervisor_run_reason_type, run_reason, REPL_RELOAD, RUN_REASON_REPL_RELOAD);
//| class RunReason:
-//| """The state of the CAN bus"""
+//| """The reason that CircuitPython started running."""
//|
//| STARTUP: object
-//| """The first VM was run after the microcontroller started up. See `microcontroller.start_reason`
-//| for more detail why the microcontroller was started."""
+//| """CircuitPython started the microcontroller started up. See `microcontroller.cpu.reset_reason`
+//| for more detail on why the microcontroller was started."""
//|
//| AUTORELOAD: object
-//| """The VM was run due to a USB write to the filesystem."""
+//| """CircuitPython restarted due to a USB write to the filesystem."""
//|
//| SUPERVISOR_RELOAD: object
-//| """The VM was run due to a call to `supervisor.reload()`."""
+//| """CircuitPython restarted due to a call to `supervisor.reload()`."""
//|
-//| RELOAD_HOTKEY: object
-//| """The VM was run due CTRL-D."""
+//| REPL_RELOAD: object
+//| """CircuitPython started due to the user typing CTRL-D in the REPL."""
//|
-MAKE_ENUM_MAP(canio_bus_state) {
- MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_ACTIVE),
- MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_PASSIVE),
- MAKE_ENUM_MAP_ENTRY(bus_state, ERROR_WARNING),
- MAKE_ENUM_MAP_ENTRY(bus_state, BUS_OFF),
+MAKE_ENUM_MAP(run_reason) {
+ MAKE_ENUM_MAP_ENTRY(run_reason, STARTUP),
+ MAKE_ENUM_MAP_ENTRY(run_reason, AUTORELOAD),
+ MAKE_ENUM_MAP_ENTRY(run_reason, SUPERVISOR_RELOAD),
+ MAKE_ENUM_MAP_ENTRY(run_reason, REPL_RELOAD),
};
-STATIC MP_DEFINE_CONST_DICT(canio_bus_state_locals_dict, canio_bus_state_locals_table);
+STATIC MP_DEFINE_CONST_DICT(supervisor_run_reason_locals_dict, supervisor_run_reason_locals_table);
-MAKE_PRINTER(canio, canio_bus_state);
+MAKE_PRINTER(supervisor, supervisor_run_reason);
-MAKE_ENUM_TYPE(canio, BusState, canio_bus_state);
+MAKE_ENUM_TYPE(supervisor, RunReason, supervisor_run_reason);
diff --git a/shared-bindings/supervisor/RunReason.h b/shared-bindings/supervisor/RunReason.h
index f9aaacae6..934c72fd8 100644
--- a/shared-bindings/supervisor/RunReason.h
+++ b/shared-bindings/supervisor/RunReason.h
@@ -30,7 +30,7 @@ typedef enum {
RUN_REASON_STARTUP,
RUN_REASON_AUTORELOAD,
RUN_REASON_SUPERVISOR_RELOAD,
- RUN_REASON_RELOAD_HOTKEY
+ RUN_REASON_REPL_RELOAD,
} supervisor_run_reason_t;
-extern const mp_obj_type_t canio_bus_state_type;
+extern const mp_obj_type_t supervisor_run_reason_type;
diff --git a/shared-bindings/supervisor/Runtime.c b/shared-bindings/supervisor/Runtime.c
index f9db38c9b..6500dadd5 100755
--- a/shared-bindings/supervisor/Runtime.c
+++ b/shared-bindings/supervisor/Runtime.c
@@ -91,15 +91,11 @@ const mp_obj_property_t supervisor_serial_bytes_available_obj = {
//| run_reason: RunReason
-//| """Returns why the Python VM was run this time."""
+//| """Returns why CircuitPython started running this particular time.
//|
STATIC mp_obj_t supervisor_get_run_reason(mp_obj_t self) {
- if (!common_hal_get_serial_bytes_available()) {
- return mp_const_false;
- }
- else {
- return mp_const_true;
- }
+ mp_raise_NotImplementedError(NULL);
+ return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(supervisor_get_run_reason_obj, supervisor_get_run_reason);