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

Commit 2ad4e09

Browse files
committed
Added Rx/Ry support
1 parent 2c5e1d7 commit 2ad4e09

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

tinyusb/src/class/hid/hid.h

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

152-
/// Standard HID Boot Protocol Gamepad Report.
152+
/// HID Gamepad Protocol Report.
153153
typedef struct TU_ATTR_PACKED
154154
{
155155
uint16_t buttons; /**< buttons mask for currently pressed buttons in the gamepad. */
156-
int8_t x; /**< Current delta x movement of the gamepad joystick 1. */
157-
int8_t y; /**< Current delta y movement of the gamepad joystick 1. */
158-
int8_t z; /**< Current delta z movement of the gamepad joystick 2. */
159-
int8_t r_z; /**< Current delta r_z movement of the gamepad joystick 2. */
160-
uint8_t hat; /**< buttons mask for currently pressed buttons in the gamepad hat */
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 */
161163
}hid_gamepad_report_t;
162164

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

tinyusb/src/class/hid/hid_device.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ 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 | Rz (1 byte each) | hat/DPAD (1 byte)
252+
// | Button Map (2 bytes) | X | Y | Z | Rx | Ry | Rz (1 byte each) | hat/DPAD (1 byte)
253253
#define TUD_HID_REPORT_DESC_GAMEPAD(...) \
254254
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
255255
HID_USAGE ( HID_USAGE_DESKTOP_GAMEPAD ) ,\
@@ -265,21 +265,23 @@ TU_ATTR_WEAK bool tud_hid_set_idle_cb(uint8_t idle_rate);
265265
HID_REPORT_COUNT ( 16 ) ,\
266266
HID_REPORT_SIZE ( 1 ) ,\
267267
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
268-
/* 8 bit X, Y, Z, Rz (min -127, max 127 ) */ \
268+
/* 8 bit X, Y, Z, Rx, Ry, Rz (min -127, max 127 ) */ \
269269
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
270270
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
271271
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
272272
HID_USAGE ( HID_USAGE_DESKTOP_Z ) ,\
273+
HID_USAGE ( HID_USAGE_DESKTOP_RX ) ,\
274+
HID_USAGE ( HID_USAGE_DESKTOP_RY ) ,\
273275
HID_USAGE ( HID_USAGE_DESKTOP_RZ ) ,\
274276
HID_LOGICAL_MIN ( 0x81 ) ,\
275277
HID_LOGICAL_MAX ( 0x7f ) ,\
276-
HID_REPORT_COUNT ( 4 ) ,\
278+
HID_REPORT_COUNT ( 6 ) ,\
277279
HID_REPORT_SIZE ( 8 ) ,\
278280
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
279281
/* 8 bit Hat Button Map */ \
280282
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
281283
HID_USAGE ( HID_USAGE_DESKTOP_HAT_SWITCH ) ,\
282-
HID_LOGICAL_MIN ( 0 ) ,\
284+
HID_LOGICAL_MIN ( 1 ) ,\
283285
HID_LOGICAL_MAX ( 8 ) ,\
284286
HID_PHYSICAL_MIN ( 0 ) ,\
285287
HID_PHYSICAL_MAX_N ( 315, 2 ) ,\

0 commit comments

Comments
 (0)