From: Alan Cox Date: Thu, 12 Apr 2018 10:44:54 +0000 (+0100) Subject: devinput: the input device layer X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=cb20890aa4ff389da387df9320e64b846851eea2;p=FUZIX.git devinput: the input device layer 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. --- diff --git a/Kernel/devinput.c b/Kernel/devinput.c new file mode 100644 index 00000000..3e843cc2 --- /dev/null +++ b/Kernel/devinput.c @@ -0,0 +1,57 @@ +#include +#include +#include + +#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