aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/events
diff options
context:
space:
mode:
authorMarvin Borner2020-05-06 22:34:38 +0200
committerMarvin Borner2020-05-06 22:34:38 +0200
commit8083536f321ad8a12ad4668c2bf41a65c3e3b2f6 (patch)
tree427d7da11944b299bdce3041259bf8fd31971ede /src/kernel/events
parentd94ffac4a584dc7a4f6f2ec567b8caab05ce9253 (diff)
Added event mapping driver
Diffstat (limited to 'src/kernel/events')
-rw-r--r--src/kernel/events/event.c34
-rw-r--r--src/kernel/events/event.h9
2 files changed, 43 insertions, 0 deletions
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 <stdint.h>
+#include <stddef.h>
+#include <common.h>
+#include <system.h>
+
+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
diff --git a/src/kernel/events/event.h b/src/kernel/events/event.h
new file mode 100644
index 0000000..3f46632
--- /dev/null
+++ b/src/kernel/events/event.h
@@ -0,0 +1,9 @@
+#ifndef MELVIX_EVENT_H
+#define MELVIX_EVENT_H
+
+#include <stdint.h>
+
+u32 event_map(u32 id, u8 *function);
+u32 event_trigger(u32 id, u8 *data);
+
+#endif \ No newline at end of file