feat(keyboard): implement generic ring buffer and add getkey

Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
juju committed 2021-07-26 10:41:51 +02:00
1 parent 0e43e73fc7
commit cf020eae84
7 files changed
+91 -3

No files matched your search

+20 -1
View File
@@ -1,7 +1,26 @@
#include "keyboard.h"
#include "io.h"
#include "utils/ring_buffer.h"
static struct ring_buffer keyboard_buffer;
void keyboard_handler(void)
{
inb(KEYBOARD_IO);
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));
}
+4
View File
@@ -6,4 +6,8 @@
void keyboard_handler(void);
int getkey(void);
void init_keyboard(void);
#endif /* !KEYBOARD_H */
+2 -1
View File
@@ -2,6 +2,7 @@
#include "io.h"
#include "pic.h"
#include "stdio.h"
#include "keyboard.h"
static void send_icw1(void)
{
@@ -41,12 +42,12 @@ void init_pic(void)
send_icw3();
send_icw4();
mask_irqs();
init_keyboard();
asm volatile("sti");
}
void acknowledge(uint32_t int_vector)
{
printf("acknowledging %d\r\n", int_vector);
uint8_t ocw2 = 0x20;
if (int_vector >= IDT_RESERVED_ENTRIES + 8)
outb(SLAVE_PIC_A, ocw2);
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.