Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion kernel/keyboard/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ pub fn init(keyboard: PS2Keyboard<'static>, keyboard_queue_producer: Queue<Event
}

// TODO: figure out what we should do, for now using set 1
keyboard.keyboard_scancode_set(ScancodeSet::Set1)?;
// Acer Aspire 7745G:
// - allows setting Set 1 and also returns Set 1 on ScancodeSet::Get, but keyboard interrupts don't fire
// - allows setting Set 2 and works
// HP Pavilion 17(-ab)-f050ng:
// - TODO
// -> we can only try setting the default Set 2 and then try ScancodeSet::Get
keyboard.set_keyboard_scancode_set(ScancodeSet::Set1)?;

// Register the interrupt handler
interrupts::register_interrupt(PS2_KEYBOARD_IRQ, ps2_keyboard_handler).map_err(|e| {
Expand Down
33 changes: 8 additions & 25 deletions kernel/mouse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#![no_std]
#![feature(abi_x86_interrupt)]

use log::{error, warn, debug};
use log::{error, warn};
use spin::Once;
use mpmc::Queue;
use event_types::Event;
use x86_64::structures::idt::InterruptStackFrame;
use mouse_data::{MouseButtons, MouseEvent, MouseMovementRelative};
use ps2::{PS2Mouse, MouseId, MousePacket};
use ps2::{PS2Mouse, MousePacket};

/// The first PS/2 port for the mouse is connected directly to IRQ 0xC.
/// Because we perform the typical PIC remapping, the remapped IRQ vector number is 0x2C.
Expand All @@ -29,26 +29,10 @@ struct MouseInterruptParams {
/// * `mouse_queue_producer`: the queue onto which the mouse interrupt handler
/// will push new mouse events when a mouse action occurs.
pub fn init(mut mouse: PS2Mouse<'static>, mouse_queue_producer: Queue<Event>) -> Result<(), &'static str> {
//TODO: set to 3, failed? id = 0, otherwise set to 4, failed? id = 3, otherwise id = 4
//the current code beneath just tries to set id = 4, so is not final
// Set Mouse ID to 4.
if let Err(e) = mouse.set_mouse_id(MouseId::Four) {
error!("Failed to set the mouse id to four: {e}");
return Err("Failed to set the mouse id to four");
}
// Read it back to check that it worked.
match mouse.mouse_id() {
Ok(id) => {
debug!("The PS/2 mouse ID is: {id:?}");
if !matches!(id, MouseId::Four) {
error!("Failed to set the mouse id to four");
return Err("Failed to set the mouse id to four");
}
}
Err(e) => {
error!("Failed to read the PS/2 mouse ID: {e}");
return Err("Failed to read the PS/2 mouse ID");
}
// Set MouseId to the highest possible one
if let Err(e) = mouse.set_mouse_id() {
error!("Failed to set the mouse id: {e}");
return Err("Failed to set the mouse id");
}

// Register the interrupt handler
Expand Down Expand Up @@ -78,13 +62,12 @@ extern "x86-interrupt" fn ps2_mouse_handler(_stack_frame: InterruptStackFrame) {
// try to redesign this to only get one byte per interrupt instead of the 3-4 bytes we
// currently get in read_mouse_packet and merge them afterwards
let mouse_packet = mouse.read_mouse_packet();
// warn!("read_mouse_packet: {mouse_packet:?}");

if mouse_packet.always_one() != 1 {
// this could signal a hardware error or a mouse which doesn't conform to the rule
warn!("Discarding mouse data packet since its third bit should always be 1.");
warn!("ps2_mouse_handler(): Discarding mouse data packet since its third bit should always be 1.");
} else if let Err(e) = handle_mouse_input(mouse_packet, queue) {
error!("ps2_mouse_handler: {e:?}");
error!("ps2_mouse_handler(): {e:?}");
}
}
} else {
Expand Down
Loading