The PS/2 mouse interface has been a staple in computing for decades, providing a reliable and efficient way to connect mice to computers. Despite the rise of newer interfaces like USB, PS/2 remains widely used, particularly in legacy systems and industrial applications. In this post, we'll delve into the world of PS/2 compatible mouse drivers, exploring their functionality, types, and importance in modern computing.
volatile uint8_t mouse_cycle = 0; volatile uint8_t mouse_packet[4]; // We use 3 for standard volatile int mouse_x = 0, mouse_y = 0; volatile uint8_t mouse_buttons = 0; ps/2 compatible mouse driver
The movement values are relative. To determine the actual delta movement, the driver must extract the sign bits from Byte 1 and construct 9-bit integers. The PS/2 mouse interface has been a staple
Optional: Set sample rate, resolution, scaling. If the mouse detects an internal error or
If the mouse detects an internal error or a transmission failure, it may send a 0xFE (Resend) command. Conversely, if the host sends a command that the mouse does not acknowledge, the mouse responds with 0xFA (Acknowledge), 0xFE (Resend), or 0xFC (Error). A robust driver must implement a retry loop (usually 3 attempts) when sending configuration commands.
The PS/2 interface has remained a standard for keyboard and mouse input in the IBM PC architecture since its introduction in 1987. Despite the prevalence of USB and Bluetooth in modern computing, the PS/2 protocol remains relevant in embedded systems, legacy hardware maintenance, and operating system development. This paper explores the low-level design of a software driver for a PS/2 compatible mouse. It details the hardware interaction via I/O ports, the initialization sequence required to enable the auxiliary device, the interpretation of the standard 3-byte data packet, and the management of hardware interrupts. The paper concludes with an analysis of the protocol's limitations and the handling of edge cases such as overflow and synchronization errors.
// Update cursor position cursor_x += x_movement; cursor_y -= y_movement; // Y axis is typically inverted in screen coordinates