Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-7]: src Pull up following revision(s) (requested by bouyer in tic...



details:   https://anonhg.NetBSD.org/src/rev/1d8f812d19db
branches:  netbsd-7
changeset: 799599:1d8f812d19db
user:      snj <snj%NetBSD.org@localhost>
date:      Thu Oct 15 20:24:30 2015 +0000

description:
Pull up following revision(s) (requested by bouyer in ticket #869):
        share/man/man4/btmagic.4: revisions 1.3-1.6
        sys/dev/bluetooth/btmagic.c: revisions 1.12, 1.14
Add support for Apple Magic Trackpad.
3 button emulation by detecting in which area of the bottom of
the device the trackpad's button is pressed.
Pointer move support with 1 finger touch, X/Y scroll with 2-finger touch.
TODO:
- detect tap to emulate button press and drag/n/drop.
- Detect and support zoom, if wsmouse allows to report this
--
Mention magic trackpad support
--
Grammar, whitespace; make AUTHORS section from HISTORY since it mostly cites
people.
--
Add basic support for tap detection, emulating a left-click.
--
New sentence, new line.

diffstat:

 share/man/man4/btmagic.4    |   45 ++++-
 sys/dev/bluetooth/btmagic.c |  360 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 380 insertions(+), 25 deletions(-)

diffs (truncated from 611 to 300 lines):

diff -r 396bcd037dac -r 1d8f812d19db share/man/man4/btmagic.4
--- a/share/man/man4/btmagic.4  Thu Oct 15 20:11:52 2015 +0000
+++ b/share/man/man4/btmagic.4  Thu Oct 15 20:24:30 2015 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: btmagic.4,v 1.2 2010/10/11 15:15:57 plunky Exp $
+.\" $NetBSD: btmagic.4,v 1.2.26.1 2015/10/15 20:24:30 snj Exp $
 .\"
 .\" Copyright (c) 2010 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,12 +27,12 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd October 11, 2010
+.Dd July 4, 2015
 .Dt BTMAGIC 4
 .Os
 .Sh NAME
 .Nm btmagic
-.Nd Apple Magic Mouse
+.Nd Apple Magic Mouse and Apple Magic Trackpad
 .Sh SYNOPSIS
 .Cd "btmagic*  at bthub?"
 .Cd "wsmouse*  at btmagic?"
@@ -42,6 +42,8 @@
 driver provides support for the
 .Tn Bluetooth
 .Dq Magic Mouse
+and
+.Dq Magic Trackpad
 from
 .Tn Apple, Inc .
 As remote devices cannot be discovered by autoconfig, configuring
@@ -49,10 +51,10 @@
 .Xr btdevctl 8
 program.
 .Pp
-The Magic Mouse uses the standard
+The Magic Mouse and Magic Trackpad use the standard
 .Tn USB
-Human Interface Device protocol to communicate, but does not provide a
-proper HID Descriptor, and requires specific initializations to enable
+Human Interface Device protocol to communicate, but do not provide a
+proper HID Descriptor, and require specific initializations to enable
 the proprietary touch reports.
 .Pp
 The Magic Mouse provides basic mouse functionality with two buttons,
@@ -69,6 +71,25 @@
 distance necessary to trigger scrolling and the additional downscale
 factor applied to scroll movements.
 .Pp
+The Magic Trackpad provides multi touch functionality and one button.
+The
+.Nm
+driver emulates 3 buttons by splitting the area at the bottom of the
+device in 3 equal zones and detects finger presence in one of these zones
+when the button is pressed.
+In addition, a tap in any area of the trackpad is interpreted as a left click.
+The timeout for tap detection defaults to 100ms
+and is adjustable with
+.Xr sysctl 8 .
+.Pp
+Pointer movement is reported for single-touch
+movements over the device, and scroll is reported for multi-touch movements.
+.Pp
+The trackpad has a base resolution of 1300dpi, which the driver scales
+by default to a less sensitive 650dpi, but this is adjustable with
+.Xr sysctl 8
+along with the additional downscale factor applied to scroll movements.
+.Pp
 .Nm
 interfaces to the system as usual through the
 .Xr wsmouse 4
@@ -77,7 +98,7 @@
 .It vendor-id
 Must be 0x05ac.
 .It product-id
-Must be 0x030d.
+Must be 0x030d or 0x030e.
 .It local-bdaddr
 Local device address.
 .It remote-bdaddr
@@ -106,7 +127,8 @@
 .Xr wsmouse 4 ,
 .Xr btdevctl 8 ,
 .Xr sysctl 8
-.Sh HISTORY
+.Sh AUTHORS
+.An -nosplit
 The
 .Nm
 driver was written by
@@ -115,3 +137,10 @@
 .Tn Linux
 driver written by
 .An Michael Poole .
+.An Manuel Bouyer
+added Magic Trackpad support, with reference to the
+.Tn Linux
+driver written by
+.An Michael Poole
+and
+.An Chase Douglas .
diff -r 396bcd037dac -r 1d8f812d19db sys/dev/bluetooth/btmagic.c
--- a/sys/dev/bluetooth/btmagic.c       Thu Oct 15 20:11:52 2015 +0000
+++ b/sys/dev/bluetooth/btmagic.c       Thu Oct 15 20:24:30 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: btmagic.c,v 1.11 2014/08/05 07:55:31 rtr Exp $ */
+/*     $NetBSD: btmagic.c,v 1.11.2.1 2015/10/15 20:24:30 snj Exp $     */
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -85,7 +85,7 @@
  *****************************************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: btmagic.c,v 1.11 2014/08/05 07:55:31 rtr Exp $");
+__KERNEL_RCSID(0, "$NetBSD: btmagic.c,v 1.11.2.1 2015/10/15 20:24:30 snj Exp $");
 
 #include <sys/param.h>
 #include <sys/conf.h>
@@ -163,12 +163,19 @@
        int                     sc_rw;
 
        /* previous touches */
-       uint32_t                sc_smask;       /* scrolling */
-       int                     sc_az[16];
-       int                     sc_aw[16];
+       uint32_t                sc_smask;       /* active(s) IDs */
+       int                     sc_nfingers;    /* number of active IDs */
+       int                     sc_ax[16];
+       int                     sc_ay[16];
 
        /* previous mouse buttons */
+       int                     sc_mb_id; /* which ID selects the button */
        uint32_t                sc_mb;
+       /* button emulation with tap */
+       int                     sc_tapmb_id; /* which ID selects the button */
+       struct timeval          sc_taptime;
+       int                     sc_taptimeout;
+       callout_t               sc_tapcallout;
 };
 
 /* sc_flags */
@@ -189,6 +196,8 @@
 static int  btmagic_connect(struct btmagic_softc *);
 static int  btmagic_sysctl_resolution(SYSCTLFN_PROTO);
 static int  btmagic_sysctl_scale(SYSCTLFN_PROTO);
+static int btmagic_tap(struct btmagic_softc *, int);
+static int  btmagic_sysctl_taptimeout(SYSCTLFN_PROTO);
 
 CFATTACH_DECL_NEW(btmagic, sizeof(struct btmagic_softc),
     btmagic_match, btmagic_attach, btmagic_detach, NULL);
@@ -216,7 +225,17 @@
 static void  btmagic_linkmode(void *, int);
 static void  btmagic_input(void *, struct mbuf *);
 static void  btmagic_input_basic(struct btmagic_softc *, uint8_t *, size_t);
-static void  btmagic_input_magic(struct btmagic_softc *, uint8_t *, size_t);
+static void  btmagic_input_magicm(struct btmagic_softc *, uint8_t *, size_t);
+static void  btmagic_input_magict(struct btmagic_softc *, uint8_t *, size_t);
+static void  btmagic_tapcallout(void *);
+
+/* report types (data[1]) */
+#define BASIC_REPORT_ID                0x10
+#define TRACKPAD_REPORT_ID     0x28
+#define MOUSE_REPORT_ID                0x29
+#define BATT_STAT_REPORT_ID    0x30
+#define BATT_STRENGHT_REPORT_ID        0x47
+#define SURFACE_REPORT_ID      0x61
 
 static const struct btproto btmagic_ctl_proto = {
        btmagic_connecting,
@@ -259,7 +278,8 @@
        if (prop_dictionary_get_uint16(aux, BTDEVvendor, &v)
            && prop_dictionary_get_uint16(aux, BTDEVproduct, &p)
            && v == USB_VENDOR_APPLE
-           && p == USB_PRODUCT_APPLE_MAGICMOUSE)
+           && (p == USB_PRODUCT_APPLE_MAGICMOUSE ||
+               p == USB_PRODUCT_APPLE_MAGICTRACKPAD))
                return 2;       /* trump bthidev(4) */
 
        return 0;
@@ -279,8 +299,12 @@
         */
        sc->sc_dev = self;
        sc->sc_state = BTMAGIC_CLOSED;
+       sc->sc_mb_id = -1;
+       sc->sc_tapmb_id = -1;
        callout_init(&sc->sc_timeout, 0);
        callout_setfunc(&sc->sc_timeout, btmagic_timeout, sc);
+       callout_init(&sc->sc_tapcallout, 0);
+       callout_setfunc(&sc->sc_tapcallout, btmagic_tapcallout, sc);
        sockopt_init(&sc->sc_mode, BTPROTO_L2CAP, SO_L2CAP_LM, 0);
 
        /*
@@ -320,6 +344,7 @@
        sc->sc_firm = 6;
        sc->sc_dist = 130;
        sc->sc_scale = 20;
+       sc->sc_taptimeout = 100;
 
        sysctl_createv(&sc->sc_log, 0, NULL, &node,
                0,
@@ -366,6 +391,14 @@
                        (void *)sc, 0,
                        CTL_HW, node->sysctl_num,
                        CTL_CREATE, CTL_EOL);
+               sysctl_createv(&sc->sc_log, 0, NULL, NULL,
+                       CTLFLAG_READWRITE,
+                       CTLTYPE_INT, "taptimeout",
+                       "timeout for tap detection in milliseconds",
+                       btmagic_sysctl_taptimeout, 0,
+                       (void *)sc, 0,
+                       CTL_HW, node->sysctl_num,
+                       CTL_CREATE, CTL_EOL);
        }
 
        /*
@@ -425,6 +458,8 @@
                sc->sc_ctl = NULL;
        }
 
+       callout_halt(&sc->sc_tapcallout, bt_lock);
+       callout_destroy(&sc->sc_tapcallout);
        callout_halt(&sc->sc_timeout, bt_lock);
        callout_destroy(&sc->sc_timeout);
 
@@ -605,6 +640,31 @@
        return 0;
 }
 
+/* validate tap timeout */
+static int
+btmagic_sysctl_taptimeout(SYSCTLFN_ARGS)
+{
+       struct sysctlnode node;
+       struct btmagic_softc *sc;
+       int t, error;
+
+       node = *rnode;
+       sc = node.sysctl_data;
+
+       t = sc->sc_taptimeout;
+       node.sysctl_data = &t;
+       error = sysctl_lookup(SYSCTLFN_CALL(&node));
+       if (error || newp == NULL)
+               return error;
+
+       if (t < max(1000 / hz, 1) || t > 999)
+               return EINVAL;
+
+       sc->sc_taptimeout = t;
+       DPRINTF(sc, "taptimeout = %u", t);
+       return 0;
+}
+
 /*****************************************************************************
  *
  *     wsmouse(4) accessops
@@ -1047,15 +1107,18 @@
                        break;
 
                switch (data[1]) {
-               case 0x10: /* Basic mouse (input) */
+               case BASIC_REPORT_ID: /* Basic mouse (input) */
                        btmagic_input_basic(sc, data + 2, len - 2);
                        break;
 
-               case 0x29: /* Magic touch (input) */
-                       btmagic_input_magic(sc, data + 2, len - 2);
+               case TRACKPAD_REPORT_ID: /* Magic trackpad (input) */
+                       btmagic_input_magict(sc, data + 2, len - 2);
+                       break;
+               case MOUSE_REPORT_ID: /* Magic touch (input) */
+                       btmagic_input_magicm(sc, data + 2, len - 2);
                        break;
 
-               case 0x30: /* Battery status (input) */
+               case BATT_STAT_REPORT_ID: /* Battery status (input) */
                        if (len != 3)
                                break;
 
@@ -1068,7 +1131,7 @@
                        }
                        break;
 
-               case 0x47: /* Battery strength (feature) */
+               case BATT_STRENGHT_REPORT_ID: /* Battery strength (feature) */
                        if (len != 3)
                                break;
 
@@ -1076,7 +1139,7 @@
                            data[2]);
                        break;
 
-               case 0x61: /* Surface detection (input) */
+               case SURFACE_REPORT_ID: /* Surface detection (input) */
                        if (len != 3)
                                break;
 



Home | Main Index | Thread Index | Old Index