Expand description
PS/2 Mouse driver (IRQ12)
Supports standard 3-byte PS/2 mouse and IntelliMouse (4-byte, scroll wheel). Initialization follows the standard PS/2 controller protocol via I/O ports 0x60 (data) and 0x64 (command/status).
Structsยง
- Event
Buffer ๐ - Mouse
Event - A decoded mouse event.
Constantsยง
- CMD_
ENABLE_ ๐AUX - CMD_
READ_ ๐CFG - CMD_
SEND_ ๐TO_ MOUSE - CMD_
WRITE_ ๐CFG - EVENT_
BUF_ ๐SIZE - MOUSE_
ACK ๐ - MOUSE_
ENABLE_ ๐STREAM - MOUSE_
GET_ ๐ID - MOUSE_
RESET ๐ - MOUSE_
SET_ ๐DEFAULTS - MOUSE_
SET_ ๐SAMPLE_ RATE - PS2_CMD ๐
- PS2_
DATA ๐ - STATUS_
INPUT_ ๐FULL - STATUS_
OUTPUT_ ๐FULL
Staticsยง
- EVENT_
BUF ๐ - INTELLIMOUSE ๐
- Whether IntelliMouse (4-byte) mode is active
- MOUSE_
ABS_ ๐X - MOUSE_
ABS_ ๐Y - MOUSE_
CYCLE ๐ - Current byte index within the current packet (0, 1, 2, [3])
- MOUSE_
READY - Mouse is initialized and streaming
- PACKET_
BUF ๐ - SCREEN_
H ๐ - SCREEN_
W ๐
Functionsยง
- decode_
packet ๐ - Decode the current packet buffer and push a
MouseEvent. - flush_
output ๐ - Drain any pending bytes in the PS/2 output buffer.
- handle_
irq - Called from the IDT IRQ12 handler (interrupt context, interrupts disabled).
- has_
event - Returns
trueif at least one mouse event is pending. - init
- Initialize the PS/2 mouse.
- mouse_
cmd ๐ - Send a command to the mouse and wait for ACK. Returns true on success.
- mouse_
cmd_ ๐arg - Send a command + argument to the mouse and wait for ACK.
- mouse_
pos - Returns the current accumulated mouse position (pixel coordinates).
- mouse_
write ๐ - Send a byte directly to the mouse (via the 0xD4 mux).
- ps2_
read ๐ - Read a byte from the PS/2 data port (waits for data).
- ps2_
write_ ๐cmd - Write a byte to the PS/2 command port.
- ps2_
write_ ๐data - Write a byte to the PS/2 data port.
- push_
event_ from_ hid - Push a mouse event from USB HID or other non-PS/2 source.
- read_
event - Dequeue the oldest mouse event (non-blocking).
- try_
enable_ ๐intellimouse - Try activating IntelliMouse scroll wheel mode. Returns true if the mouse identifies as IntelliMouse (ID = 0x03).
- wait_
read ๐ - Spin until the PS/2 output buffer has data (safe to read).
- wait_
write ๐ - Spin until the PS/2 input buffer is empty (safe to write).