Skip to content
Snippets Groups Projects
Commit 2084b1bc authored by schneider's avatar schneider
Browse files

fix(interrupts): rename api, fix api numbers, fix code style

parent 905f4ecc
No related branches found
No related tags found
No related merge requests found
Pipeline #1349 failed
...@@ -26,14 +26,14 @@ void api_interrupt_init(void) ...@@ -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) { if (int_id <= API_INT_MAX) {
enabled[int_id] = true; 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) { if (int_id <= API_INT_MAX) {
enabled[int_id] = false; enabled[int_id] = false;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#define API_VIBRA_VIBRATE 0x5 #define API_VIBRA_VIBRATE 0x5
#define API_STREAM_READ 0x6 #define API_STREAM_READ 0x6
#define API_INTERRUPT_ENABLE 0x7 #define API_INTERRUPT_ENABLE 0x7
#define API_INTERRUPT_DISABLE 0x6 #define API_INTERRUPT_DISABLE 0x8
/* clang-format on */ /* clang-format on */
...@@ -156,13 +156,13 @@ typedef uint32_t api_int_id_t; ...@@ -156,13 +156,13 @@ typedef uint32_t api_int_id_t;
* *
* :param int_id: The interrupt to be enabled * :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 * Disable/mask an API interrupt
* *
* :param int_id: The interrupt to be disabled * :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 */ #endif /* _EPICARDIUM_H */
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "api/common.h" #include "api/common.h"
#include "mphalport.h" #include "mphalport.h"
// TODO: these should be intialized as mp_const_none // TODO: these should be intialized as mp_const_none
mp_obj_t callbacks[API_INT_MAX + 1] = { mp_obj_t callbacks[API_INT_MAX + 1] = {
0, 0,
...@@ -13,12 +12,22 @@ mp_obj_t callbacks[API_INT_MAX + 1] = { ...@@ -13,12 +12,22 @@ mp_obj_t callbacks[API_INT_MAX + 1] = {
void api_interrupt_handler_catch_all(api_int_id_t id) 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) 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); api_int_id_t id = mp_obj_get_int(id_in);
if (callback_obj != mp_const_none && !mp_obj_is_callable(callback_obj)) { if (callback_obj != mp_const_none &&
!mp_obj_is_callable(callback_obj)) {
mp_raise_ValueError("handler must be None or callable"); mp_raise_ValueError("handler must be None or callable");
} }
...@@ -34,15 +43,8 @@ STATIC mp_obj_t mp_interrupt_enable_callback(mp_obj_t id_in) ...@@ -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); 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 // TODO: throw error if id is out of range or epic_interrupt_enable failed
// TOOD: check against mp_const_none epic_interrupt_enable(id);
if (id <= API_INT_MAX) {
if (callbacks[id]) {
mp_sched_schedule(
callbacks[id], MP_OBJ_NEW_SMALL_INT(id)
);
}
}
return mp_const_none; return mp_const_none;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment