rc2014: add devinput
authorAlan Cox <alan@linux.intel.com>
Tue, 31 Jul 2018 19:55:29 +0000 (20:55 +0100)
committerAlan Cox <alan@linux.intel.com>
Tue, 31 Jul 2018 19:55:29 +0000 (20:55 +0100)
Kernel/platform-rc2014/devinput.c [new file with mode: 0644]
Kernel/platform-rc2014/devinput.h [new file with mode: 0644]

diff --git a/Kernel/platform-rc2014/devinput.c b/Kernel/platform-rc2014/devinput.c
new file mode 100644 (file)
index 0000000..4e5eb54
--- /dev/null
@@ -0,0 +1,61 @@
+#include <kernel.h>
+#include <kdata.h>
+#include <input.h>
+#include <devinput.h>
+
+__sfr __at 0x01 js1;
+__sfr __at 0x02 js2;
+
+static uint8_t js_data[2]= {255, 255};
+
+uint8_t read_js(uint8_t *slot, uint8_t n, uint8_t r)
+{
+    uint8_t d = 0;
+    r &= 63;
+    if (r == js_data[n])
+        return 0;
+    js_data[n] = r;
+    if (r & 1)
+        d = STICK_DIGITAL_U;
+    if (r & 2)
+        d |= STICK_DIGITAL_D;
+    if (r & 4)
+        d |= STICK_DIGITAL_L;
+    if (r & 8)
+        d |= STICK_DIGITAL_R;
+    if (r & 16)
+        d |= BUTTON(0);
+    if (r & 32)
+        d |= BUTTON(1);
+    *slot++ = STICK_DIGITAL | (n + 1);
+    *slot = d;
+    return 2;
+}
+
+int platform_input_read(uint8_t *slot)
+{
+    if (read_js(slot, 0, js1))
+        return 2;
+    if (read_js(slot, 1, js2))
+        return 2;
+    return 0;
+}
+
+void platform_input_wait(void)
+{
+    psleep(&js_data);
+}
+
+void poll_input(void)
+{
+    if ((js1 & 63) != js_data[0] ||
+        ((js2 & 63) != js_data[1]))
+        wakeup(&js_data);
+}
+
+int platform_input_write(uint8_t flag)
+{
+    flag;
+    udata.u_error = EINVAL;
+    return -1;
+}
diff --git a/Kernel/platform-rc2014/devinput.h b/Kernel/platform-rc2014/devinput.h
new file mode 100644 (file)
index 0000000..5e7922a
--- /dev/null
@@ -0,0 +1 @@
+extern void poll_input(void);