poppin/kernel/src/interrupts/handlers/ps2_keyboard.rs
2024-06-12 02:18:10 +03:00

34 lines
1.1 KiB
Rust

use pc_keyboard::DecodedKey;
use x86_64::structures::idt::InterruptStackFrame;
use crate::{events::EVENTMAN, interrupts::PICS};
pub struct Ps2KbPressEvent(DecodedKey);
pub extern "x86-interrupt" fn ps2_kb_int(_sf: InterruptStackFrame){
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
use spin::Mutex;
use x86_64::instructions::port::Port;
lazy_static::lazy_static! {
static ref KEYBOARD: Mutex<Keyboard<layouts::Us104Key, ScancodeSet1>> =
Mutex::new(Keyboard::new(ScancodeSet1::new(),
layouts::Us104Key, 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) {
EVENTMAN.lock().dispatch(&crate::events::Event::Ps2KeyPress(Some(key)));
}
}
unsafe {
PICS.lock()
.notify_end_of_interrupt(super::InterruptIndex::Keyboard as u8);
}
}