35 lines
1.2 KiB
Rust
35 lines
1.2 KiB
Rust
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
|
|
use lazy_static::lazy_static;
|
|
use super::{PICS, InterruptIndex};
|
|
use x86_64::instructions::port::Port;
|
|
use spin::{self, Mutex};
|
|
use crate::{print};
|
|
use x86_64::structures::idt::{InterruptStackFrame};
|
|
|
|
pub const PS2_CONTROLLER_PORT: u16 = 0x60;
|
|
|
|
pub extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: InterruptStackFrame) {
|
|
lazy_static! {
|
|
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> = Mutex::new(
|
|
Keyboard::new(layouts::Us104Key, ScancodeSet1, HandleControl::Ignore)
|
|
);
|
|
}
|
|
|
|
let mut keyboard = KEYBOARD.lock();
|
|
let mut port = Port::new(PS2_CONTROLLER_PORT);
|
|
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()
|
|
.notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8());
|
|
}
|
|
}
|