Skip to content

Commit 97cc240

Browse files
committed
enable running asyncio
1 parent a8b69f2 commit 97cc240

File tree

4 files changed

+29
-4
lines changed

4 files changed

+29
-4
lines changed

extmod/moduselect.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) {
150150
mp_map_deinit(&poll_map);
151151
return mp_obj_new_tuple(3, list_array);
152152
}
153-
MICROPY_EVENT_POLL_HOOK
153+
RUN_BACKGROUND_TASKS;
154154
}
155155
}
156156
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select);
@@ -229,7 +229,7 @@ STATIC mp_uint_t poll_poll_internal(uint n_args, const mp_obj_t *args) {
229229
if (n_ready > 0 || (timeout != (mp_uint_t)-1 && mp_hal_ticks_ms() - start_tick >= timeout)) {
230230
break;
231231
}
232-
MICROPY_EVENT_POLL_HOOK
232+
RUN_BACKGROUND_TASKS;
233233
}
234234

235235
return n_ready;
@@ -318,10 +318,13 @@ STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table);
318318

319319
STATIC const mp_obj_type_t mp_type_poll = {
320320
{ &mp_type_type },
321+
.flags = MP_TYPE_FLAG_EXTENDED,
321322
.name = MP_QSTR_poll,
322-
.getiter = mp_identity_getiter,
323-
.iternext = poll_iternext,
324323
.locals_dict = (void *)&poll_locals_dict,
324+
MP_TYPE_EXTENDED_FIELDS(
325+
.getiter = mp_identity_getiter,
326+
.iternext = poll_iternext,
327+
),
325328
};
326329

327330
// poll()
@@ -354,4 +357,6 @@ const mp_obj_module_t mp_module_uselect = {
354357
.globals = (mp_obj_dict_t *)&mp_module_select_globals,
355358
};
356359

360+
MP_REGISTER_MODULE(MP_QSTR_select, mp_module_uselect, MICROPY_PY_USELECT);
361+
357362
#endif // MICROPY_PY_USELECT

py/circuitpy_mpconfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ typedef long mp_off_t;
195195
#ifndef MICROPY_CPYTHON_COMPAT
196196
#define MICROPY_CPYTHON_COMPAT (CIRCUITPY_FULL_BUILD)
197197
#endif
198+
#define MICROPY_ENABLE_SCHEDULER (MICROPY_PY_UASYNCIO)
198199
#define MICROPY_PY_BUILTINS_POW3 (CIRCUITPY_BUILTINS_POW3)
199200
#define MICROPY_PY_FSTRINGS (MICROPY_CPYTHON_COMPAT)
200201
#define MICROPY_MODULE_WEAK_LINKS (0)

py/circuitpy_mpconfig.mk

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ CFLAGS += -DCIRCUITPY_FULL_BUILD=$(CIRCUITPY_FULL_BUILD)
3636
MICROPY_PY_ASYNC_AWAIT ?= $(CIRCUITPY_FULL_BUILD)
3737
CFLAGS += -DMICROPY_PY_ASYNC_AWAIT=$(MICROPY_PY_ASYNC_AWAIT)
3838

39+
# uasyncio
40+
# By default, include uasyncio if async/await are available.
41+
MICROPY_PY_UASYNCIO ?= $(MICROPY_PY_ASYNC_AWAIT)
42+
CFLAGS += -DMICROPY_PY_UASYNCIO=$(MICROPY_PY_UASYNCIO)
43+
44+
# uasyncio normally needs select
45+
MICROPY_PY_USELECT ?= $(MICROPY_PY_UASYNCIO)
46+
CFLAGS += -DMICROPY_PY_USELECT=$(MICROPY_PY_USELECT)
47+
48+
# enable select.select if select is enabled.
49+
MICROPY_PY_USELECT_SELECT ?= $(MICROPY_PY_USELECT)
50+
#MICROPY_PY_USELECT_SELECT ?= 0
51+
CFLAGS += -DMICROPY_PY_USELECT_SELECT=$(MICROPY_PY_USELECT_SELECT)
52+
53+
3954
CIRCUITPY_AESIO ?= $(CIRCUITPY_FULL_BUILD)
4055
CFLAGS += -DCIRCUITPY_AESIO=$(CIRCUITPY_AESIO)
4156

supervisor/shared/background_callback.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
#include "py/gc.h"
3030
#include "py/mpconfig.h"
31+
#include "py/runtime.h"
3132
#include "supervisor/background_callback.h"
3233
#include "supervisor/linker.h"
3334
#include "supervisor/shared/tick.h"
@@ -73,6 +74,9 @@ bool PLACE_IN_ITCM(background_callback_pending)(void) {
7374

7475
static bool in_background_callback;
7576
void PLACE_IN_ITCM(background_callback_run_all)() {
77+
// Let the scheduler run.
78+
mp_handle_pending(true);
79+
7680
if (!background_callback_pending()) {
7781
return;
7882
}

0 commit comments

Comments
 (0)