diff --git a/epicardium/api/interrupt-sender.c b/epicardium/api/interrupt-sender.c index 3714c2797f4e460485bb678b0a2b339d3d41f9ad..03556cd0507aa5454418f1efede843ef9e020c68 100644 --- a/epicardium/api/interrupt-sender.c +++ b/epicardium/api/interrupt-sender.c @@ -26,14 +26,14 @@ void api_interrupt_init(void) } } -void api_interrupt_enable(api_int_id_t int_id) +void epic_interrupt_enable(api_int_id_t int_id) { if (int_id <= API_INT_MAX) { enabled[int_id] = true; } } -void api_interrupt_disable(api_int_id_t int_id) +void epic_interrupt_disable(api_int_id_t int_id) { if (int_id <= API_INT_MAX) { enabled[int_id] = false; diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index bfb7aed0ce3b2fcc000b5686393e7ec03c4a168c..7e8f6d3ce0cbca716631d7131b33d48fe03f7789 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -20,7 +20,7 @@ #define API_VIBRA_VIBRATE 0x5 #define API_STREAM_READ 0x6 #define API_INTERRUPT_ENABLE 0x7 -#define API_INTERRUPT_DISABLE 0x6 +#define API_INTERRUPT_DISABLE 0x8 /* clang-format on */ @@ -156,13 +156,13 @@ typedef uint32_t api_int_id_t; * * :param int_id: The interrupt to be enabled */ -API(API_INTERRUPT_ENABLE, void api_interrupt_enable(api_int_id_t int_id)); +API(API_INTERRUPT_ENABLE, void epic_interrupt_enable(api_int_id_t int_id)); /** * Disable/mask an API interrupt * * :param int_id: The interrupt to be disabled */ -API(API_INTERRUPT_DISABLE, void api_interrupt_disable(api_int_id_t int_id)); +API(API_INTERRUPT_DISABLE, void epic_interrupt_disable(api_int_id_t int_id)); #endif /* _EPICARDIUM_H */ diff --git a/pycardium/modules/interrupt.c b/pycardium/modules/interrupt.c index 245130d3cbb2d61a810d46951d7835baa20b0738..1fbea1e2a6150697f927e030ca78a107f952ea7c 100644 --- a/pycardium/modules/interrupt.c +++ b/pycardium/modules/interrupt.c @@ -5,7 +5,6 @@ #include "api/common.h" #include "mphalport.h" - // TODO: these should be intialized as mp_const_none mp_obj_t callbacks[API_INT_MAX + 1] = { 0, @@ -13,16 +12,26 @@ mp_obj_t callbacks[API_INT_MAX + 1] = { void api_interrupt_handler_catch_all(api_int_id_t id) { + // TODO: check if id is out of rante + // TOOD: check against mp_const_none + if (id <= API_INT_MAX) { + if (callbacks[id]) { + mp_sched_schedule( + callbacks[id], MP_OBJ_NEW_SMALL_INT(id) + ); + } + } } STATIC mp_obj_t mp_interrupt_set_callback(mp_obj_t id_in, mp_obj_t callback_obj) { api_int_id_t id = mp_obj_get_int(id_in); - if (callback_obj != mp_const_none && !mp_obj_is_callable(callback_obj)) { - mp_raise_ValueError("handler must be None or callable"); - } + if (callback_obj != mp_const_none && + !mp_obj_is_callable(callback_obj)) { + mp_raise_ValueError("handler must be None or callable"); + } - // TODO: throw error if id is out of range + // TODO: throw error if id is out of range if (id <= API_INT_MAX) { callbacks[id] = callback_obj; } @@ -34,15 +43,8 @@ STATIC mp_obj_t mp_interrupt_enable_callback(mp_obj_t id_in) { api_int_id_t id = mp_obj_get_int(id_in); - // TODO: throw error if id is out of range or mp_sched_schedule fails - // TOOD: check against mp_const_none - if (id <= API_INT_MAX) { - if (callbacks[id]) { - mp_sched_schedule( - callbacks[id], MP_OBJ_NEW_SMALL_INT(id) - ); - } - } + // TODO: throw error if id is out of range or epic_interrupt_enable failed + epic_interrupt_enable(id); return mp_const_none; }