8000 Merge branch 'main' into type_hints · kvc0/circuitpython@9e3fa86 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9e3fa86

Browse files
authored
Merge branch 'main' into type_hints
2 parents 612c6bb + e047ea2 commit 9e3fa86

File tree

66 files changed

+812
-442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+812
-442
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
run: |
3838
sudo apt-get install -y eatmydata
3939
sudo eatmydata apt-get install -y gettext librsvg2-bin mingw-w64
40-
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid
40+
pip install requests sh click setuptools cpp-coveralls "Sphinx<4" sphinx-rtd-theme recommonmark sphinx-autoapi sphinxcontrib-svg2pdfconverter polib pyyaml astroid isort
4141
- name: Versions
4242
run: |
4343
gcc --version

main.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545

4646
#include "background.h"
4747
#include "mpconfigboard.h"
48+
#include "supervisor/background_callback.h"
4849
#include "supervisor/cpu.h"
4950
#include "supervisor/memory.h"
5051
#include "supervisor/port.h"
@@ -100,8 +101,6 @@ void start_mp(supervisor_allocation* heap) {
100101
reset_status_led();
101102
autoreload_stop();
102103

103-
background_tasks_reset();
104-
105104
// Stack limit should be less than real stack size, so we have a chance
106105
// to recover from limit hit. (Limit is measured in bytes.)
107106
mp_stack_ctrl_init();
@@ -161,6 +160,8 @@ void stop_mp(void) {
161160
MP_STATE_VM(vfs_cur) = vfs;
162161
#endif
163162

163+
background_callback_reset();
164+
164165
gc_deinit();
165166
}
166167

@@ -492,6 +493,8 @@ void gc_collect(void) {
492493
// have lost their references in the VM even though they are mounted.
493494
gc_collect_root((void**)&MP_STATE_VM(vfs_mount_table), sizeof(mp_vfs_mount_t) / sizeof(mp_uint_t));
494495

496+
background_callback_gc_collect();
497+
495498
#if CIRCUITPY_DISPLAYIO
496499
displayio_gc_collect();
497500
#endif

ports/atmel-samd/audio_dma.c

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include "shared-bindings/audiocore/RawSample.h"
3333
#include "shared-bindings/audiocore/WaveFile.h"
34-
#include "supervisor/shared/tick.h"
34+
#include "supervisor/background_callback.h"
3535

3636
#include "py/mpstate.h"
3737
#include "py/runtime.h"
@@ -61,7 +61,6 @@ void audio_dma_free_channel(uint8_t channel) {
6161
assert(audio_dma_allocated[channel]);
6262
audio_dma_disable_channel(channel);
6363
audio_dma_allocated[channel] = false;
64-
supervisor_disable_tick();
6564
}
6665

6766
void audio_dma_disable_channel(uint8_t channel) {
@@ -73,7 +72,6 @@ void audio_dma_disable_channel(uint8_t channel) {
7372
void audio_dma_enable_channel(uint8_t channel) {
7473
if (channel >= AUDIO_DMA_CHANNEL_COUNT)
7574
return;
76-
supervisor_enable_tick();
7775
dma_enable_channel(channel);
7876
}
7977

@@ -259,6 +257,15 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma,
259257
dma->beat_size *= 2;
260258
}
261259

260+
#ifdef SAM_D5X_E5X
261+
int irq = dma->event_channel < 4 ? EVSYS_0_IRQn + dma->event_channel : EVSYS_4_IRQn;
262+
#else
263+
int irq = EVSYS_IRQn;
264+
#endif
265+
266+
NVIC_DisableIRQ(irq);
267+
NVIC_ClearPendingIRQ(irq);
268+
262269
DmacDescriptor* first_descriptor = dma_descriptor(dma_channel);
263270
setup_audio_descriptor(first_descriptor, dma->beat_size, output_spacing, output_register_address);
264271
if (single_buffer) {
@@ -281,6 +288,8 @@ audio_dma_result audio_dma_setup_playback(audio_dma_t* dma,
281288
dma_configure(dma_channel, dma_trigger_source, true);
282289
audio_dma_enable_channel(dma_channel);
283290

291+
NVIC_EnableIRQ(irq);
292+
284293
return AUDIO_DMA_OK;
285294
}
286295

@@ -321,9 +330,6 @@ void audio_dma_reset(void) {
321330
for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) {
322331
audio_dma_state[i] = NULL;
323332
audio_dma_pending[i] = false;
324-
if (audio_dma_allocated[i]) {
325-
supervisor_disable_tick();
326-
}
327333
audio_dma_allocated[i] = false;
328334
audio_dma_disable_channel(i);
329335
dma_descriptor(i)->BTCTRL.bit.VALID = false;
@@ -343,29 +349,39 @@ bool audio_dma_get_playing(audio_dma_t* dma) {
343349
return (status & DMAC_CHINTFLAG_TERR) == 0;
344350
}
345351

346-
// WARN(tannewt): DO NOT print from here. Printing calls background tasks such as this and causes a
347-
// stack overflow.
352+
// WARN(tannewt): DO NOT print from here, or anything it calls. Printing calls
353+
// background tasks such as this and causes a stack overflow.
354+
STATIC void dma_callback_fun(void *arg) {
355+
audio_dma_t* dma = arg;
356+
if (dma == NULL) {
357+
return;
358+
}
359+
360+
audio_dma_load_next_block(dma);
361+
}
348362

349-
void audio_dma_background(void) {
363+
void evsyshandler_common(void) {
350364
for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) {
351-
if (audio_dma_pending[i]) {
352-
continue;
353-
}
354365
audio_dma_t* dma = audio_dma_state[i];
355366
if (dma == NULL) {
356367
continue;
357368
}
358-
359369
bool block_done = event_interrupt_active(dma->event_channel);
360370
if (!block_done) {
361371
continue;
362372
}
363-
364-
// audio_dma_load_next_block() can call Python code, which can call audio_dma_background()
365-
// recursively at the next background processing time. So disallow recursive calls to here.
366-
audio_dma_pending[i] = true;
367-
audio_dma_load_next_block(dma);
368-
audio_dma_pending[i] = false;
373+
background_callback_add(&dma->callback, dma_callback_fun, (void*)dma);
369374
}
370375
}
376+
377+
#ifdef SAM_D5X_E5X
378+
void EVSYS_0_Handler(void) { evsyshandler_common(); }
379+
void EVSYS_1_Handler(void) { evsyshandler_common(); }
380+
void EVSYS_2_Handler(void) { evsyshandler_common(); }
381+
void EVSYS_3_Handler(void) { evsyshandler_common(); }
382+
void EVSYS_4_Handler(void) { evsyshandler_common(); }
383+
#else
384+
void EVSYS_Handler(void) { evsyshandler_common(); }
385+
#endif
386+
371387
#endif

ports/atmel-samd/audio_dma.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include "py/obj.h"
3232
#include "shared-module/audiocore/RawSample.h"
3333
#include "shared-module/audiocore/WaveFile.h"
34+
#include "supervisor/background_callback.h"
3435

3536
typedef struct {
3637
mp_obj_t sample;
@@ -49,6 +50,7 @@ typedef struct {
4950
uint8_t* second_buffer;
5051
bool first_descriptor_free;
5152
DmacDescriptor* second_descriptor;
53+
background_callback_t callback;
5254
} audio_dma_t;
5355

5456
typedef enum {

ports/atmel-samd/background.c

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,63 +39,21 @@
3939
#include "shared-module/displayio/__init__.h"
4040
#endif
4141

42-
volatile uint64_t last_finished_tick = 0;
43-
44-
bool stack_ok_so_far = true;
45-
46-
static bool running_background_tasks = false;
47-
4842
#ifdef MONITOR_BACKGROUND_TASKS
4943
// PB03 is physical pin "SCL" on the Metro M4 express
5044
// so you can't use this code AND an i2c peripheral
5145
// at the same time unless you change this
52-
STATIC void start_background_task(void) {
46+
void port_start_background_task(void) {
5347
REG_PORT_DIRSET1 = (1<<3);
5448
REG_PORT_OUTSET1 = (1<<3);
5549
}
5650

57-
STATIC void finish_background_task(void) {
51+
void port_finish_background_task(void) {
5852
REG_PORT_OUTCLR1 = (1<<3);
5953
}
6054
#else
61-
STATIC void start_background_task(void) {}
62-
STATIC void finish_background_task(void) {}
55+
void port_start_background_task(void) {}
56+
void port_finish_background_task(void) {}
6357
#endif
6458

65-
void background_tasks_reset(void) {
66-
running_background_tasks = false;
67-
}
68-
69-
void run_background_tasks(void) {
70-
// Don't call ourselves recursively.
71-
if (running_background_tasks) {
72-
return;
73-
}
74-
75-
start_background_task();
76-
77-
assert_heap_ok();
78-
running_background_tasks = true;
79-
80-
#if CIRCUITPY_AUDIOIO || CIRCUITPY_AUDIOBUSIO
81-
audio_dma_background();
82-
#endif
83-
#if CIRCUITPY_DISPLAYIO
84-
displayio_background();
85-
#endif
86-
87-
#if CIRCUITPY_NETWORK
88-
network_module_background();
89-
#endif
90-
filesystem_background();
91-
usb_background();
92-
running_background_tasks = false;
93-
assert_heap_ok();
94-
95-
last_finished_tick = port_get_raw_ticks(NULL);
96-
finish_background_task();
97-
}
98-
99-
bool background_tasks_ok(void) {
100-
return port_get_raw_ticks(NULL) - last_finished_tick < 1024;
101-
}
59+
void port_background_task(void) {}

ports/atmel-samd/background.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,4 @@
2929

3030
#include <stdbool.h>
3131

32-
void background_tasks_reset(void);
33-
void run_background_tasks(void);
34-
void run_background_vm_tasks(void);
35-
bool background_tasks_ok(void);
36-
3732
#endif // MICROPY_INCLUDED_ATMEL_SAMD_BACKGROUND_H

ports/atmel-samd/boards/aloriumtech_evo_m51/mpconfigboard.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,4 @@ EXTERNAL_FLASH_DEVICE_COUNT = 1
1313
EXTERNAL_FLASH_DEVICES = GD25Q16C
1414
LONGINT_IMPL = MPZ
1515

16-
CIRCUITPY_NETWORK = 1
17-
MICROPY_PY_WIZNET5K = 5500
1816
CIRCUITPY_PS2IO = 1

ports/atmel-samd/boards/circuitbrains_deluxe_m4/mpconfigboard.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,4 @@ EXTERNAL_FLASH_DEVICE_COUNT = 2
1111
EXTERNAL_FLASH_DEVICES = "W25Q64JV_IQ, S25FL064L"
1212
LONGINT_IMPL = MPZ
1313

14-CIRCUITPY_NETWORK = 1
15-
MICROPY_PY_WIZNET5K = 5500
1614
CIRCUITPY_PS2IO = 1

ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ LONGINT_IMPL = MPZ
1313
CIRCUITPY_AUDIOBUSIO = 0
1414
CIRCUITPY_FRAMEBUFFERIO = 0
1515
CIRCUITPY_DISPLAYIO = 0
16-
CIRCUITPY_NETWORK = 0
1716
CIRCUITPY_RGBMATRIX = 0
1817
CIRCUITPY_PS2IO = 0
1918
CIRCUITPY_AUDIOMP3 = 0

0 commit comments

Comments
 (0)
0