Skip to content

Commit ac5ad03

Browse files
authored
Merge pull request #13 from adafruit/main
Update from adafruit
2 parents 40f1bd0 + 9cdf5e1 commit ac5ad03

Some content is hidden

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

67 files changed

+797
-364
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ jobs:
274274
- "teensy41"
275275
- "teknikio_bluebird"
276276
- "thunderpack"
277+
- "tinkeringtech_scoutmakes_azul"
277278
- "trellis_m4_express"
278279
- "trinket_m0"
279280
- "trinket_m0_haxpress"

extmod/modujson.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
#include <stdio.h>
77

8+
#include "py/binary.h"
9+
#include "py/objarray.h"
810
#include "py/objlist.h"
911
#include "py/objstringio.h"
1012
#include "py/parsenum.h"
@@ -53,6 +55,8 @@ typedef struct _ujson_stream_t {
5355
mp_obj_t stream_obj;
5456
mp_uint_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode);
5557
int errcode;
58+
mp_obj_t python_readinto[2 + 1];
59+
mp_obj_array_t bytearray_obj;
5660
byte cur;
5761
} ujson_stream_t;
5862

@@ -73,9 +77,39 @@ STATIC byte ujson_stream_next(ujson_stream_t *s) {
7377
return s->cur;
7478
}
7579

80+
STATIC mp_uint_t ujson_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) {
81+
ujson_stream_t* s = obj;
82+
s->bytearray_obj.items = buf;
83+
s->bytearray_obj.len = size;
84+
*errcode = 0;
85+
mp_obj_t ret = mp_call_method_n_kw(1, 0, s->python_readinto);
86+
if (ret == mp_const_none) {
87+
*errcode = MP_EAGAIN;
88+
return MP_STREAM_ERROR;
89+
}
90+
return mp_obj_get_int(ret);
91+
}
92+
7693
STATIC mp_obj_t _mod_ujson_load(mp_obj_t stream_obj, bool return_first_json) {
77-
const mp_stream_p_t *stream_p = mp_get_stream_raise(stream_obj, MP_STREAM_OP_READ);
78-
ujson_stream_t s = {stream_obj, stream_p->read, 0, 0};
94+
const mp_stream_p_t *stream_p = mp_proto_get(MP_QSTR_protocol_stream, stream_obj);
95+
ujson_stream_t s;
96+
if (stream_p == NULL) {
97+
mp_load_method(stream_obj, MP_QSTR_readinto, s.python_readinto);
98+
s.bytearray_obj.base.type = &mp_type_bytearray;
99+
s.bytearray_obj.typecode = BYTEARRAY_TYPECODE;
100+
s.bytearray_obj.free = 0;
101+
// len and items are set at read time
102+
s.python_readinto[2] = MP_OBJ_FROM_PTR(&s.bytearray_obj);
103+
s.stream_obj = &s;
104+
s.read = ujson_python_readinto;
105+
} else {
106+
stream_p = mp_get_stream_raise(stream_obj, MP_STREAM_OP_READ);
107+
s.stream_obj = stream_obj;
108+
s.read = stream_p->read;
109+
s.errcode = 0;
110+
s.cur = 0;
111+
}
112+
79113
JSON_DEBUG("got JSON stream\n");
80114
vstr_t vstr;
81115
vstr_init(&vstr, 8);

locale/ID.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
22
#
33
# SPDX-License-Identifier: MIT
4-
54
msgid ""
65
msgstr ""
76
"Project-Id-Version: PACKAGE VERSION\n"

locale/cs.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
22
#
33
# SPDX-License-Identifier: MIT
4-
54
msgid ""
65
msgstr ""
76
"Project-Id-Version: PACKAGE VERSION\n"

locale/de_DE.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
22
#
33
# SPDX-License-Identifier: MIT
4-
54
msgid ""
65
msgstr ""
76
"Project-Id-Version: \n"

locale/es.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#
55
# SPDX-License-Identifier: MIT
66
#, fuzzy
7-
87
msgid ""
98
msgstr ""
109
"Project-Id-Version: \n"

locale/fil.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
22
#
33
# SPDX-License-Identifier: MIT
4-
54
msgid ""
65
msgstr ""
76
"Project-Id-Version: \n"

locale/fr.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
44
#
55
# SPDX-License-Identifier: MIT
6-
76
msgid ""
87
msgstr ""
98
"Project-Id-Version: 0.1\n"

locale/it_IT.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
33
#
44
# SPDX-License-Identifier: MIT
5-
65
msgid ""
76
msgstr ""
87
"Project-Id-Version: PACKAGE VERSION\n"

locale/ko.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
33
#
44
# SPDX-License-Identifier: MIT
5-
65
msgid ""
76
msgstr ""
87
"Project-Id-Version: PACKAGE VERSION\n"

locale/nl.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
22
#
33
# SPDX-License-Identifier: MIT
4-
54
msgid ""
65
msgstr ""
76
"Project-Id-Version: PACKAGE VERSION\n"

locale/pl.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
33
#
44
# SPDX-License-Identifier: MIT
5-
65
msgid ""
76
msgstr ""
87
"Project-Id-Version: \n"

locale/pt_BR.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
22
#
33
# SPDX-License-Identifier: MIT
4-
54
msgid ""
65
msgstr ""
76
"Project-Id-Version: PACKAGE VERSION\n"

locale/sv.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
22
#
33
# SPDX-License-Identifier: MIT
4-
54
msgid ""
65
msgstr ""
76
"Project-Id-Version: PACKAGE VERSION\n"

locale/zh_Latn_pinyin.po

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors)
33
#
44
# SPDX-License-Identifier: MIT
5-
65
msgid ""
76
msgstr ""
87
"Project-Id-Version: circuitpython-cn\n"

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 {

0 commit comments

Comments
 (0)