Enable interrupts
This commit is contained in:
parent
32b70bc075
commit
89345100c9
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -154,6 +154,7 @@ name = "ps2"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags",
|
"bitflags",
|
||||||
|
"parking_lot",
|
||||||
"syslog_rpc",
|
"syslog_rpc",
|
||||||
"x86_64",
|
"x86_64",
|
||||||
]
|
]
|
||||||
|
@ -5,5 +5,6 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bitflags = "2.6.0"
|
bitflags = "2.6.0"
|
||||||
|
parking_lot = "0.12.3"
|
||||||
syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" }
|
syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" }
|
||||||
x86_64 = "0.15.1"
|
x86_64 = "0.15.1"
|
||||||
|
@ -187,7 +187,12 @@ impl Ps2Controller {
|
|||||||
config_byte.set(Ps2ConfigByte::Port1Translation, false);
|
config_byte.set(Ps2ConfigByte::Port1Translation, false);
|
||||||
self.set_config_byte(config_byte);
|
self.set_config_byte(config_byte);
|
||||||
|
|
||||||
let self_test_result = self.send_command(Ps2ControllerCommand::TestController).unwrap();
|
// Flush the output buffer
|
||||||
|
unsafe { self.data_port.read() };
|
||||||
|
|
||||||
|
let self_test_result = self
|
||||||
|
.send_command(Ps2ControllerCommand::TestController)
|
||||||
|
.unwrap();
|
||||||
if self_test_result != 0x55 {
|
if self_test_result != 0x55 {
|
||||||
return Err(Ps2InitFailure::SelfTestFailed);
|
return Err(Ps2InitFailure::SelfTestFailed);
|
||||||
}
|
}
|
||||||
@ -218,6 +223,9 @@ impl Ps2Controller {
|
|||||||
if port1_test_result == 0x0 {
|
if port1_test_result == 0x0 {
|
||||||
self.port1_ok = true;
|
self.port1_ok = true;
|
||||||
self.send_command(Ps2ControllerCommand::EnablePort1);
|
self.send_command(Ps2ControllerCommand::EnablePort1);
|
||||||
|
let mut config_byte = self.get_config_byte();
|
||||||
|
config_byte.set(Ps2ConfigByte::Port1Interrupt, true);
|
||||||
|
self.set_config_byte(config_byte);
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.two_ports {
|
if self.two_ports {
|
||||||
@ -225,6 +233,9 @@ impl Ps2Controller {
|
|||||||
if port2_test_result == 0x0 {
|
if port2_test_result == 0x0 {
|
||||||
self.port2_ok = true;
|
self.port2_ok = true;
|
||||||
self.send_command(Ps2ControllerCommand::EnablePort2);
|
self.send_command(Ps2ControllerCommand::EnablePort2);
|
||||||
|
let mut config_byte = self.get_config_byte();
|
||||||
|
config_byte.set(Ps2ConfigByte::Port2Interrupt, true);
|
||||||
|
self.set_config_byte(config_byte);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,4 +253,21 @@ impl Ps2Controller {
|
|||||||
pub fn port2_ok(&self) -> bool {
|
pub fn port2_ok(&self) -> bool {
|
||||||
self.port2_ok
|
self.port2_ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn write_port1(&mut self, data: u8) {
|
||||||
|
self.send_command(Ps2ControllerCommand::WritePort1Input(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn write_port2(&mut self, data: u8) {
|
||||||
|
self.send_command(Ps2ControllerCommand::WritePort2Input(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn handle_interrupt(&mut self) {
|
||||||
|
if self.get_status().contains(Ps2Status::OutputBufFull) {
|
||||||
|
println!("Data: {:#x}", unsafe {self.data_port.read()});
|
||||||
|
} else {
|
||||||
|
println!("Spurious interrupt");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
23
src/main.rs
23
src/main.rs
@ -1,10 +1,14 @@
|
|||||||
mod controller;
|
mod controller;
|
||||||
|
|
||||||
use std::os::mikros::syscalls;
|
use std::os::mikros::{ipc, syscalls};
|
||||||
|
|
||||||
use controller::Ps2Controller;
|
use controller::Ps2Controller;
|
||||||
|
use parking_lot::Mutex;
|
||||||
|
|
||||||
|
static CONTROLLER: Mutex<Option<Ps2Controller>> = Mutex::new(None);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
dbg!(syscalls::get_pid());
|
||||||
let syslog_pid = loop {
|
let syslog_pid = loop {
|
||||||
if let Some(pid) = syscalls::try_get_registered(2) {
|
if let Some(pid) = syscalls::try_get_registered(2) {
|
||||||
break pid;
|
break pid;
|
||||||
@ -48,4 +52,21 @@ fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if controller.port1_ok() {
|
||||||
|
controller.write_port1(0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
*CONTROLLER.lock() = Some(controller);
|
||||||
|
|
||||||
|
ipc::register_callback(2, |_msg| {
|
||||||
|
println!("Keyboard interrupt");
|
||||||
|
if let Some(controller) = CONTROLLER.lock().as_mut() {
|
||||||
|
controller.handle_interrupt();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
loop {
|
||||||
|
ipc::process_messages()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user