Merge pull request #6041 from t-ikegami/enable_uasyncio
Enable _uasyncio module
This commit is contained in:
commit
01d880829a
|
@ -29,6 +29,10 @@
|
|||
#include "py/pairheap.h"
|
||||
#include "py/mphal.h"
|
||||
|
||||
#if CIRCUITPY && !(defined(__unix__) || defined(__APPLE__))
|
||||
#include "shared-bindings/supervisor/__init__.h"
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_UASYNCIO
|
||||
|
||||
// Used when task cannot be guaranteed to be non-NULL.
|
||||
|
@ -59,10 +63,12 @@ STATIC const mp_obj_type_t task_queue_type;
|
|||
STATIC const mp_obj_type_t task_type;
|
||||
|
||||
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);
|
||||
STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
|
||||
|
||||
/******************************************************************************/
|
||||
// Ticks for task ordering in pairing heap
|
||||
|
||||
#if !CIRCUITPY || (defined(__unix__) || defined(__APPLE__))
|
||||
STATIC mp_obj_t ticks(void) {
|
||||
return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_UTIME_TICKS_PERIOD - 1));
|
||||
}
|
||||
|
@ -74,6 +80,20 @@ STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
|
|||
- MICROPY_PY_UTIME_TICKS_PERIOD / 2;
|
||||
return diff;
|
||||
}
|
||||
#else
|
||||
#define _TICKS_PERIOD (1lu << 29)
|
||||
#define _TICKS_MAX (_TICKS_PERIOD - 1)
|
||||
#define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1)
|
||||
|
||||
#define ticks() supervisor_ticks_ms()
|
||||
|
||||
STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) {
|
||||
mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in);
|
||||
mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in);
|
||||
mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD;
|
||||
return diff;
|
||||
}
|
||||
#endif
|
||||
|
||||
STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) {
|
||||
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) {
|
|||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel);
|
||||
|
||||
STATIC mp_obj_t task_await(mp_obj_t self_in) {
|
||||
return task_getiter(self_in, NULL);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_await_obj, task_await);
|
||||
|
||||
STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
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) {
|
|||
dest[1] = self_in;
|
||||
} else if (attr == MP_QSTR_ph_key) {
|
||||
dest[0] = self->ph_key;
|
||||
} else if (attr == MP_QSTR___await__) {
|
||||
dest[0] = MP_OBJ_FROM_PTR(&task_await_obj);
|
||||
dest[1] = self_in;
|
||||
}
|
||||
} else if (dest[1] != MP_OBJ_NULL) {
|
||||
// Store
|
||||
|
@ -301,7 +329,11 @@ STATIC const mp_obj_type_t task_type = {
|
|||
// C-level uasyncio module
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_uasyncio_globals_table[] = {
|
||||
#if CIRCUITPY
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__asyncio) },
|
||||
#else
|
||||
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__uasyncio) },
|
||||
#endif
|
||||
{ MP_ROM_QSTR(MP_QSTR_TaskQueue), MP_ROM_PTR(&task_queue_type) },
|
||||
{ MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&task_type) },
|
||||
};
|
||||
|
@ -312,4 +344,6 @@ const mp_obj_module_t mp_module_uasyncio = {
|
|||
.globals = (mp_obj_dict_t *)&mp_module_uasyncio_globals,
|
||||
};
|
||||
|
||||
MP_REGISTER_MODULE(MP_QSTR__asyncio, mp_module_uasyncio, MICROPY_PY_UASYNCIO);
|
||||
|
||||
#endif // MICROPY_PY_UASYNCIO
|
||||
|
|
|
@ -10,13 +10,14 @@ QSPI_FLASH_FILESYSTEM = 1
|
|||
EXTERNAL_FLASH_DEVICES = "S25FL116K, S25FL216K, GD25Q16C"
|
||||
LONGINT_IMPL = MPZ
|
||||
|
||||
CIRCUITPY_BLEIO = 0
|
||||
CIRCUITPY_BLEIO_HCI = 0
|
||||
CIRCUITPY_ONEWIREIO = 0
|
||||
CIRCUITPY_SDCARDIO = 0
|
||||
CIRCUITPY_SHARPDISPLAY = 0
|
||||
|
||||
# Include these Python libraries in firmware.
|
||||
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_PortalBase
|
||||
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_Requests
|
||||
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_ESP32SPI
|
||||
FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel
|
||||
|
||||
CIRCUITPY_SHARPDISPLAY=0
|
||||
CIRCUITPY_SDCARDIO=0
|
||||
CIRCUITPY_BLEIO_HCI=0
|
||||
CIRCUITPY_BLEIO=0
|
||||
|
|
|
@ -200,13 +200,14 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
|
|||
|
||||
// extmod modules
|
||||
|
||||
#if MICROPY_PY_UERRNO
|
||||
#if CIRCUITPY
|
||||
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
|
||||
// TODO: move to shared-bindings/
|
||||
#else
|
||||
{ MP_ROM_QSTR(MP_QSTR_uerrno), MP_ROM_PTR(&mp_module_uerrno) },
|
||||
// Modules included in CircuitPython are registered using MP_REGISTER_MODULE,
|
||||
// and do not have the "u" prefix.
|
||||
|
||||
#if MICROPY_PY_UASYNCIO && !CIRCUITPY
|
||||
{ MP_ROM_QSTR(MP_QSTR__uasyncio), MP_ROM_PTR(&mp_module_uasyncio) },
|
||||
#endif
|
||||
#if MICROPY_PY_UERRNO && !CIRCUITPY
|
||||
{ MP_ROM_QSTR(MP_QSTR_uerrno), MP_ROM_PTR(&mp_module_uerrno) },
|
||||
#endif
|
||||
#if MICROPY_PY_UCTYPES
|
||||
{ MP_ROM_QSTR(MP_QSTR_uctypes), MP_ROM_PTR(&mp_module_uctypes) },
|
||||
|
@ -214,30 +215,15 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
|
|||
#if MICROPY_PY_UZLIB
|
||||
{ MP_ROM_QSTR(MP_QSTR_uzlib), MP_ROM_PTR(&mp_module_uzlib) },
|
||||
#endif
|
||||
#if MICROPY_PY_UJSON
|
||||
#if CIRCUITPY
|
||||
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
|
||||
// TODO: move to shared-bindings/
|
||||
#else
|
||||
#if MICROPY_PY_UJSON && !CIRCUITPY
|
||||
{ MP_ROM_QSTR(MP_QSTR_ujson), MP_ROM_PTR(&mp_module_ujson) },
|
||||
#endif
|
||||
#endif
|
||||
#if CIRCUITPY_ULAB
|
||||
#if CIRCUITPY
|
||||
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
|
||||
// TODO: move to shared-bindings/
|
||||
#else
|
||||
{ MP_ROM_QSTR(MP_QSTR_ulab), MP_ROM_PTR(&ulab_user_cmodule) },
|
||||
#endif
|
||||
#endif
|
||||
#if MICROPY_PY_URE
|
||||
#if CIRCUITPY
|
||||
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
|
||||
// TODO: move to shared-bindings/
|
||||
#else
|
||||
#if MICROPY_PY_URE && !CIRCUITPY
|
||||
{ MP_ROM_QSTR(MP_QSTR_ure), MP_ROM_PTR(&mp_module_ure) },
|
||||
#endif
|
||||
#endif
|
||||
#if MICROPY_PY_UHEAPQ
|
||||
{ MP_ROM_QSTR(MP_QSTR_uheapq), MP_ROM_PTR(&mp_module_uheapq) },
|
||||
#endif
|
||||
|
@ -247,14 +233,9 @@ STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
|
|||
#if MICROPY_PY_UHASHLIB
|
||||
{ MP_ROM_QSTR(MP_QSTR_hashlib), MP_ROM_PTR(&mp_module_uhashlib) },
|
||||
#endif
|
||||
#if MICROPY_PY_UBINASCII
|
||||
#if CIRCUITPY
|
||||
// CircuitPython: Defined in MICROPY_PORT_BUILTIN_MODULES, so not defined here.
|
||||
// TODO: move to shared-bindings/
|
||||
#else
|
||||
#if MICROPY_PY_UBINASCII && !CIRCUITPY
|
||||
{ MP_ROM_QSTR(MP_QSTR_ubinascii), MP_ROM_PTR(&mp_module_ubinascii) },
|
||||
#endif
|
||||
#endif
|
||||
#if MICROPY_PY_URANDOM
|
||||
{ MP_ROM_QSTR(MP_QSTR_urandom), MP_ROM_PTR(&mp_module_urandom) },
|
||||
#endif
|
||||
|
|
|
@ -29,20 +29,21 @@ RuntimeError:
|
|||
ame__
|
||||
mport
|
||||
|
||||
builtins micropython _thread aesio
|
||||
array binascii bitmaptools btree
|
||||
cexample cmath collections cppexample
|
||||
displayio errno ffi framebuf
|
||||
gc gifio hashlib json
|
||||
math qrio rainbowio re
|
||||
sys termios traceback ubinascii
|
||||
uctypes uerrno uheapq uio
|
||||
ujson ulab ulab.fft ulab.linalg
|
||||
ulab.numpy ulab.scipy ulab.scipy.linalg
|
||||
ulab.scipy.optimize ulab.scipy.signal
|
||||
ulab.scipy.special ulab.utils uos
|
||||
urandom ure uselect ustruct
|
||||
utime utimeq uzlib
|
||||
builtins micropython _asyncio _thread
|
||||
_uasyncio aesio array binascii
|
||||
bitmaptools btree cexample cmath
|
||||
collections cppexample displayio errno
|
||||
ffi framebuf gc gifio
|
||||
hashlib json math qrio
|
||||
rainbowio re sys termios
|
||||
traceback ubinascii uctypes uerrno
|
||||
uheapq uio ujson ulab
|
||||
ulab.fft ulab.linalg ulab.numpy ulab.scipy
|
||||
ulab.scipy.linalg ulab.scipy.optimize
|
||||
ulab.scipy.signal ulab.scipy.special
|
||||
ulab.utils uos urandom ure
|
||||
uselect ustruct utime utimeq
|
||||
uzlib
|
||||
ime
|
||||
|
||||
utime utimeq
|
||||
|
|
Loading…
Reference in New Issue