Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
b637d39
Initial commit
gamblor21 Oct 25, 2020
12d770b
Added __probe_for_device
gamblor21 Oct 25, 2020
8a37983
Added doc and translations
gamblor21 Oct 26, 2020
9ec2245
Clean up
gamblor21 Oct 27, 2020
2374b0d
Fixed whitespace issues
gamblor21 Oct 27, 2020
90b9ec6
Initial Sleep Support
microdev1 Sep 18, 2020
3a30887
Update soft reboot message
microdev1 Sep 18, 2020
e310b87
Get io wake working
microdev1 Sep 19, 2020
05a3f20
Add function to get time elapsed during sleep
microdev1 Sep 22, 2020
21ba61a
Add function to disable alarm
microdev1 Sep 22, 2020
e5ff55b
Renamed alarm modules
microdev1 Sep 23, 2020
4d8ffdc
restructure alarm modules
microdev1 Sep 24, 2020
da44972
Fix build error
microdev1 Sep 24, 2020
59df1a1
Add alarm_touch module
microdev1 Sep 24, 2020
e359389
Add description of alarm modules
microdev1 Sep 24, 2020
930cf14
Add check for invalid io, function to disable all alarms
microdev1 Sep 26, 2020
0e444f0
Implement sleep on code.py exit
microdev1 Sep 30, 2020
354536c
Update translation
microdev1 Oct 7, 2020
1196d4b
move to new module
tannewt Oct 14, 2020
85dadf3
More API changes
tannewt Oct 15, 2020
9a4efed
Start tweaking the workflow to sleep
tannewt Oct 28, 2020
e7da852
Fixing review comments
gamblor21 Oct 29, 2020
78477a3
Initial SPI commit
gamblor21 Oct 31, 2020
5ea09fe
Fixed stubs
gamblor21 Oct 31, 2020
76c1153
Fixed stubs
gamblor21 Nov 1, 2020
7dd5380
Fixed stubs again
gamblor21 Nov 1, 2020
8bbbb28
Fixes from testing SPI
gamblor21 Nov 2, 2020
197539b
Moved I2CDevice and SPI to match python library
gamblor21 Nov 3, 2020
4c93db3
Renamed to adafruit_bus_device
gamblor21 Nov 4, 2020
03b110b
Add abort check in I2C lock
gamblor21 Nov 11, 2020
f61c4e6
Removing from smaller builds
gamblor21 Nov 11, 2020
23ed3ef
Removing frozen libs
gamblor21 Nov 11, 2020
bb77f1d
wip: initial code changes, starting from @tannewt's sleepio branch
dhalbert Nov 16, 2020
ffff02c
Merge remote-tracking branch 'adafruit/main' into sleep
dhalbert Nov 16, 2020
682054a
WIP: redo API; not compiled yet
dhalbert Nov 19, 2020
5bb3c32
merge from main
dhalbert Nov 19, 2020
649c930
wip
dhalbert Nov 19, 2020
cd436ba
Merge remote-tracking branch 'adafruit/main' into sleep
dhalbert Nov 19, 2020
39e1f52
wip; not compiling yet
dhalbert Nov 19, 2020
e4c6699
compiles
dhalbert Nov 21, 2020
75559f3
wip: ResetReason to microcontroller.cpu
dhalbert Nov 22, 2020
a0f1ec3
wip
dhalbert Nov 23, 2020
25591a3
Merge branch 'esp32s2-common-hal-mcu-delay-us' into sleep
dhalbert Nov 23, 2020
3abee9b
compiles; maybe ready to test, or almost
dhalbert Nov 23, 2020
7a45afc
working, but need to avoid deep sleeping too fast before USB ready
dhalbert Nov 24, 2020
f868cc5
some API renaming and bug fixes; fix docs
dhalbert Nov 25, 2020
9dbea36
changed alarm.time API
dhalbert Nov 25, 2020
ef0830b
merge from upstream + wip
dhalbert Nov 25, 2020
104a089
deep sleep working; deep sleep delay when connected
dhalbert Nov 27, 2020
e308a9e
working! PinAlarm not implemented yet.
dhalbert Nov 27, 2020
596e0e4
merge from upstream
dhalbert Nov 27, 2020
f96475c
update Requests; rolled back by accident
dhalbert Nov 27, 2020
65e2fe4
fix stub problems; touch up doc
dhalbert Nov 28, 2020
2830cc9
make translate
dhalbert Nov 28, 2020
28d9e91
Disable complex arithmetic on SAMD21 builds to make space
dhalbert Nov 28, 2020
4ac4faa
Use nina-fw root certs
tannewt Dec 1, 2020
9276244
Two minor socket changes
tannewt Dec 1, 2020
9a9e972
Ignore certificates readme in doc build
tannewt Dec 1, 2020
a95285a
Translated using Weblate (Polish)
szajakubiak Dec 1, 2020
f6cba4c
Translated using Weblate (Polish)
tawez Dec 1, 2020
44e0d98
Translated using Weblate (Polish)
szajakubiak Dec 1, 2020
2b9ca4d
Translated using Weblate (Polish)
tawez Dec 1, 2020
2373857
Merge branch 'main' into bus_device
gamblor21 Dec 1, 2020
d3bbb99
Fixing stubs
gamblor21 Dec 1, 2020
8b7c23c
address review comments
dhalbert Dec 2, 2020
fe1c2fa
Removed bus device from simmel build
gamblor21 Dec 2, 2020
72fa7d8
fix doc errors
dhalbert Dec 2, 2020
73e22f9
Block all tasks (not interrupts) during flash erase
tannewt Dec 2, 2020
cb863e4
Added to partial builds where frozen removed
gamblor21 Dec 2, 2020
1c00deb
Translated using Weblate (Polish)
tawez Dec 1, 2020
9e6b2b1
Translated using Weblate (Czech)
vkuthan Dec 1, 2020
d7ba641
Merge pull request #3767 from dhalbert/sleep
tannewt Dec 2, 2020
8f6baa2
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
7655102
Update translation files
weblate Dec 2, 2020
31acfed
Merge pull request #3780 from tannewt/block_while_erasing
dhalbert Dec 2, 2020
51fd678
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
9b3186b
Merge pull request #3776 from tannewt/backup_socket_timeout
dhalbert Dec 2, 2020
c7749a5
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
348392f
Merge pull request #3775 from tannewt/nina_certs
dhalbert Dec 2, 2020
a483cd1
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
1130b80
Merge pull request #3612 from gamblor21/bus_device
tannewt Dec 2, 2020
079bf7a
Merge branch 'origin/main' into Weblate.
weblate Dec 2, 2020
03d0ec8
Update translation files
weblate Dec 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
some API renaming and bug fixes; fix docs
  • Loading branch information
