Skip to content
This repository was archived by the owner on May 18, 2021. It is now read-only.

Commit 1895cf1

Browse files
committed
change the gamepad field order
1 parent 2ad4e09 commit 1895cf1

File tree

2 files changed

+56
-21
lines changed

2 files changed

+56
-21
lines changed

tinyusb/src/class/hid/hid.h

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,52 @@ typedef enum
149149
/** \addtogroup ClassDriver_HID_Gamepad Gamepad
150150
* @{ */
151151

152+
/* From https://www.kernel.org/doc/html/latest/input/gamepad.html
153+
____________________________ __
154+
/ [__ZL__] [__ZR__] \ |
155+
/ [__ TL __] [__ TR __] \ | Front Triggers
156+
__/________________________________\__ __|
157+
/ _ \ |
158+
/ /\ __ (N) \ |
159+
/ || __ |MO| __ _ _ \ | Main Pad
160+
| <===DP===> |SE| |ST| (W) -|- (E) | |
161+
\ || ___ ___ _ / |
162+
/\ \/ / \ / \ (S) /\ __|
163+
/ \________ | LS | ____ | RS | ________/ \ |
164+
| / \ \___/ / \ \___/ / \ | | Control Sticks
165+
| / \_____/ \_____/ \ | __|
166+
| / \ |
167+
\_____/ \_____/
168+
169+
|________|______| |______|___________|
170+
D-Pad Left Right Action Pad
171+
Stick Stick
172+
173+
|_____________|
174+
Menu Pad
175+
176+
Most gamepads have the following features:
177+
- Action-Pad 4 buttons in diamonds-shape (on the right side) NORTH, SOUTH, WEST and EAST.
178+
- D-Pad (Direction-pad) 4 buttons (on the left side) that point up, down, left and right.
179+
- Menu-Pad Different constellations, but most-times 2 buttons: SELECT - START.
180+
- Analog-Sticks provide freely moveable sticks to control directions, Analog-sticks may also
181+
provide a digital button if you press them.
182+
- Triggers are located on the upper-side of the pad in vertical direction. The upper buttons
183+
are normally named Left- and Right-Triggers, the lower buttons Z-Left and Z-Right.
184+
- Rumble Many devices provide force-feedback features. But are mostly just simple rumble motors.
185+
*/
186+
152187
/// HID Gamepad Protocol Report.
153188
typedef struct TU_ATTR_PACKED
154189
{
155-
uint16_t buttons; /**< buttons mask for currently pressed buttons in the gamepad. */
156-
int8_t x; /**< Current delta x movement of the gamepad left joystick. */
157-
int8_t y; /**< Current delta y movement of the gamepad left joystick. */
158-
int8_t z; /**< Current delta z movement of the gamepad right joystick. */
159-
int8_t rx; /**< Current delta Rx movement of the gamepad analog left trigger. */
160-
int8_t ry; /**< Current delta Ry movement of the gamepad analog right trigger. */
161-
int8_t rz; /**< Current delta Rz movement of the gamepad right joystick. */
162-
uint8_t hat; /**< buttons mask for currently pressed buttons in the gamepad hat */
190+
int8_t x; ///< Delta x movement of left analog-stick
191+
int8_t y; ///< Delta y movement of left analog-stick
192+
int8_t z; ///< Delta z movement of right analog-joystick
193+
int8_t rz; ///< Delta Rz movement of right analog-joystick
194+
int8_t rx; ///< Delta Rx movement of analog left trigger
195+
int8_t ry; ///< Delta Ry movement of analog right trigger
196+
uint8_t hat; ///< Buttons mask for currently pressed buttons in the DPad/hat
197+
uint16_t buttons; ///< Buttons mask for currently pressed buttons
163198
}hid_gamepad_report_t;
164199

165200
/// Standard Gamepad Buttons Bitmap (from Linux input event codes)

tinyusb/src/class/hid/hid_device.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,36 +249,27 @@ TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
249249

250250
// Gamepad Report Descriptor Template
251251
// with 16 buttons, 2 joysticks and 1 hat/dpad with following layout
252-
// | Button Map (2 bytes) | X | Y | Z | Rx | Ry | Rz (1 byte each) | hat/DPAD (1 byte)
252+
// | X | Y | Z | Rz | Rx | Ry (1 byte each) | hat/DPAD (1 byte) | Button Map (2 bytes) |
253253
#define TUD_HID_REPORT_DESC_GAMEPAD(...) \
254254
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
255255
HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\
256256
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
257257
/* Report ID if any */\
258258
__VA_ARGS__ \
259-
/* 16 bit Button Map */ \
260-
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
261-
HID_USAGE_MIN ( 1 ) ,\
262-
HID_USAGE_MAX ( 16 ) ,\
263-
HID_LOGICAL_MIN ( 0 ) ,\
264-
HID_LOGICAL_MAX ( 1 ) ,\
265-
HID_REPORT_COUNT ( 16 ) ,\
266-
HID_REPORT_SIZE ( 1 ) ,\
267-
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
268-
/* 8 bit X, Y, Z, Rx, Ry, Rz (min -127, max 127 ) */ \
259+
/* 8 bit X, Y, Z, Rz, Rx, Ry (min -127, max 127 ) */ \
269260
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
270261
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
271262
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
272263
HID_USAGE ( HID_USAGE_DESKTOP_Z ) ,\
264+
HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\
273265
HID_USAGE ( HID_USAGE_DESKTOP_RX ) ,\
274266
HID_USAGE ( HID_USAGE_DESKTOP_RY ) ,\
275-
HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\
276267
HID_LOGICAL_MIN ( 0x81 ) ,\
277268
HID_LOGICAL_MAX ( 0x7f ) ,\
278269
HID_REPORT_COUNT ( 6 ) ,\
279270
HID_REPORT_SIZE ( 8 ) ,\
280271
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
281-
/* 8 bit Hat Button Map */ \
272+
/* 8 bit DPad/Hat Button Map */ \
282273
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
283274
HID_USAGE ( HID_USAGE_DESKTOP_HAT_SWITCH ) ,\
284275
HID_LOGICAL_MIN ( 1 ) ,\
@@ -288,6 +279,15 @@ TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
288279
HID_REPORT_COUNT ( 1 ) ,\
289280
HID_REPORT_SIZE ( 8 ) ,\
290281
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
282+
/* 16 bit Button Map */ \
283+
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
284+
HID_USAGE_MIN ( 1 ) ,\
285+
HID_USAGE_MAX ( 16 ) ,\
286+
HID_LOGICAL_MIN ( 0 ) ,\
287+
HID_LOGICAL_MAX ( 1 ) ,\
288+
HID_REPORT_COUNT ( 16 ) ,\
289+
HID_REPORT_SIZE ( 1 ) ,\
290+
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
291291
HID_COLLECTION_END \
292292

293293
// HID Generic Input & Output

0 commit comments

Comments
 (0)