k-chow/k/events/pic/keyboard.c

27 lines
472 B
C
Raw Normal View History

#include "keyboard.h"
#include "io.h"
#include "utils/ring_buffer.h"
static struct ring_buffer keyboard_buffer;
void keyboard_handler(void)
{
u8 scan_code = inb(KEYBOARD_IO);
if (!(scan_code & 0x80))
ring_buffer_push(&keyboard_buffer, &scan_code);
}
int getkey(void)
{
u8 *key = ring_buffer_pop(&keyboard_buffer);
if (!key)
return -1;
return *key;
}
void init_keyboard(void)
{
ring_buffer_init(&keyboard_buffer, sizeof(u8));
}