Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/adb now that I figured out how the checksum for the ...
details: https://anonhg.NetBSD.org/src/rev/45f334f6e1ed
branches: trunk
changeset: 965204:45f334f6e1ed
user: macallan <macallan%NetBSD.org@localhost>
date: Thu Sep 05 21:29:22 2019 +0000
description:
now that I figured out how the checksum for the Kensington Turbo Mouse's
init command works:
- document it
- calculate the checksum instead of hardcoding it, so the init command can be
easily changed
- drop the first init string - it's entirely overwritten by the 2nd
- remove some debug goop
diffstat:
sys/dev/adb/adb_ms.c | 49 ++++++++++++++++++-------------------------------
1 files changed, 18 insertions(+), 31 deletions(-)
diffs (88 lines):
diff -r f6dd38f74ea7 -r 45f334f6e1ed sys/dev/adb/adb_ms.c
--- a/sys/dev/adb/adb_ms.c Thu Sep 05 20:17:27 2019 +0000
+++ b/sys/dev/adb/adb_ms.c Thu Sep 05 21:29:22 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: adb_ms.c,v 1.18 2019/08/31 02:14:51 macallan Exp $ */
+/* $NetBSD: adb_ms.c,v 1.19 2019/09/05 21:29:22 macallan Exp $ */
/*
* Copyright (C) 1998 Colin Wood
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: adb_ms.c,v 1.18 2019/08/31 02:14:51 macallan Exp $");
+__KERNEL_RCSID(0, "$NetBSD: adb_ms.c,v 1.19 2019/09/05 21:29:22 macallan Exp $");
#include <sys/param.h>
#include <sys/device.h>
@@ -320,6 +320,16 @@
sc->sc_res = 200;
}
+static int
+adbms_turbo_csum(uint8_t *d)
+{
+ int i = 0, sum = 0;
+
+ for (i = 0; i < 7; i++)
+ sum ^= d[i];
+ return (sum ^ 0xff);
+}
+
static void
adbms_init_turbo(struct adbms_softc *sc)
{
@@ -343,22 +353,13 @@
- 0x21 - button 1 - 2, button 2 - 1
- 0x31 - button 1 - 3, button 2 - 1
* byte 4 programs a delay for button presses, apparently in 1/100 seconds
- * byte 7 is some sort of checksum, writes will only stick if it's valid
- no idea how exactly it works yet, can't be too complicated considering
- the device's age
+ * byte 7 is a simple XOR checksum, writes will only stick if it's valid
+ as in, b[7] = (b[0] ^ b[1] ^ ... ^ b[6]) ^ 0xff
*/
-/*
- * XXX
- * I doubt the first command is actually necessary. Leave in for now since it
- * doesn't do any harm either
- */
- static u_char data1[] =
- { 0xe7, 0x8c, 0, 0, 0, 0xff, 0xff, 0x94 };
-
/* this seems to be the most reasonable default */
- static u_char data2[] =
- { 0xa5, 0x0e, 0, 0, 1, 0xff, 0xff, 0x55 };
+ static u_char data[] =
+ { 0xa5, 0x0e, 0, 0, 1, 0xff, 0xff, 0/*0x55*/ };
addr = sc->sc_adbdev->current_addr;
@@ -374,23 +375,9 @@
#endif
adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL);
- adbms_send_sync(sc, ADBLISTEN(addr, 2), 8, data1);
- adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL);
- adbms_send_sync(sc, ADBLISTEN(addr, 2), 8, data2);
+ data[7] = adbms_turbo_csum(data);
+ adbms_send_sync(sc, ADBLISTEN(addr, 2), 8, data);
-#ifdef ADBMS_BRUTEFORCE
- sc->sc_buffer[1] = 0;
- int y = 0;
- while ((sc->sc_buffer[1] != data2[1]) && (y < 0x100)) {
- data2[7] = y;
- y++;
- adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL);
- adbms_send_sync(sc, ADBLISTEN(addr, 2), 8, data2);
- adbms_send_sync(sc, ADBFLUSH(addr), 0, NULL);
- adbms_send_sync(sc, ADBTALK(addr, 2), 0, NULL);
- }
- printf("y %02x\n", data2[7]);
-#endif
#ifdef ADBMS_DEBUG
int i, reg;
Home |
Main Index |
Thread Index |
Old Index