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

@ -177,7 +177,8 @@ __attribute__((weak)) void pointing_device_send(void) {
report_mouse_t pointing_device_adjust_by_defines(report_mouse_t mouse_report) {
// Support rotation of the sensor data
#if defined(POINTING_DEVICE_ROTATION_90) || defined(POINTING_DEVICE_ROTATION_180) || defined(POINTING_DEVICE_ROTATION_270)
int8_t x = mouse_report.x, y = mouse_report.y;
mouse_xy_report_t x = mouse_report.x;
mouse_xy_report_t y = mouse_report.y;
# if defined(POINTING_DEVICE_ROTATION_90)
mouse_report.x = y;
mouse_report.y = -x;
@ -347,7 +348,7 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) {
* @param[in] int16_t value
* @return int8_t clamped value
*/
static inline int8_t pointing_device_movement_clamp(int16_t value) {
static inline int8_t pointing_device_hv_clamp(int16_t value) {
if (value < INT8_MIN) {
return INT8_MIN;
} else if (value > INT8_MAX) {
@ -357,6 +358,21 @@ static inline int8_t pointing_device_movement_clamp(int16_t value) {
}
}
/**
* @brief clamps int16_t to int8_t
*
* @param[in] 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) {
if (value < XY_REPORT_MIN) {
return XY_REPORT_MIN;
} else if (value > XY_REPORT_MAX) {
return XY_REPORT_MAX;
} else {
return value;
}
}
/**
* @brief combines 2 mouse reports and returns 2
*
@ -369,10 +385,10 @@ static inline int8_t pointing_device_movement_clamp(int16_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_movement_clamp((int16_t)left_report.x + right_report.x);
left_report.y = pointing_device_movement_clamp((int16_t)left_report.y + right_report.y);
left_report.h = pointing_device_movement_clamp((int16_t)left_report.h + right_report.h);
left_report.v = pointing_device_movement_clamp((int16_t)left_report.v + right_report.v);
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.buttons |= right_report.buttons;
return left_report;
}
@ -390,7 +406,8 @@ report_mouse_t pointing_device_combine_reports(report_mouse_t left_report, repor
report_mouse_t pointing_device_adjust_by_defines_right(report_mouse_t mouse_report) {
// Support rotation of the sensor data
# if defined(POINTING_DEVICE_ROTATION_90_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT) || defined(POINTING_DEVICE_ROTATION_RIGHT)
int8_t x = mouse_report.x, y = mouse_report.y;
mouse_xy_report_t x = mouse_report.x;
mouse_xy_report_t y = mouse_report.y;
# if defined(POINTING_DEVICE_ROTATION_90_RIGHT)
mouse_report.x = y;
mouse_report.y = -x;