Skip to content

Commit 01d8808

Browse files
authored
Merge pull request #6041 from t-ikegami/enable_uasyncio
Enable _uasyncio module
2 parents c68b7a2 + 6142586 commit 01d8808

File tree

4 files changed

+65
-48
lines changed

4 files changed

+65
-48
lines changed

extmod/moduasyncio.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#include "py/pairheap.h"
3030
#include "py/mphal.h"
3131

32+
#if CIRCUITPY && !(defined(__unix__) || defined(__APPLE__))
33+
#include "shared-bindings/supervisor/__init__.h"
34+
#endif
35+
3236
#if MICROPY_PY_UASYNCIO
3337

3438
// Used when task cannot be guaranteed to be non-NULL.
@@ -59,10 +63,12 @@ STATIC const mp_obj_type_t task_queue_type;
5963
STATIC const mp_obj_type_t task_type;
6064

6165
STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
66+
STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
6267

6368
/******************************************************************************/
6469
// Ticks for task ordering in pairing heap
6570

71+
#if !CIRCUITPY || (defined(__unix__) || defined(__APPLE__))
6672
STATIC mp_obj_t ticks(void) {
6773
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
6874
}
@@ -74,6 +80,20 @@ STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
7480
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
7581
return diff;
7682
}
83+
#else
84+
#define _TICKS_PERIOD (1lu << 29)
85+
#define _TICKS_MAX (_TICKS_PERIOD - 1)
86+
#define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1)
87+
88+
#define ticks() supervisor_ticks_ms()
89+
90+
STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
91+
mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in);
92+
mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in);
93+
mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD;
94+
return diff;
95+
}
96+
#endif
7797

7898
STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
7999
mp_obj_task_t *t1 = (mp_obj_task_t *)n1;
@@ -225,6 +245,11 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) {
225245
}
226246
STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel);
227247

248+
STATIC mp_obj_t task_await(mp_obj_t self_in) {
249+
return task_getiter(self_in, NULL);
250+
}
251+
STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_await_obj, task_await);
252+
228253
STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
229254
mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in);
230255
if (dest[0] == MP_OBJ_NULL) {
@@ -243,6 +268,9 @@ STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
243268
dest[1] = self_in;
244269
} else if (attr == MP_QSTR_ph_key) {
245270
dest[0] = self->ph_key;
271+
} else if (attr == MP_QSTR___await__) {
272+
dest[0] = MP_OBJ_FROM_PTR(&task_await_obj);
273+
dest[1] = self_in;
246274
}
247275
} else if (dest[1] != MP_OBJ_NULL) {
248276
// Store
@@ -301,7 +329,11 @@ STATIC const mp_obj_type_t task_type = {
301329
// C-level uasyncio module
302330

303331
STATIC const mp_rom_map_elem_t mp_module_uasyncio_globals_table[] = {
332+
#if CIRCUITPY
333+
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__asyncio) },
334+
#else
304335
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__uasyncio) },
336+
#endif
305337
{ MP_ROM_QSTR(MP_QSTR_TaskQueue), MP_ROM_PTR(&task_queue_type) },
306338
{ MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&task_type) },
307339
};
@@ -312,4 +344,6 @@ const mp_obj_module_t mp_module_uasyncio = {
312344
.globals = (mp_obj_dict_t *)&mp_module_uasyncio_globals,
313345
};
314346

347+
MP_REGISTER_MODULE(MP_QSTR__asyncio, mp_module_uasyncio, MICROPY_PY_UASYNCIO);
348+
315349
#endif // MICROPY_PY_UASYNCIO

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ QSPI_FLASH_FILESYSTEM = 1
1010
EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C"
1111
LONGINT_IMPL = MPZ
1212

13+
CIRCUITPY_BLEIO = 0
14+
CIRCUITPY_BLEIO_HCI = 0
15+
CIRCUITPY_ONEWIREIO = 0
16+
CIRCUITPY_SDCARDIO = 0
17+
CIRCUITPY_SHARPDISPLAY = 0
18+
1319
# Include these Python libraries in firmware.
1420
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_PortalBase
1521
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests
1622
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_ESP32SPI
1723
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
18-
19-
CIRCUITPY_SHARPDISPLAY=0
20-
CIRCUITPY_SDCARDIO=0
21-
CIRCUITPY_BLEIO_HCI=0
22-
CIRCUITPY_BLEIO=0

py/objmodule.c

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -200,44 +200,30 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
200200

201201
// extmod modules
202202

