summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorScott Shawcroft <scott@adafruit.com>2020-11-10 13:09:57 -0800
committerGitHub <noreply@github.com>2020-11-10 13:09:57 -0800
commitddb3590944f5dd84da94a4a90dc28e865b2b9a30 (patch)
tree8e58248514d7723e066890d1f938bfbe00b0be62
parent75a977febd27fc69f2c2dc3c017e765d215be633 (diff)
parentfe7ed999393e369243319c48453cc2f7add3e7f0 (diff)
Merge pull request #3647 from DavePutz/issue3579
Issue3579 - Check for CTRL-C During sleep on esp32s2
-rw-r--r--ports/esp32s2/supervisor/esp_port.h35
-rw-r--r--ports/esp32s2/supervisor/port.c23
-rw-r--r--ports/esp32s2/supervisor/usb.c22
3 files changed, 71 insertions, 9 deletions
diff --git a/ports/esp32s2/supervisor/esp_port.h b/ports/esp32s2/supervisor/esp_port.h
new file mode 100644
index 000000000..1164666cd
--- /dev/null
+++ b/ports/esp32s2/supervisor/esp_port.h
@@ -0,0 +1,35 @@
+/*
+ * This file is part of the MicroPython project, http://micropython.org/
+ *
+ * The MIT License (MIT)
+ *
+ * Copyright (c) 2019 Lucian Copeland 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.
+ */
+
+#ifndef MICROPY_INCLUDED_ESP32S2_SUPERVISOR_PORT_H
+#define MICROPY_INCLUDED_ESP32S2_SUPERVISOR_PORT_H
+
+#include "freertos/FreeRTOS.h"
+#include "freertos/task.h"
+
+extern TaskHandle_t sleeping_circuitpython_task;
+
+#endif // MICROPY_INCLUDED_ESP32S2_SUPERVISOR_PORT_H
diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c
index a25bcce00..3ea1fafbb 100644
--- a/ports/esp32s2/supervisor/port.c
+++ b/ports/esp32s2/supervisor/port.c
@@ -30,6 +30,8 @@
#include "supervisor/port.h"
#include "boards/board.h"
#include "modules/module.h"
+#include "py/runtime.h"
+#include "supervisor/esp_port.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
@@ -199,25 +201,28 @@ void port_disable_tick(void) {
esp_timer_stop(_tick_timer);
}
-TickType_t sleep_time_set;
TickType_t sleep_time_duration;
+
void port_interrupt_after_ticks(uint32_t ticks) {
- sleep_time_set = xTaskGetTickCount();
- sleep_time_duration = ticks / portTICK_PERIOD_MS;
- // esp_sleep_enable_timer_wakeup(uint64_t time_in_us)
+ sleep_time_duration = (ticks * 100)/1024;
+ sleeping_circuitpython_task = xTaskGetCurrentTaskHandle();
}
void port_sleep_until_interrupt(void) {
- // FreeRTOS delay here maybe.
- // Light sleep shuts down BLE and wifi.
- // esp_light_sleep_start()
+
+ uint32_t NotifyValue = 0;
+
if (sleep_time_duration == 0) {
return;
}
- vTaskDelayUntil(&sleep_time_set, sleep_time_duration);
+ xTaskNotifyWait(0x01,0x01,&NotifyValue,
+ sleep_time_duration );
+ if (NotifyValue == 1) {
+ sleeping_circuitpython_task = NULL;
+ mp_handle_pending();
+ }
}
-
// Wrap main in app_main that the IDF expects.
extern void main(void);
void app_main(void) {
diff --git a/ports/esp32s2/supervisor/usb.c b/ports/esp32s2/supervisor/usb.c
index 1ad6af047..2bfcdfb12 100644
--- a/ports/esp32s2/supervisor/usb.c
+++ b/ports/esp32s2/supervisor/usb.c
@@ -52,6 +52,8 @@
StackType_t usb_device_stack[USBD_STACK_SIZE];
StaticTask_t usb_device_taskdef;
+TaskHandle_t sleeping_circuitpython_task = NULL;
+
// USB Device Driver task
// This top level thread process all usb events and invoke callbacks
void usb_device_task(void* param)
@@ -114,3 +116,23 @@ void init_usb_hardware(void) {
usb_device_stack,
&usb_device_taskdef);
}
+/**
+ * Callback invoked when received an "wanted" char.
+ * @param itf Interface index (for multiple cdc interfaces)
+ * @param wanted_char The wanted char (set previously)
+ */
+void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
+{
+ (void) itf; // not used
+ // Workaround for using lib/utils/interrupt_char.c
+ // Compare mp_interrupt_char with wanted_char and ignore if not matched
+ if (mp_interrupt_char == wanted_char) {
+ tud_cdc_read_flush(); // flush read fifo
+ mp_keyboard_interrupt();
+ // CircuitPython's VM is run in a separate FreeRTOS task from TinyUSB.
+ // So, we must notify the other task when a CTRL-C is received.
+ if (sleeping_circuitpython_task != NULL) {
+ xTaskNotifyGive(sleeping_circuitpython_task);
+ }
+ }
+}