ps2d: limit mouse resets to 10
This commit is contained in:
@@ -102,6 +102,8 @@ pub struct Ps2 {
|
||||
data: Pio<u8>,
|
||||
status: ReadOnly<Pio<u8>>,
|
||||
command: WriteOnly<Pio<u8>>,
|
||||
//TODO: keep in state instead
|
||||
pub mouse_resets: usize,
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
|
||||
@@ -109,6 +111,8 @@ pub struct Ps2 {
|
||||
data: Mmio<u8>,
|
||||
status: ReadOnly<Mmio<u8>>,
|
||||
command: WriteOnly<Mmio<u8>>,
|
||||
//TODO: keep in state instead
|
||||
pub mouse_resets: usize,
|
||||
}
|
||||
|
||||
impl Ps2 {
|
||||
@@ -118,6 +122,7 @@ impl Ps2 {
|
||||
data: Pio::new(0x60),
|
||||
status: ReadOnly::new(Pio::new(0x64)),
|
||||
command: WriteOnly::new(Pio::new(0x64)),
|
||||
mouse_resets: 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::controller::Ps2;
|
||||
use std::time::Duration;
|
||||
|
||||
pub const RESET_RETRIES: usize = 10;
|
||||
pub const RESET_TIMEOUT: Duration = Duration::from_millis(1000);
|
||||
pub const COMMAND_TIMEOUT: Duration = Duration::from_millis(100);
|
||||
|
||||
@@ -125,6 +126,13 @@ pub enum MouseResult {
|
||||
|
||||
impl MouseState {
|
||||
pub fn reset(&mut self, ps2: &mut Ps2) -> MouseResult {
|
||||
if ps2.mouse_resets < RESET_RETRIES {
|
||||
ps2.mouse_resets += 1;
|
||||
} else {
|
||||
log::error!("tried to reset mouse {} times, giving up", ps2.mouse_resets);
|
||||
*self = MouseState::None;
|
||||
return MouseResult::None;
|
||||
}
|
||||
match ps2.mouse_command_async(MouseCommand::Reset as u8) {
|
||||
Ok(()) => {
|
||||
*self = MouseState::Reset;
|
||||
@@ -337,7 +345,6 @@ impl MouseState {
|
||||
}
|
||||
|
||||
pub fn handle_timeout(&mut self, ps2: &mut Ps2) -> MouseResult {
|
||||
let mut res = MouseResult::None;
|
||||
match *self {
|
||||
MouseState::None | MouseState::Streaming { .. } => MouseResult::None,
|
||||
MouseState::Init => {
|
||||
@@ -346,13 +353,10 @@ impl MouseState {
|
||||
}
|
||||
MouseState::Reset => {
|
||||
log::warn!("timeout waiting for mouse reset");
|
||||
//TODO: retry reset?
|
||||
*self = MouseState::None;
|
||||
MouseResult::None
|
||||
self.reset(ps2)
|
||||
}
|
||||
MouseState::Bat => {
|
||||
log::warn!("timeout waiting for BAT completion");
|
||||
//TODO: limit number of resets
|
||||
self.reset(ps2)
|
||||
}
|
||||
MouseState::IdentifyTouchpad { .. } => {
|
||||
|
||||
Reference in New Issue
Block a user