PS/2 Mouse: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
→‎Z-axis: Simplified mouse data packet table
m Bot: Replace deprecated source tag with syntaxhighlight
 
(5 intermediate revisions by 3 users not shown)
Line 15:
! Byte !! Data byte !! Description
|-
| 0xFF0xE6 || None || ResetSet Scaling 1:1
|-
| 0xFE0xE7 || None || ResendSet Scaling 2:1
|-
| 0xF6 || None || Set Defaults
|-
| 0xF5 || None || Disable Data Reporting
|-
| 0xF4 || None || Enable Data Reporting
|-
| 0xF3
| Sample rate
| Set Sample Rate, valid values are 10, 20, 40, 60, 80, 100, and 200.
|-
| 0xF2
| None
| Get Device ID. See [["8042" PS/2 Controller#Detecting PS/2 Device Types|Detecting PS/2 Device Types]] for the response bytes.
|-
| 0xF0 || None || Set Remote Mode
|-
| 0xEE || None || Set Wrap Mode
|-
| 0xEC || None || Reset Wrap Mode
|-
| 0xEB || None || Read Data
|-
| 0xEA || None || Set Stream Mode
|-
| 0xE9 || None || Status Request
|-
| 0xE8
Line 66 ⟶ 40:
| Set Resolution
|-
| 0xE70xE9 || None || SetStatus Scaling 2:1Request
|-
| 0xE60xEA || None || Set ScalingStream 1:1Mode
|-
| 0xEB || None || Read Data
|-
| 0xEC || None || Reset Wrap Mode
|-
| 0xEE || None || Set Wrap Mode
|-
| 0xF0 || None || Set Remote Mode
|-
| 0xF2
| None
| Get Device ID. See [["8042" PS/2 Controller#Detecting PS/2 Device Types|Detecting PS/2 Device Types]] for the response bytes.
|-
| 0xF3
| Sample rate
| Set Sample Rate, valid values are 10, 20, 40, 60, 80, 100, and 200.
|-
| 0xF4 || None || Enable Data Reporting
|-
| 0xF5 || None || Disable Data Reporting
|-
| 0xF6 || None || Set Defaults
|-
| 0xEA0xFE || None || Set Stream ModeResend
|-
| 0xFF || None || Reset ('''Note: After the result of the power-on test is sent, the mouse sends its ID (0x00)''')
|-
|}
Line 107:
|}
 
Each X and Y axis value is relative. The mouse device does not track it'sits location in absolute coordinates. This should also be apparent by the 9-bit values. Instead, it sends back saying I moved this far to the left, to the right, down, or up. To keep track of a mouse position you need to accumulate these relative offsets into a absolute position offset in your code:
<pre>
mouse_x = mouse_x + mouse_packet_rel_x
Line 127:
 
To set the sample rate for example, which is a command with a data byte, one would need to do:
<sourcesyntaxhighlight lang="c">
outb(0xD4, 0x64); // tell the controller to address the mouse
outb(0xF3, 0x60); // write the mouse command code to the controller's data port
Line 136:
while(!(inb(0x64) & 1) asm("pause"); // wait until we can read
ack = inb(0x60); // read back acknowledge. This should be 0xFA
</syntaxhighlight>
</source>
 
== Mouse Extensions ==
Line 149:
 
To enable the Intellimouse Z-axis extension, you have to set some magic into the sample rate:
<sourcesyntaxhighlight lang="c">
set_mouse_rate(200); // see the example above
set_mouse_rate(100);
set_mouse_rate(80);
mouseid = identify(); // see Get Device ID, 0xF2
</syntaxhighlight>
</source>
 
After that the mouse should not return Mouse ID ''0'', but ''3'', and will send 4 bytes data packages as follows:
Line 175:
 
To enable the 4th and 5th buttons, first you have to try to enable Z-axis, and you can only follow with this if the identification returned ''3''.
<sourcesyntaxhighlight lang="c">
if(mouseid == 3) {
set_mouse_rate(200);
Line 182:
mouseid = identify();
}
</syntaxhighlight>
</source>
If this was successful, the identify command should now return Mouse ID ''4'', and the 4 bytes packets will look like this:
{| class="wikitable"
Line 189:
! BYTE!!7!!6!!5!!4!!3!!2!!1!!0
|- align="center"
| 0 || yo || xo || ys || xs || ao1 || bm || br || bl
|- align="center"
| 1 || colspan="8" | xmX-Axis Movement Value
|- align="center"
| 2 || colspan="8" | ymY-Axis Movement Value
|- align="center"
| 3 || 0 || 0 || b5thb5 || b4thb4 || colspan="4" | zmZ-Axis Movement Value
|}
Here the zmX-Axis Movement Value is stored only on the low 4 bits and the last byte is not sign extended. Bits 4 and 5 represents the pressed status of buttons 4 and 5 in that order, same as with bm, br and bl.
 
=== Emulation ===
Line 225:
[[Category:Human Interface Device]]
[[Category:Common Devices]]
[[Category:Hardware Interfaces]]