Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Apr 2007 19:08:19 GMT
From:      Rui Paulo <rpaulo@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 118538 for review
Message-ID:  <200704211908.l3LJ8Jn0045560@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=118538

Change 118538 by rpaulo@rpaulo_epsilon on 2007/04/21 19:07:22

	Apple's Mighty Mouse modifications that I submitted in PR
	usb/110357.

Affected files ...

.. //depot/projects/soc2007/rpaulo-macbook/dev/usb/ums.c#2 edit

Differences ...

==== //depot/projects/soc2007/rpaulo-macbook/dev/usb/ums.c#2 (text+ko) ====

@@ -104,7 +104,7 @@
 	u_char *sc_ibuf;
 	u_int8_t sc_iid;
 	int sc_isize;
-	struct hid_location sc_loc_x, sc_loc_y, sc_loc_z, sc_loc_t;
+	struct hid_location sc_loc_x, sc_loc_y, sc_loc_z, sc_loc_t, sc_loc_w;
 	struct hid_location *sc_loc_btn;
 
 	usb_callout_t callout_handle;	/* for spurious button ups */
@@ -116,6 +116,7 @@
 #define UMS_Z		0x01	/* z direction available */
 #define UMS_SPUR_BUT_UP	0x02	/* spurious button up events */
 #define UMS_T		0x04	/* aa direction available (tilt) */
+#define UMS_REVZ	0x08	/* Z-axis is reversed */
 	int nbuttons;
 #define MAX_BUTTONS	31	/* chosen because sc_buttons is int */
 
@@ -209,7 +210,7 @@
 	usbd_status err;
 	char devinfo[1024];
 	u_int32_t flags;
-	int i;
+	int i, wheel;
 	struct hid_location loc_btn;
 
 	sc->sc_disconnected = 1;
@@ -266,13 +267,41 @@
 		USB_ATTACH_ERROR_RETURN;
 	}
 
-	/* try to guess the Z activator: first check Z, then WHEEL */
-	if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z),
-		       hid_input, &sc->sc_loc_z, &flags) ||
-	    hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL),
-		       hid_input, &sc->sc_loc_z, &flags) ||
-	    hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_TWHEEL),
-		       hid_input, &sc->sc_loc_z, &flags)) {
+        /* Try the wheel first as the Z activator since it's tradition. */
+	wheel = hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP,
+						  HUG_WHEEL),
+			   hid_input, &sc->sc_loc_z, &flags);
+
+	if (wheel) {
+		if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
+			printf("\n%s: Wheel report 0x%04x not supported\n",
+			       device_get_nameunit(sc->sc_dev), flags);
+			sc->sc_loc_z.size = 0;     /* Bad Z coord, ignore it */
+		} else {
+			sc->flags |= UMS_Z;
+			if (usbd_get_quirks(uaa->device)->uq_flags &
+			    UQ_MS_REVZ) {
+				/* Some wheels need the Z axis reversed. */
+				sc->flags |= UMS_REVZ;
+			}
+
+		}
+		/*
+		 * We might have both a wheel and Z direction, if so put
+		 * put the Z on the W coordinate.
+		 */
+		if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP,
+						      HUG_Z),
+			       hid_input, &sc->sc_loc_w, &flags)) {
+			if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
+				printf("\n%s: Z report 0x%04x not supported\n",
+				       device_get_nameunit(sc->sc_dev), flags);
+				sc->sc_loc_w.size = 0;     /* Bad Z, ignore */
+			}
+		}
+	} else if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP,
+						     HUG_Z),
+			      hid_input, &sc->sc_loc_z, &flags)) {
 		if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) {
 			sc->sc_loc_z.size = 0;	/* Bad Z coord, ignore it */
 		} else {
@@ -424,7 +453,7 @@
 {
 	struct ums_softc *sc = addr;
 	u_char *ibuf;
-	int dx, dy, dz, dt;
+	int dx, dy, dz, dt, dw;
 	int buttons = 0;
 	int i;
 
@@ -474,6 +503,9 @@
 	dx =  hid_get_data(ibuf, &sc->sc_loc_x);
 	dy = -hid_get_data(ibuf, &sc->sc_loc_y);
 	dz = -hid_get_data(ibuf, &sc->sc_loc_z);
+        dw =  hid_get_data(ibuf, &sc->sc_loc_w);
+        if (sc->flags & UMS_REVZ)
+                dz = -dz;
 	if (sc->flags & UMS_T)
 		dt = -hid_get_data(ibuf, &sc->sc_loc_t);
 	else
@@ -482,17 +514,18 @@
 		if (hid_get_data(ibuf, &sc->sc_loc_btn[i]))
 			buttons |= (1 << UMS_BUT(i));
 
-	if (dx || dy || dz || dt || (sc->flags & UMS_Z)
+	if (dx || dy || dz || dt || dw || (sc->flags & UMS_Z)
 	    || buttons != sc->status.button) {
-		DPRINTFN(5, ("ums_intr: x:%d y:%d z:%d t:%d buttons:0x%x\n",
-			dx, dy, dz, dt, buttons));
+		DPRINTFN(5, ("ums_intr: x:%d y:%d z:%d t:%d w:%w buttons:0x%x\n",
+			dx, dy, dz, dt, dw, buttons));
 
 		sc->status.button = buttons;
 		sc->status.dx += dx;
 		sc->status.dy += dy;
 		sc->status.dz += dz;
 		/* sc->status.dt += dt;*/ /* no way to export this yet */
-		
+		/* sc->status.dw += dw; */ /* idem */
+
 		/* Discard data in case of full buffer */
 		if (sc->qcount == sizeof(sc->qbuf)) {
 			DPRINTF(("Buffer full, discarded packet"));



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200704211908.l3LJ8Jn0045560>