diff options
| author | eynsai <47629346+eynsai@users.noreply.github.com> | 2024-10-06 05:26:55 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-06 11:26:55 +0200 |
| commit | 2cb35373c6ecc4341b538cc5ad37accf3e5030e4 (patch) | |
| tree | bd578fdeceb031dc54e43a8274255c58781a0db0 | |
| parent | bf6de46d7fd9ab185c57c1ebb9372ea980846040 (diff) | |
Extended wheel reports (#24422)
extended wheel reports
| -rw-r--r-- | docs/features/pointing_device.md | 1 | ||||
| -rw-r--r-- | quantum/pointing_device/pointing_device.c | 30 | ||||
| -rw-r--r-- | quantum/pointing_device/pointing_device.h | 14 | ||||
| -rw-r--r-- | quantum/pointing_device/pointing_device_drivers.c | 10 | ||||
| -rw-r--r-- | tmk_core/protocol/report.h | 10 | ||||
| -rw-r--r-- | tmk_core/protocol/usb_descriptor.c | 24 | ||||
| -rw-r--r-- | tmk_core/protocol/vusb/vusb.c | 30 |
7 files changed, 82 insertions, 37 deletions
diff --git a/docs/features/pointing_device.md b/docs/features/pointing_device.md index a6bf521a18..0ecf82c8df 100644 --- a/docs/features/pointing_device.md +++ b/docs/features/pointing_device.md | |||
| @@ -394,6 +394,7 @@ Ideally, new sensor hardware should be added to `drivers/sensors/` and `quantum/ | |||
| 394 | | Setting | Description | Default | | 394 | | Setting | Description | Default | |
| 395 | | ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------- | | 395 | | ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------- | |
| 396 | | `MOUSE_EXTENDED_REPORT` | (Optional) Enables support for extended mouse reports. (-32767 to 32767, instead of just -127 to 127). | _not defined_ | | 396 | | `MOUSE_EXTENDED_REPORT` | (Optional) Enables support for extended mouse reports. (-32767 to 32767, instead of just -127 to 127). | _not defined_ | |
| 397 | | `WHEEL_EXTENDED_REPORT` | (Optional) Enables support for extended wheel reports. (-32767 to 32767, instead of just -127 to 127). | _not defined_ | | ||
| 397 | | `POINTING_DEVICE_ROTATION_90` | (Optional) Rotates the X and Y data by 90 degrees. | _not defined_ | | 398 | | `POINTING_DEVICE_ROTATION_90` | (Optional) Rotates the X and Y data by 90 degrees. | _not defined_ | |
| 398 | | `POINTING_DEVICE_ROTATION_180` | (Optional) Rotates the X and Y data by 180 degrees. | _not defined_ | | 399 | | `POINTING_DEVICE_ROTATION_180` | (Optional) Rotates the X and Y data by 180 degrees. | _not defined_ | |
| 399 | | `POINTING_DEVICE_ROTATION_270` | (Optional) Rotates the X and Y data by 270 degrees. | _not defined_ | | 400 | | `POINTING_DEVICE_ROTATION_270` | (Optional) Rotates the X and Y data by 270 degrees. | _not defined_ | |
diff --git a/quantum/pointing_device/pointing_device.c b/quantum/pointing_device/pointing_device.c index 74ce9108a9..7d3be9e524 100644 --- a/quantum/pointing_device/pointing_device.c +++ b/quantum/pointing_device/pointing_device.c | |||
| @@ -377,28 +377,28 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) { | |||
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | /** | 379 | /** |
| 380 | * @brief clamps int16_t to int8_t | 380 | * @brief clamps int16_t to int8_t, or int32_t to int16_t |
| 381 | * | 381 | * |
| 382 | * @param[in] int16_t value | 382 | * @param[in] hv_clamp_range_t value |
| 383 | * @return int8_t clamped value | 383 | * @return mouse_hv_report_t clamped value |
| 384 | */ | 384 | */ |
| 385 | static inline int8_t pointing_device_hv_clamp(int16_t value) { | 385 | static inline mouse_hv_report_t pointing_device_hv_clamp(hv_clamp_range_t value) { |
| 386 | if (value < INT8_MIN) { | 386 | if (value < HV_REPORT_MIN) { |
| 387 | return INT8_MIN; | 387 | return HV_REPORT_MIN; |
| 388 | } else if (value > INT8_MAX) { | 388 | } else if (value > HV_REPORT_MAX) { |
| 389 | return INT8_MAX; | 389 | return HV_REPORT_MAX; |
| 390 | } else { | 390 | } else { |
| 391 | return value; | 391 | return value; |
| 392 | } | 392 | } |
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | /** | 395 | /** |
| 396 | * @brief clamps int16_t to int8_t | 396 | * @brief clamps int16_t to int8_t, or int32_t to int16_t |
| 397 | * | 397 | * |
| 398 | * @param[in] clamp_range_t value | 398 | * @param[in] xy_clamp_range_t value |
| 399 | * @return mouse_xy_report_t clamped value | 399 | * @return mouse_xy_report_t clamped value |
| 400 | */ | 400 | */ |
| 401 | static inline mouse_xy_report_t pointing_device_xy_clamp(clamp_range_t value) { | 401 | static inline mouse_xy_report_t pointing_device_xy_clamp(xy_clamp_range_t value) { |
| 402 | if (value < XY_REPORT_MIN) { | 402 | if (value < XY_REPORT_MIN) { |
| 403 | return XY_REPORT_MIN; | 403 | return XY_REPORT_MIN; |
| 404 | } else if (value > XY_REPORT_MAX) { | 404 | } else if (value > XY_REPORT_MAX) { |
| @@ -419,10 +419,10 @@ static inline mouse_xy_report_t pointing_device_xy_clamp(clamp_range_t value) { | |||
| 419 | * @return combined report_mouse_t of left_report and right_report | 419 | * @return combined report_mouse_t of left_report and right_report |
| 420 | */ | 420 | */ |
| 421 | report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) { | 421 | report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, report_mouse_t right_report) { |
| 422 | left_report.x = pointing_device_xy_clamp((clamp_range_t)left_report.x + right_report.x); | 422 | left_report.x = pointing_device_xy_clamp((xy_clamp_range_t)left_report.x + right_report.x); |
| 423 | left_report.y = pointing_device_xy_clamp((clamp_range_t)left_report.y + right_report.y); | 423 | left_report.y = pointing_device_xy_clamp((xy_clamp_range_t)left_report.y + right_report.y); |
| 424 | left_report.h = pointing_device_hv_clamp((int16_t)left_report.h + right_report.h); | 424 | left_report.h = pointing_device_hv_clamp((hv_clamp_range_t)left_report.h + right_report.h); |
| 425 | left_report.v = pointing_device_hv_clamp((int16_t)left_report.v + right_report.v); | 425 | left_report.v = pointing_device_hv_clamp((hv_clamp_range_t)left_report.v + right_report.v); |
| 426 | left_report.buttons |= right_report.buttons; | 426 | left_report.buttons |= right_report.buttons; |
| 427 | return left_report; | 427 | return left_report; |
| 428 | } | 428 | } |
diff --git a/quantum/pointing_device/pointing_device.h b/quantum/pointing_device/pointing_device.h index 1cd4b0b5e6..b0f8533d6d 100644 --- a/quantum/pointing_device/pointing_device.h +++ b/quantum/pointing_device/pointing_device.h | |||
| @@ -95,11 +95,21 @@ typedef enum { | |||
| 95 | #ifdef MOUSE_EXTENDED_REPORT | 95 | #ifdef MOUSE_EXTENDED_REPORT |
| 96 | # define XY_REPORT_MIN INT16_MIN | 96 | # define XY_REPORT_MIN INT16_MIN |
| 97 | # define XY_REPORT_MAX INT16_MAX | 97 | # define XY_REPORT_MAX INT16_MAX |
| 98 | typedef int32_t clamp_range_t; | 98 | typedef int32_t xy_clamp_range_t; |
| 99 | #else | 99 | #else |
| 100 | # define XY_REPORT_MIN INT8_MIN | 100 | # define XY_REPORT_MIN INT8_MIN |
| 101 | # define XY_REPORT_MAX INT8_MAX | 101 | # define XY_REPORT_MAX INT8_MAX |
| 102 | typedef int16_t clamp_range_t; | 102 | typedef int16_t xy_clamp_range_t; |
| 103 | #endif | ||
| 104 | |||
| 105 | #ifdef WHEEL_EXTENDED_REPORT | ||
| 106 | # define HV_REPORT_MIN INT16_MIN | ||
| 107 | # define HV_REPORT_MAX INT16_MAX | ||
| 108 | typedef int32_t hv_clamp_range_t; | ||
| 109 | #else | ||
| 110 | # define HV_REPORT_MIN INT8_MIN | ||
| 111 | # define HV_REPORT_MAX INT8_MAX | ||
| 112 | typedef int16_t hv_clamp_range_t; | ||
| 103 | #endif | 113 | #endif |
| 104 | 114 | ||
| 105 | void pointing_device_init(void); | 115 | void pointing_device_init(void); |
diff --git a/quantum/pointing_device/pointing_device_drivers.c b/quantum/pointing_device/pointing_device_drivers.c index bf131c6eda..6cbe427401 100644 --- a/quantum/pointing_device/pointing_device_drivers.c +++ b/quantum/pointing_device/pointing_device_drivers.c | |||
| @@ -391,7 +391,7 @@ const pointing_device_driver_t pointing_device_driver = { | |||
| 391 | }; | 391 | }; |
| 392 | #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball) | 392 | #elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball) |
| 393 | 393 | ||
| 394 | mouse_xy_report_t pimoroni_trackball_adapt_values(clamp_range_t* offset) { | 394 | mouse_xy_report_t pimoroni_trackball_adapt_values(xy_clamp_range_t* offset) { |
| 395 | if (*offset > XY_REPORT_MAX) { | 395 | if (*offset > XY_REPORT_MAX) { |
| 396 | *offset -= XY_REPORT_MAX; | 396 | *offset -= XY_REPORT_MAX; |
| 397 | return (mouse_xy_report_t)XY_REPORT_MAX; | 397 | return (mouse_xy_report_t)XY_REPORT_MAX; |
| @@ -406,10 +406,10 @@ mouse_xy_report_t pimoroni_trackball_adapt_values(clamp_range_t* offset) { | |||
| 406 | } | 406 | } |
| 407 | 407 | ||
| 408 | report_mouse_t pimoroni_trackball_get_report(report_mouse_t mouse_report) { | 408 | report_mouse_t pimoroni_trackball_get_report(report_mouse_t mouse_report) { |
| 409 | static uint16_t debounce = 0; | 409 | static uint16_t debounce = 0; |
| 410 | static uint8_t error_count = 0; | 410 | static uint8_t error_count = 0; |
| 411 | pimoroni_data_t pimoroni_data = {0}; | 411 | pimoroni_data_t pimoroni_data = {0}; |
| 412 | static clamp_range_t x_offset = 0, y_offset = 0; | 412 | static xy_clamp_range_t x_offset = 0, y_offset = 0; |
| 413 | 413 | ||
| 414 | if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT) { | 414 | if (error_count < PIMORONI_TRACKBALL_ERROR_COUNT) { |
| 415 | i2c_status_t status = read_pimoroni_trackball(&pimoroni_data); | 415 | i2c_status_t status = read_pimoroni_trackball(&pimoroni_data); |
diff --git a/tmk_core/protocol/report.h b/tmk_core/protocol/report.h index 0e4f6e9def..37c8ea48f1 100644 --- a/tmk_core/protocol/report.h +++ b/tmk_core/protocol/report.h | |||
| @@ -199,6 +199,12 @@ typedef int16_t mouse_xy_report_t; | |||
| 199 | typedef int8_t mouse_xy_report_t; | 199 | typedef int8_t mouse_xy_report_t; |
| 200 | #endif | 200 | #endif |
| 201 | 201 | ||
| 202 | #ifdef WHEEL_EXTENDED_REPORT | ||
| 203 | typedef int16_t mouse_hv_report_t; | ||
| 204 | #else | ||
| 205 | typedef int8_t mouse_hv_report_t; | ||
| 206 | #endif | ||
| 207 | |||
| 202 | typedef struct { | 208 | typedef struct { |
| 203 | #ifdef MOUSE_SHARED_EP | 209 | #ifdef MOUSE_SHARED_EP |
| 204 | uint8_t report_id; | 210 | uint8_t report_id; |
| @@ -210,8 +216,8 @@ typedef struct { | |||
| 210 | #endif | 216 | #endif |
| 211 | mouse_xy_report_t x; | 217 | mouse_xy_report_t x; |
| 212 | mouse_xy_report_t y; | 218 | mouse_xy_report_t y; |
| 213 | int8_t v; | 219 | mouse_hv_report_t v; |
| 214 | int8_t h; | 220 | mouse_hv_report_t h; |
| 215 | } PACKED report_mouse_t; | 221 | } PACKED report_mouse_t; |
| 216 | 222 | ||
| 217 | typedef struct { | 223 | typedef struct { |
diff --git a/tmk_core/protocol/usb_descriptor.c b/tmk_core/protocol/usb_descriptor.c index 7454c9a7c4..0ac02bb19f 100644 --- a/tmk_core/protocol/usb_descriptor.c +++ b/tmk_core/protocol/usb_descriptor.c | |||
| @@ -165,20 +165,34 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = { | |||
| 165 | # endif | 165 | # endif |
| 166 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), | 166 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), |
| 167 | 167 | ||
| 168 | // Vertical wheel (1 byte) | 168 | // Vertical wheel (1 or 2 bytes) |
| 169 | HID_RI_USAGE(8, 0x38), // Wheel | 169 | HID_RI_USAGE(8, 0x38), // Wheel |
| 170 | # ifndef WHEEL_EXTENDED_REPORT | ||
| 170 | HID_RI_LOGICAL_MINIMUM(8, -127), | 171 | HID_RI_LOGICAL_MINIMUM(8, -127), |
| 171 | HID_RI_LOGICAL_MAXIMUM(8, 127), | 172 | HID_RI_LOGICAL_MAXIMUM(8, 127), |
| 172 | HID_RI_REPORT_COUNT(8, 0x01), | 173 | HID_RI_REPORT_COUNT(8, 0x01), |
| 173 | HID_RI_REPORT_SIZE(8, 0x08), | 174 | HID_RI_REPORT_SIZE(8, 0x08), |
| 175 | # else | ||
| 176 | HID_RI_LOGICAL_MINIMUM(16, -32767), | ||
| 177 | HID_RI_LOGICAL_MAXIMUM(16, 32767), | ||
| 178 | HID_RI_REPORT_COUNT(8, 0x01), | ||
| 179 | HID_RI_REPORT_SIZE(8, 0x10), | ||
| 180 | # endif | ||
| 174 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), | 181 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), |
| 175 | // Horizontal wheel (1 byte) | 182 | // Horizontal wheel (1 or 2 bytes) |
| 176 | HID_RI_USAGE_PAGE(8, 0x0C), // Consumer | 183 | HID_RI_USAGE_PAGE(8, 0x0C),// Consumer |
| 177 | HID_RI_USAGE(16, 0x0238), // AC Pan | 184 | HID_RI_USAGE(16, 0x0238), // AC Pan |
| 185 | # ifndef WHEEL_EXTENDED_REPORT | ||
| 178 | HID_RI_LOGICAL_MINIMUM(8, -127), | 186 | HID_RI_LOGICAL_MINIMUM(8, -127), |
| 179 | HID_RI_LOGICAL_MAXIMUM(8, 127), | 187 | HID_RI_LOGICAL_MAXIMUM(8, 127), |
| 180 | HID_RI_REPORT_COUNT(8, 0x01), | 188 | HID_RI_REPORT_COUNT(8, 0x01), |
| 181 | HID_RI_REPORT_SIZE(8, 0x08), | 189 | HID_RI_REPORT_SIZE(8, 0x08), |
| 190 | # else | ||
| 191 | HID_RI_LOGICAL_MINIMUM(16, -32767), | ||
| 192 | HID_RI_LOGICAL_MAXIMUM(16, 32767), | ||
| 193 | HID_RI_REPORT_COUNT(8, 0x01), | ||
| 194 | HID_RI_REPORT_SIZE(8, 0x10), | ||
| 195 | # endif | ||
| 182 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), | 196 | HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), |
| 183 | HID_RI_END_COLLECTION(0), | 197 | HID_RI_END_COLLECTION(0), |
| 184 | HID_RI_END_COLLECTION(0), | 198 | HID_RI_END_COLLECTION(0), |
diff --git a/tmk_core/protocol/vusb/vusb.c b/tmk_core/protocol/vusb/vusb.c index c8ab494253..886ee2375e 100644 --- a/tmk_core/protocol/vusb/vusb.c +++ b/tmk_core/protocol/vusb/vusb.c | |||
| @@ -524,23 +524,37 @@ const PROGMEM uchar shared_hid_report[] = { | |||
| 524 | # endif | 524 | # endif |
| 525 | 0x81, 0x06, // Input (Data, Variable, Relative) | 525 | 0x81, 0x06, // Input (Data, Variable, Relative) |
| 526 | 526 | ||
| 527 | // Vertical wheel (1 byte) | 527 | // Vertical wheel (1 or 2 bytes) |
| 528 | 0x09, 0x38, // Usage (Wheel) | 528 | 0x09, 0x38, // Usage (Wheel) |
| 529 | # ifndef WHEEL_EXTENDED_REPORT | ||
| 529 | 0x15, 0x81, // Logical Minimum (-127) | 530 | 0x15, 0x81, // Logical Minimum (-127) |
| 530 | 0x25, 0x7F, // Logical Maximum (127) | 531 | 0x25, 0x7F, // Logical Maximum (127) |
| 531 | 0x95, 0x01, // Report Count (1) | 532 | 0x95, 0x01, // Report Count (1) |
| 532 | 0x75, 0x08, // Report Size (8) | 533 | 0x75, 0x08, // Report Size (8) |
| 534 | # else | ||
| 535 | 0x16, 0x01, 0x80, // Logical Minimum (-32767) | ||
| 536 | 0x26, 0xFF, 0x7F, // Logical Maximum (32767) | ||
| 537 | 0x95, 0x01, // Report Count (1) | ||
| 538 | 0x75, 0x10, // Report Size (16) | ||
| 539 | # endif | ||
| 533 | 0x81, 0x06, // Input (Data, Variable, Relative) | 540 | 0x81, 0x06, // Input (Data, Variable, Relative) |
| 534 | // Horizontal wheel (1 byte) | 541 | // Horizontal wheel (1 or 2 bytes) |
| 535 | 0x05, 0x0C, // Usage Page (Consumer) | 542 | 0x05, 0x0C, // Usage Page (Consumer) |
| 536 | 0x0A, 0x38, 0x02, // Usage (AC Pan) | 543 | 0x0A, 0x38, 0x02, // Usage (AC Pan) |
| 537 | 0x15, 0x81, // Logical Minimum (-127) | 544 | # ifndef WHEEL_EXTENDED_REPORT |
| 538 | 0x25, 0x7F, // Logical Maximum (127) | 545 | 0x15, 0x81, // Logical Minimum (-127) |
| 546 | 0x25, 0x7F, // Logical Maximum (127) | ||
| 547 | 0x95, 0x01, // Report Count (1) | ||
| 548 | 0x75, 0x08, // Report Size (8) | ||
| 549 | # else | ||
| 550 | 0x16, 0x01, 0x80, // Logical Minimum (-32767) | ||
| 551 | 0x26, 0xFF, 0x7F, // Logical Maximum (32767) | ||
| 539 | 0x95, 0x01, // Report Count (1) | 552 | 0x95, 0x01, // Report Count (1) |
| 540 | 0x75, 0x08, // Report Size (8) | 553 | 0x75, 0x10, // Report Size (16) |
| 541 | 0x81, 0x06, // Input (Data, Variable, Relative) | 554 | # endif |
| 542 | 0xC0, // End Collection | 555 | 0x81, 0x06, // Input (Data, Variable, Relative) |
| 543 | 0xC0, // End Collection | 556 | 0xC0, // End Collection |
| 557 | 0xC0, // End Collection | ||
| 544 | #endif | 558 | #endif |
| 545 | 559 | ||
| 546 | #ifdef EXTRAKEY_ENABLE | 560 | #ifdef EXTRAKEY_ENABLE |
