Joystick: Simplify report descriptor and clean up error messages (#16926)

This commit is contained in:
Ryan 2022-04-26 08:54:34 +10:00 committed by GitHub
parent 178b70f355
commit 645359e5d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 24 deletions

View File

@ -5,10 +5,18 @@
#ifndef JOYSTICK_BUTTON_COUNT #ifndef JOYSTICK_BUTTON_COUNT
# define JOYSTICK_BUTTON_COUNT 8 # define JOYSTICK_BUTTON_COUNT 8
#elif JOYSTICK_BUTTON_COUNT > 32
# error Joystick feature only supports up to 32 buttons
#endif #endif
#ifndef JOYSTICK_AXES_COUNT #ifndef JOYSTICK_AXES_COUNT
# define JOYSTICK_AXES_COUNT 4 # 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 #endif
#ifndef JOYSTICK_AXES_RESOLUTION #ifndef JOYSTICK_AXES_RESOLUTION

View File

@ -347,34 +347,29 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM ConsoleReport[] = {
#endif #endif
#ifdef JOYSTICK_ENABLE #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[] = { const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = {
HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
HID_RI_USAGE(8, 0x04), // Joystick HID_RI_USAGE(8, 0x04), // Joystick
HID_RI_COLLECTION(8, 0x01), // Application HID_RI_COLLECTION(8, 0x01), // Application
HID_RI_COLLECTION(8, 0x00), // Physical HID_RI_COLLECTION(8, 0x00), // Physical
# if JOYSTICK_AXES_COUNT > 0
HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
# if JOYSTICK_AXES_COUNT >= 1
HID_RI_USAGE(8, 0x30), // X HID_RI_USAGE(8, 0x30), // X
# endif # if JOYSTICK_AXES_COUNT > 1
# if JOYSTICK_AXES_COUNT >= 2
HID_RI_USAGE(8, 0x31), // Y HID_RI_USAGE(8, 0x31), // Y
# endif # endif
# if JOYSTICK_AXES_COUNT >= 3 # if JOYSTICK_AXES_COUNT > 2
HID_RI_USAGE(8, 0x32), // Z HID_RI_USAGE(8, 0x32), // Z
# endif # endif
# if JOYSTICK_AXES_COUNT >= 4 # if JOYSTICK_AXES_COUNT > 3
HID_RI_USAGE(8, 0x33), // Rx HID_RI_USAGE(8, 0x33), // Rx
# endif # endif
# if JOYSTICK_AXES_COUNT >= 5 # if JOYSTICK_AXES_COUNT > 4
HID_RI_USAGE(8, 0x34), // Ry HID_RI_USAGE(8, 0x34), // Ry
# endif # endif
# if JOYSTICK_AXES_COUNT >= 6 # if JOYSTICK_AXES_COUNT > 5
HID_RI_USAGE(8, 0x35), // Rz HID_RI_USAGE(8, 0x35), // Rz
# endif # endif
# if JOYSTICK_AXES_COUNT >= 1
# if JOYSTICK_AXES_RESOLUTION == 8 # if JOYSTICK_AXES_RESOLUTION == 8
HID_RI_LOGICAL_MINIMUM(8, -JOYSTICK_RESOLUTION), HID_RI_LOGICAL_MINIMUM(8, -JOYSTICK_RESOLUTION),
HID_RI_LOGICAL_MAXIMUM(8, JOYSTICK_RESOLUTION), HID_RI_LOGICAL_MAXIMUM(8, JOYSTICK_RESOLUTION),
@ -389,7 +384,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM JoystickReport[] = {
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
# endif # endif
# if JOYSTICK_BUTTON_COUNT >= 1 # if JOYSTICK_BUTTON_COUNT > 0
HID_RI_USAGE_PAGE(8, 0x09), // Button HID_RI_USAGE_PAGE(8, 0x09), // Button
HID_RI_USAGE_MINIMUM(8, 0x01), HID_RI_USAGE_MINIMUM(8, 0x01),
HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT), HID_RI_USAGE_MAXIMUM(8, JOYSTICK_BUTTON_COUNT),