summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorMarcelo Bezerra <[email protected]>2021-06-07 19:04:21 +0200
committerhathach <[email protected]>2021-06-09 10:33:57 +0700
commitd5f8da44d13d3410f6c710432062807b52ebf407 (patch)
tree88cfa4075ffea604d883634b985ca6dcce52ad95 /src/class
parent1b8473902fb0e808c32183f306938accc9ce0d5f (diff)
Add optional support for 32 gamepad buttons
Diffstat (limited to 'src/class')
-rw-r--r--src/class/hid/hid.h40
-rw-r--r--src/class/hid/hid_device.h9
2 files changed, 42 insertions, 7 deletions
diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h
index 5cc9233b5..3c45dc6c1 100644
--- a/src/class/hid/hid.h
+++ b/src/class/hid/hid.h
@@ -33,10 +33,12 @@
#include "common/tusb_common.h"
+
#ifdef __cplusplus
extern "C" {
#endif
+
//--------------------------------------------------------------------+
// Common Definitions
//--------------------------------------------------------------------+
@@ -150,6 +152,22 @@ typedef enum
/** @} */
+#ifndef CFG_TUD_HID_EP_BUFSIZE
+ #define CFG_TUD_HID_EP_BUFSIZE 64
+#endif
+
+#ifndef CFG_TUSB_MAX_BUTTONS
+ #define CFG_TUSB_MAX_BUTTONS 16
+#endif
+
+#if (CFG_TUSB_MAX_BUTTONS == 16)
+ typedef uint16_t hid_gamepad_buttons_t;
+#elif (CFG_TUSB_MAX_BUTTONS == 32)
+ typedef uint32_t hid_gamepad_buttons_t;
+#else
+ #error "Invalid CFG_TUSB_MAX_BUTTONS value."
+#endif
+
//--------------------------------------------------------------------+
// GAMEPAD
//--------------------------------------------------------------------+
@@ -201,7 +219,7 @@ typedef struct TU_ATTR_PACKED
int8_t rx; ///< Delta Rx movement of analog left trigger
int8_t ry; ///< Delta Ry movement of analog right trigger
uint8_t hat; ///< Buttons mask for currently pressed buttons in the DPad/hat
- uint16_t buttons; ///< Buttons mask for currently pressed buttons
+ hid_gamepad_buttons_t buttons; ///< Buttons mask for currently pressed buttons
}hid_gamepad_report_t;
/// Standard Gamepad Buttons Bitmap (from Linux input event codes)
@@ -222,7 +240,25 @@ typedef enum
GAMEPAD_BUTTON_MODE = TU_BIT(12), ///< Mode button
GAMEPAD_BUTTON_THUMBL = TU_BIT(13), ///< L3 button
GAMEPAD_BUTTON_THUMBR = TU_BIT(14), ///< R3 button
-//GAMEPAD_BUTTON_ = TU_BIT(15), ///< Undefined button
+ GAMEPAD_BUTTON_15 = TU_BIT(15), ///< Button 15
+#ifdef CFG_TUSB_MAX_BUTTONS_32
+ GAMEPAD_BUTTON_17 = TU_BIT(16), ///< Button 17
+ GAMEPAD_BUTTON_18 = TU_BIT(17), ///< Button 16
+ GAMEPAD_BUTTON_19 = TU_BIT(18), ///< Button 16
+ GAMEPAD_BUTTON_20 = TU_BIT(19), ///< Button 16
+ GAMEPAD_BUTTON_21 = TU_BIT(20), ///< Button 16
+ GAMEPAD_BUTTON_22 = TU_BIT(21), ///< Button 16
+ GAMEPAD_BUTTON_23 = TU_BIT(22), ///< Button 16
+ GAMEPAD_BUTTON_24 = TU_BIT(23), ///< Button 16
+ GAMEPAD_BUTTON_25 = TU_BIT(24), ///< Button 16
+ GAMEPAD_BUTTON_26 = TU_BIT(25), ///< Button 16
+ GAMEPAD_BUTTON_27 = TU_BIT(26), ///< Button 16
+ GAMEPAD_BUTTON_28 = TU_BIT(27), ///< Button 16
+ GAMEPAD_BUTTON_29 = TU_BIT(28), ///< Button 16
+ GAMEPAD_BUTTON_30 = TU_BIT(29), ///< Button 16
+ GAMEPAD_BUTTON_31 = TU_BIT(30), ///< Button 16
+ GAMEPAD_BUTTON_32 = TU_BIT(31), ///< Button 16
+#endif
}hid_gamepad_button_bm_t;
/// Standard Gamepad HAT/DPAD Buttons (from Linux input event codes)
diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h
index beb755888..0ff5cab3f 100644
--- a/src/class/hid/hid_device.h
+++ b/src/class/hid/hid_device.h
@@ -43,9 +43,8 @@
#define CFG_TUD_HID_EP_BUFSIZE CFG_TUD_HID_BUFSIZE
#endif
-#ifndef CFG_TUD_HID_EP_BUFSIZE
- #define CFG_TUD_HID_EP_BUFSIZE 64
-#endif
+
+
//--------------------------------------------------------------------+
// Application API (Multiple Instances)
@@ -344,10 +343,10 @@ static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y
/* 16 bit Button Map */ \
HID_USAGE_PAGE ( HID_USAGE_PAGE_BUTTON ) ,\
HID_USAGE_MIN ( 1 ) ,\
- HID_USAGE_MAX ( 16 ) ,\
+ HID_USAGE_MAX ( CFG_TUSB_MAX_BUTTONS ) ,\
HID_LOGICAL_MIN ( 0 ) ,\
HID_LOGICAL_MAX ( 1 ) ,\
- HID_REPORT_COUNT ( 16 ) ,\
+ HID_REPORT_COUNT ( CFG_TUSB_MAX_BUTTONS ) ,\
HID_REPORT_SIZE ( 1 ) ,\
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
HID_COLLECTION_END \