PS/2 driver convert to char

This commit is contained in:
Jeremy Soller 2016-09-19 10:24:19 -06:00
parent 727647dbf1
commit c957c2a105
5 changed files with 120 additions and 82 deletions

View file

@ -1,15 +1,9 @@
use core::cmp;
use spin::Mutex;
use io::{Io, Pio, ReadOnly, WriteOnly};
pub static PS2_KEYBOARD: Mutex<Option<Ps2Keyboard>> = Mutex::new(None);
pub static PS2_MOUSE: Mutex<Option<Ps2Mouse>> = Mutex::new(None);
pub unsafe fn init() {
let (keyboard, mouse) = Ps2::new().init();
*PS2_KEYBOARD.lock() = keyboard;
*PS2_MOUSE.lock() = mouse;
Ps2::new().init();
}
bitflags! {
@ -98,34 +92,6 @@ bitflags! {
}
}
pub struct Ps2Keyboard {
data: ReadOnly<Pio<u8>>,
key: [u8; 3],
key_i: usize,
}
impl Ps2Keyboard {
fn new() -> Self {
Ps2Keyboard {
data: ReadOnly::new(Pio::new(0x60)),
key: [0; 3],
key_i: 0
}
}
pub fn on_irq(&mut self) {
let scancode = self.data.read();
self.key[self.key_i] = scancode;
self.key_i += 1;
if self.key_i >= self.key.len() || scancode < 0xE0 {
println!("KEY: {:X} {:X} {:X}", self.key[0], self.key[1], self.key[2]);
self.key = [0; 3];
self.key_i = 0;
}
}
}
pub struct Ps2Mouse {
data: ReadOnly<Pio<u8>>,
mouse: [u8; 4],
@ -278,7 +244,7 @@ impl Ps2 {
self.read()
}
fn init(&mut self) -> (Option<Ps2Keyboard>, Option<Ps2Mouse>) {
fn init(&mut self) {
// Disable devices
self.command(Command::DisableFirst);
self.command(Command::DisableSecond);
@ -352,13 +318,12 @@ impl Ps2 {
let mut config = self.config();
config.remove(FIRST_DISABLED);
config.remove(SECOND_DISABLED);
config.insert(FIRST_TRANSLATE);
config.insert(FIRST_INTERRUPT);
config.insert(SECOND_INTERRUPT);
self.set_config(config);
}
self.flush_read();
(Some(Ps2Keyboard::new()), Some(Ps2Mouse::new(mouse_extra)))
}
}

View file

@ -1,7 +1,6 @@
use spin::Mutex;
use x86::io;
use device::ps2::{PS2_KEYBOARD, PS2_MOUSE};
use device::serial::{COM1, COM2};
pub static ACKS: Mutex<[usize; 16]> = Mutex::new([0; 16]);