Sat Aug 31 02:14:51 2019 UTC ()
fix Kensington Turbo Mouse support properly
- program the buttons sanely ( as left & right mouse buttons, no toggles and
  no ridiculous debounce delay either ) - apparently the init values were
  cargo culted from cthulhu knows where
- don't fudge buttons anymore, now that they behave sanely
- add comments on what I could figure out the init command actually does
- leave in code to find checksum values for init commands, at least until I
  can figure out what exactly the checksum is
Todo: deal with models that have more than 2 buttons, figure out what the rest
      of the init command does


(macallan)
diff -r1.17 -r1.18 src/sys/dev/adb/adb_ms.c

cvs diff -r1.17 -r1.18 src/sys/dev/adb/adb_ms.c (expand / switch to unified diff)

--- src/sys/dev/adb/adb_ms.c 2019/08/30 19:24:03 1.17
+++ src/sys/dev/adb/adb_ms.c 2019/08/31 02:14:51 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: adb_ms.c,v 1.17 2019/08/30 19:24:03 macallan Exp $ */ 1/* $NetBSD: adb_ms.c,v 1.18 2019/08/31 02:14:51 macallan Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1998 Colin Wood 4 * Copyright (C) 1998 Colin Wood
5 * Copyright (C) 2006, 2007 Michael Lorenz 5 * Copyright (C) 2006, 2007 Michael Lorenz
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -22,27 +22,27 @@ @@ -22,27 +22,27 @@
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */ 32 */
33 33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35__KERNEL_RCSID(0, "$NetBSD: adb_ms.c,v 1.17 2019/08/30 19:24:03 macallan Exp $"); 35__KERNEL_RCSID(0, "$NetBSD: adb_ms.c,v 1.18 2019/08/31 02:14:51 macallan Exp $");
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/device.h> 38#include <sys/device.h>
39#include <sys/fcntl.h> 39#include <sys/fcntl.h>
40#include <sys/poll.h> 40#include <sys/poll.h>
41#include <sys/select.h> 41#include <sys/select.h>
42#include <sys/proc.h> 42#include <sys/proc.h>
43#include <sys/signalvar.h> 43#include <sys/signalvar.h>
44#include <sys/systm.h> 44#include <sys/systm.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/sysctl.h> 46#include <sys/sysctl.h>
47 47
48#include <machine/autoconf.h> 48#include <machine/autoconf.h>
@@ -316,38 +316,92 @@ adbms_init_uspeed(struct adbms_softc *sc @@ -316,38 +316,92 @@ adbms_init_uspeed(struct adbms_softc *sc
316 */ 316 */
317 adbms_send_sync(sc, cmd, 4, buffer); 317 adbms_send_sync(sc, cmd, 4, buffer);
318 318
319 sc->sc_buttons = 3; 319 sc->sc_buttons = 3;
320 sc->sc_res = 200; 320 sc->sc_res = 200;
321} 321}
322 322
323static void 323static void
324adbms_init_turbo(struct adbms_softc *sc) 324adbms_init_turbo(struct adbms_softc *sc)
325{ 325{
326 uint8_t addr; 326 uint8_t addr;
327 327
328 /* Found Kensington Turbo Mouse */ 328 /* Found Kensington Turbo Mouse */
 329
 330/*
 331 * byte 1 assigns what which button does
 332 - 0x08 - button 1 - 1, button 2 - nothing
 333 - 0x09 - both buttons - 1
 334 - 0x0a - butoon 1 - 1, button 2 - toggle 1
 335 - 0x0b - button 1 - 1, button 2 - nothing
 336 - 0x0c - button 1 - 1, button 2 - 2
 337 - 0x0e - button 1 - 1, button 2 - 3
 338 - 0x0f - button 1 - 1, button 2 - toggle 3
 339 - 0x10 - button 1 toggle 1, button 2 nothing
 340 - 0x11 - button 1 - toggle 1, button 2 - 1
 341 - 0x12 - both toggle 1
 342 - 0x14 - button 1 toggle 1, button 2 - 2
 343 - 0x21 - button 1 - 2, button 2 - 1
 344 - 0x31 - button 1 - 3, button 2 - 1
 345 * byte 4 programs a delay for button presses, apparently in 1/100 seconds
 346 * byte 7 is some sort of checksum, writes will only stick if it's valid
 347 no idea how exactly it works yet, can't be too complicated considering
 348 the device's age
 349 */
 350
 351/*
 352 * XXX
 353 * I doubt the first command is actually necessary. Leave in for now since it
 354 * doesn't do any harm either
 355 */
329 static u_char data1[] = 356 static u_char data1[] =
330 { 0xe7, 0x8c, 0, 0, 0, 0xff, 0xff, 0x94 }; 357 { 0xe7, 0x8c, 0, 0, 0, 0xff, 0xff, 0x94 };
 358
 359 /* this seems to be the most reasonable default */
331 static u_char data2[] = 360 static u_char data2[] =
332 { 0xa5, 0x14, 0, 0, 0x69, 0xff, 0xff, 0x27 }; 361 { 0xa5, 0x0e, 0, 0, 1, 0xff, 0xff, 0x55 };
333 362
334 addr = sc->sc_adbdev->current_addr; 363 addr = sc->sc_adbdev->current_addr;
335 364
 365#ifdef ADBMS_DEBUG
 366 {
 367 int i;
 368 adbms_send_sync(sc, ADBTALK(addr, 2), 0, NULL);
 369 printf("reg *");
 370 for (i = 0; i < sc->sc_msg_len; i++)
 371 printf(" %02x", sc->sc_buffer[i]);
 372 printf("\n");
 373 }
 374#endif
 375
336 adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL); 376 adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL);
337 adbms_send_sync(sc, ADBLISTEN(addr, 2), 8, data1); 377 adbms_send_sync(sc, ADBLISTEN(addr, 2), 8, data1);
338 adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL); 378 adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL);
339 adbms_send_sync(sc, ADBLISTEN(addr, 2), 8, data2); 379 adbms_send_sync(sc, ADBLISTEN(addr, 2), 8, data2);
340 380
 381#ifdef ADBMS_BRUTEFORCE
 382 sc->sc_buffer[1] = 0;
 383 int y = 0;
 384 while ((sc->sc_buffer[1] != data2[1]) && (y < 0x100)) {
 385 data2[7] = y;
 386 y++;
 387 adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL);
 388 adbms_send_sync(sc, ADBLISTEN(addr, 2), 8, data2);
 389 adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL);
 390 adbms_send_sync(sc, ADBTALK(addr, 2), 0, NULL);
 391 }
 392 printf("y %02x\n", data2[7]);
 393#endif
 394
