Add support for large Mouse Reports (#16371)

Co-authored-by: Sergey Vlasov <sigprof@gmail.com>
Co-authored-by: Ryan <fauxpark@gmail.com>
master
Drashna Jaelre 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

@ -174,6 +174,8 @@ If you define these options you will enable the associated feature, which may in
* sets the timer for leader key chords to run on each key press rather than overall
* `#define LEADER_KEY_STRICT_KEY_PROCESSING`
* Disables keycode filtering for Mod-Tap and Layer-Tap keycodes. Eg, if you enable this, you would need to specify `MT(MOD_CTL, KC_A)` if you want to use `KC_A`.
* `#define MOUSE_EXTENDED_REPORT`
* Enables support for extended reports (-32767 to 32767, instead of -127 to 127), which may allow for smoother reporting, and prevent maxing out of the reports. Applies to both Pointing Device and Mousekeys.
* `#define ONESHOT_TIMEOUT 300`
* how long before oneshot times out
* `#define ONESHOT_TAP_TOGGLE 2`

View File

@ -259,6 +259,7 @@ The following configuration options are only available when using `SPLIT_POINTIN
|`POINTING_DEVICE_ROTATION_270_RIGHT` | (Optional) Rotates the X and Y data by 270 degrees. | _not defined_ |
|`POINTING_DEVICE_INVERT_X_RIGHT` | (Optional) Inverts the X axis report. | _not defined_ |
|`POINTING_DEVICE_INVERT_Y_RIGHT` | (Optional) Inverts the Y axis report. | _not defined_ |
|`MOUSE_EXTENDED_REPORT` | (Optional) Enables support for extended mouse reports. (-32767 to 32767, instead of just -127 to 127) |
!> If there is a `_RIGHT` configuration option or callback, the [common configuration](feature_pointing_device.md?id=common-configuration) option will work for the left. For correct left/right detection you should setup a [handedness option](feature_split_keyboard?id=setting-handedness), `EE_HANDS` is usually a good option for an existing board that doesn't do handedness by hardware.

View File

@ -28,4 +28,4 @@
#define RGBLIGHT_EFFECT_TWINKLE
#define RGBLIGHT_SLEEP
#define MOUSE_EXT_REPORT
#define MOUSE_EXTENDED_REPORT

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;

View File

@ -75,6 +75,16 @@ typedef enum {
POINTING_DEVICE_BUTTON8,
} pointing_device_buttons_t;
#ifdef MOUSE_EXTENDED_REPORT
# define XY_REPORT_MIN INT16_MIN
# define XY_REPORT_MAX INT16_MAX
typedef int32_t clamp_range_t;
#else
# define XY_REPORT_MIN INT8_MIN
# define XY_REPORT_MAX INT8_MAX
typedef int16_t clamp_range_t;
#endif
void pointing_device_init(void);
void pointing_device_task(void);
void pointing_device_send(void);

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;

View File

@ -93,6 +93,11 @@ void host_mouse_send(report_mouse_t *report) {
if (!driver) return;
#ifdef MOUSE_SHARED_EP
report->report_id = REPORT_ID_MOUSE;
#endif
#ifdef MOUSE_EXTENDED_REPORT
// clip and copy to Boot protocol XY
report->boot_x = (report->x > 127) ? 127 : ((report->x < -127) ? -127 : report->x);
report->boot_y = (report->y > 127) ? 127 : ((report->y < -127) ? -127 : report->y);
#endif
(*driver->send_mouse)(report);
}

View File

@ -201,15 +201,25 @@ typedef struct {
uint32_t usage;
} __attribute__((packed)) report_programmable_button_t;
#ifdef MOUSE_EXTENDED_REPORT
typedef int16_t mouse_xy_report_t;
#else
typedef int8_t mouse_xy_report_t;
#endif
typedef struct {
#ifdef MOUSE_SHARED_EP
uint8_t report_id;
#endif
uint8_t buttons;
int8_t x;
int8_t y;
int8_t v;
int8_t h;
#ifdef MOUSE_EXTENDED_REPORT
int8_t boot_x;
int8_t boot_y;
#endif
mouse_xy_report_t x;
mouse_xy_report_t y;
int8_t v;
int8_t h;
} __attribute__((packed)) report_mouse_t;
typedef struct {

View File

@ -126,14 +126,27 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
HID_RI_REPORT_SIZE(8, 0x01),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
// X/Y position (2 bytes)
# ifdef MOUSE_EXTENDED_REPORT
// Boot protocol XY ignored in Report protocol
HID_RI_REPORT_COUNT(8, 0x02),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_INPUT(8, HID_IOF_CONSTANT),
# endif
// X/Y position (2 or 4 bytes)
HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
HID_RI_USAGE(8, 0x30), // X
HID_RI_USAGE(8, 0x31), // Y
# ifndef MOUSE_EXTENDED_REPORT
HID_RI_LOGICAL_MINIMUM(8, -127),
HID_RI_LOGICAL_MAXIMUM(8, 127),
HID_RI_REPORT_COUNT(8, 0x02),
HID_RI_REPORT_SIZE(8, 0x08),
# else
HID_RI_LOGICAL_MINIMUM(16, -32767),
HID_RI_LOGICAL_MAXIMUM(16, 32767),
HID_RI_REPORT_COUNT(8, 0x02),
HID_RI_REPORT_SIZE(8, 0x10),
# endif
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
// Vertical wheel (1 byte)

View File

@ -482,14 +482,28 @@ const PROGMEM uchar shared_hid_report[] = {
0x75, 0x01, // Report Size (1)
0x81, 0x02, // Input (Data, Variable, Absolute)
// X/Y position (2 bytes)
# ifdef MOUSE_EXTENDED_REPORT
// Boot protocol XY ignored in Report protocol
0x95, 0x02, // Report Count (2)
0x75, 0x08, // Report Size (8)
0x81, 0x03, // Input (Constant)
# endif
// X/Y position (2 or 4 bytes)
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
# ifndef MOUSE_EXTENDED_REPORT
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x95, 0x02, // Report Count (2)
0x75, 0x08, // Report Size (8)
# else
0x16, 0x01, 0x80, // Logical Minimum (-32767)
0x26, 0xFF, 0x7F, // Logical Maximum (32767)
0x95, 0x02, // Report Count (2)
0x75, 0x10, // Report Size (16)
# endif
0x81, 0x06, // Input (Data, Variable, Relative)
// Vertical wheel (1 byte)