dhalbert committed Nov 25, 2020
commit f868cc5dd02319957500180541281f41ec0d0573
50 changes: 28 additions & 22 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
#endif

// How long to wait for host to enumerate (secs).
#define CIRCUITPY_USB_ENUMERATION_DELAY 1
#define CIRCUITPY_USB_ENUMERATION_DELAY 5

// How long to flash errors on the RGB status LED before going to sleep (secs)
#define CIRCUITPY_FLASH_ERROR_PERIOD 10
Expand Down Expand Up @@ -319,26 +319,28 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
bool ok = result.return_code != PYEXEC_EXCEPTION;

ESP_LOGI("main", "common_hal_alarm_enable_deep_sleep_alarms()");
// Decide whether to deep sleep.
#if CIRCUITPY_ALARM
// Enable pin or time alarms before sleeping.
common_hal_alarm_enable_deep_sleep_alarms();
#endif

// Normally we won't deep sleep if there was an error or if we are connected to a host
// but either of those can be enabled.
// *********DON'T SLEEP IF USB HASN'T HAD TIME TO ENUMERATE.
bool will_deep_sleep =
(ok || supervisor_workflow_get_allow_deep_sleep_on_error()) &&
(!supervisor_workflow_active() || supervisor_workflow_get_allow_deep_sleep_when_connected());

