Created
July 10, 2022 06:26
-
-
Save fauxpark/3f5e5b2b6d5b91afcfaf7fb1deb2380e to your computer and use it in GitHub Desktop.
mouse report resolution multiplier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tmk_core/protocol/lufa/lufa.c b/tmk_core/protocol/lufa/lufa.c | |
index b4b03357a3..d183c4bcca 100644 | |
--- a/tmk_core/protocol/lufa/lufa.c | |
+++ b/tmk_core/protocol/lufa/lufa.c | |
@@ -96,6 +96,10 @@ uint8_t keyboard_protocol = 1; | |
static uint8_t keyboard_led_state = 0; | |
static report_keyboard_t keyboard_report_sent; | |
+report_mouse_res_t mouse_res_report = { | |
+ REPORT_ID_MOUSE, | |
+ 0x00, | |
+}; | |
/* Host driver */ | |
static uint8_t keyboard_leds(void); | |
@@ -539,6 +543,17 @@ void EVENT_USB_Device_ControlRequest(void) { | |
ReportData = (uint8_t *)&keyboard_report_sent; | |
ReportSize = sizeof(keyboard_report_sent); | |
break; | |
+#if defined(SHARED_EP_ENABLE) && defined(MOUSE_SHARED_EP) | |
+ case SHARED_INTERFACE: | |
+#else | |
+ case MOUSE_INTERFACE: | |
+#endif | |
+ | |
+ if (USB_ControlRequest.wValue == (0x0300 | REPORT_ID_MOUSE)) { | |
+ ReportData = (uint8_t *)&mouse_res_report; | |
+ ReportSize = sizeof(mouse_res_report); | |
+ } | |
+ break; | |
} | |
/* Write the report data to the control endpoint */ | |
@@ -561,14 +576,16 @@ void EVENT_USB_Device_ControlRequest(void) { | |
if (USB_DeviceState == DEVICE_STATE_Unattached) return; | |
} | |
- if (Endpoint_BytesInEndpoint() == 2) { | |
- uint8_t report_id = Endpoint_Read_8(); | |
+ uint8_t report_id = USB_ControlRequest.wValue & 0xFF; | |
+ // Discard report ID byte as we already have it from wValue | |
+ if (USB_ControlRequest.wLength == 2) { | |
+ Endpoint_Discard_8(); | |
+ } | |
- if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) { | |
- keyboard_led_state = Endpoint_Read_8(); | |
- } | |
- } else { | |
+ if (report_id == REPORT_ID_KEYBOARD || report_id == REPORT_ID_NKRO) { | |
keyboard_led_state = Endpoint_Read_8(); | |
+ } else if (report_id == REPORT_ID_MOUSE) { | |
+ mouse_res_report.res = Endpoint_Read_8(); | |
} | |
Endpoint_ClearOUT(); | |
diff --git a/tmk_core/protocol/lufa/lufa.h b/tmk_core/protocol/lufa/lufa.h | |
index 6a5205609e..bcff94776c 100644 | |
--- a/tmk_core/protocol/lufa/lufa.h | |
+++ b/tmk_core/protocol/lufa/lufa.h | |
@@ -53,6 +53,8 @@ extern "C" { | |
extern host_driver_t lufa_driver; | |
+extern report_mouse_res_t mouse_res_report; | |
+ | |
#ifdef __cplusplus | |
} | |
#endif | |
diff --git a/tmk_core/protocol/report.h b/tmk_core/protocol/report.h | |
index 7bbeb78af7..a53b75775c 100644 | |
--- a/tmk_core/protocol/report.h | |
+++ b/tmk_core/protocol/report.h | |
@@ -212,6 +212,11 @@ typedef struct { | |
int8_t h; | |
} __attribute__((packed)) report_mouse_t; | |
+typedef struct { | |
+ uint8_t report_id; | |
+ uint8_t res; | |
+} __attribute__((packed)) report_mouse_res_t; | |
+ | |
typedef struct { | |
#ifdef DIGITIZER_SHARED_EP | |
uint8_t report_id; | |
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c | |
index 063bd2c3f1..23d27db803 100644 | |
--- a/tmk_core/protocol/usb_descriptor.c | |
+++ b/tmk_core/protocol/usb_descriptor.c | |
@@ -114,12 +114,12 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { | |
# ifdef MOUSE_SHARED_EP | |
HID_RI_REPORT_ID(8, REPORT_ID_MOUSE), | |
# endif | |
- HID_RI_USAGE(8, 0x01), // Pointer | |
- HID_RI_COLLECTION(8, 0x00), // Physical | |
+ HID_RI_USAGE(8, 0x01), // Pointer | |
+ HID_RI_COLLECTION(8, 0x00), // Physical | |
// Buttons (8 bits) | |
- HID_RI_USAGE_PAGE(8, 0x09), // Button | |
- HID_RI_USAGE_MINIMUM(8, 0x01), // Button 1 | |
- HID_RI_USAGE_MAXIMUM(8, 0x08), // Button 8 | |
+ HID_RI_USAGE_PAGE(8, 0x09), // Button | |
+ HID_RI_USAGE_MINIMUM(8, 0x01), // Button 1 | |
+ HID_RI_USAGE_MAXIMUM(8, 0x08), // Button 8 | |
HID_RI_LOGICAL_MINIMUM(8, 0x00), | |
HID_RI_LOGICAL_MAXIMUM(8, 0x01), | |
HID_RI_REPORT_COUNT(8, 0x08), | |
@@ -127,9 +127,9 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { | |
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), | |
// X/Y position (2 bytes) | |
- HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop | |
- HID_RI_USAGE(8, 0x30), // X | |
- HID_RI_USAGE(8, 0x31), // Y | |
+ HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop | |
+ HID_RI_USAGE(8, 0x30), // X | |
+ HID_RI_USAGE(8, 0x31), // Y | |
HID_RI_LOGICAL_MINIMUM(8, -127), | |
HID_RI_LOGICAL_MAXIMUM(8, 127), | |
HID_RI_REPORT_COUNT(8, 0x02), | |
@@ -137,20 +137,39 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { | |
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), | |
// Vertical wheel (1 byte) | |
- HID_RI_USAGE(8, 0x38), // Wheel | |
- HID_RI_LOGICAL_MINIMUM(8, -127), | |
- HID_RI_LOGICAL_MAXIMUM(8, 127), | |
- HID_RI_REPORT_COUNT(8, 0x01), | |
- HID_RI_REPORT_SIZE(8, 0x08), | |
- HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), | |
+ HID_RI_COLLECTION(8, 0x02), // Logical | |
+ HID_RI_USAGE(8, 0x38), // Wheel | |
+ HID_RI_REPORT_COUNT(8, 0x01), | |
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), | |
+ // Wheel multiplier (2 bits) | |
+ HID_RI_USAGE(8, 0x48), // Resolution Multiplier | |
+ HID_RI_LOGICAL_MINIMUM(8, 0x00), | |
+ HID_RI_LOGICAL_MAXIMUM(8, 0x01), | |
+ HID_RI_PHYSICAL_MINIMUM(8, 0x01), | |
+ HID_RI_PHYSICAL_MAXIMUM(8, 0x04), | |
+ HID_RI_REPORT_SIZE(8, 0x02), | |
+ HID_RI_FEATURE(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), | |
+ HID_RI_END_COLLECTION(0), | |
// Horizontal wheel (1 byte) | |
- HID_RI_USAGE_PAGE(8, 0x0C), // Consumer | |
- HID_RI_USAGE(16, 0x0238), // AC Pan | |
- HID_RI_LOGICAL_MINIMUM(8, -127), | |
- HID_RI_LOGICAL_MAXIMUM(8, 127), | |
- HID_RI_REPORT_COUNT(8, 0x01), | |
- HID_RI_REPORT_SIZE(8, 0x08), | |
- HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), | |
+ HID_RI_COLLECTION(8, 0x02), // Logical | |
+ HID_RI_USAGE_PAGE(8, 0x0C), // Consumer | |
+ HID_RI_USAGE(16, 0x0238), // AC Pan | |
+ HID_RI_LOGICAL_MINIMUM(8, -127), | |
+ HID_RI_LOGICAL_MAXIMUM(8, 127), | |
+ HID_RI_REPORT_SIZE(8, 0x08), | |
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), | |
+ // Wheel Multiplier (2 bits) | |
+ HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop | |
+ HID_RI_USAGE(8, 0x48), // Resolution Multiplier | |
+ HID_RI_LOGICAL_MINIMUM(8, 0x00), | |
+ HID_RI_LOGICAL_MAXIMUM(8, 0x01), | |
+ HID_RI_REPORT_SIZE(8, 0x02), | |
+ HID_RI_FEATURE(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), | |
+ | |
+ // Padding (4 bits) | |
+ HID_RI_REPORT_SIZE(8, 0x04), | |
+ HID_RI_FEATURE(8, HID_IOF_CONSTANT | HID_IOF_VARIABLE), | |
+ HID_RI_END_COLLECTION(0), | |
HID_RI_END_COLLECTION(0), | |
HID_RI_END_COLLECTION(0), | |
# ifndef MOUSE_SHARED_EP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment