diff --git a/lib/micropython/gen-qstr.sh b/lib/micropython/gen-qstr.sh index 78ecf851363be7946005203330b18402bfd3aed5..747ae3f614104dadf98e0d579ccc3c0ae22a1c6f 100755 --- a/lib/micropython/gen-qstr.sh +++ b/lib/micropython/gen-qstr.sh @@ -11,7 +11,6 @@ shift 5 OUTPUT_DIR="$(dirname "$OUTPUT")" - # call gcc -E to generate qstr.i.last gcc -E -DNO_QSTR -I"$SOURCE_DIR/micropython" -I"$PROJECT_SRC" -I"$OUTPUT_DIR" "$@" >"$OUTPUT_DIR/qstr.i.last" diff --git a/pycardium/main.c b/pycardium/main.c index b87b4a1e26cedd4da3ccfd744c0f66894be6b2d0..3aec04919f1cbe3b6858f07697878897424ede7b 100644 --- a/pycardium/main.c +++ b/pycardium/main.c @@ -2,10 +2,12 @@ #include "api/caller.h" #include "mphalport.h" #include "card10-version.h" +#include "modules/interrupt.h" #include "max32665.h" #include "lib/utils/pyexec.h" +#include "lib/mp-readline/readline.h" #include "py/gc.h" #include "py/runtime.h" #include "py/stackctrl.h" @@ -45,6 +47,9 @@ int main(void) mp_init(); + readline_init0(); + interrupt_init0(); + /* request by badge.team */ mp_obj_list_init(mp_sys_path, 0); mp_obj_list_append(mp_sys_path, MP_ROM_QSTR(MP_QSTR_)); diff --git a/pycardium/meson.build b/pycardium/meson.build index aa637280ad625f1b482f654f5c4f293fcfe33668..3007f7b0d2855813c15fc327e1eca1d329bc28d3 100644 --- a/pycardium/meson.build +++ b/pycardium/meson.build @@ -79,7 +79,7 @@ upy = static_library( micropython_additional_sources, micropython_extmod_sources, mp_headers, - include_directories: micropython_includes, + include_directories: [micropython_includes, include_directories('../epicardium')], c_args: '-w', ) diff --git a/pycardium/modules/interrupt.c b/pycardium/modules/interrupt.c index 9e2058e591c85333058976f667c88e5450635b4f..65e3ce63cd2b6bfdd8b9d0393581435d44dfb1aa 100644 --- a/pycardium/modules/interrupt.c +++ b/pycardium/modules/interrupt.c @@ -7,20 +7,22 @@ #include "py/obj.h" #include "py/runtime.h" -// TODO: these should be intialized as mp_const_none -mp_obj_t callbacks[EPIC_INT_NUM] = { - 0, -}; +void interrupt_init0(void) +{ + int id; + for (id = 0; id < EPIC_INT_NUM; id++) { + MP_STATE_PORT(interrupt_callbacks)[id] = NULL; + } +} void epic_isr_default_handler(api_int_id_t id) { // TODO: check if id is out of rante // TOOD: check against mp_const_none + mp_obj_t callback = MP_STATE_PORT(interrupt_callbacks)[id]; if (id < EPIC_INT_NUM) { - if (callbacks[id]) { - mp_sched_schedule( - callbacks[id], MP_OBJ_NEW_SMALL_INT(id) - ); + if (callback) { + mp_sched_schedule(callback, MP_OBJ_NEW_SMALL_INT(id)); } } } @@ -35,7 +37,7 @@ mp_obj_t mp_interrupt_set_callback(mp_obj_t id_in, mp_obj_t callback_obj) // TODO: throw error if id is out of range if (id < EPIC_INT_NUM) { - callbacks[id] = callback_obj; + MP_STATE_PORT(interrupt_callbacks)[id] = callback_obj; } return mp_const_none; diff --git a/pycardium/modules/interrupt.h b/pycardium/modules/interrupt.h index 3588d1e0b9bd7fd93dd58f4f4753aa89abc35ca1..ef931034e5fd157f708da2e0cc38d5666abecbdb 100644 --- a/pycardium/modules/interrupt.h +++ b/pycardium/modules/interrupt.h @@ -2,6 +2,8 @@ #include "py/obj.h" +void interrupt_init0(void); + mp_obj_t mp_interrupt_set_callback(mp_obj_t id_in, mp_obj_t callback_obj); mp_obj_t mp_interrupt_enable_callback(mp_obj_t id_in); mp_obj_t mp_interrupt_disable_callback(mp_obj_t id_in); diff --git a/pycardium/mpconfigport.h b/pycardium/mpconfigport.h index 242c6a52f4e659879e634568fe39143b76397c79..03fd3d3ff9a087cfc5522fb371d5c453dfddeb79 100644 --- a/pycardium/mpconfigport.h +++ b/pycardium/mpconfigport.h @@ -93,7 +93,14 @@ typedef long mp_off_t; /* TODO: Document this */ #define MP_STATE_PORT MP_STATE_VM +#ifndef NO_QSTR +#include "epicardium.h" +#else +#define EPIC_INT_NUM 1 +#endif + /* For some reason, we need to define readline history manually */ #define MICROPY_PORT_ROOT_POINTERS \ - const char *readline_hist[16]; + const char *readline_hist[16]; \ + mp_obj_t interrupt_callbacks[EPIC_INT_NUM]; \