summaryrefslogtreecommitdiff
path: root/supervisor/shared
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-10-27 17:55:03 -0700
committerScott Shawcroft <scott@tannewt.org>2020-10-27 17:55:03 -0700
commit9a4efed8cbaca3aa48c6cc0ce0a4e267eef7a8e1 (patch)
treea4503697ca0d3fab4e15ee6add1171165ac32146 /supervisor/shared
parent85dadf3a561c21e284d5daf42b1b3e367ce7ebc6 (diff)
Start tweaking the workflow to sleep
Diffstat (limited to 'supervisor/shared')
-rw-r--r--supervisor/shared/rgb_led_status.c10
-rw-r--r--supervisor/shared/safe_mode.c4
-rw-r--r--supervisor/shared/serial.h29
-rw-r--r--supervisor/shared/usb/usb.c9
-rw-r--r--supervisor/shared/workflow.c32
-rw-r--r--supervisor/shared/workflow.h29
6 files changed, 108 insertions, 5 deletions
diff --git a/supervisor/shared/rgb_led_status.c b/supervisor/shared/rgb_led_status.c
index 283b9da12..bff74a1f0 100644
--- a/supervisor/shared/rgb_led_status.c
+++ b/supervisor/shared/rgb_led_status.c
@@ -367,6 +367,7 @@ void prep_rgb_status_animation(const pyexec_result_t* result,
status->found_main = found_main;
status->total_exception_cycle = 0;
status->ok = result->return_code != PYEXEC_EXCEPTION;
+ status->cycles = 0;
if (status->ok) {
// If this isn't an exception, skip exception sorting and handling
return;
@@ -411,14 +412,16 @@ 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;
+ status->cycles++;
+ new_status_color(BLACK);
+ return status->cycles;
}
uint16_t brightness = tick_diff * 255 / (ALL_GOOD_CYCLE_MS / 2);
@@ -433,7 +436,8 @@ 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;
+ status->cycles++;
+ return;
}
// First flash the file color.
if (tick_diff < EXCEPTION_TYPE_LENGTH_MS) {
diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c
index d59e754ed..fa871eeeb 100644
--- a/supervisor/shared/safe_mode.c
+++ b/supervisor/shared/safe_mode.c
@@ -52,6 +52,10 @@ safe_mode_t wait_for_safe_mode_reset(void) {
current_safe_mode = safe_mode;
return safe_mode;
}
+ if (common_hal_sleepio_get_reset_reason() != RESET_REASON_POWER_VALID &&
+ common_hal_sleepio_get_reset_reason() != RESET_REASON_BUTTON) {
+ 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.h b/supervisor/shared/serial.h
new file mode 100644
index 000000000..84f92c337
--- /dev/null
+++ b/supervisor/shared/serial.h
@@ -0,0 +1,29 @@
+/*
+ * 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 volatile bool _serial_connected;
diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c
index 89fbf56f3..7fbc5cbe6 100644
--- a/supervisor/shared/usb/usb.c
+++ b/supervisor/shared/usb/usb.c
@@ -30,6 +30,7 @@
#include "supervisor/background_callback.h"
#include "supervisor/port.h"
#include "supervisor/serial.h"
+#include "supervisor/shared/serial.h"
#include "supervisor/usb.h"
#include "lib/utils/interrupt_char.h"
#include "lib/mp-readline/readline.h"
@@ -102,14 +103,16 @@ void usb_irq_handler(void) {
// tinyusb callbacks
//--------------------------------------------------------------------+
-// Invoked when device is mounted
+// Invoked when device is plugged into a host
void tud_mount_cb(void) {
usb_msc_mount();
+ _workflow_active = true;
}
-// Invoked when device is unmounted
+// Invoked when device is unplugged from the host
void tud_umount_cb(void) {
usb_msc_umount();
+ _workflow_active = false;
}
// Invoked when usb bus is suspended
@@ -117,10 +120,12 @@ void tud_umount_cb(void) {
// USB Specs: Within 7ms, device must draw an average current less than 2.5 mA from bus
void tud_suspend_cb(bool remote_wakeup_en) {
_serial_connected = false;
+ _workflow_active = false;
}
// Invoked when usb bus is resumed
void tud_resume_cb(void) {
+ _workflow_active = true;
}
// Invoked when cdc when line state changed e.g connected/disconnected
diff --git a/supervisor/shared/workflow.c b/supervisor/shared/workflow.c
new file mode 100644
index 000000000..adcffb319
--- /dev/null
+++ b/supervisor/shared/workflow.c
@@ -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.
+ */
+
+// Set by the shared USB code.
+volatile bool _workflow_active;
+
+bool workflow_active(void) {
+ return _workflow_active;
+}
diff --git a/supervisor/shared/workflow.h b/supervisor/shared/workflow.h
new file mode 100644
index 000000000..4a138332a
--- /dev/null
+++ b/supervisor/shared/workflow.h
@@ -0,0 +1,29 @@
+/*
+ * 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 volatile bool _workflow_active;