Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Add Xbox One controller support. Report descript...



details:   https://anonhg.NetBSD.org/src/rev/79b88be3e791
branches:  trunk
changeset: 806191:79b88be3e791
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Feb 08 19:22:45 2015 +0000

description:
Add Xbox One controller support. Report descriptor from https://github.com/lloeki/xbox_one_controller

diffstat:

 sys/dev/usb/uhidev.c        |   33 ++++++++++++-
 sys/dev/usb/uhidev.h        |    5 +-
 sys/dev/usb/x1input_rdesc.h |  105 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+), 3 deletions(-)

diffs (206 lines):

diff -r 0286a71a4251 -r 79b88be3e791 sys/dev/usb/uhidev.c
--- a/sys/dev/usb/uhidev.c      Sun Feb 08 19:09:56 2015 +0000
+++ b/sys/dev/usb/uhidev.c      Sun Feb 08 19:22:45 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhidev.c,v 1.61 2014/08/10 16:44:36 tls Exp $  */
+/*     $NetBSD: uhidev.c,v 1.62 2015/02/08 19:22:45 jmcneill Exp $     */
 
 /*
  * Copyright (c) 2001, 2012 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.61 2014/08/10 16:44:36 tls Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhidev.c,v 1.62 2015/02/08 19:22:45 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -61,6 +61,8 @@
 #include <dev/usb/ugraphire_rdesc.h>
 /* Report descriptor for game controllers in "XInput" mode */
 #include <dev/usb/xinput_rdesc.h>
+/* Report descriptor for Xbox One controllers */
+#include <dev/usb/x1input_rdesc.h>
 
 #include "locators.h"
 
@@ -95,6 +97,10 @@
        /* Game controllers in "XInput" mode */
        if (USBIF_IS_XINPUT(uaa))
                return UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO;
+       /* Xbox One controllers */
+       if (USBIF_IS_X1INPUT(uaa) && uaa->ifaceno == 0)
+               return UMATCH_IFACECLASS_IFACESUBCLASS_IFACEPROTO;
+
        if (uaa->class != UICLASS_HID)
                return (UMATCH_NONE);
        if (usbd_get_quirks(uaa->device)->uq_flags & UQ_HID_IGNORE)
@@ -224,6 +230,11 @@
                size = sizeof uhid_xinput_report_descr;
                descptr = uhid_xinput_report_descr;
        }
+       if (USBIF_IS_X1INPUT(uaa)) {
+               sc->sc_flags |= UHIDEV_F_XB1;
+               size = sizeof uhid_x1input_report_descr;
+               descptr = uhid_x1input_report_descr;
+       }
 
        if (descptr) {
                desc = malloc(size, M_USBDEV, M_NOWAIT);
@@ -595,9 +606,27 @@
                        error = ENOMEM;
                        goto out3;
                }
+
+               if (sc->sc_flags & UHIDEV_F_XB1) {
+                       uint8_t init_data[] = { 0x05, 0x20 };
+                       int init_data_len = sizeof(init_data);
+                       err = usbd_intr_transfer(sc->sc_oxfer, sc->sc_opipe, 0,
+                           USBD_NO_TIMEOUT, init_data, &init_data_len,
+                           "uhidevxb1");
+                       if (err != USBD_NORMAL_COMPLETION) {
+                               DPRINTF(("uhidev_open: xb1 init failed, "
+                                   "error=%d\n", err));
+                               error = EIO;
+                               goto out4;
+                       }
+               }
        }
 
        return (0);
+out4:
+       /* Free output xfer */
+       if (sc->sc_oxfer != NULL)
+               usbd_free_xfer(sc->sc_oxfer);
 out3:
        /* Abort output pipe */
        usbd_close_pipe(sc->sc_opipe);
diff -r 0286a71a4251 -r 79b88be3e791 sys/dev/usb/uhidev.h
--- a/sys/dev/usb/uhidev.h      Sun Feb 08 19:09:56 2015 +0000
+++ b/sys/dev/usb/uhidev.h      Sun Feb 08 19:22:45 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhidev.h,v 1.15 2014/06/17 09:35:46 skrll Exp $        */
+/*     $NetBSD: uhidev.h,v 1.16 2015/02/08 19:22:45 jmcneill Exp $     */
 
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -57,6 +57,9 @@
        u_char sc_dying;
 
        kmutex_t sc_lock;               /* protects writes to sc_state */
