2 #include "../port/lib.h"
6 #include "../port/error.h"
25 extern int mouseshifted;
27 static QLock mousectlqlock;
29 static int intellimouse;
30 static int packetsize;
31 static int resolution;
32 static int accelerated;
33 static int mousehwaccel;
34 static char mouseport[5];
49 static Cmdtab mousectlmsg[] =
51 CMaccelerated, "accelerated", 0,
52 CMhwaccel, "hwaccel", 2,
53 CMintellimouse, "intellimouse", 1,
54 CMlinear, "linear", 1,
56 CMps2intellimouse, "ps2intellimouse", 1,
59 CMserial, "serial", 0,
63 * ps/2 mouse message is three bytes
65 * byte 0 - 0 0 SDY SDX 1 M R L
69 * shift & right button is the same as middle button
71 * Intellimouse and AccuPoint with extra buttons deliver
72 * byte 3 - 00 or 01 or FF according to extra button state.
73 * extra buttons are mapped in this code to buttons 4 and 5.
74 * AccuPoint generates repeated events for these buttons;
75 * it and Intellimouse generate 'down' events only, so
76 * user-level code is required to generate button 'up' events
77 * if they are needed by the application.
78 * Also on laptops with AccuPoint AND external mouse, the
79 * controller may deliver 3 or 4 bytes according to the type
80 * of the external mouse; code must adapt.
82 * On the NEC Versa series (and perhaps others?) we seem to
83 * lose a byte from the packet every once in a while, which
84 * means we lose where we are in the instruction stream.
85 * To resynchronize, if we get a byte more than two seconds
86 * after the previous byte, we assume it's the first in a packet.
89 ps2mouseputc(int c, int shift)
93 static uchar b[] = {0, 1, 4, 5, 2, 3, 6, 7, 0, 1, 2, 3, 2, 3, 6, 7 };
94 static ulong lasttick;
99 * non-ps2 keyboards might not set shift
100 * but still set mouseshifted.
102 shift |= mouseshifted;
104 * Resynchronize in stream with timing; see comment above.
107 if(TK2SEC(m - lasttick) > 2)
112 * check byte 0 for consistency
114 if(nb==0 && (c&0xc8)!=0x08)
115 if(intellimouse && (c==0x00 || c==0x01 || c==0xFF)){
116 /* last byte of 4-byte packet */
122 if(++nb == packetsize){
129 buttons = b[(msg[0]&7) | (shift ? 8 : 0)];
130 if(intellimouse && packetsize==4){
131 if((msg[3]&0xc8) == 0x08){
132 /* first byte of 3-byte packet */
136 /* fall through to emit previous packet */
138 /* The AccuPoint on the Toshiba 34[48]0CT
139 * encodes extra buttons as 4 and 5. They repeat
140 * and don't release, however, so user-level
141 * timing code is required. Furthermore,
142 * intellimice with 3buttons + scroll give a
143 * two's complement number in the lower 4 bits
144 * (bit 4 is sign extension) that describes
145 * the amount the scroll wheel has moved during
146 * the last sample. Here we use only the sign to
147 * decide whether the wheel is moving up or down
148 * and generate a single button 4 or 5 click
151 if((msg[3] >> 3) & 1)
153 else if(msg[3] & 0x7)
159 mousetrack(dx, dy, buttons, TK2MS(MACHP(0)->ticks));
170 if(mousetype == MousePS2)
173 i8042auxenable(ps2mouseputc);
174 /* make mouse streaming, enabled */
178 mousetype = MousePS2;
184 * The PS/2 Trackpoint multiplexor on the IBM Thinkpad T23 ignores
185 * acceleration commands. It is supposed to pass them on
186 * to the attached device, but my Logitech mouse is simply
187 * not behaving any differently. For such devices, we allow
188 * the user to use "hwaccel off" to tell us to back off to
189 * software acceleration even if we're using the PS/2 port.
190 * (Serial mice are always software accelerated.)
191 * For more information on the Thinkpad multiplexor, see
192 * http://wwwcssrv.almaden.ibm.com/trackpoint/
195 setaccelerated(int x)
235 setintellimouse(void)
241 i8042auxcmd(0xF3); /* set sample */
243 i8042auxcmd(0xF3); /* set sample */
245 i8042auxcmd(0xF3); /* set sample */
249 i8250setmouseputc(mouseport, m5mouseputc);
261 i8042auxcmd(0xEA); /* streaming */
262 i8042auxcmd(0xE8); /* set resolution */
264 i8042auxcmd(0xF4); /* enabled */
274 qlock(&mousectlqlock);
276 qunlock(&mousectlqlock);
280 ct = lookupcmd(cb, mousectlmsg, nelem(mousectlmsg));
283 setaccelerated(cb->nf == 1 ? 1 : atoi(cb->f[1]));
295 case CMps2intellimouse:
301 setres(atoi(cb->f[1]));
308 setaccelerated(accelerated);
315 if(mousetype == Mouseserial)
319 if(strcmp(cb->f[2], "M") == 0)
320 i8250mouse(cb->f[1], m3mouseputc, 0);
321 else if(strcmp(cb->f[2], "MI") == 0)
322 i8250mouse(cb->f[1], m5mouseputc, 0);
324 i8250mouse(cb->f[1], mouseputc, cb->nf == 1);
326 i8250mouse(cb->f[1], mouseputc, cb->nf == 1);
328 mousetype = Mouseserial;
329 strncpy(mouseport, cb->f[1], sizeof(mouseport)-1);
333 if(strcmp(cb->f[1], "on")==0)
335 else if(strcmp(cb->f[1], "off")==0)
338 cmderror(cb, "bad mouse control message");
341 qunlock(&mousectlqlock);