comparison 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
comparison
equal deleted inserted replaced
23:5dd47d6eebac 24:d8627924d40d
1 #include "kernel.h"
2
3 static int shiftstate = 0;
4 static volatile uint8_t charAvail = 0;
5 static volatile char kbdchar = ' ';
6
7 static char keymap[128] = {
8 '?','?','1','2', '3', '4', '5','6', '7', '8','9', '0', '-','=', 0xe, '?',
9 'q','w','e','r', 't', 'y', 'u','i', 'o', 'p','[', ']', '\n','?', 'a', 's',
10 'd','f','g','h', 'j', 'k', 'l',';', '\'', '?','?', '?', 'z','x', 'c', 'v',
11 'b','n','m',',', '.', '/', '?','?', '?', ' ','?', '?', '?','?', '?', '?',
12
13 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?',
14 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?',
15 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?',
16 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?'
17 };
18
19 static char keymapUPPER[128] = {
20 '?','?','!','@', '#', '$', '%','^', '&', '*','(', ')', '_','+', '?', '?',
21 'Q','W','E','R', 'T', 'Y', 'U','I', 'O', 'P','{', '}', '|','?', 'A', 'S',
22 'D','F','G','H', 'J', 'K', 'L',':', '"', '?','?', '?', 'Z','X', 'C', 'V',
23 'B','N','M','<', '>', '?', '?','?', '?', ' ','?', '?', '?','?', '?', '?',
24
25 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?',
26 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?',
27 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?',
28 '?','?','?','?', '?', '?', '?','?', '?', '?','?', '?', '?','?', '?', '?'
29 };
30
31 void keyboardDriverUpdate(unsigned char scancode)
32 {
33 switch(scancode) {
34 case 0x2a:
35 shiftstate = 1;
36 break;
37 case 0xaa:
38 shiftstate = 0;
39 break;
40 default:
41 if (scancode < 128) {
42 if (charAvail == 0) {
43 if (shiftstate == 0) {
44 kbdchar = keymap[scancode];
45 } else {
46 kbdchar = keymapUPPER[scancode];
47 }
48
49 charAvail = 1;
50 }
51 } else {
52 // Key release
53 //printf("Unhandled scancode: 0x%x\n", scancode);
54 }
55 break;
56 }
57 }
58
59 char getChar()
60 {
61 while (charAvail == 0);
62 char c = kbdchar;
63 charAvail = 0;
64 return c;
65 }
66
67 void getline(char *buffer, int len)
68 {
69 char c;
70 int i = 0;
71 while (i < len-1) {
72 c = getChar();
73 //printf("%x", c);
74 if (c == '\n') {
75 // Enter
76 break;
77 }
78 if (c == 0x0e)
79 {
80 // Backspace
81 if (i>0)
82 {
83 int r, c;
84 get_cursor(&r, &c);
85 set_cursor(r, c - 1);
86 printf(" ");
87 set_cursor(r, c - 1);
88 i--;
89 }
90 continue;
91 }
92 buffer[i] = c;
93 printf("%c", c);
94 i++;
95 }
96 buffer[i] = 0;
97 }
98