summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2022-04-26 08:54:34 +1000
committerGitHub <noreply@github.com>2022-04-26 08:54:34 +1000
commit645359e5d06758172fe3b6c22ad62641af56b4ad (patch)
treea81cb3731b8c472c1708b545bab913d15a601e01
parent178b70f3558f51996d3a9962478cd72c5697d904 (diff)
downloadqmk_firmware-645359e5d06758172fe3b6c22ad62641af56b4ad.tar.gz
qmk_firmware-645359e5d06758172fe3b6c22ad62641af56b4ad.zip
Joystick: Simplify report descriptor and clean up error messages (#16926)
-rw-r--r--quantum/joystick.h8
-rw-r--r--tmk_core/protocol/usb_descriptor.c43
2 files changed, 27 insertions, 24 deletions
diff --git a/quantum/joystick.h b/quantum/joystick.h
index 002df3a6d9..5d81b14ef2 100644
--- a/quantum/joystick.h
+++ b/quantum/joystick.h
@@ -5,10 +5,18 @@
#ifndef JOYSTICK_BUTTON_COUNT
# define JOYSTICK_BUTTON_COUNT 8
+#elif JOYSTICK_BUTTON_COUNT > 32
+# error Joystick feature only supports up to 32 buttons
#endif
#ifndef JOYSTICK_AXES_COUNT
# define JOYSTICK_AXES_COUNT 4
+#elif JOYSTICK_AXES_COUNT > 6
+# error Joystick feature only supports up to 6 axes
+#endif
+
+#if JOYSTICK_AXES_COUNT == 0 && JOYSTICK_BUTTON_COUNT == 0
+# error Joystick feature requires at least one axis or button
#endif
#ifndef JOYSTICK_AXES_RESOLUTION
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c
index 0b992ba6c5..063bd2c3f1 100644
--- a/tmk_core/protocol/usb_descriptor.c
+++ b/tmk_core/protocol/usb_descriptor.c
@@ -347,49 +347,44 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
#endif
#ifdef JOYSTICK_ENABLE
-# if JOYSTICK_AXES_COUNT == 0 && JOYSTICK_BUTTON_COUNT == 0
-# error Need at least one axis or button for joystick
-# endif
const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = {
- HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
- HID_RI_USAGE(8, 0x04), // Joystick
- HID_RI_COLLECTION(8, 0x01), // Application
- HID_RI_COLLECTION(8, 0x00), // Physical
+ HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
+ HID_RI_USAGE(8, 0x04), // Joystick
+ HID_RI_COLLECTION(8, 0x01), // Application
+ HID_RI_COLLECTION(8, 0x00), // Physical
+# if JOYSTICK_AXES_COUNT > 0
HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
-# if JOYSTICK_AXES_COUNT >= 1
HID_RI_USAGE(8, 0x30), // X
-# endif
-# if JOYSTICK_AXES_COUNT >= 2
+# if JOYSTICK_AXES_COUNT > 1
HID_RI_USAGE(8, 0x31), // Y
-# endif
-# if JOYSTICK_AXES_COUNT >= 3
+# endif
+# if JOYSTICK_AXES_COUNT > 2
HID_RI_USAGE(8, 0x32), // Z
-# endif
-# if JOYSTICK_AXES_COUNT >= 4
+# endif
+# if JOYSTICK_AXES_COUNT > 3
HID_RI_USAGE(8, 0x33), // Rx
-# endif
-# if JOYSTICK_AXES_COUNT >= 5
+# endif
+# if JOYSTICK_AXES_COUNT > 4
HID_RI_USAGE(8, 0x34), // Ry
-# endif
-# if JOYSTICK_AXES_COUNT >= 6
+# endif
+# if JOYSTICK_AXES_COUNT > 5
HID_RI_USAGE(8, 0x35), // Rz
-# endif
-# if JOYSTICK_AXES_COUNT >= 1
- # if JOYSTICK_AXES_RESOLUTION == 8
+# endif
+# if JOYSTICK_AXES_RESOLUTION == 8
HID_RI_LOGICAL_MINIMUM(8, -JOYSTICK_RESOLUTION),
HID_RI_LOGICAL_MAXIMUM(8, JOYSTICK_RESOLUTION),
HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT),
HID_RI_REPORT_SIZE(8, 0x08),
- # else
+# else
HID_RI_LOGICAL_MINIMUM(16, -JOYSTICK_RESOLUTION),
HID_RI_LOGICAL_MAXIMUM(16, JOYSTICK_RESOLUTION),
HID_RI_REPORT_COUNT(8, JOYSTICK_AXES_COUNT),
HID_RI_REPORT_SIZE(8, 0x10),
- # endif
+# endif
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
# endif
-# if JOYSTICK_BUTTON_COUNT >= 1
+# if JOYSTICK_BUTTON_COUNT > 0
HID_RI_USAGE_PAGE(8, 0x09), // Button
HID_RI_USAGE_MINIMUM(8, 0x01),
HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT),