@@ -161,7 +161,7 @@ STATIC void start_mp(supervisor_allocation* heap) {
161
161
162
162
#if CIRCUITPY_ALARM
163
163
// Record which alarm woke us up, if any. An object may be created so the heap must be functional.
164
- alarm_save_wake_alarm ();
164
+ shared_alarm_save_wake_alarm ();
165
165
// Reset alarm module only after we retrieved the wakeup alarm.
166
166
alarm_reset ();
167
167
#endif
@@ -305,8 +305,6 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
305
305
}
306
306
#endif
307
307
308
- // TODO: on deep sleep, make sure display is refreshed before sleeping (for e-ink).
309
-
310
308
cleanup_after_vm (heap );
311
309
312
310
if (result .return_code & PYEXEC_FORCED_EXIT ) {
@@ -329,12 +327,12 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
329
327
330
328
rgb_status_animation_t animation ;
331
329
prep_rgb_status_animation (& result , found_main , safe_mode , & animation );
332
- bool asleep = false;
330
+ bool fake_sleeping = false;
333
331
while (true) {
334
332
RUN_BACKGROUND_TASKS ;
335
333
if (reload_requested ) {
336
334
#if CIRCUITPY_ALARM
337
- if (asleep ) {
335
+ if (fake_sleeping ) {
338
336
board_init ();
339
337
}
340
338
#endif
@@ -345,7 +343,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
345
343
346
344
if (serial_connected () && serial_bytes_available ()) {
347
345
#if CIRCUITPY_ALARM
348
- if (asleep ) {
346
+ if (fake_sleeping ) {
349
347
board_init ();
350
348
}
351
349
#endif
@@ -361,7 +359,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
361
359
// an alarm alerts faster than our USB delay or if we pretended to deep
362
360
// sleep.
363
361
#if CIRCUITPY_ALARM
364
- if (asleep && alarm_woken_from_sleep ()) {
362
+ if (fake_sleeping && common_hal_alarm_woken_from_sleep ()) {
365
363
serial_write_compressed (translate ("Woken up by alarm.\n" ));
366
364
board_init ();
367
365
supervisor_set_run_reason (RUN_REASON_STARTUP );
@@ -400,20 +398,15 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
400
398
if (result .return_code & PYEXEC_DEEP_SLEEP ) {
401
399
// Make sure we have been awake long enough for USB to connect (enumeration delay).
402
400
int64_t connecting_delay_ticks = CIRCUITPY_USB_CONNECTED_SLEEP_DELAY * 1024 - port_get_raw_ticks (NULL );
403
- if (connecting_delay_ticks > 0 ) {
404
- // Set when we've waited long enough so that we wake up from the
405
- // port_idle_until_interrupt below and loop around to the real deep
406
- // sleep in the else clause.
407
- port_interrupt_after_ticks (connecting_delay_ticks );
408
- // Deep sleep if we're not connected to a host.
409
- } else if (!asleep ) {
410
- asleep = true;
401
+ // Until it's safe to decide whether we're real/fake sleeping, just run the RGB
402
+ if (connecting_delay_ticks < 0 && !fake_sleeping ) {
403
+ fake_sleeping = true;
411
404
new_status_color (BLACK );
412
405
board_deinit ();
413
406
if (!supervisor_workflow_active ()) {
414
407
// Enter true deep sleep. When we wake up we'll be back at the
415
408
// top of main(), not in this loop.
416
- alarm_enter_deep_sleep ();
409
+ common_hal_alarm_enter_deep_sleep ();
417
410
// Does not return.
418
411
} else {
419
412
serial_write_compressed (translate ("Pretending to deep sleep until alarm, CTRL-C or file write.\n" ));
@@ -422,15 +415,19 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
422
415
}
423
416
#endif
424
417
425
- if (!asleep ) {
418
+ if (!fake_sleeping ) {
426
419
tick_rgb_status_animation (& animation );
427
420
} else {
428
421
// This waits until a pretend deep sleep alarm occurs. They are set
429
422
// during common_hal_alarm_set_deep_sleep_alarms. On some platforms
430
423
// it may also return due to another interrupt, that's why we check
431
424
// for deep sleep alarms above. If it wasn't a deep sleep alarm,
432
425
// then we'll idle here again.
433
- port_idle_until_interrupt ();
426
+ #if CIRCUITPY_ALARM
427
+ common_hal_alarm_pretending_deep_sleep ();
428
+ #else
429
+ port_idle_until_interrupt ();
430
+ #endif
434
431
}
435
432
}
436
433
}
0 commit comments