From 6a61e8f220b31887cea64e77eb9ec58ad79daff0 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 18 Jul 2019 21:49:57 -0700 Subject: [PATCH] Keyboard typing support --- Cargo.toml | 1 + src/interrupts.rs | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 0b77b42..f675c64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ volatile = "0.2.6" spin = "0.5.0" x86_64 = "0.7.2" pic8259_simple = "0.1.1" +pc-keyboard = "0.5.0" [dependencies.lazy_static] version = "1.3.0" diff --git a/src/interrupts.rs b/src/interrupts.rs index 84a198d..e8fcfab 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -43,8 +43,6 @@ lazy_static! { }; } - - pub fn init_idt() { IDT.load(); } @@ -74,11 +72,26 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut InterruptSt extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut InterruptStackFrame) { use x86_64::instructions::port::Port; + use pc_keyboard::{Keyboard, ScancodeSet1, DecodedKey, HandleControl, layouts}; + use spin::Mutex; + lazy_static! { + static ref KEYBOARD: Mutex> = + Mutex::new(Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::Ignore)); + } + + let mut keyboard = KEYBOARD.lock(); let mut port = Port::new(0x60); let scancode: u8 = unsafe { port.read() }; - print!("k"); + if let Ok(Some(key_event)) = keyboard.add_byte(scancode) { + if let Some(key) = keyboard.process_keyevent(key_event) { + match key { + DecodedKey::Unicode(character) => print!("{}", character), + DecodedKey::RawKey(key) => print!("{:?}", key), + } + } + } unsafe { PICS.lock().notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8()) }