feat(idt): use new ring_buffer functions

This commit is contained in:
Malo Lecomte 2021-07-17 05:27:44 +02:00
parent 0b394c2c08
commit 1cb57e6a9f
4 changed files with 16 additions and 12 deletions

@ -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;
}

@ -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;

@ -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;

@ -8,6 +8,7 @@
#include <stdint.h>
int8_t getkey(void);
void add_key_to_buffer(void);
int getkey(void);
#endif /* !KEYBOARD_H */