Commit 5ab506c8 authored by Vojtech Pavlik's avatar Vojtech Pavlik

Update of the X-Box USB pad driver and documentation to version 0.0.5.

parent e9c3815e
usb-xpad - Linux USB driver for XBOX HID gamecontrollers xpad - Linux USB driver for X-Box gamepads
This is the very first release of a driver for XBOX gamecontrollers. This is the very first release of a driver for X-Box gamepads.
Basically, this was hacked away in just a few hours, so don't expect Basically, this was hacked away in just a few hours, so don't expect
miracles. miracles.
In particular, there is currently NO support for the rumble pack.
You won't find many ff-aware linux applications anyway.
0. Status 0. Status
--------- ---------
...@@ -14,31 +17,38 @@ The jstest-program from joystick-1.2.15 (jstest-version 2.1.0) reports ...@@ -14,31 +17,38 @@ The jstest-program from joystick-1.2.15 (jstest-version 2.1.0) reports
8 axes and 10 buttons. 8 axes and 10 buttons.
Alls 8 axes work, though they all have the same range (-32768..32767) Alls 8 axes work, though they all have the same range (-32768..32767)
and the zero-setting is not correct for the triggers. and the zero-setting is not correct for the triggers (I don't know if that
9 of the 10 buttons work (my black button does not work, though I can is some limitation of jstest, since the input device setup should be fine. I
see no reason for it not to), all of them are in digital mode, though didn't have a look at jstest itself yet).
(the six buttons on the right side are "analog" ones).
All of the 10 buttons work (in digital mode). The six buttons on the
right side (A, B, X, Y, black, white) are said to be "analog" and
report their values as 8 bit unsigned, not sure what this is good for.
I tested the controller with quake3, and configuration and
in game functionality were OK. However, I find it rather difficult to
play first person shooters with a pad. Your mileage may vary.
1. USB adapter 1. USB adapter
-------------- --------------
Before you can actually use the driver, you need to get yourself an Before you can actually use the driver, you need to get yourself an
adapter cable to connect the XBOX-controller to your Linux-Box. adapter cable to connect the X-Box controller to your Linux-Box.
Such a cable is pretty easy to build. The Controller itself is a USB device Such a cable is pretty easy to build. The Controller itself is a USB compound
(a hub with three ports; two expansion slots and the controller device) device (a hub with three ports for two expansion slots and the controller
with the only differnce in a nonstandard connector (5 pins vs. 4 on device) with the only difference in a nonstandard connector (5 pins vs. 4 on
standard USB connector). standard USB connector).
You just need to solder an USB connector onto the cable and keep the You just need to solder a USB connector onto the cable and keep the
yellow wire unconnected. The other pins have the same order on both yellow wire unconnected. The other pins have the same order on both
connectors so there no magic to it. Detailed info on these matters can be found connectors so there is no magic to it. Detailed info on these matters
on the net. can be found on the net ([1], [2], [3]).
Thanks to the trip splitter found on the cable you don't even need to cut the Thanks to the trip splitter found on the cable you don't even need to cut the
original cable, you can buy an extension cable and cut that instead. That way, original one. You can buy an extension cable and cut that instead. That way,
you can still use the controller with your XBOX, if you have one ;) you can still use the controller with your X-Box, if you have one ;)
2. driver installation 2. driver installation
...@@ -46,22 +56,26 @@ you can still use the controller with your XBOX, if you have one ;) ...@@ -46,22 +56,26 @@ you can still use the controller with your XBOX, if you have one ;)
Once you have the adapter cable and the controller is connected, you need Once you have the adapter cable and the controller is connected, you need
to load your USB subsystem and should cat /proc/bus/usb/devices. to load your USB subsystem and should cat /proc/bus/usb/devices.
There should be an entry like the one in InterAct_german.dump. There should be an entry like the one at the end [4].
Currently (as of version 0.0.4), the following three devices are included:
original Microsoft XBOX controller (US), vendor=0x045e, product=0x0202
original Microsoft XBOX controller (Japan), vendor=0x045e, product=0x0285
InterAct PowerPad Pro (Germany), vendor=0x05fd, product=0x107a
Don't worry if the vendor and/or product ID don't match, those are easy to If you have another controller that is not listed above and is not recognized
add to the driver. You could do it yourself, just add the appropriate line by the driver, please drop me a line with the appropriate info (that is, include
into the list after the line the name, vendor and product ID, as well as the country where you bought it;
'} xpad_device[] = {' sending the whole dump out of /proc/bus/usb/devices along would be even better).
, but before the line that says
'{ 0x0000, 0x0000, "unknown...." }'.
In theory, the driver should work with other controllers than mine In theory, the driver should work with other controllers than mine
(InterAct PowerPad pro, bought in Germany) just fine, but see for yourself. (InterAct PowerPad pro, bought in Germany) just fine, but I cannot test this
for I only have this one controller.
If you compiled and installed the driver, test the functionality: If you compiled and installed the driver, test the functionality:
> modprobe usb-xpad > modprobe xpad
> modprobe joydev > modprobe joydev
> jstest /dev/input/js0 > jstest /dev/js0
There should be a single line showing 18 inputs (8 axes, 10 buttons), and There should be a single line showing 18 inputs (8 axes, 10 buttons), and
it's values should change if you move the sticks and push the buttons. it's values should change if you move the sticks and push the buttons.
...@@ -76,9 +90,27 @@ I have to thank ITO Takayuki for the detailed info on his site ...@@ -76,9 +90,27 @@ I have to thank ITO Takayuki for the detailed info on his site
http://euc.jp/periphs/xbox-controller.ja.html. http://euc.jp/periphs/xbox-controller.ja.html.
His useful info and both the usb-skeleton as well as the iforce input driver His useful info and both the usb-skeleton as well as the iforce input driver
helped a lot in rapid prototyping the basic functionality. (Greg Kroah-Hartmann; Vojtech Pavlik) helped a lot in rapid prototyping
the basic functionality.
4. References
-------------
1. http://euc.jp/periphs/xbox-controller.ja.html (ITO Takayuki)
2. http://xpad.xbox-scene.com/
3. http://www.xboxhackz.com/Hackz-Reference.htm
4. /proc/bus/usb/devices - dump from InterAct PowerPad Pro (Germany):
T: Bus=01 Lev=03 Prnt=04 Port=00 Cnt=01 Dev#= 5 Spd=12 MxCh= 0
D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS=32 #Cfgs= 1
P: Vendor=05fd ProdID=107a Rev= 1.00
C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA
I: If#= 0 Alt= 0 #EPs= 2 Cls=58(unk. ) Sub=42 Prot=00 Driver=(none)
E: Ad=81(I) Atr=03(Int.) MxPS= 32 Ivl= 10ms
E: Ad=02(O) Atr=03(Int.) MxPS= 32 Ivl= 10ms
-- --
Marko Friedemann <mfr@bmx-chemnitz.de> Marko Friedemann <mfr@bmx-chemnitz.de>
2002-07-02 2002-07-16
/* /*
* USB XBOX HID Gamecontroller - v0.0.3 * X-Box gamepad - v0.0.5
* *
* Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de> * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de>
* *
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of * published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
* *
* This driver is based on: * This driver is based on:
* - information from http://euc.jp/periphs/xbox-controller.ja.html * - information from http://euc.jp/periphs/xbox-controller.ja.html
* - the iForce driver drivers/char/joystick/iforce.c * - the iForce driver drivers/char/joystick/iforce.c
* - the skeleton-driver drivers/usb/usb-skeleton.c * - the skeleton-driver drivers/usb/usb-skeleton.c
* *
* Thanks to: * Thanks to:
* - ITO Takayuki for providing xpad information on his website * - ITO Takayuki for providing essential xpad information on his website
* - Vojtech Pavlik - iforce driver / input subsystem * - Vojtech Pavlik - iforce driver / input subsystem
* - Greg Kroah-Hartman - usb-skeleton driver * - Greg Kroah-Hartman - usb-skeleton driver
* *
* TODO: * TODO:
* - get the black button to work * - fine tune axes
* - fine tune axes * - fix "analog" buttons (reported as digital now)
* - fix "analog" buttons * - get rumble working
* - get rumble working
* *
* History: * History:
* *
* 2002-06-27 - 0.0.1 - first version, just said "XBOX HID controller" * 2002-06-27 - 0.0.1 : first version, just said "XBOX HID controller"
* *
* 2002-07-02 - 0.0.2 - basic working version * 2002-07-02 - 0.0.2 : basic working version
* all axes and 9 of the 10 buttons work (german InterAct device) * - all axes and 9 of the 10 buttons work (german InterAct device)
* the black button does not work * - the black button does not work
* *
* 2002-07-14 - 0.0.3 : rework by Vojtech Pavlik
* - indentation fixes
* - usb + input init sequence fixes
*
* 2002-07-16 - 0.0.4 : minor changes, merge with Vojtech's v0.0.3
* - verified the lack of HID and report descriptors
* - verified that ALL buttons WORK
* - fixed d-pad to axes mapping
*
* 2002-07-17 - 0.0.5 : simplified d-pad handling
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/input.h> #include <linux/input.h>
#include <linux/sched.h>
#include <linux/signal.h>
#include <linux/errno.h>
#include <linux/poll.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/fcntl.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/list.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/devfs_fs_kernel.h> #include <linux/devfs_fs_kernel.h>
#include <linux/usb.h> #include <linux/usb.h>
#define DRIVER_VERSION "v0.0.3" #define DRIVER_VERSION "v0.0.5"
#define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>" #define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>"
#define DRIVER_DESC "X-Box pad driver" #define DRIVER_DESC "X-Box pad driver"
...@@ -75,29 +77,24 @@ static struct xpad_device { ...@@ -75,29 +77,24 @@ static struct xpad_device {
} xpad_device[] = { } xpad_device[] = {
{ 0x045e, 0x0202, "Microsoft X-Box pad (US)" }, { 0x045e, 0x0202, "Microsoft X-Box pad (US)" },
{ 0x045e, 0x0285, "Microsoft X-Box pad (Japan)" }, { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)" },
{ 0x05fd, 0x107a, "InterAct X-Box pad (Germany)" }, { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)" },
{ 0x0000, 0x0000, "X-Box pad" } { 0x0000, 0x0000, "X-Box pad" }
}; };
static signed short xpad_btn[] = { static signed short xpad_btn[] = {
BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, /* 6 "analog" buttons */ BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, /* "analog" buttons */
BTN_START, BTN_BACK, BTN_THUMBL, BTN_THUMBR, /* start/back + stick press */ BTN_START, BTN_BACK, BTN_THUMBL, BTN_THUMBR, /* start/back/sticks */
-1 /* terminating entry */ -1 /* terminating entry */
}; };
static signed short xpad_abs[] = { static signed short xpad_abs[] = {
ABS_X, ABS_Y, /* left stick */ ABS_X, ABS_Y, /* left stick */
ABS_RX, ABS_RY, /* right stick */ ABS_RX, ABS_RY, /* right stick */
ABS_Z, ABS_RZ, /* triggers left/right */ ABS_Z, ABS_RZ, /* triggers left/right */
ABS_HAT0X, ABS_HAT0Y, /* dpad */ ABS_HAT0X, ABS_HAT0Y, /* digital pad */
-1 /* terminating entry */ -1 /* terminating entry */
}; };
static struct {
__s32 x;
__s32 y;
} xpad_hat_to_axis[] = { {0, 0}, {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1} };
static struct usb_device_id xpad_table [] = { static struct usb_device_id xpad_table [] = {
{ USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */ { USB_INTERFACE_INFO('X', 'B', 0) }, /* X-Box USB-IF not approved class */
{ } { }
...@@ -113,28 +110,17 @@ struct usb_xpad { ...@@ -113,28 +110,17 @@ struct usb_xpad {
unsigned char idata[XPAD_PKT_LEN]; /* input data */ unsigned char idata[XPAD_PKT_LEN]; /* input data */
char phys[65]; /* physical device path */ char phys[65]; /* physical device path */
int open_count; /* how many times has this been opened */ int open_count; /* reference count */
}; };
/* /*
* xpad_process_packet * xpad_process_packet
*
* Completes a request by converting the data into events for the input subsystem.
*
* The used report descriptor given below was taken from ITO Takayukis website:
* http://euc.jp/periphs/xbox-controller.ja.html
* *
* ---------------------------------------------------------------------------------------------------------------- * Completes a request by converting the data into events for the
* | padding | byte-cnt | dpad sb12 | reserved | bt A | bt B | bt X | bt Y | bt black | bt white | * input subsystem.
* | 01234567 | 01234567 | 0123 4567 | 01234567 | 01234567 | 01234567 | 01234567 | 01234567 | 01234567 | 01234567 |
* | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
* ----------------------------------------------------------------------------------------------------------------
* *
* --------------------------------------------------------------------------------------------------------------- * The used report descriptor was taken from ITO Takayukis website:
* | trig L | trig R | left stick X | left stick Y | right stick X | right stick Y | * http://euc.jp/periphs/xbox-controller.ja.html
* | 01234567 | 01234567 | 01234567 | 01234567 | 01234567 | 01234567 | 01234567 | 01234567 | 01234567 | 01234567 |
* | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |
* ---------------------------------------------------------------------------------------------------------------
*/ */
static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data) static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *data)
...@@ -154,8 +140,8 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d ...@@ -154,8 +140,8 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
input_report_abs(dev, ABS_RZ, data[11]); input_report_abs(dev, ABS_RZ, data[11]);
/* digital pad */ /* digital pad */
input_report_abs(dev, ABS_HAT0X, xpad_hat_to_axis[data[2] & 0x0f].x); input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04));
input_report_abs(dev, ABS_HAT0Y, xpad_hat_to_axis[data[2] & 0x0f].y); input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01));
/* start/back buttons and stick press left/right */ /* start/back buttons and stick press left/right */
input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4); input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4);
...@@ -224,7 +210,7 @@ static void * xpad_probe(struct usb_device *udev, unsigned int ifnum, const stru ...@@ -224,7 +210,7 @@ static void * xpad_probe(struct usb_device *udev, unsigned int ifnum, const stru
return NULL; return NULL;
} }
memset(xpad, 0, sizeof(struct usb_xpad)); memset(xpad, 0, sizeof(struct usb_xpad));
xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL);
if (!xpad->irq_in) { if (!xpad->irq_in) {
err("cannot allocate memory for new pad irq urb"); err("cannot allocate memory for new pad irq urb");
...@@ -234,11 +220,13 @@ static void * xpad_probe(struct usb_device *udev, unsigned int ifnum, const stru ...@@ -234,11 +220,13 @@ static void * xpad_probe(struct usb_device *udev, unsigned int ifnum, const stru
ep_irq_in = udev->actconfig->interface[ifnum].altsetting[0].endpoint + 0; ep_irq_in = udev->actconfig->interface[ifnum].altsetting[0].endpoint + 0;
FILL_INT_URB(xpad->irq_in, udev, usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress), FILL_INT_URB(xpad->irq_in, udev,
xpad->idata, XPAD_PKT_LEN, xpad_irq_in, xpad, ep_irq_in->bInterval); usb_rcvintpipe(udev, ep_irq_in->bEndpointAddress),
xpad->idata, XPAD_PKT_LEN, xpad_irq_in, xpad,
ep_irq_in->bInterval);
xpad->udev = udev; xpad->udev = udev;
xpad->dev.idbus = BUS_USB; xpad->dev.idbus = BUS_USB;
xpad->dev.idvendor = udev->descriptor.idVendor; xpad->dev.idvendor = udev->descriptor.idVendor;
xpad->dev.idproduct = udev->descriptor.idProduct; xpad->dev.idproduct = udev->descriptor.idProduct;
...@@ -248,38 +236,38 @@ static void * xpad_probe(struct usb_device *udev, unsigned int ifnum, const stru ...@@ -248,38 +236,38 @@ static void * xpad_probe(struct usb_device *udev, unsigned int ifnum, const stru
xpad->dev.phys = xpad->phys; xpad->dev.phys = xpad->phys;
xpad->dev.open = xpad_open; xpad->dev.open = xpad_open;
xpad->dev.close = xpad_close; xpad->dev.close = xpad_close;
usb_make_path(udev, path, 64); usb_make_path(udev, path, 64);
snprintf(xpad->phys, 64, "%s/input0", path); snprintf(xpad->phys, 64, "%s/input0", path);
xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); xpad->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
for (i = 0; xpad_btn[i] >= 0; i++) for (i = 0; xpad_btn[i] >= 0; i++)
set_bit(xpad_btn[i], xpad->dev.keybit); set_bit(xpad_btn[i], xpad->dev.keybit);
for (i = 0; xpad_abs[i] >= 0; i++) { for (i = 0; xpad_abs[i] >= 0; i++) {
signed short t = xpad_abs[i]; signed short t = xpad_abs[i];
set_bit(t, xpad->dev.absbit); set_bit(t, xpad->dev.absbit);
switch (t) { switch (t) {
case ABS_X: case ABS_X:
case ABS_Y: case ABS_Y:
case ABS_RX: case ABS_RX:
case ABS_RY: case ABS_RY: /* the two sticks */
xpad->dev.absmax[t] = 32767; xpad->dev.absmax[t] = 32767;
xpad->dev.absmin[t] = -32768; xpad->dev.absmin[t] = -32768;
xpad->dev.absflat[t] = 128; xpad->dev.absflat[t] = 128;
xpad->dev.absfuzz[t] = 16; xpad->dev.absfuzz[t] = 16;
break; break;
case ABS_Z: case ABS_Z:
case ABS_RZ: case ABS_RZ: /* the triggers */
xpad->dev.absmax[t] = 255; xpad->dev.absmax[t] = 255;
xpad->dev.absmin[t] = 0; xpad->dev.absmin[t] = 0;
break; break;
case ABS_HAT0X: case ABS_HAT0X:
case ABS_HAT0Y: case ABS_HAT0Y: /* the d-pad */
xpad->dev.absmax[t] = 1; xpad->dev.absmax[t] = 1;
xpad->dev.absmin[t] = -1; xpad->dev.absmin[t] = -1;
break; break;
...@@ -304,10 +292,10 @@ static void xpad_disconnect(struct usb_device *udev, void *ptr) ...@@ -304,10 +292,10 @@ static void xpad_disconnect(struct usb_device *udev, void *ptr)
} }
static struct usb_driver xpad_driver = { static struct usb_driver xpad_driver = {
.name = "xpad", .name = "xpad",
.probe = xpad_probe, .probe = xpad_probe,
.disconnect = xpad_disconnect, .disconnect = xpad_disconnect,
.id_table = xpad_table, .id_table = xpad_table,
}; };
static int __init usb_xpad_init(void) static int __init usb_xpad_init(void)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment