aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatasha Moongrave <natasha@256phi.eu>2026-03-11 11:20:49 +0100
committerNatasha Moongrave <natasha@256phi.eu>2026-03-11 11:20:49 +0100
commit747c381d7cf7f24b128ccaf27566b417d0e77573 (patch)
tree8f9fa8f6c88e5967a18ff13f244703156a756d50
parentb7ed90635d228e6c8b4ca4cf16cae84faedfeb8c (diff)
rewrote keyboard_interrupt_handler() in src/interrupts.rs to use pc_keyboard package to translate scancodes into their proper keys and print them to the screen
-rw-r--r--StrixKernel/src/interrupts.rs43
1 files changed, 22 insertions, 21 deletions
diff --git a/StrixKernel/src/interrupts.rs b/StrixKernel/src/interrupts.rs
index 6f19088..fbc6d67 100644
--- a/StrixKernel/src/interrupts.rs
+++ b/StrixKernel/src/interrupts.rs
@@ -87,28 +87,29 @@ extern "x86-interrupt" fn timer_interrupt_handler(
extern "x86-interrupt" fn keyboard_interrupt_handler(
_stack_frame: InterruptStackFrame)
{
- use x86_64::instructions::port::Port;
-
- let mut port = Port::new(0x60);
- let scancode: u8 = unsafe { port.read() };
-
- let key = match scancode {
- 0x02 => Some('1'),
- 0x03 => Some('2'),
- 0x04 => Some('3'),
- 0x05 => Some('4'),
- 0x06 => Some('5'),
- 0x07 => Some('6'),
- 0x08 => Some('7'),
- 0x09 => Some('8'),
- 0x0a => Some('9'),
- 0x0b => Some('0'),
- _ => None,
- };
- if let Some(key) = key {
- print!("{}", key);
- }
+ use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
+ use spin::Mutex;
+ use x86_64::instructions::port::Port;
+
+ 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) {
+ match key {
+ DecodedKey::Unicode(character) => print!("{}", character),
+ DecodedKey::RawKey(key) => print!("{:?}", key),
+ }
+ }
+ }
unsafe {
PICS.lock()