+
+       u_int sc_flags;
+#define UHIDEV_F_XB1   0x0001  /* Xbox 1 controller */
 };
 
 struct uhidev {
diff -r 0286a71a4251 -r 79b88be3e791 sys/dev/usb/x1input_rdesc.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/usb/x1input_rdesc.h       Sun Feb 08 19:22:45 2015 +0000
@@ -0,0 +1,105 @@
+/* $NetBSD: x1input_rdesc.h,v 1.1 2015/02/08 19:22:45 jmcneill Exp $ */
+
+/*-
+ * Copyright (C) 2014 Loic Nageleisen
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of the copyright holders nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define        USBIF_IS_X1INPUT(uaa)                   \
+       ((uaa)->class == UICLASS_VENDOR &&      \
+        (uaa)->subclass == 0x47 &&             \
+        (uaa)->proto == 0xd0)
+
+static const uByte uhid_x1input_report_descr[] = {
+    0x05, 0x01,                     // Usage Page (Generic Desktop)
+    0x09, 0x05,                     // Usage (Game Pad)
+    0xa1, 0x01,                     // Collection (Application)
+
+                                    //   # button packet
+    0xa1, 0x00,                     //   Collection (Physical)
+    0x85, 0x20,                     //     Report ID (0x20)
+
+                                    //     # skip unknown field and counter
+    0x05, 0x01,                     //     Usage Page (Generic Desktop)
+    0x09, 0x00,                     //     Usage (Undefined)
+    0x75, 0x08,                     //     Report Size (8)
+    0x95, 0x02,                     //     Report Count (2)
+    0x81, 0x03,                     //     Input (Constant, Variable, Absolute)
+
+                                    //     payload size
+    0x05, 0x01,                     //     Usage Page (Generic Desktop)
+    0x09, 0x3b,                     //     Usage (Byte Count)
+    0x75, 0x08,                     //     Report Size (8)
+    0x95, 0x01,                     //     Report Count (1)
+    0x81, 0x02,                     //     Input (Data, Variable, Absolute)
+
+                                    //     # 16 buttons
+    0x05, 0x09,                     //     Usage Page (Button)
+    0x19, 0x01,                     //     Usage Minimum (Button 1)
+    0x29, 0x10,                     //     Usage Maximum (Button 16)
+    0x15, 0x00,                     //     Logical Minimum (0)
+    0x25, 0x01,                     //     Logical Maximum (1)
+    0x75, 0x01,                     //     Report Size (1)
+    0x95, 0x10,                     //     Report Count (16)
+    0x81, 0x02,                     //     Input (Data, Variable, Absolute)
+
+                                    //     # triggers
+    0x15, 0x00,                     //     Logical Minimum (0)
+    0x26, 0xff, 0x03,               //     Logical Maximum (1023)
+    0x35, 0x00,                     //     Physical Minimum (0)
+    0x46, 0xff, 0x03,               //     Physical Maximum (1023)
+    0x75, 0x10,                     //     Report Size (16)
+    0x95, 0x02,                     //     Report Count (2)
+    0x05, 0x01,                     //     Usage Page (Generic Desktop)
+    0x09, 0x33,                     //     Usage (Rx)
+    0x09, 0x34,                     //     Usage (Ry)
+    0x81, 0x02,                     //     Input (Data, Variable, Absolute)
+
+                                    //     # sticks
+    0x75, 0x10,                     //     Report Size (16)
+    0x16, 0x00, 0x80,               //     Logical Minimum (-32768)
+    0x26, 0xff, 0x7f,               //     Logical Maximum (32767)
+    0x36, 0x00, 0x80,               //     Physical Minimum (-32768)
+    0x46, 0xff, 0x7f,               //     Physical Maximum (32767)
+    0x05, 0x01,                     //     Usage Page (Generic Desktop)
+    0x09, 0x01,                     //     Usage (Pointer)
+    0xa1, 0x00,                     //     Collection (Physical)
+    0x95, 0x02,                     //       Report Count (2)
+    0x05, 0x01,                     //       Usage Page (Generic Desktop)
+    0x09, 0x30,                     //       Usage (X)
+    0x09, 0x31,                     //       Usage (Y)
+    0x81, 0x02,                     //       Input (Data, Variable, Absolute)
+    0xc0,                           //     End Collection
+    0x05, 0x01,                     //     Usage Page (Generic Desktop)
+    0x09, 0x01,                     //     Usage (Pointer)
+    0xa1, 0x00,                     //     Collection (Physical)
+    0x95, 0x02,                     //       Report Count (2)
+    0x05, 0x01,                     //       Usage Page (Generic Desktop)
+    0x09, 0x32,                     //       Usage (Z)
+    0x09, 0x35,                     //       Usage (Rz)
+    0x81, 0x02,                     //       Input (Data, Variable, Absolute)
+    0xc0,                           //     End Collection
+    0xc0,                           //   End Collection
+};



Home | Main Index | Thread Index | Old Index