This article is Copyright 2001, Adam Chapweske Electrical Interface / Protocol: The PS/2 mouse uses the same protocol as the PS/2 (AT) keyboard. This standard originally appeared in the IBM technical reference manual, but I am not aware of any current official publication of this standard. However, you may click here for the (detailed) information I have gathered about that protocol. Inputs, Resolution, and Scaling: The standard PS/2 mouse supports the following inputs: X (right/left) movement, Y (up/down) movement, left button, middle button, and right button. The mouse reads these inputs at a regular freqency and updates various counters and flags to reflect movement and button states. There are many PS/2 pointing devices that have additional inputs and may report data differently than described in this document. One popular extension I cover later in this document is the Microsoft Intellimouse, which includes support for the standard inputs as well as a scrolling wheel and two additional buttons. The standard mouse has two counters that keep track of movement: the X-movement counter and the Y-movement counter. These are 9-bit 2's complement values and each has an associated overflow flag. Their contents, along with the state of the three mouse buttons, are sent to the host in the form of a 3-byte movement data packet (as described in the next section.) The movement counters represent the amount of movement that has occurred since the last movment data packet was sent to the host. When the mouse reads its inputs, it records the current state of its buttons, then checks for movement. If movement has occurred, it increments (for +X or +Y movement) or decrements (for -X or -Y movement) its X and/or Y movement counters. If either of the counters has overflowed, it sets the appropriate overflow flag. The parameter that determines the amount by which the movement counters are incremented/decremented is the resolution. The default resolution is 4 counts/mm and the host may change that value using the "Set Resolution" (0xE8) command. There is a parameter that does not effect the movement counters,
but does effect the reported(1) value of these counters.
This parameter is scaling. By default, the mouse uses 1:1 scaling,
which has no effect on the reported mouse movement. However, the host
may select 1:2 scaling by sending the "Set Scaling 2:1" (0xE7) command.
If 2:1 scaling is enabled, the mouse will apply the following algorithm to
the counters before sending their contents to the host:
Movement Data Packet: The standard PS/2 mouse sends movement (and button) information to the host using the following 3-byte packet (4): The movement counters are 9-bit 2's complement integers, where the most significant bit appears as a sign bit in Byte 1 of the movement data packet. These counters are updated when the mouse reads its input and finds movement has occurred. Their value is the amount of movement that has occurred since the last movement data packet was sent to the host (ie, after a packet is sent to the host, the movement counters are reset.) The range of values that can be expressed by the movement counters is -255 to +255. If this range is exceeded, the appropriate overflow bit is set and the counter is not incremented/decremented until it is reset. As I mentioned earlier, the movement counters are reset whenever a movement data packet is successfully sent to the host. They are also reset after the mouse receives any command from the host other than the "Resend" (0xFE) command. Modes of Operation: Data reporting is handled according to the mode in which the mouse is operating. There are four standard modes of operation:
Reset Mode: The mouse enters reset mode at power-on or in response to the "Reset" (0xFF) command. After entring this mode, the mouse performs a diagnostic self-test referred to as BAT (Basic Assurance Test) and sets the follwing default values:
Following the BAT completion code (0xAA or 0xFC), the mouse sends its device ID of 0x00. This distinguishes it from a keyboard, or a mouse in an extended mode. I have read documents saything the host is not supposed to transmit any data until it receives a device ID. However I've found that some BIOS's will send the "Reset" (0xFF) command immediately following the 0xAA received after a power-on reset. After the mouse has sent its device ID to the host, it will enter Stream Mode. Note that one of the default values set by the mouse is "Data Reporting Disabled". This means the mouse will not send any movement data packets to the host until the "Enable Data Reporting" (0xF4) command is received. Stream Mode: In stream mode, the mouse sends movement data when it detects movement or a change in state of one or more mouse buttons. The maximum rate at which this data reporting may occur is known as the sample rate. This parameter ranges from 10 samples/sec to 200 samples/sec. Its default value is 100 samples/sec and the host may change that value by using the "Set Sample Rate" (0xF3) command. Stream mode is the default mode of operation. Remote Mode: In this mode, the mouse reads its inputs and updates its counters/flags at the current sampling rate, but it only notifies the host of movement (and change in button state) when that information is requested by the host. The host does this by issuing the "Read Data" (0xEB) command. After receiveing this command, the mouse will send a movement data packet, and reset its movement counters. Wrap Mode: This is an "echoing" mode in which every byte received by the mouse is sent back to the host. Even if the byte represents a valid command, the mouse will not respond to that command--it will only echo that byte back to the host. There are two exceptions to this: the "Reset" (0xFF) command and "Reset Wrap Mode" (0xEC) command. The mouse treats these as valid commands and does not echo them back to the host. Intellimouse Extensions: A popular extension to the standard PS/2 mouse is the Microsoft Intellimouse. This includes support for a total of five mouse buttons and three axises of movement (right-left, up-down, and a scrolling wheel). These additional features require the use of a 4-byte movement data packet rather than the standard 3-byte packet. Since standard PS/2 mouse drivers cannot recognize this packet format, the Microsoft Intellimouse is required to operate exactly like a standard PS/2 mouse unless it knows the drivers support the extended packet format. This way, if a Microsoft Intellimouse is used on a computer which only supports the standard PS/2 mouse, the Microsoft Intellimouse will still function, except for its scrolling wheel and 4th and 5th buttons. The Microsoft Intellimouse operates just like a standard PS/2 mouse (ie, it uses a 3-byte movement data packet, responds to all commands in the same way as a standard PS/2 mouse, and reports a device ID of 0x00.) To enter scrolling wheel mode, the host sends the following command sequence: Set sample rate 200The host then issues the "Get device ID" command (0xF2) and waits for a response. If a standard PS/2 mouse (ie, non-Intellimouse) is attached, it will respond with a device ID of 0x00. In this case, the host will recognize the fact that the mouse does have a scrolling wheel and will continue to treat it as a standard PS/2 mouse. However, if a Microsoft Intellimouse is attached, it will respond with an ID of 0x03. This tells the host that the attached pointing device has a scrolling wheel and the host will then expect the mouse to use the following 4-byte movement data packet: To enter scrolling wheel + 5 button mode, the host sends the following command sequence: Set sample rate 200The host then issues the "Get device ID" command (0xF2) and waits for a response. A Microsoft Intellimouse will respond with a device ID of 0x04, then use the following 4-byte movement data packet: You may have seen mice with two scrolling wheels--one vertical and the other horizontal. These mice use the Microsoft Intellimouse data packet format as described above. If the vertical wheel is scrolled upward, the Z-counter is incremented by one and if that wheel is scrolled down, the Z-counter is decremented by one. This is normal operation for a scrolling wheel. However, if the horizontal wheel is scrolled right, the Z-counter is incremented by two and if it is scrolled left, the Z-counter is decremented by two. This seems like an odd way to implement the second scrolling wheel, but it works since the placement of the two wheels make it impossible to use both of them at the same time (and if you try to trick the software and use both at the same time, it will ignore the horizontal wheel.) Command Set: The following are the only commands that may be sent to the mouse... If the mouse is in Stream mode, the host should disable data reporting (command 0xF5) before sending any other commands...
Right, Middle, Left Btn = 1 if button pressed; 0 if button
is not pressed.
Initialization: The PS/2 mouse is normally detected/initialized only when the computer is booting up. That is, the mouse is not hot-pluggable and you must restart your computer whenever you add/remove a PS/2 mouse (furthermore, some motherboards may be damaged if you add/remove a PS/2 mouse while the computer is running.) The initial detection of the PS/2 mouse occurrs during POST. If a mouse is detected, the BIOS will allow the operating system to configure/enable the mouse. Otherwise, it will inhibit communication on the mouse's bus. If you boot the computer with a mouse attached, then detach/reattach the mouse while in Windows, the OS may be able to detect the mouse was reattached. Microsoft tried to support this, but it only works about 50% of the time. The following is the communication between my computer (running Win98SE) and mouse when it boots up with a standard PS/2 mouse attached. It is fairly typical of how a PS/2 mouse is initialized and if you want to emulate a PS/2 mouse it must (at minimum) be able to support the following sequence of commands...
Mouse: AA Self-test passed Mouse: 00 Mouse ID Host: FF Reset command Mouse: FA Acknowledge Mouse: AA Self-test passed Mouse: 00 Mouse ID Host: FF Reset command Mouse: FA Acknowledge Mouse: AA Self-test passed Mouse: 00 Mouse ID Host: FF Reset command Mouse: FA Acknowledge Mouse: AA Self-test passed Mouse: 00 Mouse ID Host: F3 Set Sample Rate : Attempt to Enter Microsoft Mouse: FA Acknowledge : Scrolling Mouse mode Host: C8 decimal 200 : Mouse: FA Acknowledge : Host: F3 Set Sample Rate : Mouse: FA Acknowledge : Host: 64 decimal 100 : Mouse: FA Acknowledge : Host: F3 Set Sample Rate : Mouse: FA Acknowledge : Host: 50 decimal 80 : Mouse: FA Acknowledge : Host: F2 Read Device Type : Mouse: FA Acknowledge : Mouse: 00 Mouse ID : Response 03 if microsoft scrolling mouse Host: F3 Set Sample Rate Mouse: FA Acknowledge Host: 0A decimal 10 Mouse: FA Acknowledge Host: F2 Read Device Type Mouse: FA Acknowledge Mouse: 00 Mouse ID Host: E8 Set resolution Mouse: FA Acknowledge Host: 03 8 Counts/mm Mouse: FA Acknowledge Host: E6 Set Scaling 1:1 Mouse: FA Acknowledge Host: F3 Set Sample Rate Mouse: FA Acknowledge Host: 28 decimal 40 Mouse: FA Acknowledge Host: F4 Enable Mouse: FA Acknowledge Initialization complete... If I then press the Left Button...
Mouse: AA Self-test passed Mouse: 00 Mouse ID Host: FF Reset command Mouse: FA Acknowledge Mouse: AA Self-test passed Mouse: 00 Mouse ID Host: FF Reset command Mouse: FA Acknowledge Mouse: AA Self-test passed Mouse: 00 Mouse ID Host: FF Reset command Mouse: FA Acknowledge Mouse: AA Self-test passed Mouse: 00 Mouse ID Host: F3 Set Sample Rate : Attempt to Enter Microsoft Mouse: FA Acknowledge : Scrolling Mouse mode Host: C8 decimal 200 : Mouse: FA Acknowledge : Host: F3 Set Sample Rate : Mouse: FA Acknowledge : Host: 64 decimal 100 : Mouse: FA Acknowledge : Host: F3 Set Sample Rate : Mouse: FA Acknowledge : Host: 50 decimal 80 : Mouse: FA Acknowledge : Host: F2 Read Device Type : Mouse: FA Acknowledge : Mouse: 03 Mouse ID : Response 03 if microsoft scrolling mouse Host: E8 Set Resolution Mouse: FA Acknowledge Host: 03 8 counts/mm Mouse: FA Acknowledge Host: E6 Set scaling 1:1 Dev: FA Acknowledge Host: F3 Set Sample Rate Mouse: FA Acknowledge Host: 28 decimal 40 Mouse: FA Acknowledge Host: F4 Enable device Mouse: FA Acknowledge If I then press the left mouse button: ...and then release the left mouse button button: ... (starts same as before) ...Emulation/Interfacing:
To Emulate a Mouse: 1) 2:1 scaling only applies to the automatic data reporting in Stream mode. It does not effect the reported data sent in response to the "Read Data" (0xEB) command.Other Sources / References:
|