From 1cb57e6a9ff2fd8a44f58a10d6894911e62e4cfd Mon Sep 17 00:00:00 2001 From: Malo Lecomte Date: Sat, 17 Jul 2021 05:27:44 +0200 Subject: [PATCH] feat(idt): use new ring_buffer functions --- k/idt.c | 7 +------ k/idt.h | 4 ++-- k/pic/keyboard.c | 14 +++++++++++--- k/pic/keyboard.h | 3 ++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/k/idt.c b/k/idt.c index db4ab15..14ed46d 100644 --- a/k/idt.c +++ b/k/idt.c @@ -32,14 +32,9 @@ void handle_interrupt(struct int_args *args) { if (args->int_code >= 32) { - int8_t key = getkey(); - if (key >= 0) - { - printf("%d\r\n", key); - } + add_key_to_buffer(); outb(MASTER_PORT_A, OCW2_EOI); - return; } diff --git a/k/idt.h b/k/idt.h index 2bfac15..fb5af6e 100644 --- a/k/idt.h +++ b/k/idt.h @@ -40,8 +40,8 @@ struct idt_r uint32_t addr; // base address of the IDT } __attribute__ ((packed)); -// FIXME: This struct is used to get int_code and err_code pushed to the stack -// by the isr. We can refactor this by offsetting esp before pushing it. +// This struct is used to get int_code and err_code pushed to the stack +// by the isr. struct int_args { uint32_t int_code; diff --git a/k/pic/keyboard.c b/k/pic/keyboard.c index d4bfd08..ba5c076 100644 --- a/k/pic/keyboard.c +++ b/k/pic/keyboard.c @@ -1,12 +1,20 @@ #include "pic/keyboard.h" #include "io.h" -#include "stdio.h" +#include "utils/ring_buffer.h" -int8_t getkey(void) +static struct ring_buffer keyboard_buffer = { 0 }; + +void add_key_to_buffer(void) { uint8_t key = inb(KEYBOARD_IO); + write_entry(&keyboard_buffer, key); +} - if (key & KEYBOARD_RELEASE) +int getkey(void) +{ + uint8_t key = read_entry(&keyboard_buffer); + + if (!key) return -1; return key; diff --git a/k/pic/keyboard.h b/k/pic/keyboard.h index dd09e7d..fd7e8b4 100644 --- a/k/pic/keyboard.h +++ b/k/pic/keyboard.h @@ -8,6 +8,7 @@ #include -int8_t getkey(void); +void add_key_to_buffer(void); +int getkey(void); #endif /* !KEYBOARD_H */