diff --git a/epicardium/api/interrupt-sender.c b/epicardium/api/interrupt-sender.c index 03556cd0507aa5454418f1efede843ef9e020c68..804b0a8bbe0d48224f4a9aee538f9f60e1c389a3 100644 --- a/epicardium/api/interrupt-sender.c +++ b/epicardium/api/interrupt-sender.c @@ -4,16 +4,19 @@ static bool enabled[API_INT_MAX + 1]; -void api_interrupt_trigger(api_int_id_t id) +int api_interrupt_trigger(api_int_id_t id) { - if (id <= API_INT_MAX) { - if (enabled[id]) { - while (API_CALL_MEM->int_id) - ; - API_CALL_MEM->int_id = id; - TMR_TO_Start(MXC_TMR5, 1, 0); - } + if (id > API_INT_MAX) { + return EINVAL; } + + if (enabled[id]) { + while (API_CALL_MEM->int_id) + ; + API_CALL_MEM->int_id = id; + TMR_TO_Start(MXC_TMR5, 1, 0); + } + return 0; } void api_interrupt_init(void) @@ -26,16 +29,22 @@ void api_interrupt_init(void) } } -void epic_interrupt_enable(api_int_id_t int_id) +int epic_interrupt_enable(api_int_id_t int_id) { - if (int_id <= API_INT_MAX) { - enabled[int_id] = true; + if (int_id > API_INT_MAX) { + return EINVAL; } + + enabled[int_id] = true; + return 0; } -void epic_interrupt_disable(api_int_id_t int_id) +int epic_interrupt_disable(api_int_id_t int_id) { - if (int_id <= API_INT_MAX) { - enabled[int_id] = false; + if (int_id > API_INT_MAX) { + return EINVAL; } + + enabled[int_id] = false; + return 0; } diff --git a/epicardium/api/interrupt-sender.h b/epicardium/api/interrupt-sender.h index fe22908785a954d2971a0de591e32c922b3d59bc..4f690167ceff8622418b4983da17b29085a446f4 100644 --- a/epicardium/api/interrupt-sender.h +++ b/epicardium/api/interrupt-sender.h @@ -1,4 +1,4 @@ #pragma once #include "api/common.h" void api_interrupt_init(void); -void api_interrupt_trigger(api_int_id_t id); +int api_interrupt_trigger(api_int_id_t id); diff --git a/epicardium/epicardium.h b/epicardium/epicardium.h index 7e8f6d3ce0cbca716631d7131b33d48fe03f7789..9add57508e7aa91b3bb0f718bec2aaeddb990817 100644 --- a/epicardium/epicardium.h +++ b/epicardium/epicardium.h @@ -156,13 +156,13 @@ typedef uint32_t api_int_id_t; * * :param int_id: The interrupt to be enabled */ -API(API_INTERRUPT_ENABLE, void epic_interrupt_enable(api_int_id_t int_id)); +API(API_INTERRUPT_ENABLE, int 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 epic_interrupt_disable(api_int_id_t int_id)); +API(API_INTERRUPT_DISABLE, int 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 1fbea1e2a6150697f927e030ca78a107f952ea7c..b45680c723a8150fd440665065ff8170f8e3e6bc 100644 --- a/pycardium/modules/interrupt.c +++ b/pycardium/modules/interrupt.c @@ -44,17 +44,33 @@ 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 epic_interrupt_enable failed - epic_interrupt_enable(id); + if (epic_interrupt_enable(id) < 0) { + } return mp_const_none; } +STATIC mp_obj_t mp_interrupt_disable_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 epic_interrupt_enable failed + if (epic_interrupt_disable(id) < 0) { + } + + return mp_const_none; +} + + STATIC MP_DEFINE_CONST_FUN_OBJ_2( interrupt_set_callback_obj, mp_interrupt_set_callback ); STATIC MP_DEFINE_CONST_FUN_OBJ_1( interrupt_enable_callback_obj, mp_interrupt_enable_callback ); +STATIC MP_DEFINE_CONST_FUN_OBJ_1( + interrupt_disable_callback_obj, mp_interrupt_disable_callback +); STATIC const mp_rom_map_elem_t interrupt_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_interrupt) }, @@ -62,6 +78,8 @@ STATIC const mp_rom_map_elem_t interrupt_module_globals_table[] = { MP_ROM_PTR(&interrupt_set_callback_obj) }, { MP_ROM_QSTR(MP_QSTR_enable_callback), MP_ROM_PTR(&interrupt_enable_callback_obj) }, + { MP_ROM_QSTR(MP_QSTR_disable_callback), + MP_ROM_PTR(&interrupt_disable_callback_obj) }, { MP_ROM_QSTR(MP_QSTR_BHI160), MP_OBJ_NEW_SMALL_INT(2) }, }; STATIC MP_DEFINE_CONST_DICT( diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h index 048ed267b5c3bd87f17d27d4f308dc71229639e4..4c7e2f753eb0f12f98f8ea1d4490297284be5408 100644 --- a/pycardium/modules/qstrdefs.h +++ b/pycardium/modules/qstrdefs.h @@ -28,4 +28,5 @@ Q(vibrate) Q(set_callback) Q(enable_callback) +Q(disable_callback) Q(BHI160)