Skip to content

Commit 6e9429d

Browse files
committed
soft reboot for pretending deep sleep.
1 parent 15764b4 commit 6e9429d

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

main.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
404404
new_status_color(BLACK);
405405
board_deinit();
406406
if (!supervisor_workflow_active()) {
407-
// Enter true deep sleep. When we wake up we'll be back at the
408-
// top of main(), not in this loop.
407+
// Enter deep sleep. When we wake up we'll return from
408+
// this loop.
409409
common_hal_alarm_enter_deep_sleep();
410-
// Does not return.
410+
// Does not return.
411411
} else {
412412
serial_write_compressed(translate("Pretending to deep sleep until alarm, CTRL-C or file write.\n"));
413413
}
@@ -426,10 +426,21 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
426426

427427
#if CIRCUITPY_ALARM
428428
common_hal_alarm_pretending_deep_sleep();
429+
bool serial_in = (serial_connected() &&
430+
serial_bytes_available());
431+
supervisor_set_run_reason(RUN_REASON_STARTUP);
432+
board_init();
433+
if (serial_in) {
434+
bool ctrl_d = serial_read() == CHAR_CTRL_D;
435+
if (ctrl_d) {
436+
supervisor_set_run_reason(RUN_REASON_REPL_RELOAD);
437+
}
438+
return ctrl_d;
439+
}
440+
return true;
429441
#else
430442
port_idle_until_interrupt();
431443
#endif
432-
//return false; // to go REPL
433444
}
434445
}
435446
}

ports/nrf/common-hal/alarm/__init__.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ void NORETURN common_hal_alarm_enter_deep_sleep(void) {
346346
while(1) ;
347347
}
348348

349-
// old version deep sleep code that was used in alarm_enter_deep_sleep()
349+
// old version deep sleep code that was used in common_hal_alarm_enter_deep_sleep()
350350
// for anyone who might want true System OFF sleep ..
351351
#if 0
352352
void OLD_go_system_off(void) {
@@ -384,16 +384,17 @@ void common_hal_alarm_pretending_deep_sleep(void) {
384384

385385
alarm_reset();
386386

387+
#if 0
387388
// if one of Alarm event occurred, reset myself
388389
if (cause == NRF_SLEEP_WAKEUP_GPIO ||
389390
cause == NRF_SLEEP_WAKEUP_TIMER ||
390391
cause == NRF_SLEEP_WAKEUP_TOUCHPAD) {
391392
reset_cpu();
392393
}
393394
// else, just return and go into REPL
395+
#endif
394396
}
395397

396398
void common_hal_alarm_gc_collect(void) {
397-
void* p = shared_alarm_get_wake_alarm();
398-
gc_collect_ptr(p);
399+
gc_collect_ptr(shared_alarm_get_wake_alarm());
399400
}

0 commit comments

Comments
 (0)