summaryrefslogtreecommitdiff
path: root/supervisor/shared
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-12-02 12:51:43 -0800
committerGitHub <noreply@github.com>2020-12-02 12:51:43 -0800
commitd7ba641ff646b48e5ad38ff72a2dcfe17bb54624 (patch)
treea0c4f9fb561b2caa38636645ca27f0ddad59f087 /supervisor/shared
parent5b3c930e384ef6440f0f7b5167bb54ea68a8be76 (diff)
parent72fa7d88b881d2ed9978c0bd65ce5f8d6eb51703 (diff)
Merge pull request #3767 from dhalbert/sleep
Initial alarm and sleep PR: time alarms with light and deep sleep; PinAlarms not yet implemented
Diffstat (limited to 'supervisor/shared')
-rw-r--r--supervisor/shared/rgb_led_status.c8
-rw-r--r--supervisor/shared/rgb_led_status.h2
-rw-r--r--supervisor/shared/safe_mode.c8
-rw-r--r--supervisor/shared/serial.c4
-rw-r--r--supervisor/shared/usb/usb.c1
-rw-r--r--supervisor/shared/workflow.c47
-rw-r--r--supervisor/shared/workflow.h32
7 files changed, 95 insertions, 7 deletions
diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c
index 283b9da12..006bb1b34 100644
--- a/supervisor/shared/rgb_led_status.c
+++ b/supervisor/shared/rgb_led_status.c
@@ -411,14 +411,15 @@ void prep_rgb_status_animation(const pyexec_result_t* result,
#endif
}
-void tick_rgb_status_animation(rgb_status_animation_t* status) {
+bool tick_rgb_status_animation(rgb_status_animation_t* status) {
#if defined(MICROPY_HW_NEOPIXEL) || (defined(MICROPY_HW_APA102_MOSI) && defined(MICROPY_HW_APA102_SCK)) || (defined(CP_RGB_STATUS_LED))
uint32_t tick_diff = supervisor_ticks_ms32() - status->pattern_start;
if (status->ok) {
// All is good. Ramp ALL_DONE up and down.
if (tick_diff > ALL_GOOD_CYCLE_MS) {
status->pattern_start = supervisor_ticks_ms32();
- tick_diff = 0;
+ new_status_color(BLACK);
+ return true;
}
uint16_t brightness = tick_diff * 255 / (ALL_GOOD_CYCLE_MS / 2);
@@ -433,7 +434,7 @@ void tick_rgb_status_animation(rgb_status_animation_t* status) {
} else {
if (tick_diff > status->total_exception_cycle) {
status->pattern_start = supervisor_ticks_ms32();
- tick_diff = 0;
+ return true;
}
// First flash the file color.
if (tick_diff < EXCEPTION_TYPE_LENGTH_MS) {
@@ -482,4 +483,5 @@ void tick_rgb_status_animation(rgb_status_animation_t* status) {
}
}
#endif
+ return false; // Animation is not finished.
}
diff --git a/supervisor/shared/rgb_led_status.h b/supervisor/shared/rgb_led_status.h
index e4e1981a2..84c97796a 100644
--- a/supervisor/shared/rgb_led_status.h
+++ b/supervisor/shared/rgb_led_status.h
@@ -76,6 +76,6 @@ void prep_rgb_status_animation(const pyexec_result_t* result,
bool found_main,
safe_mode_t safe_mode,
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
diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c
index d59e754ed..9032e4045 100644
--- a/supervisor/shared/safe_mode.c
+++ b/supervisor/shared/safe_mode.c
@@ -29,6 +29,8 @@
#include "mphalport.h"
#include "shared-bindings/digitalio/DigitalInOut.h"
+#include "shared-bindings/microcontroller/Processor.h"
+#include "shared-bindings/microcontroller/ResetReason.h"
#include "supervisor/serial.h"
#include "supervisor/shared/rgb_led_colors.h"
@@ -52,6 +54,12 @@ safe_mode_t wait_for_safe_mode_reset(void) {
current_safe_mode = safe_mode;
return safe_mode;
}
+
+ const mcu_reset_reason_t reset_reason = common_hal_mcu_processor_get_reset_reason();
+ if (reset_reason != RESET_REASON_POWER_ON &&
+ reset_reason != RESET_REASON_RESET_PIN) {
+ return NO_SAFE_MODE;
+ }
port_set_saved_word(SAFE_MODE_DATA_GUARD | (MANUAL_SAFE_MODE << 8));
// Wait for a while to allow for reset.
temp_status_color(SAFE_MODE);
diff --git a/supervisor/shared/serial.c b/supervisor/shared/serial.c
index 7383cc228..303f89e75 100644
--- a/supervisor/shared/serial.c
+++ b/supervisor/shared/serial.c
@@ -69,9 +69,7 @@ bool serial_connected(void) {
#if defined(DEBUG_UART_TX) && defined(DEBUG_UART_RX)
return true;
#else
- // True if DTR is asserted, and the USB connection is up.
- // tud_cdc_get_line_state(): bit 0 is DTR, bit 1 is RTS
- return (tud_cdc_get_line_state() & 1) && tud_ready();
+ return tud_cdc_connected();
#endif
}
diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c
index 93d3436e9..ff08ade18 100644
--- a/supervisor/shared/usb/usb.c
+++ b/supervisor/shared/usb/usb.c
@@ -31,6 +31,7 @@
#include "supervisor/port.h"
#include "supervisor/serial.h"
#include "supervisor/usb.h"
+#include "supervisor/shared/workflow.h"
#include "lib/utils/interrupt_char.h"
#include "lib/mp-readline/readline.h"
diff --git a/supervisor/shared/workflow.c b/supervisor/shared/workflow.c
new file mode 100644
index 000000000..4986c0957
--- /dev/null
+++ b/supervisor/shared/workflow.c
@@ -0,0 +1,47 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Scott Shawcroft 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 <stdbool.h>
+#include "py/mpconfig.h"
+#include "tusb.h"
+
+void supervisor_workflow_reset(void) {
+}
+
+// Return true as soon as USB communication with host has started,
+// even before enumeration is done.
+// Not that some chips don't notice when USB is unplugged after first being plugged in,
+// so this is not perfect, but tud_suspended() check helps.
+bool supervisor_workflow_connecting(void) {
+ return tud_connected() && !tud_suspended();
+}
+
+// Return true if host has completed connection to us (such as USB enumeration).
+bool supervisor_workflow_active(void) {
+ // Eventually there might be other non-USB workflows, such as BLE.
+ // tud_ready() checks for usb mounted and not suspended.
+ return tud_ready();
+}
diff --git a/supervisor/shared/workflow.h b/supervisor/shared/workflow.h
new file mode 100644
index 000000000..22a9fa468
--- /dev/null
+++ b/supervisor/shared/workflow.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2020 Scott Shawcroft 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.
+ */
+
+#pragma once
+
+extern void supervisor_workflow_reset(void);
+
+extern bool supervisor_workflow_connecting(void);
+extern bool supervisor_workflow_active(void);