#include #include "minilisp.h" #include "alloc.h" #include "stream.h" #include "compiler_new.h" #include #include #define KBUFSZ 5 static char usb_key_in[KBUFSZ]; static int ki = 0; void uspi_keypress_handler (const char *str) { printf("[uspi-keyboard] pressed: '%s' (%d)\r\n",str,str[0]); char k=str[0]; if (strlen(str)>1) { if (k==27) { k = str[2]; printf("[uspi-keyboard] esc seq key2: %d",k); } if (k==68) k=19; if (k==67) k=20; if (k==65) k=17; if (k==66) k=18; } usb_key_in[ki] = k; ki++; if (ki>=KBUFSZ) ki = 0; } Cell* usbkeys_open(Cell* cpath) { if (!cpath || cpath->tag!=TAG_STR) { printf("[usbkeys] open error: non-string path given\r\n"); return alloc_nil(); } for (int i=0; i0) { ki--; c = usb_key_in[0]; // FIFO for (int i=0; iaddr)[0] = c; return res; } Cell* usbkeys_write(Cell* arg) { // could be used to control LEDs return NULL; } Cell* usbkeys_mmap(Cell* arg) { return alloc_nil(); } void mount_usbkeys() { fs_mount_builtin("/keyboard", usbkeys_open, usbkeys_read, usbkeys_write, 0, usbkeys_mmap); }