File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- #include <kclib/stdio.h>
21#include <kernel/hw/keyboard.h>
32#include <kernel/hw/pic.h>
3+ #include <kernel/idt.h>
44#include <kernel/io.h>
5+ #include <utils/charqueue.h>
56
6- static bool is_kb_setup = false;
7+ static bool is_kb_setup = false;
8+ static charqueue * kb_keypress_charqueue ;
79
810static inline kb_ps2_status_register_t kb_read_status_register (void ) {
911 return (kb_ps2_status_register_t ){.raw = inb (kb_ps2_status_port )};
@@ -47,7 +49,16 @@ static inline bool kb_reset (void) {
4749 return true;
4850}
4951
52+ static registers_t * kb_handler (registers_t * registers ) {
53+ unsigned char scancode = kb_read_data ();
54+ pic_send_eoi (1 );
55+ push_charqueue (kb_keypress_charqueue , scancode );
56+ return registers ;
57+ }
58+
5059void init_kb (void ) {
60+ kb_keypress_charqueue = create_charqueue ();
61+
5162 // TODO: actually verify the PS2 controller exists
5263
5364 kb_send_command (kb_ps2_disable_port_1 , false);
@@ -70,4 +81,9 @@ void init_kb (void) {
7081 cfg_byte .irq1_enable = 1 ;
7182 kb_write_cfg_byte (cfg_byte );
7283 is_kb_setup = kb_reset ();
84+
85+ if (kb_keypress_charqueue != nullptr ) {
86+ idt_register_handler (0x21 , kb_handler );
87+ pic_clr_mask (1 );
88+ }
7389}
You can’t perform that action at this time.
0 commit comments