1
0
Fork 0

Joystick: add support for 8-way hat switch (#24515)

This commit is contained in:
Ryan 2024-11-10 09:10:10 +11:00 committed by GitHub
parent 69093f6de9
commit a3cfb1dab7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 124 additions and 2 deletions

View file

@ -193,6 +193,10 @@ void host_joystick_send(joystick_t *joystick) {
},
# endif
# ifdef JOYSTICK_HAS_HAT
.hat = joystick->hat,
# endif
# if JOYSTICK_BUTTON_COUNT > 0
.buttons =
{

View file

@ -246,6 +246,11 @@ typedef struct {
joystick_axis_t axes[JOYSTICK_AXIS_COUNT];
#endif
#ifdef JOYSTICK_HAS_HAT
int8_t hat : 4;
uint8_t reserved : 4;
#endif
#if JOYSTICK_BUTTON_COUNT > 0
uint8_t buttons[(JOYSTICK_BUTTON_COUNT - 1) / 8 + 1];
#endif

View file

@ -247,6 +247,23 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
# endif
# ifdef JOYSTICK_HAS_HAT
// Hat Switch (4 bits)
HID_RI_USAGE(8, 0x39), // Hat Switch
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0x07),
HID_RI_PHYSICAL_MINIMUM(8, 0),
HID_RI_PHYSICAL_MAXIMUM(16, 315),
HID_RI_UNIT(8, 0x14), // Degree, English Rotation
HID_RI_REPORT_COUNT(8, 1),
HID_RI_REPORT_SIZE(8, 4),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE | HID_IOF_NULLSTATE),
// Padding (4 bits)
HID_RI_REPORT_COUNT(8, 0x04),
HID_RI_REPORT_SIZE(8, 0x01),
HID_RI_INPUT(8, HID_IOF_CONSTANT),
# endif
# if JOYSTICK_BUTTON_COUNT > 0
HID_RI_USAGE_PAGE(8, 0x09), // Button
HID_RI_USAGE_MINIMUM(8, 0x01),

View file

@ -621,6 +621,23 @@ const PROGMEM uchar shared_hid_report[] = {
0x81, 0x02, // Input (Data, Variable, Absolute)
# endif
# ifdef JOYSTICK_HAS_HAT
// Hat Switch (4 bits)
0x09, 0x39, // Usage (Hat Switch)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x07, // Logical Maximum (7)
0x35, 0x00, // Physical Minimum (0)
0x46, 0x3B, 0x01, // Physical Maximum (315)
0x65, 0x14, // Unit (Degree, English Rotation)
0x95, 0x01, // Report Count (1)
0x75, 0x04, // Report Size (4)
0x81, 0x42, // Input (Data, Variable, Absolute, Null State)
// Padding (4 bits)
0x95, 0x04, // Report Count (4)
0x75, 0x01, // Report Size (1)
0x81, 0x01, // Input (Constant)
# endif
# if JOYSTICK_BUTTON_COUNT > 0
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (Button 1)