Skip to content

Commit 92d83f7

Browse files
authored
Merge pull request #4 from adafruit/main
Merging 11/11 changes
2 parents 34ee6e3 + ddb3590 commit 92d83f7

File tree

4 files changed

+89
-10
lines changed

4 files changed

+89
-10
lines changed

ports/esp32s2/supervisor/esp_port.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* This file is part of the MicroPython project, http://micropython.org/
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2019 Lucian Copeland for Adafruit Industries
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* in the Software without restriction, including without limitation the rights
11+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12+
* copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in
16+
* all copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+
* THE SOFTWARE.
25+
*/
26+
27+
#ifndef MICROPY_INCLUDED_ESP32S2_SUPERVISOR_PORT_H
28+
#define MICROPY_INCLUDED_ESP32S2_SUPERVISOR_PORT_H
29+
30+
#include "freertos/FreeRTOS.h"
31+
#include "freertos/task.h"
32+
33+
extern TaskHandle_t sleeping_circuitpython_task;
34+
35+
#endif // MICROPY_INCLUDED_ESP32S2_SUPERVISOR_PORT_H

ports/esp32s2/supervisor/port.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "supervisor/port.h"
3131
#include "boards/board.h"
3232
#include "modules/module.h"
33+
#include "py/runtime.h"
34+
#include "supervisor/esp_port.h"
3335

3436
#include "freertos/FreeRTOS.h"
3537
#include "freertos/task.h"
@@ -148,7 +150,18 @@ uint32_t *port_stack_get_limit(void) {
148150
}
149151

150152
uint32_t *port_stack_get_top(void) {
151-
return port_stack_get_limit() + CONFIG_ESP_MAIN_TASK_STACK_SIZE / (sizeof(uint32_t) / sizeof(StackType_t));
153+
// The sizeof-arithmetic is so that the pointer arithmetic is done on units
154+
// of uint32_t instead of units of StackType_t. StackType_t is an alias
155+
// for a byte sized type.
156+
//
157+
// The main stack is bigger than CONFIG_ESP_MAIN_TASK_STACK_SIZE -- an
158+
// "extra" size is added to it (TASK_EXTRA_STACK_SIZE). This total size is
159+
// available as ESP_TASK_MAIN_STACK. Presumably TASK_EXTRA_STACK_SIZE is
160+
// additional stack that can be used by the esp-idf runtime. But what's
161+
// important for us is that some very outermost stack frames, such as
162+
// pyexec_friendly_repl, could lie inside the "extra" area and be invisible
163+
// to the garbage collector.
164+
return port_stack_get_limit() + ESP_TASK_MAIN_STACK / (sizeof(uint32_t) / sizeof(StackType_t));
152165
}
153166

154167
supervisor_allocation _fixed_stack;
@@ -188,25 +201,28 @@ void port_disable_tick(void) {
188201
esp_timer_stop(_tick_timer);
189202
}
190203

191-
TickType_t sleep_time_set;
192204
TickType_t sleep_time_duration;
205+
193206
void port_interrupt_after_ticks(uint32_t ticks) {
194-
sleep_time_set = xTaskGetTickCount();
195-
sleep_time_duration = ticks / portTICK_PERIOD_MS;
196-
// esp_sleep_enable_timer_wakeup(uint64_t time_in_us)
207+
sleep_time_duration = (ticks * 100)/1024;
208+
sleeping_circuitpython_task = xTaskGetCurrentTaskHandle();
197209
}
198210

199211
void port_sleep_until_interrupt(void) {
200-
// FreeRTOS delay here maybe.
201-
// Light sleep shuts down BLE and wifi.
202-
// esp_light_sleep_start()
212+
213+
uint32_t NotifyValue = 0;
214+
203215
if (sleep_time_duration == 0) {
204216
return;
205217
}
206-
vTaskDelayUntil(&sleep_time_set, sleep_time_duration);
218+
xTaskNotifyWait(0x01,0x01,&NotifyValue,
219+
sleep_time_duration );
220+
if (NotifyValue == 1) {
221+
sleeping_circuitpython_task = NULL;
222+
mp_handle_pending();
223+
}
207224
}
208225

209-
210226
// Wrap main in app_main that the IDF expects.
211227
extern void main(void);
212228
void app_main(void) {

ports/esp32s2/supervisor/usb.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
StackType_t usb_device_stack[USBD_STACK_SIZE];
5353
StaticTask_t usb_device_taskdef;
5454

55+
TaskHandle_t sleeping_circuitpython_task = NULL;
56+
5557
// USB Device Driver task
5658
// This top level thread process all usb events and invoke callbacks
5759
void usb_device_task(void* param)
@@ -114,3 +116,23 @@ void init_usb_hardware(void) {
114116
usb_device_stack,
115117
&usb_device_taskdef);
116118
}
119+
/**
120+
* Callback invoked when received an "wanted" char.
121+
* @param itf Interface index (for multiple cdc interfaces)
122+
* @param wanted_char The wanted char (set previously)
123+
*/
124+
void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char)
125+
{
126+
(void) itf; // not used
127+
// Workaround for using lib/utils/interrupt_char.c
128+
// Compare mp_interrupt_char with wanted_char and ignore if not matched
129+
if (mp_interrupt_char == wanted_char) {
130+
tud_cdc_read_flush(); // flush read fifo
131+
mp_keyboard_interrupt();
132+
// CircuitPython's VM is run in a separate FreeRTOS task from TinyUSB.
133+
// So, we must notify the other task when a CTRL-C is received.
134+
if (sleeping_circuitpython_task != NULL) {
135+
xTaskNotifyGive(sleeping_circuitpython_task);
136+
}
137+
}
138+
}

shared-module/displayio/TileGrid.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,16 @@ bool common_hal_displayio_tilegrid_get_hidden(displayio_tilegrid_t* self) {
8383

8484
void common_hal_displayio_tilegrid_set_hidden(displayio_tilegrid_t* self, bool hidden) {
8585
self->hidden = hidden;
86+
if(!hidden){
87+
self->full_change = true;
88+
}
8689
}
8790

8891
void displayio_tilegrid_set_hidden_by_parent(displayio_tilegrid_t *self, bool hidden) {
8992
self->hidden_by_parent = hidden;
93+
if(!hidden){
94+
self->full_change = true;
95+
}
9096
}
9197

9298
bool displayio_tilegrid_get_previous_area(displayio_tilegrid_t *self, displayio_area_t* area) {

0 commit comments

Comments
 (0)