Keyboard typing support

This commit is contained in:
greg 2019-07-18 21:49:57 -07:00
parent 817a99d589
commit 6a61e8f220
2 changed files with 17 additions and 3 deletions

View File

@ -10,6 +10,7 @@ volatile = "0.2.6"
spin = "0.5.0" spin = "0.5.0"
x86_64 = "0.7.2" x86_64 = "0.7.2"
pic8259_simple = "0.1.1" pic8259_simple = "0.1.1"
pc-keyboard = "0.5.0"
[dependencies.lazy_static] [dependencies.lazy_static]
version = "1.3.0" version = "1.3.0"

View File

@ -43,8 +43,6 @@ lazy_static! {
}; };
} }
pub fn init_idt() { pub fn init_idt() {
IDT.load(); IDT.load();
} }
@ -74,11 +72,26 @@ extern "x86-interrupt" fn timer_interrupt_handler(_stack_frame: &mut InterruptSt
extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut InterruptStackFrame) { extern "x86-interrupt" fn keyboard_interrupt_handler(_stack_frame: &mut InterruptStackFrame) {
use x86_64::instructions::port::Port; use x86_64::instructions::port::Port;
use pc_keyboard::{Keyboard, ScancodeSet1, DecodedKey, HandleControl, layouts};
use spin::Mutex;
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(0x60); let mut port = Port::new(0x60);
let scancode: u8 = unsafe { port.read() }; let scancode: u8 = unsafe { port.read() };
print!("k"); 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 { unsafe {
PICS.lock().notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8()) PICS.lock().notify_end_of_interrupt(InterruptIndex::Keyboard.as_u8())
} }