summaryrefslogtreecommitdiffstats
path: root/tmk_core/protocol/vusb
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2022-11-27 03:14:45 +1100
committerGitHub <noreply@github.com>2022-11-27 03:14:45 +1100
commit1e95f7be8f214c544bf99f415916a4a5f07a1e9b (patch)
tree99e7148ab4c464f40da8f0ee01e079843a26cf14 /tmk_core/protocol/vusb
parenta5a20cc792540c0de61f064bd8dafcdc5815d4cc (diff)
Joystick feature improvements (#19052)
Diffstat (limited to 'tmk_core/protocol/vusb')
-rw-r--r--tmk_core/protocol/vusb/vusb.c77
1 files changed, 74 insertions, 3 deletions
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 <http://www.gnu.org/licenses/>.
# 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)