ESP_LOGI("main", "ok %d", will_deep_sleep);
ESP_LOGI("main", "...on_error() %d", supervisor_workflow_get_allow_deep_sleep_on_error());
ESP_LOGI("main", "supervisor_workflow_active() %d", supervisor_workflow_active());
ESP_LOGI("main", "...when_connected() %d", supervisor_workflow_get_allow_deep_sleep_when_connected());
will_deep_sleep = false;

prep_rgb_status_animation(&result, found_main, safe_mode, &animation);
while (true) {
// Normally we won't deep sleep if there was an error or if we are connected to a host
// but either of those can be enabled.
// It's ok to deep sleep if we're not connected to a host, but we need to make sure
// we're giving enough time for USB enumeration to happen.
bool deep_sleep_allowed =
(ok || supervisor_workflow_get_allow_deep_sleep_on_error()) &&
(!supervisor_workflow_active() || supervisor_workflow_get_allow_deep_sleep_when_connected()) &&
(supervisor_ticks_ms64() > CIRCUITPY_USB_ENUMERATION_DELAY * 1024);

ESP_LOGI("main", "ok %d", deep_sleep_allowed);
ESP_LOGI("main", "...on_error() %d", supervisor_workflow_get_allow_deep_sleep_on_error());
ESP_LOGI("main", "supervisor_workflow_active() %d", supervisor_workflow_active());
ESP_LOGI("main", "...when_connected() %d", supervisor_workflow_get_allow_deep_sleep_when_connected());
ESP_LOGI("main", "supervisor_ticks_ms64() %lld", supervisor_ticks_ms64());
RUN_BACKGROUND_TASKS;
if (reload_requested) {
supervisor_set_run_reason(RUN_REASON_AUTO_RELOAD);
Expand All @@ -360,7 +362,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
print_code_py_status_message(safe_mode);
}
// We won't be going into the REPL if we're going to sleep.
if (!will_deep_sleep) {
if (!deep_sleep_allowed) {
print_safe_mode_message(safe_mode);
serial_write("\n");
serial_write_compressed(translate("Press any key to enter the REPL. Use CTRL-D to reload."));
Expand All @@ -379,27 +381,31 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
#endif

bool animation_done = false;
if (will_deep_sleep && ok) {

if (deep_sleep_allowed && ok) {
// Skip animation if everything is OK.
animation_done = true;
} else {
animation_done = tick_rgb_status_animation(&animation);
}
// Do an error animation only once before deep-sleeping.
if (animation_done && will_deep_sleep) {
int64_t remaining_enumeration_wait = CIRCUITPY_USB_ENUMERATION_DELAY * 1024 - supervisor_ticks_ms64();
// If USB isn't enumerated then deep sleep after our waiting period.
if (ok && remaining_enumeration_wait < 0) {
if (animation_done) {
if (deep_sleep_allowed) {
common_hal_mcu_deep_sleep();
// Does not return.
}

// Wake up every so often to flash the error code.
if (!ok) {
port_interrupt_after_ticks(CIRCUITPY_FLASH_ERROR_PERIOD * 1024);
} else {
port_interrupt_after_ticks(remaining_enumeration_wait);
int64_t remaining_enumeration_wait =
CIRCUITPY_USB_ENUMERATION_DELAY * 1024 - supervisor_ticks_ms64();
if (remaining_enumeration_wait > 0) {
port_interrupt_after_ticks(remaining_enumeration_wait);
}
port_sleep_until_interrupt();
}
port_sleep_until_interrupt();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/alarm/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//|
//| 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
//| called. To light sleep until a non-time alarm use `alarm.sleep_until_alarms()`. 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
Expand All @@ -51,7 +51,7 @@
//|
//| An error includes an uncaught exception, or sys.exit() called with a non-zero argument
//|
//| To set alarms for deep sleep use `alarm.restart_on_alarm()` they will apply to next deep sleep only."""
//| To set alarms for deep sleep use `alarm.set_deep_sleep_alarms()` 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.)"""
Expand Down
34 changes: 17 additions & 17 deletions shared-bindings/alarm/pin/PinAlarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,26 @@
//| """Trigger an alarm when a pin changes state."""
//|
//| def __init__(self, *pins: microcontroller.Pin, value: bool, all_same_value: bool = False, 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_until_alarm()` or
//| `alarm.restart_on_alarm()`.
//| """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_until_alarms()` or
//| `alarm.set_deep_sleep_alarms()`.
//|
//| :param pins: The pins to monitor. On some ports, the choice of pins
//| may be limited due to hardware restrictions, particularly for deep-sleep alarms.
//| :param microcontroller.Pin \*pins: The pins to monitor. On some ports, the choice of pins
//| may be limited due to hardware restrictions, particularly for deep-sleep alarms.
//| :param bool value: When active, trigger when the pin value is high (``True``) or low (``False``).
//| On some ports, multiple `PinAlarm` objects may need to have coordinated values
//| for deep-sleep alarms.
//| :param bool all_same_value: If ``True``, all pins listed must be at `value` to trigger the alarm.
//| If ``False``, any one of the pins going to `value` will trigger the alarm.
//| On some ports, multiple `PinAlarm` objects may need to have coordinated values
//| for deep-sleep alarms.
//| :param bool all_same_value: If ``True``, all pins listed must be at ``value`` to trigger the alarm.
//| If ``False``, any one of the pins going to ``value`` will trigger the alarm.
//| :param bool edge: If ``True``, trigger only when there is a transition to the specified
//| value of `value`. If ``True``, if the alarm becomes active when the pin value already
//| matches `value`, the alarm is not triggered: the pin must transition from ``not value``
//| to ``value`` 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 value opposite
//| opposite that of `value`. For instance, if `value` 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.
//| value of ``value``. If ``True``, if the alarm becomes active when the pin value already
//| matches ``value``, the alarm is not triggered: the pin must transition from ``not value``
//| to ``value`` 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 the level opposite
//| opposite that of ``value``. For instance, if ``value`` 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.
//| """
//| ...
//|
Expand Down
6 changes: 3 additions & 3 deletions shared-bindings/alarm/time/DurationAlarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
//| """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
//| """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()`.
//| `alarm`-enabling function, such as `alarm.sleep_until_alarms()` or
//| `alarm.set_deep_sleep_alarms()`.
//| """
//| ...
//|
Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/microcontroller/Processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ const mp_obj_property_t mcu_processor_frequency_obj = {
},
};

//| reset_reason: `microcontroller.ResetReason`
//| """The reason the microcontroller started up from reset state."""
//| 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());
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/supervisor/RunReason.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ MAKE_ENUM_VALUE(supervisor_run_reason_type, run_reason, REPL_RELOAD, RUN_REASON_
//| """The reason that CircuitPython started running."""
//|
//| STARTUP: object
//| """CircuitPython started the microcontroller started up. See `microcontroller.cpu.reset_reason`
//| """CircuitPython started the microcontroller started up. See `microcontroller.Processor.reset_reason`
//| for more detail on why the microcontroller was started."""
//|
//| AUTO_RELOAD: object
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/supervisor/Runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const mp_obj_property_t supervisor_serial_bytes_available_obj = {


//| run_reason: RunReason
//| """Returns why CircuitPython started running this particular time.
//| """Returns why CircuitPython started running this particular time."""
//|
STATIC mp_obj_t supervisor_get_run_reason(mp_obj_t self) {
return cp_enum_find(&supervisor_run_reason_type, _run_reason);
Expand Down
37 changes: 19 additions & 18 deletions shared-bindings/supervisor/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,19 @@
//| This object is the sole instance of `supervisor.Runtime`."""
//|

//| def allow_deep_sleep(*, when_connected: bool = False, on_error: bool = False):
//| """Configure when CircuitPython can go into deep sleep. Deep sleep can occur
//| after a program has finished running or when `supervisor.deep_sleep_now()` is called.
//| def allow_deep_sleep(*, when_connected: bool = False, on_error: bool = False) -> None:
//| """Configure when CircuitPython can go into deep sleep. Deep sleep can occur
//| after a program has finished running or when `supervisor.exit_and_deep_sleep()` is called.
//|
//| :param bool when_connected: If ``True``, CircuitPython will go into deep sleep
//| when a program finishes, even if it is connected to a host computer over USB or other means.
//| It will disconnect from the host before sleeping.
//| If ``False``, deep sleep will not be entered if connected.
//| :param bool on_error: If ``True``, deep sleep will be entered if even a program
//| terminated due to an exception or fatal error. If ``False``, an error will cause
//| CircuitPython to stay awake, flashing error codes on the status RGB LED, if available.
//| ...
//| :param bool when_connected: If ``True``, CircuitPython will go into deep sleep
//| when a program finishes, even if it is connected to a host computer over USB or other means.
//| It will disconnect from the host before sleeping.
//| If ``False``, deep sleep will not be entered if connected.
//| :param bool on_error: If ``True``, deep sleep will be entered if even a program
//| terminated due to an exception or fatal error. If ``False``, an error will cause
//| CircuitPython to stay awake, flashing error codes on the status RGB LED, if available.
//| """
//| ...
//|
STATIC mp_obj_t supervisor_allow_deep_sleep(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
enum { ARG_when_connected, ARG_on_error };
Expand All @@ -77,16 +78,16 @@ STATIC mp_obj_t supervisor_allow_deep_sleep(size_t n_args, const mp_obj_t *pos_a
}
MP_DEFINE_CONST_FUN_OBJ_KW(supervisor_allow_deep_sleep_obj, 0, supervisor_allow_deep_sleep);

//| def deep_sleep(): -> None
//| def exit_and_deep_sleep() -> None:
//| """Go into deep sleep mode immediately, if not connected to a host computer.
//| But if connected and `supervisor.runtime.allow_deep_sleep(when_connected=true)`
//| has not been called, simply restart.
//|
//| But if connected and ``supervisor.allow_deep_sleep(when_connected=true)``
//| has not been called, simply restart."""
//| ...

STATIC mp_obj_t supervisor_deep_sleep(void) {
STATIC mp_obj_t supervisor_exit_and_deep_sleep(void) {
common_hal_mcu_deep_sleep();
}
MP_DEFINE_CONST_FUN_OBJ_0(supervisor_deep_sleep_obj, supervisor_deep_sleep);
MP_DEFINE_CONST_FUN_OBJ_0(supervisor_exit_and_deep_sleep_obj, supervisor_exit_and_deep_sleep);

//| def enable_autoreload() -> None:
//| """Enable autoreload based on USB file write activity."""
Expand Down Expand Up @@ -156,7 +157,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(supervisor_set_next_stack_limit_obj, supervisor_set_ne
STATIC const mp_rom_map_elem_t supervisor_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_supervisor) },
{ MP_ROM_QSTR(MP_QSTR_allow_deep_sleep), MP_ROM_PTR(&supervisor_allow_deep_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_deep_sleep), MP_ROM_PTR(&supervisor_deep_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_exit_and_deep_sleep), MP_ROM_PTR(&supervisor_exit_and_deep_sleep_obj) },
{ MP_ROM_QSTR(MP_QSTR_enable_autoreload), MP_ROM_PTR(&supervisor_enable_autoreload_obj) },
{ MP_ROM_QSTR(MP_QSTR_disable_autoreload), MP_ROM_PTR(&supervisor_disable_autoreload_obj) },
{ MP_ROM_QSTR(MP_QSTR_set_rgb_status_brightness), MP_ROM_PTR(&supervisor_set_rgb_status_brightness_obj) },
Expand Down