6666
6767#include "boards/board.h"
6868
69- // REMOVE ***********
70- #include "esp_log.h"
71-
7269#if CIRCUITPY_ALARM
7370#include "shared-bindings/alarm/__init__.h"
7471#endif
9895#include "common-hal/canio/CAN.h"
9996#endif
10097
101- // How long to wait for host to start connecting..
102- #define CIRCUITPY_USB_CONNECTING_DELAY 1
103-
104- // How long to flash errors on the RGB status LED before going to sleep (secs)
105- #define CIRCUITPY_FLASH_ERROR_PERIOD 10
106-
10798#if MICROPY_ENABLE_PYSTACK
10899static size_t PLACE_IN_DTCM_BSS (_pystack [CIRCUITPY_PYSTACK_SIZE / sizeof (size_t )]);
109100#endif
@@ -259,17 +250,6 @@ STATIC void print_code_py_status_message(safe_mode_t safe_mode) {
259250 }
260251}
261252
262- // Should we go into deep sleep when program finishes?
263- // Normally we won't deep sleep if there was an error or if we are connected to a host
264- // but either of those can be enabled.
265- // It's ok to deep sleep if we're not connected to a host, but we need to make sure
266- // we're giving enough time for USB to start to connect
267- STATIC bool deep_sleep_allowed (void ) {
268- return
269- (ok || supervisor_workflow_get_allow_deep_sleep_on_error ()) &&
270- !supervisor_workflow_connecting ()
271- (supervisor_ticks_ms64 () > CIRCUITPY_USB_CONNECTING_DELAY * 1024 );
272-
273253STATIC bool run_code_py (safe_mode_t safe_mode ) {
274254 bool serial_connected_at_start = serial_connected ();
275255 #if CIRCUITPY_AUTORELOAD_DELAY_MS > 0
@@ -290,10 +270,12 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
290270 if (safe_mode == NO_SAFE_MODE ) {
291271 new_status_color (MAIN_RUNNING );
292272
293- static const char * const supported_filenames [] = STRING_LIST ("code.txt" , "code.py" , "main.py" , "main.txt" );
273+ static const char * const supported_filenames [] = STRING_LIST (
274+ "code.txt" , "code.py" , "main.py" , "main.txt" );
294275 #if CIRCUITPY_FULL_BUILD
295- static const char * const double_extension_filenames [] = STRING_LIST ("code.txt.py" , "code.py.txt" , "code.txt.txt" ,"code.py.py" ,
296- "main.txt.py" , "main.py.txt" , "main.txt.txt" ,"main.py.py" );
276+ static const char * const double_extension_filenames [] = STRING_LIST (
277+ "code.txt.py" , "code.py.txt" , "code.txt.txt" ,"code.py.py" ,
278+ "main.txt.py" , "main.py.txt" , "main.txt.txt" ,"main.py.py" );
297279 #endif
298280
299281 stack_resize ();
@@ -319,24 +301,16 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
319301 // Program has finished running.
320302
321303 // Display a different completion message if the user has no USB attached (cannot save files)
322- if (!serial_connected_at_start && ! deep_sleep_allowed () ) {
304+ if (!serial_connected_at_start ) {
323305 serial_write_compressed (translate ("\nCode done running. Waiting for reload.\n" ));
324306 }
325307
326308 bool serial_connected_before_animation = false;
327309 #if CIRCUITPY_DISPLAYIO
328310 bool refreshed_epaper_display = false;
329311 #endif
330- rgb_status_animation_t animation ;
331- bool ok = result .return_code != PYEXEC_EXCEPTION ;
332-
333- #if CIRCUITPY_ALARM
334- // Enable pin or time alarms before sleeping.
335- // If immediate_wake is true, then there's an alarm that would trigger immediately,
336- // so don't sleep.
337- bool immediate_wake = !common_hal_alarm_enable_deep_sleep_alarms ();
338- #endif
339312
313+ rgb_status_animation_t animation ;
340314 prep_rgb_status_animation (& result , found_main , safe_mode , & animation );
341315 while (true) {
342316
@@ -360,12 +334,10 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
360334 if (!serial_connected_at_start ) {
361335 print_code_py_status_message (safe_mode );
362336 }
363- // We won't be going into the REPL if we're going to sleep.
364- if (!deep_sleep_allowed ()) {
365- print_safe_mode_message (safe_mode );
366- serial_write ("\n" );
367- serial_write_compressed (translate ("Press any key to enter the REPL. Use CTRL-D to reload." ));
368- }
337+
338+ print_safe_mode_message (safe_mode );
339+ serial_write ("\n" );
340+ serial_write_compressed (translate ("Press any key to enter the REPL. Use CTRL-D to reload." ));
369341 }
370342 if (serial_connected_before_animation && !serial_connected ()) {
371343 serial_connected_at_start = false;
@@ -379,37 +351,7 @@ STATIC bool run_code_py(safe_mode_t safe_mode) {
379351 }
380352 #endif
381353
382- bool animation_done = false;
383-
384- if (deep_sleep_allowed () && ok ) {
385- // Skip animation if everything is OK.
386- animation_done = true;
387- } else {
388- animation_done = tick_rgb_status_animation (& animation );
389- }
390- // Do an error animation only once before deep-sleeping.
391- if (animation_done ) {
392- if (immediate_wake ) {
393- // Don't sleep, we are already supposed to wake up.
394- return true;
395- }
396- if (deep_sleep_allowed ()) {
397- common_hal_mcu_deep_sleep ();
398- // Does not return.
399- }
400-
401- // Wake up every so often to flash the error code.
402- if (!ok ) {
403- port_interrupt_after_ticks (CIRCUITPY_FLASH_ERROR_PERIOD * 1024 );
404- } else {
405- int64_t remaining_connecting_wait =
406- CIRCUITPY_USB_CONNECTING_DELAY * 1024 - supervisor_ticks_ms64 ();
407- if (remaining_connecting_wait > 0 ) {
408- port_interrupt_after_ticks (remaining_connecting_wait );
409- }
410- port_sleep_until_interrupt ();
411- }
412- }
354+ tick_rgb_status_animation (& animation );
413355 }
414356}
415357
0 commit comments