From d5f8da44d13d3410f6c710432062807b52ebf407 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Mon, 7 Jun 2021 19:04:21 +0200 Subject: [PATCH 01/11] Add optional support for 32 gamepad buttons --- src/class/hid/hid.h | 40 ++++++++++++++++++++++++++++++++++++-- src/class/hid/hid_device.h | 9 ++++----- src/tusb_option.h | 6 ++++++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 5cc9233b..3c45dc6c 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 beb75588..0ff5cab3 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 \ diff --git a/src/tusb_option.h b/src/tusb_option.h index 5cfcc08e..a7939d9c 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -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_ */ /** @} */ From 3842c806a6bd90a3be8431c4fa3fb8c46220a6bf Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Mon, 7 Jun 2021 20:16:05 +0200 Subject: [PATCH 02/11] clean up --- src/class/hid/hid.h | 16 ++++++---------- src/class/hid/hid_device.h | 4 ++-- src/tusb_option.h | 17 +++++++++++++---- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 3c45dc6c..eac30c62 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -152,20 +152,16 @@ typedef enum /** @} */ -#ifndef CFG_TUD_HID_EP_BUFSIZE - #define CFG_TUD_HID_EP_BUFSIZE 64 +#ifndef CFG_TUD_MAX_BUTTONS + #define CFG_TUD_MAX_BUTTONS 16 #endif -#ifndef CFG_TUSB_MAX_BUTTONS - #define CFG_TUSB_MAX_BUTTONS 16 -#endif - -#if (CFG_TUSB_MAX_BUTTONS == 16) +#if (CFG_TUD_MAX_BUTTONS == 16) typedef uint16_t hid_gamepad_buttons_t; -#elif (CFG_TUSB_MAX_BUTTONS == 32) +#elif (CFG_TUD_MAX_BUTTONS == 32) typedef uint32_t hid_gamepad_buttons_t; #else - #error "Invalid CFG_TUSB_MAX_BUTTONS value." + #error "Invalid CFG_TUD_MAX_BUTTONS value." #endif //--------------------------------------------------------------------+ @@ -241,7 +237,7 @@ typedef enum GAMEPAD_BUTTON_THUMBL = TU_BIT(13), ///< L3 button GAMEPAD_BUTTON_THUMBR = TU_BIT(14), ///< R3 button GAMEPAD_BUTTON_15 = TU_BIT(15), ///< Button 15 -#ifdef CFG_TUSB_MAX_BUTTONS_32 +#if (CFG_TUD_MAX_BUTTONS > 16) GAMEPAD_BUTTON_17 = TU_BIT(16), ///< Button 17 GAMEPAD_BUTTON_18 = TU_BIT(17), ///< Button 16 GAMEPAD_BUTTON_19 = TU_BIT(18), ///< Button 16 diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 0ff5cab3..39ec6be7 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -343,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 ( CFG_TUSB_MAX_BUTTONS ) ,\ + HID_USAGE_MAX ( CFG_TUD_MAX_BUTTONS ) ,\ HID_LOGICAL_MIN ( 0 ) ,\ HID_LOGICAL_MAX ( 1 ) ,\ - HID_REPORT_COUNT ( CFG_TUSB_MAX_BUTTONS ) ,\ + HID_REPORT_COUNT ( CFG_TUD_MAX_BUTTONS ) ,\ HID_REPORT_SIZE ( 1 ) ,\ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ HID_COLLECTION_END \ diff --git a/src/tusb_option.h b/src/tusb_option.h index a7939d9c..3adb4fcf 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -309,6 +309,16 @@ #define TUP_MCU_STRICT_ALIGN 0 #endif +//--------------------------------------------------------------------+ +// HID Gamepad options +//--------------------------------------------------------------------+ + +// CFG_TUD_MAX_BUTTONS lets you choose if you want 16 or 32 buttons on you HID gamepad +#ifndef CFG_TUD_MAX_BUTTONS + #define CFG_TUD_MAX_BUTTONS 16 +#endif + + //------------------------------------------------------------------ // Configuration Validation //------------------------------------------------------------------ @@ -316,10 +326,9 @@ #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 + +#if (CFG_TUD_MAX_BUTTONS != 16 && CFG_TUD_MAX_BUTTONS != 32) + #error "Unsupported CFG_TUD_MAX_BUTTONS" #endif #endif /* _TUSB_OPTION_H_ */ From ce634f226e59cccfb236371f85a62cb610ef80f6 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Mon, 7 Jun 2021 20:44:53 +0200 Subject: [PATCH 03/11] remove excess empty lines --- src/class/hid/hid.h | 2 -- src/tusb_option.h | 1 - 2 files changed, 3 deletions(-) diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index eac30c62..0764bc22 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -33,12 +33,10 @@ #include "common/tusb_common.h" - #ifdef __cplusplus extern "C" { #endif - //--------------------------------------------------------------------+ // Common Definitions //--------------------------------------------------------------------+ diff --git a/src/tusb_option.h b/src/tusb_option.h index 3adb4fcf..6a6e31ee 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -318,7 +318,6 @@ #define CFG_TUD_MAX_BUTTONS 16 #endif - //------------------------------------------------------------------ // Configuration Validation //------------------------------------------------------------------ From f37c8ed749a7bdc264de132f8d81dec47a7972f6 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Mon, 7 Jun 2021 21:29:24 +0200 Subject: [PATCH 04/11] Add CFG_TUD_MAX_BUTTONS to the example --- examples/device/hid_composite/src/tusb_config.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/device/hid_composite/src/tusb_config.h b/examples/device/hid_composite/src/tusb_config.h index 3e608ed3..bc9192d1 100644 --- a/examples/device/hid_composite/src/tusb_config.h +++ b/examples/device/hid_composite/src/tusb_config.h @@ -104,6 +104,10 @@ // HID buffer size Should be sufficient to hold ID (if any) + Data #define CFG_TUD_HID_EP_BUFSIZE 16 +// Number of button on the gamepad 16 or 32 +#define CFG_TUD_MAX_BUTTONS 16 + + #ifdef __cplusplus } #endif From e12195705c2b849379145618691c2e8564762aa7 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Tue, 8 Jun 2021 09:24:50 +0200 Subject: [PATCH 05/11] Pull request changes Remove configuration options and just bump number of buttons to 32 Fix button numbereing and comments in --- .../device/hid_composite/src/tusb_config.h | 4 -- src/class/hid/hid.h | 48 +++++++------------ src/class/hid/hid_device.h | 4 +- src/tusb_option.h | 14 ------ 4 files changed, 19 insertions(+), 51 deletions(-) diff --git a/examples/device/hid_composite/src/tusb_config.h b/examples/device/hid_composite/src/tusb_config.h index bc9192d1..3e608ed3 100644 --- a/examples/device/hid_composite/src/tusb_config.h +++ b/examples/device/hid_composite/src/tusb_config.h @@ -104,10 +104,6 @@ // HID buffer size Should be sufficient to hold ID (if any) + Data #define CFG_TUD_HID_EP_BUFSIZE 16 -// Number of button on the gamepad 16 or 32 -#define CFG_TUD_MAX_BUTTONS 16 - - #ifdef __cplusplus } #endif diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 0764bc22..a344c910 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -150,18 +150,6 @@ typedef enum /** @} */ -#ifndef CFG_TUD_MAX_BUTTONS - #define CFG_TUD_MAX_BUTTONS 16 -#endif - -#if (CFG_TUD_MAX_BUTTONS == 16) - typedef uint16_t hid_gamepad_buttons_t; -#elif (CFG_TUD_MAX_BUTTONS == 32) - typedef uint32_t hid_gamepad_buttons_t; -#else - #error "Invalid CFG_TUD_MAX_BUTTONS value." -#endif - //--------------------------------------------------------------------+ // GAMEPAD //--------------------------------------------------------------------+ @@ -213,7 +201,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 - hid_gamepad_buttons_t buttons; ///< Buttons mask for currently pressed buttons + uint32_t buttons; ///< Buttons mask for currently pressed buttons }hid_gamepad_report_t; /// Standard Gamepad Buttons Bitmap (from Linux input event codes) @@ -234,25 +222,23 @@ 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_15 = TU_BIT(15), ///< Button 15 -#if (CFG_TUD_MAX_BUTTONS > 16) + GAMEPAD_BUTTON_16 = TU_BIT(15), ///< Button 15 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 + GAMEPAD_BUTTON_18 = TU_BIT(17), ///< Button 18 + GAMEPAD_BUTTON_19 = TU_BIT(18), ///< Button 19 + GAMEPAD_BUTTON_20 = TU_BIT(19), ///< Button 20 + GAMEPAD_BUTTON_21 = TU_BIT(20), ///< Button 21 + GAMEPAD_BUTTON_22 = TU_BIT(21), ///< Button 22 + GAMEPAD_BUTTON_23 = TU_BIT(22), ///< Button 23 + GAMEPAD_BUTTON_24 = TU_BIT(23), ///< Button 24 + GAMEPAD_BUTTON_25 = TU_BIT(24), ///< Button 25 + GAMEPAD_BUTTON_26 = TU_BIT(25), ///< Button 26 + GAMEPAD_BUTTON_27 = TU_BIT(26), ///< Button 27 + GAMEPAD_BUTTON_28 = TU_BIT(27), ///< Button 28 + GAMEPAD_BUTTON_29 = TU_BIT(28), ///< Button 29 + GAMEPAD_BUTTON_30 = TU_BIT(29), ///< Button 30 + GAMEPAD_BUTTON_31 = TU_BIT(30), ///< Button 31 + GAMEPAD_BUTTON_32 = TU_BIT(31), ///< Button 32 }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 39ec6be7..543bc3b3 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -343,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 ( CFG_TUD_MAX_BUTTONS ) ,\ + HID_USAGE_MAX ( 32 ) ,\ HID_LOGICAL_MIN ( 0 ) ,\ HID_LOGICAL_MAX ( 1 ) ,\ - HID_REPORT_COUNT ( CFG_TUD_MAX_BUTTONS ) ,\ + HID_REPORT_COUNT ( 32 ) ,\ HID_REPORT_SIZE ( 1 ) ,\ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\ HID_COLLECTION_END \ diff --git a/src/tusb_option.h b/src/tusb_option.h index 6a6e31ee..5cfcc08e 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -309,15 +309,6 @@ #define TUP_MCU_STRICT_ALIGN 0 #endif -//--------------------------------------------------------------------+ -// HID Gamepad options -//--------------------------------------------------------------------+ - -// CFG_TUD_MAX_BUTTONS lets you choose if you want 16 or 32 buttons on you HID gamepad -#ifndef CFG_TUD_MAX_BUTTONS - #define CFG_TUD_MAX_BUTTONS 16 -#endif - //------------------------------------------------------------------ // Configuration Validation //------------------------------------------------------------------ @@ -325,11 +316,6 @@ #error Control Endpoint Max Packet Size cannot be larger than 64 #endif - -#if (CFG_TUD_MAX_BUTTONS != 16 && CFG_TUD_MAX_BUTTONS != 32) - #error "Unsupported CFG_TUD_MAX_BUTTONS" -#endif - #endif /* _TUSB_OPTION_H_ */ /** @} */ From de71e72e31ca1d534e5e0413f9da0a0e84a9aa69 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Tue, 8 Jun 2021 09:26:17 +0200 Subject: [PATCH 06/11] Fix comment in hid.h --- src/class/hid/hid.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index a344c910..8ab24ab3 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -217,12 +217,12 @@ typedef enum GAMEPAD_BUTTON_TR = TU_BIT(7), ///< R1 button GAMEPAD_BUTTON_TL2 = TU_BIT(8), ///< L2 button GAMEPAD_BUTTON_TR2 = TU_BIT(9), ///< R2 button - GAMEPAD_BUTTON_SELECT = TU_BIT(10), ///< Select button + GAMEPAD_BUTTON_SELECT = TU_BIT(10), ///< Select button GAMEPAD_BUTTON_START = TU_BIT(11), ///< Start button 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_16 = TU_BIT(15), ///< Button 15 + GAMEPAD_BUTTON_16 = TU_BIT(15), ///< Button 16 GAMEPAD_BUTTON_17 = TU_BIT(16), ///< Button 17 GAMEPAD_BUTTON_18 = TU_BIT(17), ///< Button 18 GAMEPAD_BUTTON_19 = TU_BIT(18), ///< Button 19 From d3b6e28387c63a1519cd1958ee7e21bd2980d099 Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Tue, 8 Jun 2021 09:31:40 +0200 Subject: [PATCH 07/11] indent fix --- src/class/hid/hid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 8ab24ab3..782a1a55 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -217,7 +217,7 @@ typedef enum GAMEPAD_BUTTON_TR = TU_BIT(7), ///< R1 button GAMEPAD_BUTTON_TL2 = TU_BIT(8), ///< L2 button GAMEPAD_BUTTON_TR2 = TU_BIT(9), ///< R2 button - GAMEPAD_BUTTON_SELECT = TU_BIT(10), ///< Select button + GAMEPAD_BUTTON_SELECT = TU_BIT(10), ///< Select button GAMEPAD_BUTTON_START = TU_BIT(11), ///< Start button GAMEPAD_BUTTON_MODE = TU_BIT(12), ///< Mode button GAMEPAD_BUTTON_THUMBL = TU_BIT(13), ///< L3 button From e393fb32a0830e9d371f3e335cc0cca92b75cbbb Mon Sep 17 00:00:00 2001 From: Marcelo Bezerra <23555060+mmosca@users.noreply.github.com> Date: Tue, 8 Jun 2021 09:39:53 +0200 Subject: [PATCH 08/11] re-adding ifdef removed accidentally --- src/class/hid/hid_device.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 543bc3b3..1d1213e3 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -43,8 +43,9 @@ #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) From 2c0947ebb621e3e53933300cbfd1dce7e0f31338 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 9 Jun 2021 10:30:13 +0700 Subject: [PATCH 09/11] update gamepad helper --- src/class/hid/hid.h | 1 + src/class/hid/hid_device.c | 2 +- src/class/hid/hid_device.h | 6 +++--- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h index 782a1a55..b4e8a9c4 100644 --- a/src/class/hid/hid.h +++ b/src/class/hid/hid.h @@ -222,6 +222,7 @@ 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 + // Note: Button number start from 1 on host OS GAMEPAD_BUTTON_16 = TU_BIT(15), ///< Button 16 GAMEPAD_BUTTON_17 = TU_BIT(16), ///< Button 17 GAMEPAD_BUTTON_18 = TU_BIT(17), ///< Button 18 diff --git a/src/class/hid/hid_device.c b/src/class/hid/hid_device.c index 151a3622..e44f282c 100644 --- a/src/class/hid/hid_device.c +++ b/src/class/hid/hid_device.c @@ -149,7 +149,7 @@ bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id, } bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, - int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons) + int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons) { hid_gamepad_report_t report = { diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 1d1213e3..19e9315f 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -72,9 +72,9 @@ bool tud_hid_n_keyboard_report(uint8_t instance, uint8_t report_id, uint8_t modi // use template layout report as defined by hid_mouse_report_t bool tud_hid_n_mouse_report(uint8_t instance, uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); -// Gamepad: convenient helper to send mouse report if application +// Gamepad: convenient helper to send gamepad report if application // use template layout report TUD_HID_REPORT_DESC_GAMEPAD -bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons); +bool tud_hid_n_gamepad_report(uint8_t instance, uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons); //--------------------------------------------------------------------+ // Application API (Single Port) @@ -85,7 +85,7 @@ static inline uint8_t tud_hid_get_protocol(void); static inline bool tud_hid_report(uint8_t report_id, void const* report, uint8_t len); static inline bool tud_hid_keyboard_report(uint8_t report_id, uint8_t modifier, uint8_t keycode[6]); static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8_t x, int8_t y, int8_t vertical, int8_t horizontal); -static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons); +static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons); //--------------------------------------------------------------------+ // Callbacks (Weak is optional) From dca9bc97d66fe2912d2643e4f36cb839d08a31da Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 9 Jun 2021 10:45:37 +0700 Subject: [PATCH 10/11] miss a helper --- src/class/hid/hid_device.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/class/hid/hid_device.h b/src/class/hid/hid_device.h index 19e9315f..e2c950dd 100644 --- a/src/class/hid/hid_device.h +++ b/src/class/hid/hid_device.h @@ -152,7 +152,7 @@ static inline bool tud_hid_mouse_report(uint8_t report_id, uint8_t buttons, int8 return tud_hid_n_mouse_report(0, report_id, buttons, x, y, vertical, horizontal); } -static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint16_t buttons) +static inline bool tud_hid_gamepad_report(uint8_t report_id, int8_t x, int8_t y, int8_t z, int8_t rz, int8_t rx, int8_t ry, uint8_t hat, uint32_t buttons) { return tud_hid_n_gamepad_report(0, report_id, x, y, z, rz, rx, ry, hat, buttons); } From d81a37d1bed3e9a905a1472eaafe2f750892eaac Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 9 Jun 2021 12:10:44 +0700 Subject: [PATCH 11/11] fix enum overflow with msp430 --- src/common/tusb_common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/tusb_common.h b/src/common/tusb_common.h index 3350ed86..889ad7b2 100644 --- a/src/common/tusb_common.h +++ b/src/common/tusb_common.h @@ -51,7 +51,7 @@ #define U32_TO_U8S_BE(u32) TU_U32_BYTE3(u32), TU_U32_BYTE2(u32), TU_U32_BYTE1(u32), TU_U32_BYTE0(u32) #define U32_TO_U8S_LE(u32) TU_U32_BYTE0(u32), TU_U32_BYTE1(u32), TU_U32_BYTE2(u32), TU_U32_BYTE3(u32) -#define TU_BIT(n) (1U << (n)) +#define TU_BIT(n) (1UL << (n)) //--------------------------------------------------------------------+ // Includes