k-chow/k/events/pic/keyboard.c
Julien CLEMENT cf020eae84 feat(keyboard): implement generic ring buffer and add getkey
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
2021-07-26 10:41:51 +02:00

27 lines
472 B
C

#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));
}