Add optional support for 32 gamepad buttons

This commit is contained in:
Marcelo Bezerra 2021-06-07 19:04:21 +02:00 committed by hathach
parent 1b8473902f
commit d5f8da44d1
3 changed files with 48 additions and 7 deletions

View File

@ -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)

View File

@ -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 \

View File

@ -316,6 +316,12 @@
#error Control Endpoint Max Packet Size cannot be larger than 64
#endif
#ifndef TUD_OPT_GAMEPAD_32_BUTTONS
#define CFG_TUSB_MAX_BUTTONS 16
#else
#define CFG_TUSB_MAX_BUTTONS 32
#endif
#endif /* _TUSB_OPTION_H_ */
/** @} */