From 6cc9513ab0cd5e21354c51ab83a89af9f2eb517e Mon Sep 17 00:00:00 2001 From: Ryan Date: Sun, 13 Nov 2022 10:28:11 +1100 Subject: Digitizer feature improvements (#19034) --- tmk_core/protocol/host.c | 9 ++++---- tmk_core/protocol/report.h | 7 +++--- tmk_core/protocol/usb_descriptor.c | 44 ++++++++++++++++++-------------------- tmk_core/protocol/vusb/vusb.c | 24 ++++++++++----------- 4 files changed, 41 insertions(+), 43 deletions(-) (limited to 'tmk_core/protocol') diff --git a/tmk_core/protocol/host.c b/tmk_core/protocol/host.c index b441d2d5d9..5fee872326 100644 --- a/tmk_core/protocol/host.c +++ b/tmk_core/protocol/host.c @@ -217,10 +217,11 @@ void host_digitizer_send(digitizer_t *digitizer) { # ifdef DIGITIZER_SHARED_EP .report_id = REPORT_ID_DIGITIZER, # endif - .tip = digitizer->tipswitch & 0x1, - .inrange = digitizer->inrange & 0x1, - .x = (uint16_t)(digitizer->x * 0x7FFF), - .y = (uint16_t)(digitizer->y * 0x7FFF), + .in_range = digitizer->in_range, + .tip = digitizer->tip, + .barrel = digitizer->barrel, + .x = (uint16_t)(digitizer->x * 0x7FFF), + .y = (uint16_t)(digitizer->y * 0x7FFF), }; send_digitizer(&report); diff --git a/tmk_core/protocol/report.h b/tmk_core/protocol/report.h index 8bc4a57c0c..543c44e33c 100644 --- a/tmk_core/protocol/report.h +++ b/tmk_core/protocol/report.h @@ -226,9 +226,10 @@ typedef struct { #ifdef DIGITIZER_SHARED_EP uint8_t report_id; #endif - uint8_t tip : 1; - uint8_t inrange : 1; - uint8_t pad2 : 6; + bool in_range : 1; + bool tip : 1; + bool barrel : 1; + uint8_t reserved : 5; uint16_t x; uint16_t y; } __attribute__((packed)) report_digitizer_t; diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index 7117d2fc11..3c170f1112 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c @@ -181,39 +181,37 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM DigitizerReport[] = { const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { # define SHARED_REPORT_STARTED # endif - HID_RI_USAGE_PAGE(8, 0x0D), // Digitizers - HID_RI_USAGE(8, 0x01), // Digitizer - HID_RI_COLLECTION(8, 0x01), // Application + HID_RI_USAGE_PAGE(8, 0x0D), // Digitizers + HID_RI_USAGE(8, 0x01), // Digitizer + HID_RI_COLLECTION(8, 0x01), // Application # ifdef DIGITIZER_SHARED_EP HID_RI_REPORT_ID(8, REPORT_ID_DIGITIZER), # endif - HID_RI_USAGE(8, 0x20), // Stylus - HID_RI_COLLECTION(8, 0x00), // Physical - // Tip Switch (1 bit) - HID_RI_USAGE(8, 0x42), // Tip Switch + HID_RI_USAGE(8, 0x20), // Stylus + HID_RI_COLLECTION(8, 0x00), // Physical + // In Range, Tip Switch & Barrel Switch (3 bits) + HID_RI_USAGE(8, 0x32), // In Range + HID_RI_USAGE(8, 0x42), // Tip Switch + HID_RI_USAGE(8, 0x44), // Barrel Switch HID_RI_LOGICAL_MINIMUM(8, 0x00), HID_RI_LOGICAL_MAXIMUM(8, 0x01), + HID_RI_REPORT_COUNT(8, 0x03), HID_RI_REPORT_SIZE(8, 0x01), - HID_RI_REPORT_COUNT(8, 0x01), - HID_RI_INPUT(8, HID_IOF_VARIABLE), - // In Range (1 bit) - HID_RI_USAGE(8, 0x32), // In Range - HID_RI_INPUT(8, HID_IOF_VARIABLE), - // Padding (6 bits) - HID_RI_REPORT_COUNT(8, 0x06), - HID_RI_INPUT(8, HID_IOF_CONSTANT | HID_IOF_VARIABLE), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + // Padding (5 bits) + HID_RI_REPORT_COUNT(8, 0x05), + HID_RI_INPUT(8, HID_IOF_CONSTANT), // X/Y Position (4 bytes) - HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop + HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop + HID_RI_USAGE(8, 0x30), // X + HID_RI_USAGE(8, 0x31), // Y HID_RI_LOGICAL_MAXIMUM(16, 0x7FFF), + HID_RI_REPORT_COUNT(8, 0x02), HID_RI_REPORT_SIZE(8, 0x10), - HID_RI_REPORT_COUNT(8, 0x01), - HID_RI_UNIT(8, 0x33), // Inch, English Linear - HID_RI_UNIT_EXPONENT(8, 0x0E), // -2 - HID_RI_USAGE(8, 0x30), // X - HID_RI_INPUT(8, HID_IOF_VARIABLE), - HID_RI_USAGE(8, 0x31), // Y - HID_RI_INPUT(8, HID_IOF_VARIABLE), + HID_RI_UNIT(8, 0x33), // Inch, English Linear + HID_RI_UNIT_EXPONENT(8, 0x0E), // -2 + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), HID_RI_END_COLLECTION(0), HID_RI_END_COLLECTION(0), # ifndef DIGITIZER_SHARED_EP diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index 84b01b203e..ac35043e2a 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c @@ -532,32 +532,30 @@ const PROGMEM uchar shared_hid_report[] = { 0x09, 0x01, // Usage (Digitizer) 0xA1, 0x01, // Collection (Application) 0x85, REPORT_ID_DIGITIZER, // Report ID - 0x09, 0x22, // Usage (Finger) + 0x09, 0x20, // Usage (Stylus) 0xA1, 0x00, // Collection (Physical) - // Tip Switch (1 bit) + // In Range, Tip Switch & Barrel Switch (3 bits) + 0x09, 0x32, // Usage (In Range) 0x09, 0x42, // Usage (Tip Switch) + 0x09, 0x44, // Usage (Barrel Switch) 0x15, 0x00, // Logical Minimum 0x25, 0x01, // Logical Maximum - 0x95, 0x01, // Report Count (1) - 0x75, 0x01, // Report Size (16) - 0x81, 0x02, // Input (Data, Variable, Absolute) - // In Range (1 bit) - 0x09, 0x32, // Usage (In Range) + 0x95, 0x03, // Report Count (3) + 0x75, 0x01, // Report Size (1) 0x81, 0x02, // Input (Data, Variable, Absolute) - // Padding (6 bits) - 0x95, 0x06, // Report Count (6) + // Padding (5 bits) + 0x95, 0x05, // Report Count (5) 0x81, 0x03, // Input (Constant) // X/Y Position (4 bytes) 0x05, 0x01, // Usage Page (Generic Desktop) + 0x09, 0x30, // Usage (X) + 0x09, 0x31, // Usage (Y) 0x26, 0xFF, 0x7F, // Logical Maximum (32767) - 0x95, 0x01, // Report Count (1) + 0x95, 0x02, // Report Count (2) 0x75, 0x10, // Report Size (16) 0x65, 0x33, // Unit (Inch, English Linear) 0x55, 0x0E, // Unit Exponent (-2) - 0x09, 0x30, // Usage (X) - 0x81, 0x02, // Input (Data, Variable, Absolute) - 0x09, 0x31, // Usage (Y) 0x81, 0x02, // Input (Data, Variable, Absolute) 0xC0, // End Collection 0xC0, // End Collection -- cgit v1.2.3