Blame view

Documentation/input/gamepad.rst 7.31 KB
b08c118cd   Dmitry Torokhov   Input: docs - spl...
1
2
3
  ---------------------------
  Linux Gamepad Specification
  ---------------------------
6e0fe2e57   David Herrmann   input: document g...
4

5c631b713   Mauro Carvalho Chehab   Input: convert ga...
5
  :Author: 2013 by David Herrmann <dh.herrmann@gmail.com>
b08c118cd   Dmitry Torokhov   Input: docs - spl...
6
7
  Introduction
  ~~~~~~~~~~~~
6e0fe2e57   David Herrmann   input: document g...
8
9
10
  Linux provides many different input drivers for gamepad hardware. To avoid
  having user-space deal with different button-mappings for each gamepad, this
  document defines how gamepads are supposed to report their data.
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
11
12
13
  Geometry
  ~~~~~~~~
  As "gamepad" we define devices which roughly look like this::
6e0fe2e57   David Herrmann   input: document g...
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
  
              ____________________________              __
             / [__ZL__]          [__ZR__] \               |
            / [__ TL __]        [__ TR __] \              | Front Triggers
         __/________________________________\__         __|
        /                                  _   \          |
       /      /\           __             (N)   \         |
      /       ||      __  |MO|  __     _       _ \        | Main Pad
     |    <===DP===> |SE|      |ST|   (W) -|- (E) |       |
      \       ||    ___          ___       _     /        |
      /\      \/   /   \        /   \     (S)   /\      __|
     /  \________ | LS  | ____ |  RS | ________/  \       |
    |         /  \ \___/ /    \ \___/ /  \         |      | Control Sticks
    |        /    \_____/      \_____/    \        |    __|
    |       /                              \       |
     \_____/                                \_____/
  
         |________|______|    |______|___________|
           D-Pad    Left       Right   Action Pad
                   Stick       Stick
  
                     |_____________|
                        Menu Pad
  
  Most gamepads have the following features:
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
39

6e0fe2e57   David Herrmann   input: document g...
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
    - Action-Pad
      4 buttons in diamonds-shape (on the right side). The buttons are
      differently labeled on most devices so we define them as NORTH,
      SOUTH, WEST and EAST.
    - D-Pad (Direction-pad)
      4 buttons (on the left side) that point up, down, left and right.
    - Menu-Pad
      Different constellations, but most-times 2 buttons: SELECT - START
      Furthermore, many gamepads have a fancy branded button that is used as
      special system-button. It often looks different to the other buttons and
      is used to pop up system-menus or system-settings.
    - Analog-Sticks
      Analog-sticks provide freely moveable sticks to control directions. Not
      all devices have both or any, but they are present at most times.
      Analog-sticks may also provide a digital button if you press them.
    - Triggers
      Triggers are located on the upper-side of the pad in vertical direction.
      Not all devices provide them, but the upper buttons are normally named
      Left- and Right-Triggers, the lower buttons Z-Left and Z-Right.
    - Rumble
      Many devices provide force-feedback features. But are mostly just
      simple rumble motors.
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
62
63
  Detection
  ~~~~~~~~~
6e0fe2e57   David Herrmann   input: document g...
64
65
66
67
68
69
70
71
  All gamepads that follow the protocol described here map BTN_GAMEPAD. This is
  an alias for BTN_SOUTH/BTN_A. It can be used to identify a gamepad as such.
  However, not all gamepads provide all features, so you need to test for all
  features that you need, first. How each feature is mapped is described below.
  
  Legacy drivers often don't comply to these rules. As we cannot change them
  for backwards-compatibility reasons, you need to provide fixup mappings in
  user-space yourself. Some of them might also provide module-options that
01d081858   Antonio Ospite   Input: fix typos ...
72
  change the mappings so you can advise users to set these.
6e0fe2e57   David Herrmann   input: document g...
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
  
  All new gamepads are supposed to comply with this mapping. Please report any
  bugs, if they don't.
  
  There are a lot of less-featured/less-powerful devices out there, which re-use
  the buttons from this protocol. However, they try to do this in a compatible
  fashion. For example, the "Nintendo Wii Nunchuk" provides two trigger buttons
  and one analog stick. It reports them as if it were a gamepad with only one
  analog stick and two trigger buttons on the right side.
  But that means, that if you only support "real" gamepads, you must test
  devices for _all_ reported events that you need. Otherwise, you will also get
  devices that report a small subset of the events.
  
  No other devices, that do not look/feel like a gamepad, shall report these
  events.
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
88
89
  Events
  ~~~~~~
6e0fe2e57   David Herrmann   input: document g...
90
  Gamepads report the following events:
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
91
  - Action-Pad:
6e0fe2e57   David Herrmann   input: document g...
92
93
94
95
    Every gamepad device has at least 2 action buttons. This means, that every
    device reports BTN_SOUTH (which BTN_GAMEPAD is an alias for). Regardless
    of the labels on the buttons, the codes are sent according to the
    physical position of the buttons.
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
96

