3 * Copyright (C) 2007 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
4 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * Copyright (C) 2009 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 unsigned char scancode
= 0;
41 unsigned keyboard_setlayout (char *layout
)
43 if (!strcmp (layout
, "us")) {
44 kbd_layout
[0] = (unsigned char *) &kbdus
;
45 kbd_layout
[1] = (unsigned char *) &kbdus_shift
;
47 strcpy (kbdmap
, "us");
52 if (!strcmp (layout
, "cz")) {
53 kbd_layout
[0] = (unsigned char *) &kbdcz
;
54 kbd_layout
[1] = (unsigned char *) &kbdcz_shift
;
56 strcpy (kbdmap
, "cz");
64 unsigned keyboard_getlayout (char *layout
)
66 if (!strcmp (kbdmap
, layout
))
75 char k
= rs232_read ();
80 if ((k
>= '0' && k
<= '9') || (k
>= 'A' && k
<= 'Z') || (k
>= 'a' && k
<= 'z')) {
89 } else if (k
== 127) {
94 char s
[KBD_MAX_QUAUE
];
99 char key
= kbd_q
.key
[0];
103 memcpy (s
, kbd_q
.key
+1, kbd_q
.p
);
105 memcpy (kbd_q
.key
, s
, kbd_q
.p
);
110 void setkey (char key
)
112 char s
[KBD_MAX_QUAUE
];
114 if (kbd_q
.p
>= KBD_MAX_QUAUE
)
119 memcpy (s
+1, kbd_q
.key
, kbd_q
.p
);
123 memcpy (kbd_q
.key
, s
, kbd_q
.p
);
126 unsigned key_pressed (int keycode
)
128 if (scancode
== keycode
)
131 if (scancode
== keycode
+128)
138 void keyboard_handler (struct regs
*r
)
140 int i
, setsignal
= 0;
142 /* Read from the keyboard's data buffer */
143 scancode
= inb (0x60);
145 /* If the top bit of the byte we read from the keyboard is
146 * set, that means that a key has just been released */
147 if (scancode
& 0x80) {
148 /* You can use this one to see if the user released the
149 * shift, alt, or control keys... */
150 //DPRINT ("key up: %d", scancode);
152 //kbd_q.state[0] = 2; // up
154 if (key_pressed (CTRL
) == 2)
156 if (key_pressed (ALT
) == 2)
158 if (key_pressed (DEL
) == 2)
160 if (key_pressed (SHIFTL
) == 2 || key_pressed (SHIFTR
) == 2)
163 /* Here, a key was just pressed. Please note that if you
164 * hold a key down, you will get repeated key press
167 /* Just to show you how this works, we simply translate
168 * the keyboard scancode into an ASCII value, and then
169 * display it to the screen. You can get creative and
170 * use some flags to see if a shift is pressed and use a
171 * different layout, or you can add another 128 entries
172 * to the above layout to correspond to 'shift' being
173 * held. If shift is held using the larger lookup table,
174 * you would add 128 to the scancode when you look for it */
176 //DPRINT ("key down: %d", scancode);
178 /* CTRL+ALT+DEL - magic keys */
179 if (key_pressed (CTRL
))
181 if (key_pressed (ALT
))
183 if (key_pressed (DEL
))
187 if (key_pressed (SHIFTL
) || key_pressed (SHIFTR
))
190 /* TTY changing - alt+F1-F4*/
192 if (key_pressed (F1
))
193 tty_change ((tty_t
*) tty_find ("tty0"));
194 else if (key_pressed (F2
))
195 tty_change ((tty_t
*) tty_find ("tty1"));
196 else if (key_pressed (F3
))
197 tty_change ((tty_t
*) tty_find ("tty2"));
198 else if (key_pressed (F4
))
199 tty_change ((tty_t
*) tty_find ("tty3"));
200 else if (key_pressed (PAGEUP
))
202 else if (key_pressed (PAGEDOWN
))
206 if (key_pressed (ARROWUP
))
208 if (key_pressed (ARROWDOWN
))
211 /* reboot pc, when are pressed ctrl+alt+del */
212 if (modes
& 0x1 && modes
& 0x2) {
214 printf ("\nRebooting ..");
221 /* CTRL + C - sigterm */
223 if (key_pressed (KB_C
)) {
229 /* SHIFT - BIG LETTERS */
231 setkey (kbd_layout
[1][scancode
]);
233 setkey (kbd_layout
[0][scancode
]);
239 /* CTRL + C was pressed - send sigterm to app */
241 if (!signal (SIGTERM
, (sighandler_t
) SIG_IGN
))
242 DPRINT ("signal () - error\n");
247 unsigned int init_keyboard ()
250 #ifdef CONFIG_DRV_KEYBOARD
252 irq_install_handler (1, keyboard_handler
);
254 /* set default kbd layout - US */
255 kbd_layout
[0] = (unsigned char *) &kbdus
;
256 kbd_layout
[1] = (unsigned char *) &kbdus_shift
;
258 strcpy (kbdmap
, CONFIG_UI_KBD_LAYOUT
);
260 if (!strcmp (kbdmap
, "us")) {
261 keyboard_setlayout ("us");
263 kprintf ("Loaded en_US keyboard layout\n");
266 if (!strcmp (kbdmap
, "cz")) {
267 keyboard_setlayout ("cz");
269 kprintf ("Loaded cs_CZ keyboard layout\n");
272 for(i
= 0; i
< 20; i
++)
273 currtty
->shell
[i
] = '\0';
275 for(i
= 0; i
< KBD_MAX_QUAUE
; i
++)