19static volatile uint8_t
kbd_buf[KBD_BUF_SIZE];
34 0, 27,
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'0',
'-',
'=',
'\b',
'\t',
35 'q',
'w',
'e',
'r',
't',
'y',
'u',
'i',
'o',
'p',
'[',
']',
'\n', 0,
'a',
's',
36 'd',
'f',
'g',
'h',
'j',
'k',
'l',
';',
'\'',
'`', 0,
'\\',
'z',
'x',
'c',
'v',
37 'b',
'n',
'm',
',',
'.',
'/', 0,
'*', 0,
' '
42 0, 27,
'!',
'@',
'#',
'$',
'%',
'^',
'&',
'*',
'(',
')',
'_',
'+',
'\b',
'\t',
43 'Q',
'W',
'E',
'R',
'T',
'Y',
'U',
'I',
'O',
'P',
'{',
'}',
'\n', 0,
'A',
'S',
44 'D',
'F',
'G',
'H',
'J',
'K',
'L',
':',
'"',
'~', 0,
'|',
'Z',
'X',
'C',
'V',
45 'B',
'N',
'M',
'<',
'>',
'?', 0,
'*', 0,
' '
54 uint32_t next = (
kbd_head + 1) & (KBD_BUF_SIZE - 1);
79 if (raw == 0xE0) {
e0_pending =
true;
return false; }
83 bool pressed = !(raw & 0x80);
84 uint8_t code = raw & 0x7F;
88 if (code == 0x2A || code == 0x36)
shift_down = pressed;
89 else if (code == 0x1D) ctrl_down = pressed;
90 else if (code == 0x38) alt_down = pressed;
91 else if (code == 0x3A && pressed) caps_on = !caps_on;
93 if (code == 0x1D) ctrl_down = pressed;
94 else if (code == 0x38) alt_down = pressed;
99 if (!ext && code < 0x3A) {
101 bool is_letter = base >=
'a' && base <=
'z';
102 bool use_shift =
shift_down ^ (caps_on && is_letter);
103 c = use_shift ?
sc_upper[code] : base;
121 if ((
inb(PS2_STATUS) & 0x01) == 0 || (
inb(PS2_STATUS) & 0b100000) == 1)
124 uint8_t scancode =
inb(PS2_DATA);
129 while (
inb(PS2_STATUS) & 0x01)
Provides utilities for IO operations with the hardware.
uint8_t inb(uint16_t port)
Inputs a byte from the specified port.
void irq_register(uint8_t irq, irq_handler_fn fn)
Registers a handler function for the specified IRQ number.
IRQ Handler and utilities.
static volatile uint32_t kbd_tail
next slot to READ: only the main code changes this
static volatile uint32_t kbd_head
next slot to WRITE: only the handler changes this
static const char sc_lower[0x3A]
The lowercase character conversion table for set 1.
int kbd_buf_pop(void)
Pops byte from the keyboard key buffer.
static const char sc_upper[0x3A]
The uppercase (shifted) character conversion table for set 1.
bool kbd_decode(uint8_t raw, struct key_event *ev)
Convert a keyboard byte into the correct char.
static bool e0_pending
saw 0xE0, the next byte completes the key
void keyboard_init(void)
Initialize the keyboard driver and register the handler with the IRQ handler.
bool shift_down
Keyboard modifier key status.
int kbd_getchar(void)
Waits for a key to be pressed and returns the character.
static volatile uint8_t kbd_buf[KBD_BUF_SIZE]
The buffer holding the keys codes.
static bool kbd_buf_push(uint8_t b)
Pushes byte to key buffer.
static void keyboard_handler(struct interrupt_frame *frame)
Pushes the key code to the key buffer.
Handler and utilities for the keyboard.
void pic_clear_mask(uint8_t irq)
Unmasks (Enables) a line.
Handles the legacy PIC for IRQ interrupts.
The frame holding the registers when an interrupt happens.
bool extended
came after an 0xE0 prefix
uint8_t scancode
the code with bit 7 removed
char ascii
0 if the key has no printable character
bool pressed
true = key down, false = key up