From 1e95f7be8f214c544bf99f415916a4a5f07a1e9b Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 27 Nov 2022 03:14:45 +1100 Subject: Joystick feature improvements (#19052) --- tmk_core/protocol/vusb/vusb.c | 77 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) (limited to 'tmk_core/protocol/vusb') diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index ac35043e2a..2d17761978 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -35,6 +35,10 @@ along with this program. If not, see . # include "raw_hid.h" #endif +#ifdef JOYSTICK_ENABLE +# include "joystick.h" +#endif + #if defined(CONSOLE_ENABLE) # define RBUF_SIZE 128 # include "ring_buffer.h" @@ -275,6 +279,14 @@ static void send_extra(report_extra_t *report) { #endif } +void send_joystick(report_joystick_t *report) { +#ifdef JOYSTICK_ENABLE + if (usbInterruptIsReadyShared()) { + usbSetInterruptShared((void *)report, sizeof(report_joystick_t)); + } +#endif +} + void send_digitizer(report_digitizer_t *report) { #ifdef DIGITIZER_ENABLE if (usbInterruptIsReadyShared()) { @@ -526,6 +538,65 @@ const PROGMEM uchar shared_hid_report[] = { 0xC0, // End Collection #endif +#ifdef JOYSTICK_ENABLE + // Joystick report descriptor + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x04, // Usage (Joystick) + 0xA1, 0x01, // Collection (Application) + 0x85, REPORT_ID_JOYSTICK, // Report ID + 0xA1, 0x00, // Collection (Physical) +# if JOYSTICK_AXIS_COUNT > 0 + 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x30, // Usage (X) +# if JOYSTICK_AXIS_COUNT > 1 + 0x09, 0x31, // Usage (Y) +# endif +# if JOYSTICK_AXIS_COUNT > 2 + 0x09, 0x32, // Usage (Z) +# endif +# if JOYSTICK_AXIS_COUNT > 3 + 0x09, 0x33, // Usage (Rx) +# endif +# if JOYSTICK_AXIS_COUNT > 4 + 0x09, 0x34, // Usage (Ry) +# endif +# if JOYSTICK_AXIS_COUNT > 5 + 0x09, 0x35, // Usage (Rz) +# endif +# if JOYSTICK_AXIS_RESOLUTION == 8 + 0x15, -JOYSTICK_MAX_VALUE, // Logical Minimum + 0x25, JOYSTICK_MAX_VALUE, // Logical Maximum + 0x95, JOYSTICK_AXIS_COUNT, // Report Count + 0x75, 0x08, // Report Size (8) +# else + 0x16, HID_VALUE_16(-JOYSTICK_MAX_VALUE), // Logical Minimum + 0x26, HID_VALUE_16(JOYSTICK_MAX_VALUE), // Logical Maximum + 0x95, JOYSTICK_AXIS_COUNT, // Report Count + 0x75, 0x10, // Report Size (16) +# endif + 0x81, 0x02, // Input (Data, Variable, Absolute) +# endif + +# if JOYSTICK_BUTTON_COUNT > 0 + 0x05, 0x09, // Usage Page (Button) + 0x19, 0x01, // Usage Minimum (Button 1) + 0x29, JOYSTICK_BUTTON_COUNT, // Usage Maximum + 0x15, 0x00, // Logical Minimum (0) + 0x25, 0x01, // Logical Maximum (1) + 0x95, JOYSTICK_BUTTON_COUNT, // Report Count + 0x75, 0x01, // Report Size (1) + 0x81, 0x02, // Input (Data, Variable, Absolute) + +# if (JOYSTICK_BUTTON_COUNT % 8) != 0 + 0x95, 8 - (JOYSTICK_BUTTON_COUNT % 8), // Report Count + 0x75, 0x01, // Report Size (1) + 0x81, 0x03, // Input (Constant) +# endif +# endif + 0xC0, // End Collection + 0xC0, // End Collection +#endif + #ifdef DIGITIZER_ENABLE // Digitizer report descriptor 0x05, 0x0D, // Usage Page (Digitizers) @@ -587,9 +658,9 @@ const PROGMEM uchar shared_hid_report[] = { #ifdef RAW_ENABLE const PROGMEM uchar raw_hid_report[] = { - 0x06, RAW_USAGE_PAGE_LO, RAW_USAGE_PAGE_HI, // Usage Page (Vendor Defined) - 0x09, RAW_USAGE_ID, // Usage (Vendor Defined) - 0xA1, 0x01, // Collection (Application) + 0x06, HID_VALUE_16(RAW_USAGE_PAGE), // Usage Page (Vendor Defined) + 0x09, RAW_USAGE_ID, // Usage (Vendor Defined) + 0xA1, 0x01, // Collection (Application) // Data to host 0x09, 0x62, // Usage (Vendor Defined) 0x15, 0x00, // Logical Minimum (0) -- cgit v1.2.3