From 8083536f321ad8a12ad4668c2bf41a65c3e3b2f6 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 6 May 2020 22:34:38 +0200 Subject: Added event mapping driver --- src/kernel/events/event.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/kernel/events/event.c (limited to 'src/kernel/events/event.c') diff --git a/src/kernel/events/event.c b/src/kernel/events/event.c new file mode 100644 index 0000000..cfefb67 --- /dev/null +++ b/src/kernel/events/event.c @@ -0,0 +1,34 @@ +#include +#include +#include +#include + +typedef u32 (*event_func)(u8 *); + +u32 (*event_table[])() = { [MAP_KEYBOARD] = NULL, [MAP_MOUSE] = NULL }; + +u32 event_map(u32 id, u8 *function) +{ + if (id >= sizeof(event_map) / sizeof(*event_map)) + return -1; + + event_table[id] = (u32)function; + return 0; +} + +u32 event_trigger(u32 id, u8 *data) +{ + if (id >= sizeof(event_map) / sizeof(*event_map)) { + panic("Unknown event id!"); + return -1; + } + + event_func location = (event_func)event_table[id]; + if (!location) { + warn("Event %d not mapped!", id); + return -1; + } + + location(data); + return 0; +} \ No newline at end of file -- cgit v1.2.3