Browse Source

Extended wheel reports (#24422)

extended wheel reports
eynsai 1 year ago
parent
commit
2cb35373c6

+ 1 - 0
docs/features/pointing_device.md

@@ -394,6 +394,7 @@ Ideally, new sensor hardware should be added to `drivers/sensors/` and `quantum/
 | Setting                                        | Description                                                                                                                      | Default       |
 | ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------- |
 | `MOUSE_EXTENDED_REPORT`                        | (Optional) Enables support for extended mouse reports. (-32767 to 32767, instead of just -127 to 127).                           | _not defined_ |
+| `WHEEL_EXTENDED_REPORT`                        | (Optional) Enables support for extended wheel reports. (-32767 to 32767, instead of just -127 to 127).                           | _not defined_ |
 | `POINTING_DEVICE_ROTATION_90`                  | (Optional) Rotates the X and Y data by  90 degrees.                                                                              | _not defined_ |
 | `POINTING_DEVICE_ROTATION_180`                 | (Optional) Rotates the X and Y data by 180 degrees.                                                                              | _not defined_ |
 | `POINTING_DEVICE_ROTATION_270`                 | (Optional) Rotates the X and Y data by 270 degrees.                                                                              | _not defined_ |

+ 15 - 15
quantum/pointing_device/pointing_device.c

@@ -377,28 +377,28 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) {
 }
 
 /**
- * @brief clamps int16_t to int8_t
+ * @brief clamps int16_t to int8_t, or int32_t to int16_t
  *
- * @param[in] int16_t value
- * @return int8_t clamped value
+ * @param[in] hv_clamp_range_t value
+ * @return mouse_hv_report_t clamped value
  */
-static inline int8_t pointing_device_hv_clamp(int16_t value) {
-    if (value < INT8_MIN) {
-        return INT8_MIN;
-    } else if (value > INT8_MAX) {
-        return INT8_MAX;
+static inline mouse_hv_report_t pointing_device_hv_clamp(hv_clamp_range_t value) {
+    if (value < HV_REPORT_MIN) {
+        return HV_REPORT_MIN;
+    } else if (value > HV_REPORT_MAX) {
+        return HV_REPORT_MAX;
     } else {
         return value;
     }
 }
 
 /**
- * @brief clamps int16_t to int8_t
+ * @brief clamps int16_t to int8_t, or int32_t to int16_t
  *
- * @param[in] clamp_range_t value
+ * @param[in] xy_clamp_range_t value
  * @return mouse_xy_report_t clamped value
  */
-static inline mouse_xy_report_t pointing_device_xy_clamp(clamp_range_t value) {
+static inline mouse_xy_report_t pointing_device_xy_clamp(xy_clamp_range_t value) {
     if (value < XY_REPORT_MIN) {
         return XY_REPORT_MIN;
     } else if (value > XY_REPORT_MAX) {
@@ -419,10 +419,10 @@ static inline mouse_xy_report_t pointing_device_xy_clamp(clamp_range_t value) {
  * @return combined report_mouse_t of left_report and right_report
  */
 report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) {
-    left_report.x = pointing_device_xy_clamp((clamp_range_t)left_report.x + right_report.x);
-    left_report.y = pointing_device_xy_clamp((clamp_range_t)left_report.y + right_report.y);
-    left_report.h = pointing_device_hv_clamp((int16_t)left_report.h + right_report.h);
-    left_report.v = pointing_device_hv_clamp((int16_t)left_report.v + right_report.v);
+    left_report.x = pointing_device_xy_clamp((xy_clamp_range_t)left_report.x + right_report.x);
+    left_report.y = pointing_device_xy_clamp((xy_clamp_range_t)left_report.y + right_report.y);
+    left_report.h = pointing_device_hv_clamp((hv_clamp_range_t)left_report.h + right_report.h);
+    left_report.v = pointing_device_hv_clamp((hv_clamp_range_t)left_report.v + right_report.v);
     left_report.buttons |= right_report.buttons;
     return left_report;
 }

+ 12 - 2
quantum/pointing_device/pointing_device.h

@@ -95,11 +95,21 @@ typedef enum {
 #ifdef MOUSE_EXTENDED_REPORT
 #    define XY_REPORT_MIN INT16_MIN
 #    define XY_REPORT_MAX INT16_MAX
-typedef int32_t clamp_range_t;
+typedef int32_t xy_clamp_range_t;
 #else
 #    define XY_REPORT_MIN INT8_MIN
 #    define XY_REPORT_MAX INT8_MAX
-typedef int16_t clamp_range_t;
+typedef int16_t xy_clamp_range_t;
+#endif
+
+#ifdef WHEEL_EXTENDED_REPORT
+#    define HV_REPORT_MIN INT16_MIN
+#    define HV_REPORT_MAX INT16_MAX
+typedef int32_t hv_clamp_range_t;
+#else
+#    define HV_REPORT_MIN INT8_MIN
+#    define HV_REPORT_MAX INT8_MAX
+typedef int16_t hv_clamp_range_t;
 #endif
 
 void           pointing_device_init(void);

+ 5 - 5
quantum/pointing_device/pointing_device_drivers.c

@@ -391,7 +391,7 @@ const pointing_device_driver_t pointing_device_driver = {
 };
 #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball)
 
-mouse_xy_report_t pimoroni_trackball_adapt_values(clamp_range_t* offset) {
+mouse_xy_report_t pimoroni_trackball_adapt_values(xy_clamp_range_t* offset) {
     if (*offset > XY_REPORT_MAX) {
         *offset -= XY_REPORT_MAX;
         return (mouse_xy_report_t)XY_REPORT_MAX;
@@ -406,10 +406,10 @@ mouse_xy_report_t pimoroni_trackball_adapt_values(clamp_range_t* offset) {
 }
 
 report_mouse_t pimoroni_trackball_get_report(report_mouse_t mouse_report) {
-    static uint16_t      debounce      = 0;
-    static uint8_t       error_count   = 0;
-    pimoroni_data_t      pimoroni_data = {0};
-    static clamp_range_t x_offset = 0, y_offset = 0;
+    static uint16_t         debounce      = 0;
+    static uint8_t          error_count   = 0;
+    pimoroni_data_t         pimoroni_data = {0};
+    static xy_clamp_range_t x_offset = 0, y_offset = 0;
 
     if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT) {
         i2c_status_t status = read_pimoroni_trackball(&pimoroni_data);

+ 8 - 2
tmk_core/protocol/report.h

@@ -199,6 +199,12 @@ typedef int16_t mouse_xy_report_t;
 typedef int8_t mouse_xy_report_t;
 #endif
 
+#ifdef WHEEL_EXTENDED_REPORT
+typedef int16_t mouse_hv_report_t;
+#else
+typedef int8_t mouse_hv_report_t;
+#endif
+
 typedef struct {
 #ifdef MOUSE_SHARED_EP
     uint8_t report_id;
@@ -210,8 +216,8 @@ typedef struct {
 #endif
     mouse_xy_report_t x;
     mouse_xy_report_t y;
-    int8_t            v;
-    int8_t            h;
+    mouse_hv_report_t v;
+    mouse_hv_report_t h;
 } PACKED report_mouse_t;
 
 typedef struct {

+ 19 - 5
tmk_core/protocol/usb_descriptor.c

@@ -165,20 +165,34 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
 #    endif
             HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
 
-            // Vertical wheel (1 byte)
-            HID_RI_USAGE(8, 0x38),         // Wheel
+            // Vertical wheel (1 or 2 bytes)
+            HID_RI_USAGE(8, 0x38),     // Wheel
+#    ifndef WHEEL_EXTENDED_REPORT
             HID_RI_LOGICAL_MINIMUM(8, -127),
             HID_RI_LOGICAL_MAXIMUM(8, 127),
             HID_RI_REPORT_COUNT(8, 0x01),
             HID_RI_REPORT_SIZE(8, 0x08),
+#    else
+            HID_RI_LOGICAL_MINIMUM(16, -32767),
+            HID_RI_LOGICAL_MAXIMUM(16,  32767),
+            HID_RI_REPORT_COUNT(8, 0x01),
+            HID_RI_REPORT_SIZE(8, 0x10),
+#    endif
             HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
-            // Horizontal wheel (1 byte)
-            HID_RI_USAGE_PAGE(8, 0x0C),    // Consumer
-            HID_RI_USAGE(16, 0x0238),      // AC Pan
+            // Horizontal wheel (1 or 2 bytes)
+            HID_RI_USAGE_PAGE(8, 0x0C),// Consumer
+            HID_RI_USAGE(16, 0x0238),  // AC Pan
+#    ifndef WHEEL_EXTENDED_REPORT
             HID_RI_LOGICAL_MINIMUM(8, -127),
             HID_RI_LOGICAL_MAXIMUM(8, 127),
             HID_RI_REPORT_COUNT(8, 0x01),
             HID_RI_REPORT_SIZE(8, 0x08),
+#    else
+            HID_RI_LOGICAL_MINIMUM(16, -32767),
+            HID_RI_LOGICAL_MAXIMUM(16,  32767),
+            HID_RI_REPORT_COUNT(8, 0x01),
+            HID_RI_REPORT_SIZE(8, 0x10),
+#    endif
             HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
         HID_RI_END_COLLECTION(0),
     HID_RI_END_COLLECTION(0),

+ 22 - 8
tmk_core/protocol/vusb/vusb.c

@@ -524,23 +524,37 @@ const PROGMEM uchar shared_hid_report[] = {
 #    endif
     0x81, 0x06, //     Input (Data, Variable, Relative)
 
-    // Vertical wheel (1 byte)
+    // Vertical wheel (1 or 2 bytes)
     0x09, 0x38, //     Usage (Wheel)
+#    ifndef WHEEL_EXTENDED_REPORT
     0x15, 0x81, //     Logical Minimum (-127)
     0x25, 0x7F, //     Logical Maximum (127)
     0x95, 0x01, //     Report Count (1)
     0x75, 0x08, //     Report Size (8)
+#    else
+    0x16, 0x01, 0x80, //     Logical Minimum (-32767)
+    0x26, 0xFF, 0x7F, //     Logical Maximum (32767)
+    0x95, 0x01,       //     Report Count (1)
+    0x75, 0x10,       //     Report Size (16)
+#    endif
     0x81, 0x06, //     Input (Data, Variable, Relative)
-    // Horizontal wheel (1 byte)
+    // Horizontal wheel (1 or 2 bytes)
     0x05, 0x0C,       //     Usage Page (Consumer)
     0x0A, 0x38, 0x02, //     Usage (AC Pan)
-    0x15, 0x81,       //     Logical Minimum (-127)
-    0x25, 0x7F,       //     Logical Maximum (127)
+#    ifndef WHEEL_EXTENDED_REPORT
+    0x15, 0x81, //     Logical Minimum (-127)
+    0x25, 0x7F, //     Logical Maximum (127)
+    0x95, 0x01, //     Report Count (1)
+    0x75, 0x08, //     Report Size (8)
+#    else
+    0x16, 0x01, 0x80, //     Logical Minimum (-32767)
+    0x26, 0xFF, 0x7F, //     Logical Maximum (32767)
     0x95, 0x01,       //     Report Count (1)
-    0x75, 0x08,       //     Report Size (8)
-    0x81, 0x06,       //     Input (Data, Variable, Relative)
-    0xC0,             //   End Collection
-    0xC0,             // End Collection
+    0x75, 0x10,       //     Report Size (16)
+#    endif
+    0x81, 0x06, //     Input (Data, Variable, Relative)
+    0xC0,       //   End Collection
+    0xC0,       // End Collection
 #endif
 
 #ifdef EXTRAKEY_ENABLE