1 | # |
---|
2 | # $Id$ |
---|
3 | # |
---|
4 | |
---|
5 | SOURCE: http://www.kryslix.com/nsfaq/Q.12.html |
---|
6 | |
---|
7 | Subject: What protocol do mice use? |
---|
8 | Date: 09/16/97 |
---|
9 | Updated: 11/16/00 This document was adapated from a web page produced by |
---|
10 | Tomi Engdahl <then@delta.hut.fi> |
---|
11 | Microsoft serial mouse |
---|
12 | Description |
---|
13 | |
---|
14 | The Microsoft serial mouse is the most popular 2 button mouse. It is |
---|
15 | supported by all major operating systems. The maximum tracking rate for |
---|
16 | a Microsoft mouse is 40 reports/second * 127 counts per report, in other |
---|
17 | words, 5080 counts per second. The most common range for mice is is 100 |
---|
18 | to 400 CPI (counts per inch) but can be up to 1000 CPI. A 100CPI mouse |
---|
19 | can discriminate motion up to 50.8 inches/second while a 400 CPI mouse |
---|
20 | can only discriminate motion up to 12.7 inches/second. |
---|
21 | Pinout |
---|
22 | |
---|
23 | 9 pin 25 pin Line Comments |
---|
24 | shell 1 GND |
---|
25 | 3 2 TD Serial data from host to mouse (only for power) |
---|
26 | 2 3 RD Serial data from mouse to host |
---|
27 | 7 4 RTS Positive voltage to mouse |
---|
28 | 8 5 CTS |
---|
29 | 6 6 DSR |
---|
30 | 5 7 SGND |
---|
31 | 4 20 DTR Positive voltage to mouse and reset/detection |
---|
32 | |
---|
33 | RTS = Request to Send CTS = Clear to Send |
---|
34 | DSR = Data Set Ready DTR = Data Terminal Ready |
---|
35 | GND = Protective Ground SGND = Signal Ground |
---|
36 | |
---|
37 | To function correctly, both the RTS and DTR lines must be |
---|
38 | positive. DTR/DSR and RTS/CTS must NOT be shorted. RTS may be toggled |
---|
39 | negative for at least 100ms to reset the mouse. (After a cold boot, the |
---|
40 | RTS line is usually negative. This provides an automatic toggle when |
---|
41 | RTS is brought positive). When DTR is toggled the mouse should send a |
---|
42 | single byte 0x45 (ASCII 'M'). |
---|
43 | |
---|
44 | Serial data parameters: |
---|
45 | 1200bps, 7 databits, 1 stop-bit |
---|
46 | |
---|
47 | Data packet format: |
---|
48 | |
---|
49 | Data is sent in 3 byte packets for each event (a button is pressed or |
---|
50 | released or the mouse moves): |
---|
51 | |
---|
52 | D7 D6 D5 D4 D3 D2 D1 D0 |
---|
53 | |
---|
54 | Byte 1 X 1 LB RB Y7 Y6 X7 X6 |
---|
55 | Byte 2 X 0 X5 X4 X3 X2 X1 X0 |
---|
56 | Byte 3 X 0 Y5 Y4 Y3 Y2 Y1 Y0 |
---|
57 | |
---|
58 | LB is the state of the left button (1 means down) |
---|
59 | RB is the state of the right button (1 means down) |
---|
60 | X7-X0 movement in X direction since last packet (signed byte) |
---|
61 | Y7-Y0 movement in Y direction since last packet (signed byte) |
---|
62 | |
---|
63 | 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. |
---|
64 | |
---|
65 | Graphical representation of a packet |
---|
66 | |
---|
67 | 1st byte 2nd byte 3rd byte |
---|
68 | ================ =============== ================ |
---|
69 | - 1 ? ? Y Y X X - 0 X X X X X X - 0 Y Y Y Y Y Y |
---|
70 | ================ =============== ================ |
---|
71 | | | \ / \ / \---------/ \---------/ |
---|
72 | | | | | | | |
---|
73 | | | | \----\ | | |
---|
74 | | | \--------|-------|--------\ | |
---|
75 | | | / \ /---------\ / \ /---------\ |
---|
76 | | | ================ ================= |
---|
77 | | | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
---|
78 | Left Button --/ | ================ ================= |
---|
79 | Right Button ----/ X increment Y increment |
---|
80 | |
---|
81 | 3 Button Logitech extension |
---|
82 | |
---|
83 | Logitech extended the 2 button mouse protocol to support 3 button mice |
---|
84 | by adding a 4th byte when the middle button is pressed (and the first |
---|
85 | packet after it is released). If a 4th byte is encountered (i.e., an |
---|
86 | extra byte with D6 set to 0) then D5 of that byte (0x20) indicates the |
---|
87 | status of the middle mouse button. |
---|
88 | |
---|
89 | Mouse systems mouse |
---|
90 | |
---|
91 | Serial data parameters: |
---|
92 | |
---|
93 | 1200bps, 8 databits, 1 stop-bit |
---|
94 | |
---|
95 | 5 byte Mouse Systems packet |
---|
96 | |
---|
97 | D7 D6 D5 D4 D3 D2 D1 D0 |
---|
98 | |
---|
99 | Byte 1 1 0 0 0 0 LB CB RB |
---|
100 | Byte 2 X7 X6 X5 X4 X3 X2 X1 X0 |
---|
101 | Byte 3 Y7 Y6 Y5 Y4 Y3 Y4 Y1 Y0 |
---|
102 | Byte 4 X7' X6' X5' X4' X3' X2' X1' X0' |
---|
103 | Byte 5 Y7' Y6' Y5' Y4' Y3' Y4' Y1' Y0' |
---|
104 | |
---|
105 | LB is left button state (0=pressed, 1=released) |
---|
106 | CB is center button state (0=pressed, 1=released) |
---|
107 | RB is right button state (0=pressed, 1=released) |
---|
108 | X7-X0 movement in X direction since last packet in signed byte |
---|
109 | format (-128..+127), positive direction right |
---|
110 | Y7-Y0 movement in Y direction since last packet in signed byte |
---|
111 | format (-128..+127), positive direction up |
---|
112 | X7'-X0' movement in X direction since sending of X7-X0 packet in signed byte |
---|
113 | format (-128..+127), positive direction right |
---|
114 | Y7'-Y0' movement in Y direction since sending of Y7-Y0 in signed byte |
---|
115 | format (-128..+127), positive direction up |
---|
116 | |
---|
117 | The last two bytes in the packet (bytes 4 and 5) contain information |
---|
118 | about movement data changes which have occured after data bytes 2 and |
---|
119 | 3 have been sent. |
---|
120 | |
---|
121 | PS/2 mouse |
---|
122 | |
---|
123 | The standard PS/2 mouse (such as the Logitech mouse) defaults to 160 CPI |
---|
124 | and can be switched to 40, 80, 160 or 320 CPI via software. The Microsoft |
---|
125 | mouse driver for Windows 3.x and Windows 95 defaults to 160 counts per |
---|
126 | inch. The maximum tracking rate for PS/2 mouse is 40 reports/second * |
---|
127 | 255 counts per report, or 10200 counts per second. A 100 CPI mouse could |
---|
128 | discriminate motion up to 102 inches per second while a 400 CPI mouse |
---|
129 | could discriminate motion up to 25.2 inches per second. |
---|
130 | |
---|
131 | Connector pinout |
---|
132 | |
---|
133 | Pin Wire Name |
---|
134 | 1 DATA |
---|
135 | 2 Reserved |
---|
136 | 3 Ground |
---|
137 | 4 +5V Supply |
---|
138 | 5 CLK |
---|
139 | 6 Reserved |
---|
140 | Shield Chassis |
---|
141 | |
---|
142 | Packet Format |
---|
143 | |
---|
144 | D7 D6 D5 D4 D3 D2 D1 D0 |
---|
145 | Byte 1 XV XV YS XS 1 M R L |
---|
146 | Byte 2 X7 X6 X5 X4 X3 X2 X1 X0 |
---|
147 | Byte 3 Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 |
---|
148 | |
---|
149 | L Left button state (1 = pressed down) |
---|
150 | M Middle button state (1 = pressed down) |
---|
151 | R Right button state (1 = pressed down) |
---|
152 | X0-X7 Movement in X direction |
---|
153 | Y0-Y7 Movement in Y direction |
---|
154 | XS,YS Movement data sign bits (1 = negative) |
---|
155 | XV,YV Movement data overflow bits (1 = overflow has occured) |
---|
156 | |
---|
157 | Physical connector |
---|
158 | |
---|
159 | The PS/2 mouse connector has the following pinout when looking at the |
---|
160 | connector on the back of the computer: |
---|
161 | |
---|
162 | 4 u 6 |
---|
163 | 1 . 2 |
---|
164 | 3 5 |
---|
165 | |
---|
166 | 1. GND |
---|
167 | 2. +5V |
---|
168 | 3. DATA |
---|
169 | 4. CLOCK |
---|
170 | 5. Not used |
---|
171 | 6. Not used |
---|
172 | |
---|
173 | Bi-directional transmission is controlled by the CLK and DATA lines. Both |
---|
174 | are fed by an open collector device which lets either host or mouse force |
---|
175 | the line to "0". During non-transmission, CLK is at "1" and DATA can be at |
---|
176 | "0" or "1". |
---|
177 | |
---|
178 | The host can inhibit mouse transmission by forcing CLK to "0". If the |
---|
179 | host inhibits the mouse while it is transmitting, the byte must be |
---|
180 | retransmitted (if the inhibit state arrived before the 11th clock). |
---|
181 | |
---|
182 | Receiving data: Check 'clock'. If inactive, there is a bit on the 'data' |
---|
183 | line. Each transmission unit is one start bit, eight data bits, odd |
---|
184 | parity and one stop bit. Start bits are low, stop bits high. Each clock |
---|
185 | active or inactive period is 30 to 50 microseconds. Data transition to |
---|
186 | falling edge of clock is 5 to 25 microseconds. |
---|
187 | |
---|
188 | Sending: Check that both clock and data are high. Pull down data for |
---|
189 | start bit, and start clocking. |
---|
190 | |
---|
191 | NOTE: Logitech has made the extension to this protocol to allow three |
---|
192 | buttons (the M bit is always 0 on 2 button mice). |
---|
193 | |
---|
194 | References |
---|
195 | |
---|
196 | * Original PC mouse info page by Tomi Engdahl |
---|
197 | http://www.hut.fi/~then/mytexts/mouse.html |
---|
198 | |
---|
199 | * PC Magazine May 28, 1991 |
---|
200 | |
---|
201 | * Programmer's Reference to Genius Mouse |
---|
202 | ftp://x2ftp.oulu.fi/pub/msdos/programming/docs/gmouse.doc |
---|
203 | |
---|
204 | * Logitech Pointing Device Hardware Information Product Support Document # 1410 |
---|
205 | ftp://ftp.logitech.com/pub/TechSupport/MOUSE/HELP/1410.txt |
---|
206 | |
---|
207 | * Mice: How do they work? by Richard Torrens |
---|
208 | http://box.argonet.co.uk/users/4qd/meece.html |
---|
209 | |
---|
210 | * In Pursuit Of The Perfect Portable Pointer by Intelink Electronics |
---|
211 | from EDN Products Edition April 16, 1977 pages 43-45 |
---|
212 | |
---|
213 | * Programming the Microsoft Mouse |
---|
214 | http://www.geocities.com/SiliconValley/2151/mouse.html |
---|