devinput: the input device layer
authorAlan Cox <alan@linux.intel.com>
Thu, 12 Apr 2018 10:44:54 +0000 (11:44 +0100)
committerAlan Cox <alan@linux.intel.com>
Thu, 12 Apr 2018 10:44:54 +0000 (11:44 +0100)
This is designed to be as trivial as possible. The real complexity if any is
in tweaking platform tty code to queue all the up/down events when the keyboard
is grabbed.

Kernel/devinput.c [new file with mode: 0644]

diff --git a/Kernel/devinput.c b/Kernel/devinput.c
new file mode 100644 (file)
index 0000000..3e843cc
--- /dev/null
@@ -0,0 +1,57 @@
+#include <kernel.h>
+#include <kdata.h>
+#include <input.h>
+
+#ifdef CONFIG_INPUT
+
+uint8_t keyboard_grab;
+
+int inputdev_read(uint8_t flag)
+{
+    uint8_t m[8];
+    int s;
+
+    while(1)
+    {
+        s = platform_input_read(m + 1);
+        if (s > 0) {
+            *m = s;
+            udata.u_count = min(udata.u_count, s + 1);
+            return uput(m, udata.u_base, udata.u_count);
+        }
+        if (s == 0 && (flag & O_NDELAY)) {
+            udata.u_error = EAGAIN;
+            return -1;
+        }
+        if (s < 0)
+            return -1;
+        platform_input_wait();
+    }
+}
+
+int inputdev_write(uint8_t flag)
+{
+    return platform_input_write(flag);
+}
+
+int inputdev_ioctl(uarg_t request, char *data)
+{
+    uint8_t r;
+    if (request != INPUT_GRABKB)
+        return -1;
+    r = ((uint8_t)data) & 0x03;
+    if (r > CONFIG_INPUT_GRABMAX) {
+        udata.u_error = EOPNOTSUPP;
+        return -1;
+    }
+    keyboard_grab = r;
+    return 0;
+}
+
+int inputdev_close(void)
+{
+    keyboard_grab = INPUT_GRAB_NONE;
+    return 0;
+}
+
+#endif