Serial Mice Protocols
I remembered there was such a thing as a serial mouse and I wondered how they worked. A bit of googling found me this link (which as of this posting has an SSL error). I'm going to reproduce it below but I wanted to write some notes about it first.
- The Microsoft Serial Mouse was the most popular mouse as of 1997, supported by and probably copied by all.
- The "resolution" was around 400-1000 CPI (counts per inch) compared to a gaming mouse today of around 16,000k. This had to do with internal buffering and the speed it updated the location of the movement to the computer.
- It could send 40 reports per second, where a report is a 3 byte update describing buttons and x and y changes.
- The original packet format is similar to midi. Each packet is a known length (3 bytes). For some unknown reason the first bit of each byte is ignored. The second bit is used for synchronizing packets. The first byte has the 2nd bit 1, and the following two have it 0.
- Because each byte only has 6 bits of usable data, they split the first two bits of each X and Y report off into the first byte. (See the awesome ascii art in the document below.) This gives 8 bits of data for each X and Y movement in each report (Represented as a signed integer.)
- Logitech expanded the format to 5 bytes (without wasting space) to support their 3 button mice.
- PS2 Also supported 3 buttons and didn't waste space. It was a bit faster as a standard too.
- I missed that baud rate was mentioned in the article. I guessed 40 reports a second at 3 bytes a report is 960 bps (bits per second) which might have been (at 4 bits per baud) a baud rate of 240. But it's clearly stated "1200bps, 7 databits, 1 stop-bit" for the MS and Logitech mouse and "1200bps, 8 databits, 1 stop-bit" for the Mouse Systems mouse.
This text (which is part of a "not so frequently asked questions" section of that site, which states "The information containted in these NSFAQ's have no assurance of accuracy other than I would not purposefully put up an inaccurate NSFAQ.") was curated by Paul Borman who copied this section from a Tomi Engdahl. URLs last only as long as the organizations do and unfortunately many of these links predate the wayback machine. None of the references currently exist however a few were thankfully archived their links have been changed to the archives.
Full text of Subject: What protocol do mice use? with formatting cleanup follows;
What protocol do mice use?
Subject: What protocol do mice use? Date: 09/16/97 Updated: 11/16/00
This document was adapted from a web page produced by Tomi Engdahl <firstname.lastname@example.org>.
Microsoft serial mouse
9 pin 25 pin Line Comments shell 1 GND 3 2 TD Serial data from host to mouse (only for power) 2 3 RD Serial data from mouse to host 7 4 RTS Positive voltage to mouse 8 5 CTS 6 6 DSR 5 7 SGND 4 20 DTR Positive voltage to mouse and reset/detection RTS = Request to Send CTS = Clear to Send DSR = Data Set Ready DTR = Data Terminal Ready GND = Protective Ground SGND = Signal Ground
Serial data parameters:
1200bps, 7 databits, 1 stop-bit
Data packet format:
Data is sent in 3 byte packets for each event (a button is pressed or released or the mouse moves):
D7 D6 D5 D4 D3 D2 D1 D0 Byte 1 X 1 LB RB Y7 Y6 X7 X6 Byte 2 X 0 X5 X4 X3 X2 X1 X0 Byte 3 X 0 Y5 Y4 Y3 Y2 Y1 Y0 LB is the state of the left button (1 means down) RB is the state of the right button (1 means down) X7-X0 movement in X direction since last packet (signed byte) Y7-Y0 movement in Y direction since last packet (signed byte)
The high order bit of each byte (D7) is ignored. Bit D6 indicates the start of an event, which allows the software to synchronize with the mouse.
Graphical representation of a packet
1st byte 2nd byte 3rd byte ================ =============== ================ - 1 ? ? Y Y X X - 0 X X X X X X - 0 Y Y Y Y Y Y ================ =============== ================ | | \ / \ / \---------/ \---------/ | | | | | | | | | \----\ | | | | \--------|-------|--------\ | | | / \ /---------\ / \ /---------\ | | ================ ================= | | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Left Button --/ | ================ ================= Right Button ----/ X increment Y increment
3 Button Logitech extension
Mouse systems mouse
Serial data parameters:
1200bps, 8 databits, 1 stop-bit
5 byte Mouse Systems packet
D7 D6 D5 D4 D3 D2 D1 D0 Byte 1 1 0 0 0 0 LB CB RB Byte 2 X7 X6 X5 X4 X3 X2 X1 X0 Byte 3 Y7 Y6 Y5 Y4 Y3 Y4 Y1 Y0 Byte 4 X7' X6' X5' X4' X3' X2' X1' X0' Byte 5 Y7' Y6' Y5' Y4' Y3' Y4' Y1' Y0' LB is left button state (0=pressed, 1=released) CB is center button state (0=pressed, 1=released) RB is right button state (0=pressed, 1=released) X7-X0 movement in X direction since last packet in signed byte format (-128..+127), positive direction right Y7-Y0 movement in Y direction since last packet in signed byte format (-128..+127), positive direction up X7'-X0' movement in X direction since sending of X7-X0 packet in signed byte format (-128..+127), positive direction right Y7'-Y0' movement in Y direction since sending of Y7-Y0 in signed byte format (-128..+127), positive direction up
The last two bytes in the packet (bytes 4 and 5) contain information about movement data changes which have occurred after data bytes 2 and 3 have been sent.
The standard PS/2 mouse (such as the Logitech mouse) defaults to 160 CPI and can be switched to 40, 80, 160 or 320 CPI via software. The Microsoft mouse driver for Windows 3.x and Windows 95 defaults to 160 counts per inch. The maximum tracking rate for PS/2 mouse is 40 reports/second * 255 counts per report, or 10200 counts per second. A 100 CPI mouse could discriminate motion up to 102 inches per second while a 400 CPI mouse could discriminate motion up to 25.2 inches per second.
Pin Wire Name 1 DATA 2 Reserved 3 Ground 4 +5V Supply 5 CLK 6 Reserved Shield Chassis
D7 D6 D5 D4 D3 D2 D1 D0 Byte 1 XV XV YS XS 1 M R L Byte 2 X7 X6 X5 X4 X3 X2 X1 X0 Byte 3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 L Left button state (1 = pressed down) M Middle button state (1 = pressed down) R Right button state (1 = pressed down) X0-X7 Movement in X direction Y0-Y7 Movement in Y direction XS,YS Movement data sign bits (1 = negative) XV,YV Movement data overflow bits (1 = overflow has occurred)
The PS/2 mouse connector has the following pinout when looking at the connector on the back of the computer:
4 u 6 1 . 2 3 5 1. GND 2. +5V 3. DATA 4. CLOCK 5. Not used 6. Not used