tmk / tmk_keyboard

Keyboard firmwares for Atmel AVR and Cortex-M
3.98k stars 1.7k forks source link

adb_usb: mouse enhancements #692

Closed eshaz closed 3 years ago

eshaz commented 3 years ago
tmk commented 3 years ago

Can you test this patch with the Open Firmware? The patch adds support for Boot protocol mouse and I think it should work with the Open firmware.

diff --git a/converter/adb_usb/Makefile b/converter/adb_usb/Makefile
index 31771eb1..535f760b 100644
--- a/converter/adb_usb/Makefile
+++ b/converter/adb_usb/Makefile
@@ -100,7 +100,7 @@ ADB_MOUSE_SCROLL_SPEED ?= 10    # 1 (fastest) to 127 (slowest)
 # ADB Classic Mouse Protocol supports 7-bit mouse x,y precision (i.e. Original Apple Mouse)
 # ADB Extended Mouse Protocol supports 7, 10, 13, and 16-bit precisions
 # i.e. Kensington Turbo Mouse 5 uses 10-bit precision
-ADB_MOUSE_PRECISION ?= 10  # Sets bit precision of the mouse
+ADB_MOUSE_PRECISION ?= 16  # Sets bit precision of the mouse

 # Optimize size but this may cause error "relocation truncated to fit"
 #EXTRALDFLAGS = -Wl,--relax
diff --git a/tmk_core/common/host.c b/tmk_core/common/host.c
index 56d65e50..d2454f80 100644
--- a/tmk_core/common/host.c
+++ b/tmk_core/common/host.c
@@ -65,6 +65,11 @@ void host_keyboard_send(report_keyboard_t *report)
 void host_mouse_send(report_mouse_t *report)
 {
     if (!driver) return;
+#ifdef ENABLE_16_BIT_MOUSE_REPORT
+    // clip and copy to Boot protocol XY
+    report->boot_x = (report->x > 127) ? 127 : ((report->x < -127) ? -127 : report->x);
+    report->boot_y = (report->y > 127) ? 127 : ((report->y < -127) ? -127 : report->y);
+#endif
     (*driver->send_mouse)(report);
 }

diff --git a/tmk_core/common/report.h b/tmk_core/common/report.h
index 298591a4..21da014b 100644
--- a/tmk_core/common/report.h
+++ b/tmk_core/common/report.h
@@ -160,6 +160,8 @@ typedef struct {
 #ifdef ENABLE_16_BIT_MOUSE_REPORT
 typedef struct {
     uint8_t buttons;
+    int8_t boot_x;
+    int8_t boot_y;
     int16_t x;
     int16_t y;
     int16_t v;
diff --git a/tmk_core/protocol/lufa/descriptor.c b/tmk_core/protocol/lufa/descriptor.c
index cc0a0af1..347c70b3 100644
--- a/tmk_core/protocol/lufa/descriptor.c
+++ b/tmk_core/protocol/lufa/descriptor.c
@@ -117,15 +117,21 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] =

             HID_RI_USAGE_PAGE(8, 0x09), /* Button */
             HID_RI_USAGE_MINIMUM(8, 0x01),  /* Button 1 */
-            HID_RI_USAGE_MAXIMUM(8, 0x05),  /* Button 5 */
+            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, 0x05),
+            HID_RI_REPORT_COUNT(8, 0x08),
             HID_RI_REPORT_SIZE(8, 0x01),
             HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
-            HID_RI_REPORT_COUNT(8, 0x01),
-            HID_RI_REPORT_SIZE(8, 0x03),
-            HID_RI_INPUT(8, HID_IOF_CONSTANT),
+
+            /* Boot protocol XY ignored in Report protocol */
+            HID_RI_USAGE_PAGE(8, 0xff), /* Vendor */
+            HID_RI_USAGE(8, 0xff), /* Vendor  */
+            HID_RI_LOGICAL_MINIMUM(8, -127),
+            HID_RI_LOGICAL_MAXIMUM(8, 127),
+            HID_RI_REPORT_COUNT(8, 0x02),
+            HID_RI_REPORT_SIZE(8, 0x08),
+            HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),

             HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
             HID_RI_USAGE(8, 0x30), /* Usage X */
eshaz commented 3 years ago

@tmk The patch worked great! Since that worked, I think it would make sense to remove this because it should no longer be necessary for the user to configure: https://github.com/tmk/tmk_keyboard/blob/40fe2a8fdd5f4fe28ba3332d87ba5a5d5a580bae/converter/adb_usb/Makefile#L105-L108 I can apply the patch to this PR and make this change if you are ready for that. Let me know how you want to proceed.

tmk commented 3 years ago

Thank you for the test and sorry for late reply.

16-bit mouse report with boot protocol support seems to be promising. I just opned new PR based on your work for extended mouse report and will look into a bit more before merging into repo.

Scroll emulation part of this PR was merged as this commit. https://github.com/tmk/tmk_keyboard/commit/9b58ee7db0079a6b434d35d1d65608bd544811e8

tmk commented 3 years ago

Merged '16-bit mouse report' around 4ed3e40fc05 82a562bd81

Thank you for your contribution!