cleaned up some log messages, polished up the kb driver a bit, etc
This commit is contained in:
@ -16,6 +16,8 @@ static idtr_t idtr;
|
||||
|
||||
static bool vectors[IDT_MAX_DESCRIPTORS];
|
||||
|
||||
extern struct keyboard_state keyb_state;
|
||||
|
||||
void exception_handler(unsigned int i)
|
||||
{
|
||||
if (i <= 31) { // TODO: implement proper handling for each exception, also implement the proper gates & error code checking
|
||||
@ -28,10 +30,7 @@ void exception_handler(unsigned int i)
|
||||
|
||||
if (i == PIC_KEYB) {
|
||||
unsigned char in = inb(0x60);
|
||||
#ifdef __TESTING__
|
||||
printf("scancode: %x\n", in);
|
||||
#endif
|
||||
|
||||
do_keypress(decode_scancode(in));
|
||||
PIC_sendEOI(1);
|
||||
}
|
||||
}
|
||||
|
@ -40,19 +40,21 @@ void init_kb(void)
|
||||
#ifdef __TESTING__
|
||||
puts("Initializing keyboard driver!");
|
||||
#endif
|
||||
keyb_state.ready = false;
|
||||
init_queue(&kb_cmd_queue);
|
||||
|
||||
keyb_state.leds = 0;
|
||||
keyb_state.flags = 0;
|
||||
|
||||
queue_kb_command(KEYB_CMD_ENABLE_SCANNING);
|
||||
queue_kb_command(KEYB_CMD_SET_DEFAULT_PARAMS);
|
||||
|
||||
//queue_kb_command(KEYB_CMD_SET_TYPEMATIC);
|
||||
//queue_kb_command(0x1F);
|
||||
|
||||
queue_kb_command(KEYB_CMD_SET_TYPEMATIC);
|
||||
queue_kb_command(0x1F);
|
||||
|
||||
send_kb_commands();
|
||||
|
||||
keyb_state.ready = true;
|
||||
|
||||
|
||||
#ifdef __TESTING__
|
||||
puts("Initialized keyboard driver!");
|
||||
@ -89,7 +91,85 @@ void send_kb_commands(void)
|
||||
}
|
||||
|
||||
|
||||
kb_key_press_t decode_scancode(uint8_t scancode)
|
||||
{return (kb_key_press_t) scancode;}
|
||||
kb_key_code_t decode_scancode(uint8_t scancode)
|
||||
{return (kb_key_code_t) scancode;}
|
||||
|
||||
key_press_t do_keypress(kb_key_code_t keycode)
|
||||
{
|
||||
key_press_t packet;
|
||||
|
||||
if (!keyb_state.ready) {
|
||||
packet.key_code = KEY_NONE;
|
||||
return packet;
|
||||
}
|
||||
|
||||
|
||||
if (keycode >= KEY_ESC_R) {
|
||||
packet.key_code = keycode - KEY_PRESS_RELEASE_DIFF;
|
||||
packet.release = true;
|
||||
} else {
|
||||
packet.key_code = keycode;
|
||||
packet.release = false;
|
||||
}
|
||||
|
||||
switch (keycode) {
|
||||
case KEY_LEFT_SHIFT:
|
||||
keyb_state.flags |= (STATUS_FLAG_LSHIFT);
|
||||
break;
|
||||
case KEY_LEFT_SHIFT_R:
|
||||
keyb_state.flags &= ~(STATUS_FLAG_LSHIFT);
|
||||
break;
|
||||
case KEY_RIGHT_SHIFT:
|
||||
keyb_state.flags |= (STATUS_FLAG_RSHIFT);
|
||||
break;
|
||||
case KEY_RIGHT_SHIFT_R:
|
||||
keyb_state.flags &= ~(STATUS_FLAG_RSHIFT);
|
||||
break;
|
||||
case KEY_LEFT_CTRL:
|
||||
keyb_state.flags |= (STATUS_FLAG_CTRL);
|
||||
break;
|
||||
case KEY_LEFT_CTRL_R:
|
||||
keyb_state.flags &= ~(STATUS_FLAG_CTRL);
|
||||
break;
|
||||
case KEY_LEFT_ALT:
|
||||
keyb_state.flags |= (STATUS_FLAG_ALT);
|
||||
break;
|
||||
case KEY_LEFT_ALT_R:
|
||||
keyb_state.flags &= ~(STATUS_FLAG_ALT);
|
||||
break;
|
||||
case KEY_CAPSLOCK:
|
||||
keyb_state.flags ^= (STATUS_FLAG_CAPS_LOCK);
|
||||
keyb_state.leds ^= (KEYB_LED_CAP_LCK);
|
||||
queue_kb_command(KEYB_CMD_SET_LEDS);
|
||||
queue_kb_command(keyb_state.leds);
|
||||
break;
|
||||
case KEY_NUMLOCK:
|
||||
keyb_state.flags ^= (STATUS_FLAG_NUM_LOCK);
|
||||
keyb_state.leds ^= (KEYB_LED_NUM_LCK);
|
||||
queue_kb_command(KEYB_CMD_SET_LEDS);
|
||||
queue_kb_command(keyb_state.leds);
|
||||
break;
|
||||
case KEY_SCROLLLOCK:
|
||||
keyb_state.flags ^= (STATUS_FLAG_NUM_LOCK);
|
||||
keyb_state.leds ^= (KEYB_LED_SCRL_LCK);
|
||||
queue_kb_command(KEYB_CMD_SET_LEDS);
|
||||
queue_kb_command(keyb_state.leds);
|
||||
break;
|
||||
// case KEY_INSERT TODO: this shit baby
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
send_kb_commands();
|
||||
packet.flags = keyb_state.flags;
|
||||
return packet;
|
||||
}
|
||||
|
||||
/**
|
||||
* shift
|
||||
* ctrl
|
||||
* alt
|
||||
* caps
|
||||
* num
|
||||
* scroll
|
||||
*/
|
||||
|
@ -56,7 +56,7 @@ void pic_disable(void)
|
||||
outb(PIC1_DATA, 0xFF);
|
||||
outb(PIC2_DATA, 0xFF);
|
||||
#ifdef __TESTING__
|
||||
kinfo("Disabled the PIC");
|
||||
kinfo("Masked off the PIC");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -72,10 +72,14 @@ void IRQ_set_mask(uint8_t IRQline) // Masked IRQlines are ignored by the PIC, ma
|
||||
IRQline -= 8;
|
||||
}
|
||||
|
||||
printf("%x %x\n", port, IRQline);
|
||||
|
||||
value = inb(port) | (1 << IRQline);
|
||||
outb(port, value);
|
||||
|
||||
#ifdef __TESTING__
|
||||
kinfo("Masked IRQ line");
|
||||
printf("IRQ line: %d\n", IRQline);
|
||||
#endif
|
||||
}
|
||||
|
||||
void IRQ_clear_mask(uint8_t IRQline)
|
||||
@ -92,6 +96,10 @@ void IRQ_clear_mask(uint8_t IRQline)
|
||||
|
||||
value = inb(port) & ~(1 << IRQline);
|
||||
outb(port, value);
|
||||
#ifdef __TESTING__
|
||||
kinfo("Cleared mask from IRQ line");
|
||||
printf("IRQ line: %d\n", IRQline);
|
||||
#endif
|
||||
}
|
||||
|
||||
static uint16_t __pic_get_irq_reg(int ocw3)
|
||||
|
Reference in New Issue
Block a user