Skip to content

IBM PC Mouse

hasu@tmk edited this page Oct 3, 2024 · 30 revisions

See this for serial mouse.

PS/2 Mouse Protocol

https://www.win.tue.nl/~aeb/linux/kbd/scancodes-13.html

PS/2 Mouse Driver

https://github.com/freebsd/freebsd-src/blob/598f0580f6822e2492231d055f49465a5b55d270/sys/dev/atkbdc/psm.c

https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/drivers/input/serio/libps2.c

TrackPoint

https://web.archive.org/web/20100613123840/http://wwwcssrv.almaden.ibm.com/trackpoint/files/ykt3eext.pdf

https://github.com/torvalds/linux/blob/996d585b079ad494a30cac10e08585bcd5345125/drivers/input/mouse/trackpoint.c

https://github.com/torvalds/linux/blob/996d585b079ad494a30cac10e08585bcd5345125/drivers/input/mouse/trackpoint.h

E1 - READ SECONDARY ID

This command will read the secondary device ID of the pointing device (2 bytes). First byte is variant ID(IBM=01) and second one indicates revision of specification.

https://github.com/torvalds/linux/blob/996d585b079ad494a30cac10e08585bcd5345125/drivers/input/mouse/trackpoint.c#L269

Logitech PS/2++ protocol

https://www.win.tue.nl/~aeb/linux/kbd/scancodes-13.html

https://github.com/torvalds/linux/blob/d2912cb15bdda8ba4a5dd73396ad62641af2f520/drivers/input/mouse/logips2pp.c#L41

https://web.archive.org/web/20030714000535/www.dqcs.com/logitech/ps2ppspec.htm

Standard 3-button Mouse

Mouse ID

0x00

Mouse Data

byte|7       6       5       4       3       2       1       0
----+--------------------------------------------------------------
   0|Yovflw  Xovflw  Ysign   Xsign   1       Middle  Right   Left
   1|                    X movement
   2|                    Y movement

Microsoft IntelliMouse

Mouse ID

0x03

Magic Sequence

f3 c8 f3 64 f3 50(set sample rate 200, 100, 80)

Mouse Data

byte|7       6       5       4       3       2       1       0
----+--------------------------------------------------------------
   0|Yovflw  Xovflw  Ysign   Xsign   1       Middle  Right   Left
   1|                    X movement
   2|                    Y movement
   3|                    V movement

Microsoft IntelliMouse Explorer

https://en.wikipedia.org/wiki/IntelliMouse

Mouse ID

0x04

Magic Sequence

f3 c8 f3 c8 f3 50(set sample rate 200, 200, 80)

Mouse Data

byte|7       6       5       4       3       2       1       0
----+--------------------------------------------------------------
   0|Yovflw  Xovflw  Ysign   Xsign   1       Middle  Right   Left
   1|                    X movement
   2|                    Y movement
   3|0       0       Forward Back             V movement

Kensington ThinkingMouse

https://github.com/freebsd/freebsd-src/blob/598f0580f6822e2492231d055f49465a5b55d270/sys/dev/atkbdc/psm.c#L5417

https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/drivers/input/mouse/psmouse-base.c#L656

Mouse ID

0x02

Magic Sequence

set sample rate 20, 60, 40, 20, 20, 60, 40, 20, 20

Mouse Data

byte|7       6       5       4       3       2       1       0
----+--------------------------------------------------------------
   0|Yovflw  Xovflw  Ysign   Xsign   4thBtn  Middle  Right   Left
   1|                    X movement
   2|                    Y movement
		/*
		 * Without this bit of weirdness moving up gives wildly
		 * high Y changes.
		 */
		packet[1] |= (packet[0] & 0x40) << 1;

https://github.com/torvalds/linux/blob/5bfc75d92efd494db37f5c4c173d3639d4772966/drivers/input/mouse/psmouse-base.c#L206

Logitech PS/2++

Logitech Mouse report consists of 3 bytes and reports following data.

  • X: 9-bit, -255(0x101) to 255(0x0FF)
  • Y: 9-bit, -255(0x101) to 255(0x0FF)
  • Wheel: 5-bit, -15(0x11) to 15(0x0F)
  • Buttons: Left, Right, Middle, Back, Forward, Up, Down, Task, ...

https://github.com/torvalds/linux/blob/d2912cb15bdda8ba4a5dd73396ad62641af2f520/drivers/input/mouse/logips2pp.c#L41

Mouse Data

Byte0 is compatible to Standard PS/2 mouse data. But Logitech mouse never overflow its counts, so the overflow bits are used to discriminate mouse report types.

Byte0:

