This commit is contained in:
Dan Halbert 2020-11-19 15:43:39 -05:00
parent 5bb3c321e9
commit 649c930536
17 changed files with 234 additions and 48 deletions

18
main.c
View File

@ -63,6 +63,10 @@
#include "boards/board.h" #include "boards/board.h"
#if CIRCUITPY_ALARM
#include "shared-bindings/alarm/__init__.h"
#endif
#if CIRCUITPY_DISPLAYIO #if CIRCUITPY_DISPLAYIO
#include "shared-module/displayio/__init__.h" #include "shared-module/displayio/__init__.h"
#endif #endif
@ -88,10 +92,6 @@
#include "common-hal/canio/CAN.h" #include "common-hal/canio/CAN.h"
#endif #endif
#if CIRCUITPY_SLEEP
#include "shared-bindings/sleep/__init__.h"
#endif
void do_str(const char *src, mp_parse_input_kind_t input_kind) { void do_str(const char *src, mp_parse_input_kind_t input_kind) {
mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0); mp_lexer_t *lex = mp_lexer_new_from_str_len(MP_QSTR__lt_stdin_gt_, src, strlen(src), 0);
if (lex == NULL) { if (lex == NULL) {
@ -320,7 +320,7 @@ bool run_code_py(safe_mode_t safe_mode) {
#endif #endif
rgb_status_animation_t animation; rgb_status_animation_t animation;
bool ok = result->return_code != PYEXEC_EXCEPTION; bool ok = result->return_code != PYEXEC_EXCEPTION;
#if CIRCUITPY_SLEEP #if CIRCUITPY_ALARM
// If USB isn't enumerated then deep sleep. // If USB isn't enumerated then deep sleep.
if (ok && !supervisor_workflow_active() && supervisor_ticks_ms64() > CIRCUITPY_USB_ENUMERATION_DELAY * 1024) { if (ok && !supervisor_workflow_active() && supervisor_ticks_ms64() > CIRCUITPY_USB_ENUMERATION_DELAY * 1024) {
common_hal_sleep_deep_sleep(); common_hal_sleep_deep_sleep();
@ -361,7 +361,7 @@ bool run_code_py(safe_mode_t safe_mode) {
#endif #endif
bool animation_done = tick_rgb_status_animation(&animation); bool animation_done = tick_rgb_status_animation(&animation);
if (animation_done && supervisor_workflow_active()) { if (animation_done && supervisor_workflow_active()) {
#if CIRCUITPY_SLEEP #if CIRCUITPY_ALARM
int64_t remaining_enumeration_wait = CIRCUITPY_USB_ENUMERATION_DELAY * 1024 - supervisor_ticks_ms64(); 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 USB isn't enumerated then deep sleep after our waiting period.
if (ok && remaining_enumeration_wait < 0) { if (ok && remaining_enumeration_wait < 0) {
@ -423,9 +423,13 @@ void __attribute__ ((noinline)) run_boot_py(safe_mode_t safe_mode) {
if (!skip_boot_output) { if (!skip_boot_output) {
// Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write, // Wait 1.5 seconds before opening CIRCUITPY_BOOT_OUTPUT_FILE for write,
// in case power is momentary or will fail shortly due to, say a low, battery. // in case power is momentary or will fail shortly due to, say a low, battery.
if (common_hal_sleep_get_reset_reason() == RESET_REASON_POWER_VALID) { #if CIRCUITPY_ALARM
if (common_hal_sleep_get_reset_reason() == RESET_REASON_POWER_ON) {
#endif
mp_hal_delay_ms(1500); mp_hal_delay_ms(1500);
#if CIRCUITPY_ALARM
} }
#endif
// USB isn't up, so we can write the file. // USB isn't up, so we can write the file.
filesystem_set_internal_writable_by_usb(false); filesystem_set_internal_writable_by_usb(false);

View File

@ -0,0 +1,52 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 @microDev1 (GitHub)
* 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 "esp_sleep.h"
#include "shared-bindings/alarm/time/DurationAlarm.h"
void common_hal_alarm_pin_pin_pin_alarm_construct(alarm_pin_pin_alarm_obj_t *self, mcu_pin_obj_t *pin, bool level, bool edge, bool pull) {
self->pin = pin;
self->level = level;
self->edge = edge;
self->pull = pull;
mcu_pin_obj_t *common_hal_alarm_pin_pin_alarm_get_pin(alarm_pin_pin_alarm_obj_t *self) {
return self->pin;
}
bool common_hal_alarm_pin_pin_alarm_get_level(alarm_pin_pin_alarm_obj_t *self) {
return self->level;
}
bool common_hal_alarm_pin_pin_alarm_get_edge(alarm_pin_pin_alarm_obj_t *self) {
return self->edge;
}
bool common_hal_alarm_pin_pin_alarm_get_pull(alarm_pin_pin_alarm_obj_t *self) {
return self->pull;
}

View File

@ -0,0 +1,36 @@
/*
* 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"
typedef struct {
mp_obj_base_t base;
mcu_pin_obj_t *pin;
bool level;
bool edge;
bool pull;
} alarm_pin_pin_alarm_obj_t;

View File

@ -0,0 +1,48 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 @microDev1 (GitHub)
* 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 "esp_sleep.h"
#include "shared-bindings/alarm/time/DurationAlarm.h"
void common_hal_alarm_time_duration_alarm_construct(alarm_time_duration_alarm_obj_t *self, mp_float_t duration) {
self->duration = duration;
}
mp_float_t common_hal_alarm_time_duration_alarm_get_duration(alarm_time_duration_alarm_obj_t *self) {
return self->duration;
}
void common_hal_alarm_time_duration_alarm_enable(alarm_time_duration_alarm_obj_t *self)
if (esp_sleep_enable_timer_wakeup((uint64_t) (self->duration * 1000000)) == ESP_ERR_INVALID_ARG) {
mp_raise_ValueError(translate("duration out of range"));
}
}
void common_hal_alarm_time_duration_alarm_disable (alarm_time_duration_alarm_obj_t *self) {
(void) self;
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
}

View File

@ -0,0 +1,34 @@
/*
* This file is part of the MicroPython project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2020 @microDev1 (GitHub)
* 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"
typedef struct {
mp_obj_base_t base;
mp_float_t duration; // seconds
} alarm_time_duration_alarm_obj_t;

View File

@ -1,13 +0,0 @@
#include "esp_sleep.h"
#include "shared-bindings/alarm_time/__init__.h"
void common_hal_alarm_time_duration (uint32_t ms) {
if (esp_sleep_enable_timer_wakeup((ms) * 1000) == ESP_ERR_INVALID_ARG) {
mp_raise_ValueError(translate("time out of range"));
}
}
void common_hal_alarm_time_disable (void) {
esp_sleep_disable_wakeup_source(ESP_SLEEP_WAKEUP_TIMER);
}

View File

@ -302,9 +302,8 @@ SRC_COMMON_HAL_ALL = \
_pew/PewPew.c \ _pew/PewPew.c \
_pew/__init__.c \ _pew/__init__.c \
alarm/__init__.c \ alarm/__init__.c \
alarm/pin/__init__.c \ alarm/pin/PinAlarm.c \
alarm/time/__init__.c \ alarm/time/DurationAlarm.c \
alarm/touch/__init__.c \
analogio/AnalogIn.c \ analogio/AnalogIn.c \
analogio/AnalogOut.c \ analogio/AnalogOut.c \
analogio/__init__.c \ analogio/__init__.c \

View File

@ -42,9 +42,6 @@ CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO)
# TODO: CIRCUITPY_ALARM will gradually be added to # TODO: CIRCUITPY_ALARM will gradually be added to
# as many ports as possible # as many ports as possible
# so make this 1 or CIRCUITPY_FULL_BUILD eventually # so make this 1 or CIRCUITPY_FULL_BUILD eventually
CIRCUITPY_SLEEPIO ?= 0
CFLAGS += -DCIRCUITPY_SLEEPIO=$(CIRCUITPY_SLEEPIO)
CIRCUITPY_ALARM ?= 0 CIRCUITPY_ALARM ?= 0
CFLAGS += -DCIRCUITPY_ALARM=$(CIRCUITPY_ALARM) CFLAGS += -DCIRCUITPY_ALARM=$(CIRCUITPY_ALARM)

View File

@ -28,7 +28,7 @@
#include "shared-bindings/alarm/ResetReason.h" #include "shared-bindings/alarm/ResetReason.h"
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_VALID); MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, POWER_VALID, RESET_REASON_POWER_ON);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, SOFTWARE, RESET_REASON_SOFTWARE); 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, DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM);
MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EXTERNAL); MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EXTERNAL);
@ -36,23 +36,31 @@ MAKE_ENUM_VALUE(alarm_reset_reason_type, reset_reason, EXTERNAL, RESET_REASON_EX
//| class ResetReason: //| class ResetReason:
//| """The reason the chip was last reset""" //| """The reason the chip was last reset"""
//| //|
//| POWER_VALID: object //| POWER_ON: object
//| """The chip was reset and started once power levels were valid.""" //| """The chip was started from power off."""
//|
//| BROWNOUT: object
//| """The chip was reset due to voltage brownout."""
//| //|
//| SOFTWARE: object //| SOFTWARE: object
//| """The chip was reset from software.""" //| """The chip was reset from software."""
//| //|
//| DEEP_SLEEP_ALARM: object //| DEEP_SLEEP_ALARM: object
//| """The chip was reset for deep sleep and started by an alarm.""" //| """The chip was reset for deep sleep and restarted by an alarm."""
//| //|
//| EXTERNAL: object //| RESET_PIN: object
//| """The chip was reset by an external input such as a button.""" //| """The chip was reset by a signal on its reset pin. The pin might be connected to a reset buton."""
//|
//| WATCHDOG: object
//| """The chip was reset by its watchdog timer."""
//| //|
MAKE_ENUM_MAP(alarm_reset_reason) { MAKE_ENUM_MAP(alarm_reset_reason) {
MAKE_ENUM_MAP_ENTRY(reset_reason, POWER_VALID), MAKE_ENUM_MAP_ENTRY(reset_reason, POWER_ON),
MAKE_ENUM_MAP_ENTRY(reset_reason, BROWNOUT),
MAKE_ENUM_MAP_ENTRY(reset_reason, SOFTWARE), MAKE_ENUM_MAP_ENTRY(reset_reason, SOFTWARE),
MAKE_ENUM_MAP_ENTRY(reset_reason, DEEP_SLEEP_ALARM), MAKE_ENUM_MAP_ENTRY(reset_reason, DEEP_SLEEP_ALARM),
MAKE_ENUM_MAP_ENTRY(reset_reason, EXTERNAL), 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(alarm_reset_reason_locals_dict, alarm_reset_reason_locals_table);

View File

@ -28,12 +28,16 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H #define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H
typedef enum { typedef enum {
RESET_REASON_POWER_APPLIED, RESET_REASON_POWER_ON,
RESET_REASON_BROWNOUT,
RESET_REASON_SOFTWARE, RESET_REASON_SOFTWARE,
RESET_REASON_DEEP_SLEEP_ALARM, RESET_REASON_DEEP_SLEEP_ALARM,
RESET_REASON_BUTTON, RESET_REASON_RESET_PIN,
RESET_REASON_WATCHDOG,
} alarm_reset_reason_t; } alarm_reset_reason_t;
extern const mp_obj_type_t alarm_reset_reason_type; extern const mp_obj_type_t alarm_reset_reason_type;
extern alarm_reset_reason_t common_hal_alarm_get_reset_reason(void);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H #endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM__RESET_REASON__H

View File

@ -91,10 +91,14 @@ STATIC mp_obj_t alarm_pin_pin_alarm_binary_op(mp_binary_op_t op, mp_obj_t lhs_in
if (MP_OBJ_IS_TYPE(rhs_in, &alarm_pin_pin_alarm_type)) { if (MP_OBJ_IS_TYPE(rhs_in, &alarm_pin_pin_alarm_type)) {
// Pins are singletons, so we can compare them directly. // Pins are singletons, so we can compare them directly.
return mp_obj_new_bool( return mp_obj_new_bool(
common_hal_pin_pin_alarm_get_pin(lhs_in) == common_hal_pin_pin_alarm_get_pin(rhs_in) && common_hal_alarm_pin_pin_alarm_get_pin(lhs_in) ==
common_hal_pin_pin_alarm_get_level(lhs_in) == common_hal_pin_pin_alarm_get_level(rhs_in) && common_hal_alarm_pin_pin_alarm_get_pin(rhs_in) &&
common_hal_pin_pin_alarm_get_edge(lhs_in) == common_hal_pin_pin_alarm_get_edge(rhs_in) && common_hal_alarm_pin_pin_alarm_get_level(lhs_in) ==
common_hal_pin_pin_alarm_get_pull(lhs_in) == common_hal_pin_pin_alarm_get_pull(rhs_in)) common_hal_alarm_pin_pin_alarm_get_level(rhs_in) &&
common_hal_alarm_pin_pin_alarm_get_edge(lhs_in) ==
common_hal_alarm_pin_pin_alarm_get_edge(rhs_in) &&
common_hal_alarm_pin_pin_alarm_get_pull(lhs_in) ==
common_hal_alarm_pin_pin_alarm_get_pull(rhs_in));
} }
return mp_const_false; return mp_const_false;

View File

@ -28,9 +28,14 @@
#define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H #define MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H
#include "py/obj.h" #include "py/obj.h"
#include "common-hal/microcontroller/Pin.h"
extern const mp_obj_type_t alarm_pin_pin_alarm_type; extern const mp_obj_type_t alarm_pin_pin_alarm_type;
extern void common_hal_alarm_pin_pin_pin_alarm_construct(alarm_pin_pin_alarm_obj_t *self, const mcu_pin_obj_t *pin, bool level, bool edge, bool pull); extern void common_hal_alarm_pin_pin_pin_alarm_construct(alarm_pin_pin_alarm_obj_t *self, const mcu_pin_obj_t *pin, bool level, bool edge, bool pull);
extern mcu_pin_obj_t *common_hal_alarm_pin_pin_alarm_get_pin(alarm_pin_pin_alarm_obj_t *self);
extern bool common_hal_alarm_pin_pin_alarm_get_level(alarm_pin_pin_alarm_obj_t *self);
extern bool common_hal_alarm_pin_pin_alarm_get_edge(alarm_pin_pin_alarm_obj_t *self);
extern bool common_hal_alarm_pin_pin_alarm_get_pull(alarm_pin_pin_alarm_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H #endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_PIN_PIN_ALARM_H

View File

@ -31,4 +31,10 @@
extern const mp_obj_type_t alarm_time_duration_alarm_type; extern const mp_obj_type_t alarm_time_duration_alarm_type;
extern void common_hal_alarm_time_duration_alarm_construct(alarm_time_duration_alarm_obj_t *self, mp_float_t duration);
extern mp_float_t common_hal_alarm_time_duration_alarm_get_duration(alarm_time_duration_alarm_obj_t *self);
extern void common_hal_alarm_time_duration_alarm_enable(alarm_time_duration_alarm_obj_t *self);
extern void common_hal_alarm_time_duration_alarm_disable (alarm_time_duration_alarm_obj_t *self);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_DURATION_ALARM_H #endif // MICROPY_INCLUDED_SHARED_BINDINGS_ALARM_TIME_DURATION_ALARM_H

View File

@ -367,7 +367,6 @@ void prep_rgb_status_animation(const pyexec_result_t* result,
status->found_main = found_main; status->found_main = found_main;
status->total_exception_cycle = 0; status->total_exception_cycle = 0;
status->ok = result->return_code != PYEXEC_EXCEPTION; status->ok = result->return_code != PYEXEC_EXCEPTION;
status->cycles = 0;
if (status->ok) { if (status->ok) {
// If this isn't an exception, skip exception sorting and handling // If this isn't an exception, skip exception sorting and handling
return; return;
@ -419,9 +418,8 @@ bool tick_rgb_status_animation(rgb_status_animation_t* status) {
// All is good. Ramp ALL_DONE up and down. // All is good. Ramp ALL_DONE up and down.
if (tick_diff > ALL_GOOD_CYCLE_MS) { if (tick_diff > ALL_GOOD_CYCLE_MS) {
status->pattern_start = supervisor_ticks_ms32(); status->pattern_start = supervisor_ticks_ms32();
status->cycles++;
new_status_color(BLACK); new_status_color(BLACK);
return status->cycles; return true;
} }
uint16_t brightness = tick_diff * 255 / (ALL_GOOD_CYCLE_MS / 2); uint16_t brightness = tick_diff * 255 / (ALL_GOOD_CYCLE_MS / 2);
@ -436,8 +434,7 @@ bool tick_rgb_status_animation(rgb_status_animation_t* status) {
} else { } else {
if (tick_diff > status->total_exception_cycle) { if (tick_diff > status->total_exception_cycle) {
status->pattern_start = supervisor_ticks_ms32(); status->pattern_start = supervisor_ticks_ms32();
status->cycles++; return true;
return;
} }
// First flash the file color. // First flash the file color.
if (tick_diff < EXCEPTION_TYPE_LENGTH_MS) { if (tick_diff < EXCEPTION_TYPE_LENGTH_MS) {

View File

@ -76,6 +76,6 @@ void prep_rgb_status_animation(const pyexec_result_t* result,
bool found_main, bool found_main,
safe_mode_t safe_mode, safe_mode_t safe_mode,
rgb_status_animation_t* status); rgb_status_animation_t* status);
void tick_rgb_status_animation(rgb_status_animation_t* status); bool tick_rgb_status_animation(rgb_status_animation_t* status);
#endif // MICROPY_INCLUDED_SUPERVISOR_RGB_LED_STATUS_H #endif // MICROPY_INCLUDED_SUPERVISOR_RGB_LED_STATUS_H

View File

@ -29,6 +29,9 @@
#include "mphalport.h" #include "mphalport.h"
#include "shared-bindings/digitalio/DigitalInOut.h" #include "shared-bindings/digitalio/DigitalInOut.h"
#if CIRCUITPY_ALARM
#include "shared-bindings/alarm/ResetReason.h"
#endif
#include "supervisor/serial.h" #include "supervisor/serial.h"
#include "supervisor/shared/rgb_led_colors.h" #include "supervisor/shared/rgb_led_colors.h"
@ -52,10 +55,12 @@ safe_mode_t wait_for_safe_mode_reset(void) {
current_safe_mode = safe_mode; current_safe_mode = safe_mode;
return safe_mode; return safe_mode;
} }
if (common_hal_sleep_get_reset_reason() != RESET_REASON_POWER_VALID && #if CIRCUITPY_ALARM
common_hal_sleep_get_reset_reason() != RESET_REASON_BUTTON) { if (common_hal_alarm_get_reset_reason() != RESET_REASON_POWER_ON &&
common_hal_alarm_get_reset_reason() != RESET_REASON_RESET_PIN) {
return NO_SAFE_MODE; return NO_SAFE_MODE;
} }
#endif
port_set_saved_word(SAFE_MODE_DATA_GUARD | (MANUAL_SAFE_MODE << 8)); port_set_saved_word(SAFE_MODE_DATA_GUARD | (MANUAL_SAFE_MODE << 8));
// Wait for a while to allow for reset. // Wait for a while to allow for reset.
temp_status_color(SAFE_MODE); temp_status_color(SAFE_MODE);