6e0fe2e57   David Herrmann   input: document g...
97
98
    Please note that 2- and 3-button pads are fairly rare and old. You might
    want to filter gamepads that do not report all four.
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
99
100
  
      - 2-Button Pad:
6e0fe2e57   David Herrmann   input: document g...
101
102
103
        If only 2 action-buttons are present, they are reported as BTN_SOUTH and
        BTN_EAST. For vertical layouts, the upper button is BTN_EAST. For
        horizontal layouts, the button more on the right is BTN_EAST.
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
104
105
  
      - 3-Button Pad:
6e0fe2e57   David Herrmann   input: document g...
106
107
108
109
        If only 3 action-buttons are present, they are reported as (from left
        to right): BTN_WEST, BTN_SOUTH, BTN_EAST
        If the buttons are aligned perfectly vertically, they are reported as
        (from top down): BTN_WEST, BTN_SOUTH, BTN_EAST
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
110
111
  
      - 4-Button Pad:
6e0fe2e57   David Herrmann   input: document g...
112
113
114
115
116
        If all 4 action-buttons are present, they can be aligned in two
        different formations. If diamond-shaped, they are reported as BTN_NORTH,
        BTN_WEST, BTN_SOUTH, BTN_EAST according to their physical location.
        If rectangular-shaped, the upper-left button is BTN_NORTH, lower-left
        is BTN_WEST, lower-right is BTN_SOUTH and upper-right is BTN_EAST.
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
117
  - D-Pad:
6e0fe2e57   David Herrmann   input: document g...
118
119
120
121
122
    Every gamepad provides a D-Pad with four directions: Up, Down, Left, Right
    Some of these are available as digital buttons, some as analog buttons. Some
    may even report both. The kernel does not convert between these so
    applications should support both and choose what is more appropriate if
    both are reported.
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
123
124
  
      - Digital buttons are reported as:
6e0fe2e57   David Herrmann   input: document g...
125
        BTN_DPAD_*
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
126
127
  
      - Analog buttons are reported as:
6e0fe2e57   David Herrmann   input: document g...
128
        ABS_HAT0X and ABS_HAT0Y
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
129
130
131
    (for ABS values negative is left/up, positive is right/down)
  
  - Analog-Sticks:
6e0fe2e57   David Herrmann   input: document g...
132
133
134
135
    The left analog-stick is reported as ABS_X, ABS_Y. The right analog stick is
    reported as ABS_RX, ABS_RY. Zero, one or two sticks may be present.
    If analog-sticks provide digital buttons, they are mapped accordingly as
    BTN_THUMBL (first/left) and BTN_THUMBR (second/right).
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
136
137
138
    (for ABS values negative is left/up, positive is right/down)
  
  - Triggers:
6e0fe2e57   David Herrmann   input: document g...
139
140
141
    Trigger buttons can be available as digital or analog buttons or both. User-
    space must correctly deal with any situation and choose the most appropriate
    mode.
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
142

6e0fe2e57   David Herrmann   input: document g...
143
144
145
    Upper trigger buttons are reported as BTN_TR or ABS_HAT1X (right) and BTN_TL
    or ABS_HAT1Y (left). Lower trigger buttons are reported as BTN_TR2 or
    ABS_HAT2X (right/ZR) and BTN_TL2 or ABS_HAT2Y (left/ZL).
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
146

6e0fe2e57   David Herrmann   input: document g...
147
148
    If only one trigger-button combination is present (upper+lower), they are
    reported as "right" triggers (BTN_TR/ABS_HAT1X).
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
149
150
151
    (ABS trigger values start at 0, pressure is reported as positive values)
  
  - Menu-Pad:
6e0fe2e57   David Herrmann   input: document g...
152
153
    Menu buttons are always digital and are mapped according to their location
    instead of their labels. That is:
5c631b713   Mauro Carvalho Chehab   Input: convert ga...
154
155
156
157
158
159
160
161
  
      - 1-button Pad:
  
        Mapped as BTN_START
  
      - 2-button Pad:
  
        Left button mapped as BTN_SELECT, right button mapped as BTN_START
6e0fe2e57   David Herrmann   input: document g...
162
163
    Many pads also have a third button which is branded or has a special symbol
    and meaning. Such buttons are mapped as BTN_MODE. Examples are the Nintendo
01d081858   Antonio Ospite   Input: fix typos ...
164
    "HOME" button, the XBox "X"-button or Sony "PS" button.
6e0fe2e57   David Herrmann   input: document g...
165

5c631b713   Mauro Carvalho Chehab   Input: convert ga...
166
  - Rumble:
6e0fe2e57   David Herrmann   input: document g...
167

5c631b713   Mauro Carvalho Chehab   Input: convert ga...
168
    Rumble is advertised as FF_RUMBLE.