Mercurial > lcfOS
diff cos/kernel/keyboard.c @ 24:d8627924d40d
Split up in more files and reboot command
author | windel |
---|---|
date | Fri, 02 Dec 2011 14:00:02 +0100 |
parents | |
children | 3a6a9b929db0 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cos/kernel/keyboard.c Fri Dec 02 14:00:02 2011 +0100 @@ -0,0 +1,98 @@ +#include "kernel.h" + +static int shiftstate = 0; +static volatile uint8_t charAvail = 0; +static volatile char kbdchar = ' '; + +static char keymap[128] = { + '?','?','1','2', '3', '4', '5','6', '7', '8','9', '0', '-','=', 0xe, '?', + 'q','w','e','r', 't', 'y', 'u','i', 'o', 'p','[', ']', '\n','?', 'a', 's', + 'd','f','g','h', 'j', 'k', 'l',';', '\'', '?','?', '?', 'z','x', 'c', 'v', + 'b','n','m',',', '.', '/', '?','?', '?', ' ','?', '?', '?','?', '?', '?', + + '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', + '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', + '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', + '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?' +}; + +static char keymapUPPER[128] = { + '?','?','!','@', '#', '$', '%','^', '&', '*','(', ')', '_','+', '?', '?', + 'Q','W','E','R', 'T', 'Y', 'U','I', 'O', 'P','{', '}', '|','?', 'A', 'S', + 'D','F','G','H', 'J', 'K', 'L',':', '"', '?','?', '?', 'Z','X', 'C', 'V', + 'B','N','M','<', '>', '?', '?','?', '?', ' ','?', '?', '?','?', '?', '?', + + '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', + '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', + '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?', + '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?' +}; + +void keyboardDriverUpdate(unsigned char scancode) +{ + switch(scancode) { + case 0x2a: + shiftstate = 1; + break; + case 0xaa: + shiftstate = 0; + break; + default: + if (scancode < 128) { + if (charAvail == 0) { + if (shiftstate == 0) { + kbdchar = keymap[scancode]; + } else { + kbdchar = keymapUPPER[scancode]; + } + + charAvail = 1; + } + } else { + // Key release + //printf("Unhandled scancode: 0x%x\n", scancode); + } + break; + } +} + +char getChar() +{ + while (charAvail == 0); + char c = kbdchar; + charAvail = 0; + return c; +} + +void getline(char *buffer, int len) +{ + char c; + int i = 0; + while (i < len-1) { + c = getChar(); + //printf("%x", c); + if (c == '\n') { + // Enter + break; + } + if (c == 0x0e) + { + // Backspace + if (i>0) + { + int r, c; + get_cursor(&r, &c); + set_cursor(r, c - 1); + printf(" "); + set_cursor(r, c - 1); + i--; + } + continue; + } + buffer[i] = c; + printf("%c", c); + i++; + } + buffer[i] = 0; +} +