Merge pull request #3647 from DavePutz/issue3579
Issue3579 - Check for CTRL-C During sleep on esp32s2
This commit is contained in:
commit
ddb3590944
35
ports/esp32s2/supervisor/esp_port.h
Normal file
35
ports/esp32s2/supervisor/esp_port.h
Normal file
@ -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
|
@ -30,6 +30,8 @@
|
|||||||
#include "supervisor/port.h"
|
#include "supervisor/port.h"
|
||||||
#include "boards/board.h"
|
#include "boards/board.h"
|
||||||
#include "modules/module.h"
|
#include "modules/module.h"
|
||||||
|
#include "py/runtime.h"
|
||||||
|
#include "supervisor/esp_port.h"
|
||||||
|
|
||||||
#include "freertos/FreeRTOS.h"
|
#include "freertos/FreeRTOS.h"
|
||||||
#include "freertos/task.h"
|
#include "freertos/task.h"
|
||||||
@ -199,24 +201,27 @@ void port_disable_tick(void) {
|
|||||||
esp_timer_stop(_tick_timer);
|
esp_timer_stop(_tick_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
TickType_t sleep_time_set;
|
|
||||||
TickType_t sleep_time_duration;
|
TickType_t sleep_time_duration;
|
||||||
|
|
||||||
void port_interrupt_after_ticks(uint32_t ticks) {
|
void port_interrupt_after_ticks(uint32_t ticks) {
|
||||||
sleep_time_set = xTaskGetTickCount();
|
sleep_time_duration = (ticks * 100)/1024;
|
||||||
sleep_time_duration = ticks / portTICK_PERIOD_MS;
|
sleeping_circuitpython_task = xTaskGetCurrentTaskHandle();
|
||||||
// esp_sleep_enable_timer_wakeup(uint64_t time_in_us)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void port_sleep_until_interrupt(void) {
|
void port_sleep_until_interrupt(void) {
|
||||||
// FreeRTOS delay here maybe.
|
|
||||||
// Light sleep shuts down BLE and wifi.
|
uint32_t NotifyValue = 0;
|
||||||
// esp_light_sleep_start()
|
|
||||||
if (sleep_time_duration == 0) {
|
if (sleep_time_duration == 0) {
|
||||||
return;
|
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.
|
// Wrap main in app_main that the IDF expects.
|
||||||
extern void main(void);
|
extern void main(void);
|
||||||
|
@ -52,6 +52,8 @@
|
|||||||
StackType_t usb_device_stack[USBD_STACK_SIZE];
|
StackType_t usb_device_stack[USBD_STACK_SIZE];
|
||||||
StaticTask_t usb_device_taskdef;
|
StaticTask_t usb_device_taskdef;
|
||||||
|
|
||||||
|
TaskHandle_t sleeping_circuitpython_task = NULL;
|
||||||
|
|
||||||
// USB Device Driver task
|
// USB Device Driver task
|
||||||
// This top level thread process all usb events and invoke callbacks
|
// This top level thread process all usb events and invoke callbacks
|
||||||
void usb_device_task(void* param)
|
void usb_device_task(void* param)
|
||||||
@ -114,3 +116,23 @@ void init_usb_hardware(void) {
|
|||||||
usb_device_stack,
|
usb_device_stack,
|
||||||
&usb_device_taskdef);
|
&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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user