1
0
Fork 0

Add support for large Mouse Reports (#16371)

Co-authored-by: Sergey Vlasov <sigprof@gmail.com>
Co-authored-by: Ryan <fauxpark@gmail.com>
This commit is contained in:
Drashna Jael're 2022-06-08 18:39:16 -07:00 committed by GitHub
parent 84944df6a6
commit 0ab51ee29d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 123 additions and 39 deletions

View file

@ -22,8 +22,8 @@
#include "timer.h"
#include <stddef.h>
// hid mouse reports cannot exceed -127 to 127, so constrain to that value
#define constrain_hid(amt) ((amt) < -127 ? -127 : ((amt) > 127 ? 127 : (amt)))
#define CONSTRAIN_HID(amt) ((amt) < INT8_MIN ? INT8_MIN : ((amt) > INT8_MAX ? INT8_MAX : (amt)))
#define CONSTRAIN_HID_XY(amt) ((amt) < XY_REPORT_MIN ? XY_REPORT_MIN : ((amt) > XY_REPORT_MAX ? XY_REPORT_MAX : (amt)))
// get_report functions should probably be moved to their respective drivers.
#if defined(POINTING_DEVICE_DRIVER_adns5050)
@ -35,8 +35,8 @@ report_mouse_t adns5050_get_report(report_mouse_t mouse_report) {
if (debug_mouse) dprintf("Raw ] X: %d, Y: %d\n", data.dx, data.dy);
# endif
mouse_report.x = data.dx;
mouse_report.y = data.dy;
mouse_report.x = (mouse_xy_report_t)data.dx;
mouse_report.y = (mouse_xy_report_t)data.dy;
}
return mouse_report;
@ -55,11 +55,8 @@ const pointing_device_driver_t pointing_device_driver = {
report_mouse_t adns9800_get_report_driver(report_mouse_t mouse_report) {
report_adns9800_t sensor_report = adns9800_get_report();
int8_t clamped_x = constrain_hid(sensor_report.x);
int8_t clamped_y = constrain_hid(sensor_report.y);
mouse_report.x = clamped_x;
mouse_report.y = clamped_y;
mouse_report.x = CONSTRAIN_HID_XY(sensor_report.x);
mouse_report.y = CONSTRAIN_HID_XY(sensor_report.y);
return mouse_report;
}
@ -107,16 +104,16 @@ const pointing_device_driver_t pointing_device_driver = {
# endif
report_mouse_t cirque_pinnacle_get_report(report_mouse_t mouse_report) {
pinnacle_data_t touchData = cirque_pinnacle_read_data();
static uint16_t x = 0, y = 0, mouse_timer = 0;
int8_t report_x = 0, report_y = 0;
static bool is_z_down = false;
pinnacle_data_t touchData = cirque_pinnacle_read_data();
static uint16_t x = 0, y = 0, mouse_timer = 0;
mouse_xy_report_t report_x = 0, report_y = 0;
static bool is_z_down = false;
cirque_pinnacle_scale_data(&touchData, cirque_pinnacle_get_scale(), cirque_pinnacle_get_scale()); // Scale coordinates to arbitrary X, Y resolution
if (x && y && touchData.xValue && touchData.yValue) {
report_x = (int8_t)(touchData.xValue - x);
report_y = (int8_t)(touchData.yValue - y);
report_x = (mouse_xy_report_t)(touchData.xValue - x);
report_y = (mouse_xy_report_t)(touchData.yValue - y);
}
x = touchData.xValue;
y = touchData.yValue;
@ -157,11 +154,26 @@ const pointing_device_driver_t pointing_device_driver = {
// clang-format on
#elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball)
mouse_xy_report_t pimoroni_trackball_adapt_values(clamp_range_t* offset) {
if (*offset > XY_REPORT_MAX) {
*offset -= XY_REPORT_MAX;
return (mouse_xy_report_t)XY_REPORT_MAX;
} else if (*offset < XY_REPORT_MIN) {
*offset += XY_REPORT_MAX;
return (mouse_xy_report_t)XY_REPORT_MIN;
} else {
mouse_xy_report_t temp_return = *offset;
*offset = 0;
return temp_return;
}
}
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 int16_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 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);
@ -174,8 +186,8 @@ report_mouse_t pimoroni_trackball_get_report(report_mouse_t mouse_report) {
if (!debounce) {
x_offset += pimoroni_trackball_get_offsets(pimoroni_data.right, pimoroni_data.left, PIMORONI_TRACKBALL_SCALE);
y_offset += pimoroni_trackball_get_offsets(pimoroni_data.down, pimoroni_data.up, PIMORONI_TRACKBALL_SCALE);
pimoroni_trackball_adapt_values(&mouse_report.x, &x_offset);
pimoroni_trackball_adapt_values(&mouse_report.y, &y_offset);
mouse_report.x = pimoroni_trackball_adapt_values(&x_offset);
mouse_report.y = pimoroni_trackball_adapt_values(&y_offset);
} else {
debounce--;
}
@ -221,8 +233,8 @@ report_mouse_t pmw3360_get_report(report_mouse_t mouse_report) {
# endif
MotionStart = timer_read();
}
mouse_report.x = constrain_hid(data.dx);
mouse_report.y = constrain_hid(data.dy);
mouse_report.x = CONSTRAIN_HID_XY(data.dx);
mouse_report.y = CONSTRAIN_HID_XY(data.dy);
}
return mouse_report;
@ -259,8 +271,8 @@ report_mouse_t pmw3389_get_report(report_mouse_t mouse_report) {
# endif
MotionStart = timer_read();
}
mouse_report.x = constrain_hid(data.dx);
mouse_report.y = constrain_hid(data.dy);
mouse_report.x = CONSTRAIN_HID_XY(data.dx);
mouse_report.y = CONSTRAIN_HID_XY(data.dy);
}
return mouse_report;