203-
#if MICROPY_PY_UERRNO
204-
#if CIRCUITPY
205-
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
206-
// TODO: move to shared-bindings/
207-
#else
208-
{ MP_ROM_QSTR(MP_QSTR_uerrno), MP_ROM_PTR(&mp_module_uerrno) },
203+
// Modules included in CircuitPython are registered using MP_REGISTER_MODULE,
204+
// and do not have the "u" prefix.
205+
206+
#if MICROPY_PY_UASYNCIO && !CIRCUITPY
207+
{ MP_ROM_QSTR(MP_QSTR__uasyncio), MP_ROM_PTR(&mp_module_uasyncio) },
209208
#endif
209+
#if MICROPY_PY_UERRNO && !CIRCUITPY
210+
{ MP_ROM_QSTR(MP_QSTR_uerrno), MP_ROM_PTR(&mp_module_uerrno) },
210211
#endif
211212
#if MICROPY_PY_UCTYPES
212213
{ MP_ROM_QSTR(MP_QSTR_uctypes), MP_ROM_PTR(&mp_module_uctypes) },
213214
#endif
214215
#if MICROPY_PY_UZLIB
215216
{ MP_ROM_QSTR(MP_QSTR_uzlib), MP_ROM_PTR(&mp_module_uzlib) },
216217
#endif
217-
#if MICROPY_PY_UJSON
218-
#if CIRCUITPY
219-
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
220-
// TODO: move to shared-bindings/
221-
#else
218+
#if MICROPY_PY_UJSON && !CIRCUITPY
222219
{ MP_ROM_QSTR(MP_QSTR_ujson), MP_ROM_PTR(&mp_module_ujson) },
223220
#endif
224-
#endif
225221
#if CIRCUITPY_ULAB
226-
#if CIRCUITPY
227-
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
228-
// TODO: move to shared-bindings/
229-
#else
230222
{ MP_ROM_QSTR(MP_QSTR_ulab), MP_ROM_PTR(&ulab_user_cmodule) },
231223
#endif
232-
#endif
233-
#if MICROPY_PY_URE
234-
#if CIRCUITPY
235-
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
236-
// TODO: move to shared-bindings/
237-
#else
224+
#if MICROPY_PY_URE && !CIRCUITPY
238225
{ MP_ROM_QSTR(MP_QSTR_ure), MP_ROM_PTR(&mp_module_ure) },
239226
#endif
240-
#endif
241227
#if MICROPY_PY_UHEAPQ
242228
{ MP_ROM_QSTR(MP_QSTR_uheapq), MP_ROM_PTR(&mp_module_uheapq) },
243229
#endif
@@ -247,14 +233,9 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
247233
#if MICROPY_PY_UHASHLIB
248234
{ MP_ROM_QSTR(MP_QSTR_hashlib), MP_ROM_PTR(&mp_module_uhashlib) },
249235
#endif
250-
#if MICROPY_PY_UBINASCII
251-
#if CIRCUITPY
252-
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
253-
// TODO: move to shared-bindings/
254-
#else
236+
#if MICROPY_PY_UBINASCII && !CIRCUITPY
255237
{ MP_ROM_QSTR(MP_QSTR_ubinascii), MP_ROM_PTR(&mp_module_ubinascii) },
256238
#endif
257-
#endif
258239
#if MICROPY_PY_URANDOM
259240
{ MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&mp_module_urandom) },
260241
#endif

tests/unix/extra_coverage.py.exp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,21 @@ RuntimeError:
2929
ame__
3030
mport
3131

32-
builtins micropython _thread aesio
33-
array binascii bitmaptools btree
34-
cexample cmath collections cppexample
35-
displayio errno ffi framebuf
36-
gc gifio hashlib json
37-
math qrio rainbowio re
38-
sys termios traceback ubinascii
39-
uctypes uerrno uheapq uio
40-
ujson ulab ulab.fft ulab.linalg
41-
ulab.numpy ulab.scipy ulab.scipy.linalg
42-
ulab.scipy.optimize ulab.scipy.signal
43-
ulab.scipy.special ulab.utils uos
44-
urandom ure uselect ustruct
45-
utime utimeq uzlib
32+
builtins micropython _asyncio _thread
33+
_uasyncio aesio array binascii
34+
bitmaptools btree cexample cmath
35+
collections cppexample displayio errno
36+
ffi framebuf gc gifio
37+
hashlib json math qrio
38+
rainbowio re sys termios
39+
traceback ubinascii uctypes uerrno
40+
uheapq uio ujson ulab
41+
ulab.fft ulab.linalg ulab.numpy ulab.scipy
42+
ulab.scipy.linalg ulab.scipy.optimize
43+
ulab.scipy.signal ulab.scipy.special
44+
ulab.utils uos urandom ure
45+
uselect ustruct utime utimeq
46+
uzlib
4647
ime
4748

4849
utime utimeq

0 commit comments

Comments
 (0)