341#ifdef ADBMS_DEBUG 395#ifdef ADBMS_DEBUG
342 int i, reg; 396 int i, reg;
343 for (reg = 1; reg < 4; reg++) { 397 for (reg = 1; reg < 4; reg++) {
344 adbms_send_sync(sc, ADBTALK(addr, reg), 0, NULL); 398 adbms_send_sync(sc, ADBTALK(addr, reg), 0, NULL);
345 printf("reg %d", reg); 399 printf("reg %d", reg);
346 for (i = 0; i < sc->sc_msg_len; i++) 400 for (i = 0; i < sc->sc_msg_len; i++)
347 printf(" %02x", sc->sc_buffer[i]); 401 printf(" %02x", sc->sc_buffer[i]);
348 printf("\n"); 402 printf("\n");
349 } 403 }
350#endif 404#endif
351} 405}
352 406
353static void 407static void
@@ -597,29 +651,26 @@ adbms_process_event(struct adbms_softc * @@ -597,29 +651,26 @@ adbms_process_event(struct adbms_softc *
597 dx |= (ddx << shift); 651 dx |= (ddx << shift);
598 dy |= (ddy << shift); 652 dy |= (ddy << shift);
599 shift += 3; 653 shift += 3;
600 } 654 }
601 sign = 1 << (shift - 1); 655 sign = 1 << (shift - 1);
602 smask = 0xffffffff << shift; 656 smask = 0xffffffff << shift;
603 if (dx & sign) 657 if (dx & sign)
604 dx |= smask; 658 dx |= smask;
605 if (dy & sign) 659 if (dy & sign)
606 dy |= smask; 660 dy |= smask;
607#ifdef ADBMS_DEBUG 661#ifdef ADBMS_DEBUG
608 printf("%d %d %08x %d\n", dx, dy, smask, shift); 662 printf("%d %d %08x %d\n", dx, dy, smask, shift);
609#endif 663#endif
610 if (sc->sc_adbdev->handler_id == ADBMS_TURBO) { 
611 buttons = (buttons != 0) ? 1 : 0; 
612 } 
613 } 664 }
614 665
615 if (sc->sc_class == MSCLASS_TRACKPAD) { 666 if (sc->sc_class == MSCLASS_TRACKPAD) {
616 667
617 if (sc->sc_tapping == 1) { 668 if (sc->sc_tapping == 1) {
618 if (sc->sc_down) { 669 if (sc->sc_down) {
619 /* finger is down - collect motion data */ 670 /* finger is down - collect motion data */
620 sc->sc_x += dx; 671 sc->sc_x += dx;
621 sc->sc_y += dy; 672 sc->sc_y += dy;
622 } 673 }
623 DPRINTF("buttons: %02x\n", buttons); 674 DPRINTF("buttons: %02x\n", buttons);
624 switch (sc->sc_buttons) { 675 switch (sc->sc_buttons) {
625 case 2: 676 case 2: