xref: /OK3568_Linux_fs/kernel/Documentation/input/gamepad.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun---------------------------
2*4882a593SmuzhiyunLinux Gamepad Specification
3*4882a593Smuzhiyun---------------------------
4*4882a593Smuzhiyun
5*4882a593Smuzhiyun:Author: 2013 by David Herrmann <dh.herrmann@gmail.com>
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunIntroduction
9*4882a593Smuzhiyun~~~~~~~~~~~~
10*4882a593SmuzhiyunLinux provides many different input drivers for gamepad hardware. To avoid
11*4882a593Smuzhiyunhaving user-space deal with different button-mappings for each gamepad, this
12*4882a593Smuzhiyundocument defines how gamepads are supposed to report their data.
13*4882a593Smuzhiyun
14*4882a593SmuzhiyunGeometry
15*4882a593Smuzhiyun~~~~~~~~
16*4882a593SmuzhiyunAs "gamepad" we define devices which roughly look like this::
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun            ____________________________              __
19*4882a593Smuzhiyun           / [__ZL__]          [__ZR__] \               |
20*4882a593Smuzhiyun          / [__ TL __]        [__ TR __] \              | Front Triggers
21*4882a593Smuzhiyun       __/________________________________\__         __|
22*4882a593Smuzhiyun      /                                  _   \          |
23*4882a593Smuzhiyun     /      /\           __             (N)   \         |
24*4882a593Smuzhiyun    /       ||      __  |MO|  __     _       _ \        | Main Pad
25*4882a593Smuzhiyun   |    <===DP===> |SE|      |ST|   (W) -|- (E) |       |
26*4882a593Smuzhiyun    \       ||    ___          ___       _     /        |
27*4882a593Smuzhiyun    /\      \/   /   \        /   \     (S)   /\      __|
28*4882a593Smuzhiyun   /  \________ | LS  | ____ |  RS | ________/  \       |
29*4882a593Smuzhiyun  |         /  \ \___/ /    \ \___/ /  \         |      | Control Sticks
30*4882a593Smuzhiyun  |        /    \_____/      \_____/    \        |    __|
31*4882a593Smuzhiyun  |       /                              \       |
32*4882a593Smuzhiyun   \_____/                                \_____/
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun       |________|______|    |______|___________|
35*4882a593Smuzhiyun         D-Pad    Left       Right   Action Pad
36*4882a593Smuzhiyun                 Stick       Stick
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun                   |_____________|
39*4882a593Smuzhiyun                      Menu Pad
40*4882a593Smuzhiyun
41*4882a593SmuzhiyunMost gamepads have the following features:
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun  - Action-Pad
44*4882a593Smuzhiyun    4 buttons in diamonds-shape (on the right side). The buttons are
45*4882a593Smuzhiyun    differently labeled on most devices so we define them as NORTH,
46*4882a593Smuzhiyun    SOUTH, WEST and EAST.
47*4882a593Smuzhiyun  - D-Pad (Direction-pad)
48*4882a593Smuzhiyun    4 buttons (on the left side) that point up, down, left and right.
49*4882a593Smuzhiyun  - Menu-Pad
50*4882a593Smuzhiyun    Different constellations, but most-times 2 buttons: SELECT - START
51*4882a593Smuzhiyun    Furthermore, many gamepads have a fancy branded button that is used as
52*4882a593Smuzhiyun    special system-button. It often looks different to the other buttons and
53*4882a593Smuzhiyun    is used to pop up system-menus or system-settings.
54*4882a593Smuzhiyun  - Analog-Sticks
55*4882a593Smuzhiyun    Analog-sticks provide freely moveable sticks to control directions. Not
56*4882a593Smuzhiyun    all devices have both or any, but they are present at most times.
57*4882a593Smuzhiyun    Analog-sticks may also provide a digital button if you press them.
58*4882a593Smuzhiyun  - Triggers
59*4882a593Smuzhiyun    Triggers are located on the upper-side of the pad in vertical direction.
60*4882a593Smuzhiyun    Not all devices provide them, but the upper buttons are normally named
61*4882a593Smuzhiyun    Left- and Right-Triggers, the lower buttons Z-Left and Z-Right.
62*4882a593Smuzhiyun  - Rumble
63*4882a593Smuzhiyun    Many devices provide force-feedback features. But are mostly just
64*4882a593Smuzhiyun    simple rumble motors.
65*4882a593Smuzhiyun
66*4882a593SmuzhiyunDetection
67*4882a593Smuzhiyun~~~~~~~~~
68*4882a593Smuzhiyun
69*4882a593SmuzhiyunAll gamepads that follow the protocol described here map BTN_GAMEPAD. This is
70*4882a593Smuzhiyunan alias for BTN_SOUTH/BTN_A. It can be used to identify a gamepad as such.
71*4882a593SmuzhiyunHowever, not all gamepads provide all features, so you need to test for all
72*4882a593Smuzhiyunfeatures that you need, first. How each feature is mapped is described below.
73*4882a593Smuzhiyun
74*4882a593SmuzhiyunLegacy drivers often don't comply to these rules. As we cannot change them
75*4882a593Smuzhiyunfor backwards-compatibility reasons, you need to provide fixup mappings in
76*4882a593Smuzhiyunuser-space yourself. Some of them might also provide module-options that
77*4882a593Smuzhiyunchange the mappings so you can advise users to set these.
78*4882a593Smuzhiyun
79*4882a593SmuzhiyunAll new gamepads are supposed to comply with this mapping. Please report any
80*4882a593Smuzhiyunbugs, if they don't.
81*4882a593Smuzhiyun
82*4882a593SmuzhiyunThere are a lot of less-featured/less-powerful devices out there, which re-use
83*4882a593Smuzhiyunthe buttons from this protocol. However, they try to do this in a compatible
84*4882a593Smuzhiyunfashion. For example, the "Nintendo Wii Nunchuk" provides two trigger buttons
85*4882a593Smuzhiyunand one analog stick. It reports them as if it were a gamepad with only one
86*4882a593Smuzhiyunanalog stick and two trigger buttons on the right side.
87*4882a593SmuzhiyunBut that means, that if you only support "real" gamepads, you must test
88*4882a593Smuzhiyundevices for _all_ reported events that you need. Otherwise, you will also get
89*4882a593Smuzhiyundevices that report a small subset of the events.
90*4882a593Smuzhiyun
91*4882a593SmuzhiyunNo other devices, that do not look/feel like a gamepad, shall report these
92*4882a593Smuzhiyunevents.
93*4882a593Smuzhiyun
94*4882a593SmuzhiyunEvents
95*4882a593Smuzhiyun~~~~~~
96*4882a593Smuzhiyun
97*4882a593SmuzhiyunGamepads report the following events:
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun- Action-Pad:
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun  Every gamepad device has at least 2 action buttons. This means, that every
102*4882a593Smuzhiyun  device reports BTN_SOUTH (which BTN_GAMEPAD is an alias for). Regardless
103*4882a593Smuzhiyun  of the labels on the buttons, the codes are sent according to the
104*4882a593Smuzhiyun  physical position of the buttons.
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun  Please note that 2- and 3-button pads are fairly rare and old. You might
107*4882a593Smuzhiyun  want to filter gamepads that do not report all four.
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun    - 2-Button Pad:
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun      If only 2 action-buttons are present, they are reported as BTN_SOUTH and
112*4882a593Smuzhiyun      BTN_EAST. For vertical layouts, the upper button is BTN_EAST. For
113*4882a593Smuzhiyun      horizontal layouts, the button more on the right is BTN_EAST.
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun    - 3-Button Pad:
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun      If only 3 action-buttons are present, they are reported as (from left
118*4882a593Smuzhiyun      to right): BTN_WEST, BTN_SOUTH, BTN_EAST
119*4882a593Smuzhiyun      If the buttons are aligned perfectly vertically, they are reported as
120*4882a593Smuzhiyun      (from top down): BTN_WEST, BTN_SOUTH, BTN_EAST
121*4882a593Smuzhiyun
122*4882a593Smuzhiyun    - 4-Button Pad:
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun      If all 4 action-buttons are present, they can be aligned in two
125*4882a593Smuzhiyun      different formations. If diamond-shaped, they are reported as BTN_NORTH,
126*4882a593Smuzhiyun      BTN_WEST, BTN_SOUTH, BTN_EAST according to their physical location.
127*4882a593Smuzhiyun      If rectangular-shaped, the upper-left button is BTN_NORTH, lower-left
128*4882a593Smuzhiyun      is BTN_WEST, lower-right is BTN_SOUTH and upper-right is BTN_EAST.
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun- D-Pad:
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun  Every gamepad provides a D-Pad with four directions: Up, Down, Left, Right
133*4882a593Smuzhiyun  Some of these are available as digital buttons, some as analog buttons. Some
134*4882a593Smuzhiyun  may even report both. The kernel does not convert between these so
135*4882a593Smuzhiyun  applications should support both and choose what is more appropriate if
136*4882a593Smuzhiyun  both are reported.
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun    - Digital buttons are reported as:
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun      BTN_DPAD_*
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun    - Analog buttons are reported as:
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun      ABS_HAT0X and ABS_HAT0Y
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun  (for ABS values negative is left/up, positive is right/down)
147*4882a593Smuzhiyun
148*4882a593Smuzhiyun- Analog-Sticks:
149*4882a593Smuzhiyun
150*4882a593Smuzhiyun  The left analog-stick is reported as ABS_X, ABS_Y. The right analog stick is
151*4882a593Smuzhiyun  reported as ABS_RX, ABS_RY. Zero, one or two sticks may be present.
152*4882a593Smuzhiyun  If analog-sticks provide digital buttons, they are mapped accordingly as
153*4882a593Smuzhiyun  BTN_THUMBL (first/left) and BTN_THUMBR (second/right).
154*4882a593Smuzhiyun
155*4882a593Smuzhiyun  (for ABS values negative is left/up, positive is right/down)
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun- Triggers:
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun  Trigger buttons can be available as digital or analog buttons or both. User-
160*4882a593Smuzhiyun  space must correctly deal with any situation and choose the most appropriate
161*4882a593Smuzhiyun  mode.
162*4882a593Smuzhiyun
163*4882a593Smuzhiyun  Upper trigger buttons are reported as BTN_TR or ABS_HAT1X (right) and BTN_TL
164*4882a593Smuzhiyun  or ABS_HAT1Y (left). Lower trigger buttons are reported as BTN_TR2 or
165*4882a593Smuzhiyun  ABS_HAT2X (right/ZR) and BTN_TL2 or ABS_HAT2Y (left/ZL).
166*4882a593Smuzhiyun
167*4882a593Smuzhiyun  If only one trigger-button combination is present (upper+lower), they are
168*4882a593Smuzhiyun  reported as "right" triggers (BTN_TR/ABS_HAT1X).
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun  (ABS trigger values start at 0, pressure is reported as positive values)
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun- Menu-Pad:
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun  Menu buttons are always digital and are mapped according to their location
175*4882a593Smuzhiyun  instead of their labels. That is:
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun    - 1-button Pad:
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun      Mapped as BTN_START
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun    - 2-button Pad:
182*4882a593Smuzhiyun
183*4882a593Smuzhiyun      Left button mapped as BTN_SELECT, right button mapped as BTN_START
184*4882a593Smuzhiyun
185*4882a593Smuzhiyun  Many pads also have a third button which is branded or has a special symbol
186*4882a593Smuzhiyun  and meaning. Such buttons are mapped as BTN_MODE. Examples are the Nintendo
187*4882a593Smuzhiyun  "HOME" button, the XBox "X"-button or Sony "PS" button.
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun- Rumble:
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun  Rumble is advertised as FF_RUMBLE.
192