From c8b71f22942c70b59886d28b92c434c02f274f99 Mon Sep 17 00:00:00 2001 From: charlesbvll Date: Thu, 22 Jul 2021 16:20:23 +0200 Subject: [PATCH] keyboard config --- Cargo.toml | 1 + src/interrupts.rs | 25 ++++++++++++++++++++++++- src/main.rs | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index badb8d8..a6da8d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ spin = "0.5.2" x86_64 = "0.14.2" uart_16550 = "0.2.0" pic8259 = "0.10.1" +pc-keyboard = "0.5.0" [dependencies.lazy_static] version = "1.0" diff --git a/src/interrupts.rs b/src/interrupts.rs index 66bbe86..d7b33ae 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -40,7 +40,29 @@ extern "x86-interrupt" fn timer_interrupt_handler( extern "x86-interrupt" fn keyboard_interrupt_handler( _stack_frame: InterruptStackFrame) { - print!("k"); + use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1}; + use spin::Mutex; + use x86_64::instructions::port::Port; + + 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() }; + 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() @@ -48,6 +70,7 @@ extern "x86-interrupt" fn keyboard_interrupt_handler( } } + pub fn init_idt() { IDT.load(); } diff --git a/src/main.rs b/src/main.rs index bd88a97..3caf346 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use rust_os::println; pub extern "C" fn _start() -> ! { println!("Hello World{}", "!"); - rust_os::init(); // new + rust_os::init(); // as before #[cfg(test)]