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 /quantum | |
| parent | bf6de46d7fd9ab185c57c1ebb9372ea980846040 (diff) | |
Extended wheel reports (#24422)
extended wheel reports
Diffstat (limited to 'quantum')
| -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 |
3 files changed, 32 insertions, 22 deletions
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); |