Bit Description
Bit 7 Y-overflow (1 if report comes from an external device)
Bit 6 X-overflow (1 when Logitech specific report)

1. Cursor with 3 buttons

This is compatible to standard report when Byte0 X-overflow bit is 0.

Byte0:

Bit Description
Bit 7 0(Y-overflow)
Bit 6 0(X-overflow)
Bit 5 Y-sign
Bit 4 X-sign
Bit 3 1
Bit 2 Middle button
Bit 1 Right button
Bit 0 Left button

Byte1: X movement, 8-bit

Byte2: Y movement, 8-bit

2. Extra Button Data 1(Forward, Back button)

When Byte0 X-overflow bit is 1, Byte0 both sign bits are 0 and Byte1 is 0xD2

Byte0:

Bit Description
Bit 7 -(Y-overflow)
Bit 6 1(X-overflow)
Bit 5 0(Y-sign)
Bit 4 0(X-sign)
Bit 3 1
Bit 2 -(Middle button)
Bit 1 -(Right button)
Bit 0 -(Left button)

Byte1:

Bit Description
Bit 7 1
Bit 6 1
Bit 5 0
Bit 4 1
Bit 3 -
Bit 2 -
Bit 1 -
Bit 0 -

Byte2:

Bit Description
Bit 7 0
Bit 6 0
Bit 5 Forward button
Bit 4 Back button
Bit 3 0
Bit 2 0
Bit 1 0
Bit 0 0

3. Extra Button Data 2

When Overflow bits(Bit7, Bit6) of Byte0 are x1 and Byte1 is 0xE2

Byte0:

Bit Description
Bit 7 -(Y-overflow)
Bit 6 1(X-overflow)
Bit 5 0(Y-sign)
Bit 4 0(X-sign)
Bit 3 1
Bit 2 -(Middle button)
Bit 1 -(Right button)
Bit 0 -(Left button)

Byte1:

Bit Description
Bit 7 1
Bit 6 1
Bit 5 1
Bit 4 0
Bit 3 -
Bit 2 -
Bit 1 -
Bit 0 -

Byte2:

Bit Description
Bit 7 0
Bit 6 0
Bit 5 0
Bit 4 Down button
Bit 3 Up button
Bit 2 Task button
Bit 1 ??? button
Bit 0 ??? button

4. Wheel Data

When X-overflow bit is 1(Byte0 == 0xC8|3-buttons) and Byte1 is 0xD6 or 0xDE

Wheel movement: 5-bit, -1(0x1F) or 1(0x01) [-15(0x11) to 15(0x0F) in theory]

Byte1:

Bit Description
Bit 7 1
Bit 6 1
Bit 5 0
Bit 4 1
Bit 3 -
Bit 2 1
Bit 1 1
Bit 0 0

Byte2:

Bit Description
Bit 7 0/1 (1 if horizontal)
Bit 6 1 = virtual scroll by Up/Down button
Bit 5 0
Bit 4 0
Bit 3 Wheel-sign
Bit 2 Wheel-2
Bit 1 Wheel-1
Bit 0 Wheel-0

PS/2 Mouse Commands

FF - Reset

FE - Resend

F6 - Set Defaults

F5 - Disable Device

F4 - Enable Device

F3 - Set Sampling Rate

Set mouse sample rate in Hz.

Param: {10d, 20d, 40d, 60d, 80d, 100d, 200d}

F2 - Read Mouse ID

The reply is a single byte 00. Wait at least 10ms after issuing this command. BallPoint (trackball) devices return a single byte 02, Intellimouse returns 03, Explorer Mouse returns 04, 4d Mouse returns 06, 4dplus Mouse returns 08,as does the Typhoon mouse.

F0 - Remote Mode

EB - Read Data

EA - Stream Mode

E9 - Read Status

Responds with 3-byte status report.

Byte0:

Bit Description
Bit 7 0 = Always (Reserved for future use)
Bit 6 0 = Stream mode / 1 = Remote mode
Bit 5 0 = Disable / 1 = Enable
Bit 4 0 = Scaling 1:1 / 1 = Scaling 2:1
Bit 3 0 = Always (Reserved for future use)
Bit 2 1 = Left button depressed
Bit 1 1 = Middle button depressed
Bit 0 1 = Right button depressed

Byte 1: Current resolution setting (Same format as second byte of ”E8” command)

Byte 2: Current sampling rate (Same format as second byte of ”F3” command)

E8 - Set Resolution

This command is followed by a byte indicating the resolution (0, 1, 2, 3: 1, 2, 4, 8 units per mm, respectively).

Param: {00, 01, 02, 03}

E7 - Set Scaling 2:1

E6 - Set Scaling 1:1

Clone this wiki locally