feat(keyboard): add distinct module for keyboard
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
ee6e6c49cc
commit
9b5004bf81
34
src/interrupts/pic/keyboard.rs
Normal file
34
src/interrupts/pic/keyboard.rs
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +1,15 @@
|
|||||||
use pic8259::ChainedPics;
|
use pic8259::ChainedPics;
|
||||||
use crate::{print, println};
|
use crate::{println};
|
||||||
use lazy_static::lazy_static;
|
pub use pit::{timer_interrupt_handler};
|
||||||
use pc_keyboard::{layouts, DecodedKey, HandleControl, Keyboard, ScancodeSet1};
|
pub use keyboard::keyboard_interrupt_handler;
|
||||||
use x86_64::structures::idt::{InterruptStackFrame};
|
|
||||||
use x86_64::instructions::port::Port;
|
|
||||||
use spin::{self, Mutex};
|
|
||||||
pub use pit::{timer_interrupt_handler, gettick};
|
|
||||||
|
|
||||||
pub mod pit;
|
pub mod pit;
|
||||||
|
pub mod keyboard;
|
||||||
|
|
||||||
pub const PIC_1_OFFSET: u8 = 32;
|
pub const PIC_1_OFFSET: u8 = 32;
|
||||||
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
pub const PIC_2_OFFSET: u8 = PIC_1_OFFSET + 8;
|
||||||
|
|
||||||
|
|
||||||
pub const PS2_CONTROLLER_PORT: u16 = 0x60;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum InterruptIndex {
|
pub enum InterruptIndex {
|
||||||
@ -41,27 +36,3 @@ pub fn init_pic() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
use super::{PICS, InterruptIndex};
|
use super::{PICS, InterruptIndex};
|
||||||
use x86_64::structures::idt::InterruptStackFrame;
|
use x86_64::structures::idt::InterruptStackFrame;
|
||||||
use crate::{println};
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
static mut TICKS: u64 = 0;
|
static mut TICKS: u64 = 0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user