From 8a6dc3a444acb074b3ce5d9f83ad9c4cfe0c00c6 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 29 Mar 2015 23:37:13 +0100 Subject: [PATCH] px4plus: work on keyboard driver --- Kernel/include/keycode.h | 5 ++ Kernel/platform-px4plus/cpu7508.s | 2 + Kernel/platform-px4plus/devtty.c | 78 ++++++++++++++++++++++++++++++- 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/Kernel/include/keycode.h b/Kernel/include/keycode.h index 7f41d90f..272788da 100644 --- a/Kernel/include/keycode.h +++ b/Kernel/include/keycode.h @@ -14,6 +14,9 @@ #define KEY_DEL 0x7F #define KEY_BS CTRL('H') #define KEY_ESC CTRL('[') +#define KEY_TAB CTRL('I') +#define KEY_ENTER CTRL('J') +#define KEY_CLEAR CTRL('L') #define KEY_LEFT ESC('D') #define KEY_RIGHT ESC('C') @@ -21,6 +24,7 @@ #define KEY_DOWN ESC('B') #define KEY_HOME ESC('H') +#define KEY_HELP ESC('h') #define KEY_INSERT ESC('i') #define KEY_COPY ESC('c') #define KEY_PASTE ESC('v') @@ -33,6 +37,7 @@ #define KEY_PLUS ESC('+') #define KEY_MINUS ESC('-') #define KEY_EXIT ESC('q') +#define KEY_PAUSE ESC('p') #define KEY_F1 ESC('1') #define KEY_F2 ESC('2') diff --git a/Kernel/platform-px4plus/cpu7508.s b/Kernel/platform-px4plus/cpu7508.s index 267ab6ae..75e4b5a1 100644 --- a/Kernel/platform-px4plus/cpu7508.s +++ b/Kernel/platform-px4plus/cpu7508.s @@ -82,9 +82,11 @@ c7508_1sec: c7508_keyin: ld l, a ld h, #0 + push hl push af call _key_pressed pop af + pop hl ret ; diff --git a/Kernel/platform-px4plus/devtty.c b/Kernel/platform-px4plus/devtty.c index b9e0eb74..c415e22b 100644 --- a/Kernel/platform-px4plus/devtty.c +++ b/Kernel/platform-px4plus/devtty.c @@ -6,7 +6,11 @@ #include #include -/* Console is only port we provide, port 2 there but used for floppies */ +/* Console is only port we provide, port 2 there but used for floppies. + Eventually wants supporting but needs some tricky handling of flow + control as a single UART is switched multiple ways including for + the fd */ + char tbuf1[TTYSIZ]; struct s_queue ttyinq[NUM_DEV_TTY+1] = { /* ttyinq[0] is never used */ @@ -51,3 +55,75 @@ int tty_carrier(uint8_t minor) minor; return 1; } + +/* + * Keyboard interface. This is not a make break interface except for + * the shift keys. We don't support item keyboards just the standard + * ones. + */ + +static uint8_t shifts = 0; +#define SHIFT_CTRL (1 << 2) +#define SHIFT_LSHIFT (1 << 3) +#define SHIFT_CAPSLOCK (1 << 4) +#define SHIFT_GRPH (1 << 5) +#define SHIFT_RSHIFT (1 << 6) +#define SHIFT_NUM (1 << 7) + +/* Map table. Interleave original and shift as the low bits are never 8-15 */ +static uint8_t keymap[] = { + KEY_ESC, KEY_PAUSE, KEY_HELP, KEY_F1, KEY_F2, KEY_F3, KEY_F4, KEY_F5, + KEY_ESC, KEY_PAUSE, KEY_HELP, KEY_F6, KEY_F7, KEY_F8, KEY_F9, KEY_F10, + KEY_STOP, '1', '2', '3', '4', '5', '6', '7', + KEY_STOP, '!', '"', KEY_POUND, '$', '%', '&', '\'', + 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', + 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', + 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', + 'D', 'F', 'G', 'H', 'J', 'K', 'L', '+', + 'b', 'n', 'm', ',', '.', '/', '[', ']', + 'B', 'N', 'M', '<', '>', '?', '{', '}', + '8', '9', '0', '-', '^', KEY_UP, KEY_BS, KEY_TAB, + '(', ')', '_', '=', '~', KEY_UP, KEY_HOME, KEY_TAB, + 'o', 'p', '@', KEY_LEFT, KEY_DOWN, KEY_RIGHT, 'a', 's', + 'O', 'P', '`', KEY_LEFT, KEY_DOWN, KEY_RIGHT, 'A', 'S', + ':', KEY_ENTER, '\\', ' ', 'z', 'x', 'c', 'v', + '*', KEY_ENTER, '|', ' ', 'Z', 'X', 'C', 'V', + KEY_INSERT, KEY_DEL, 0, 0, 0, 0, 0, 0, + KEY_PRINT, KEY_CLEAR +}; + +static uint8_t key_decoder(uint8_t c) +{ + if (shifts & (SHIFT_LSHIFT|SHIFT_RSHIFT)) + c |= 8; + c = keymap[c]; + if (c >= 'a' && c <= 'z') { + if (shifts & SHIFT_CTRL) + c -= 64; + else if (shifts & SHIFT_CAPSLOCK) + c -= 32; + } else if (c >= 'A' && c <= 'Z' && (shifts & SHIFT_CTRL)) + c -= 32; + + /* We don't use graph or num currently */ + return c; +} + + +void key_pressed(uint16_t code) +{ + uint8_t c = code; + uint8_t clow = c & 7; + + if (c >= 0xB0) + shifts |= clow; + else if (c >= 0xA0) + shifts &= ~clow; + else if (c <= 0x81) { + /* Typed symbol */ + c = key_decoder(c); /* Consider shifts */ + if (c) + tty_inproc(1, c); + } + +} \ No newline at end of file -- 2.34.1