[solved] Problems with the keyboard buffer
Posted: Mon Dec 19, 2011 1:06 am
Hello!
While writing own keyboard driver for my OS, I got the problem with keyboard leds - my system just freezes when I try to set them. I've noticed that it happens "thankfully" to the keyboard buffer - it just doesn't get empty. What's the matter?
Thanks,
Alex
/* Added later */
Here's the code:
While writing own keyboard driver for my OS, I got the problem with keyboard leds - my system just freezes when I try to set them. I've noticed that it happens "thankfully" to the keyboard buffer - it just doesn't get empty. What's the matter?
Thanks,
Alex
/* Added later */
Here's the code:
Code: Select all
kbd_state_t kbd_state;
void kbd_init (void)
{
kbd_state.shift = FALSE;
kbd_state.ctrl = FALSE;
kbd_state.alt = FALSE;
kbd_state.num_lock = TRUE;
kbd_state.caps_lock = FALSE;
kbd_state.scroll_lock = FALSE;
kbd_state.leds = NUM_LED;
kbd_state.escaped = 0;
}
void update_kbd_leds (void)
{
kbd_leds (kbd_state.leds); /* See the kbd_leds function below */
}
void kbd_process_interrupt(void)
{
unsigned char scancode, ascii, creg;
scancode = inportb(0x60);
switch(scancode) {
case 0x36:
case 0x2a:
kbd_state.shift = TRUE;
break;
case 0x36+0x80:
case 0x2a+0x80:
kbd_state.shift = FALSE;
break;
case 0x1D:
kbd_state.ctrl = TRUE;
break;
case 0x1D+0x80:
kbd_state.ctrl = FALSE;
break;
case 0x38:
kbd_state.alt = TRUE;
break;
case 0x38+0x80:
kbd_state.alt = FALSE;
break;
default:
if (kbd_state.escaped) {
switch (kbd_state.escaped) {
case 0xE0:
switch (scancode) {
case 0x48: //up
ascii = 0x1C;
break;
case 0x4B: //left
ascii = 0x1D;
break;
case 0x4D: //right
ascii = 0x1E;
break;
case 0x50: //down
ascii = 0x1F;
break;
}
break;
default:
break;
}
kbd_state.escaped = 0;
} else {
if (scancode == 0xE0) {
kbd_state.escaped = 0xE0;
} else {
if(kbd_state.shift) {
ascii = scancodes_shifted[scancode];
} else {
ascii = scancodes[scancode];
}
}
}
break;
}
creg = inportb(0x61);
creg |= 1;
outportb(0x61, creg);
if (scancode < 0x80) {
keypressed (scancode, ascii);
}
}
void kbd_wait (void) /* This is where we freeze */
{
while (inportb (0x64) & 2) /* do nothing */;
}
void kbd_leds (unsigned char status) /* And this is what doesn't work */
{
kbd_wait ();
outportb(0x60,0xED);
kbd_wait ();
outportb(0x60,status);
}