Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended wheel reports #24422

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/features/pointing_device.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ Ideally, new sensor hardware should be added to `drivers/sensors/` and `quantum/
| Setting | Description | Default |
| ---------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `MOUSE_EXTENDED_REPORT` | (Optional) Enables support for extended mouse reports. (-32767 to 32767, instead of just -127 to 127). | _not defined_ |
| `WHEEL_EXTENDED_REPORT` | (Optional) Enables support for extended wheel reports. (-32767 to 32767, instead of just -127 to 127). | _not defined_ |
| `POINTING_DEVICE_ROTATION_90` | (Optional) Rotates the X and Y data by 90 degrees. | _not defined_ |
| `POINTING_DEVICE_ROTATION_180` | (Optional) Rotates the X and Y data by 180 degrees. | _not defined_ |
| `POINTING_DEVICE_ROTATION_270` | (Optional) Rotates the X and Y data by 270 degrees. | _not defined_ |
Expand Down
30 changes: 15 additions & 15 deletions quantum/pointing_device/pointing_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,28 +377,28 @@ void pointing_device_set_cpi_on_side(bool left, uint16_t cpi) {
}

/**
* @brief clamps int16_t to int8_t
* @brief clamps int16_t to int8_t, or int32_t to int16_t
*
* @param[in] int16_t value
* @return int8_t clamped value
* @param[in] hv_clamp_range_t value
* @return mouse_hv_report_t clamped value
*/
static inline int8_t pointing_device_hv_clamp(int16_t value) {
if (value < INT8_MIN) {
return INT8_MIN;
} else if (value > INT8_MAX) {
return INT8_MAX;
static inline mouse_hv_report_t pointing_device_hv_clamp(hv_clamp_range_t value) {
if (value < HV_REPORT_MIN) {
return HV_REPORT_MIN;
} else if (value > HV_REPORT_MAX) {
return HV_REPORT_MAX;
} else {
return value;
}
}

/**
* @brief clamps int16_t to int8_t
* @brief clamps int16_t to int8_t, or int32_t to int16_t
*
* @param[in] clamp_range_t value
* @param[in] xy_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) {
static inline mouse_xy_report_t pointing_device_xy_clamp(xy_clamp_range_t value) {
if (value < XY_REPORT_MIN) {
return XY_REPORT_MIN;
} else if (value > XY_REPORT_MAX) {
Expand All @@ -419,10 +419,10 @@ static inline mouse_xy_report_t pointing_device_xy_clamp(clamp_range_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_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.x = pointing_device_xy_clamp((xy_clamp_range_t)left_report.x + right_report.x);
left_report.y = pointing_device_xy_clamp((xy_clamp_range_t)left_report.y + right_report.y);
left_report.h = pointing_device_hv_clamp((hv_clamp_range_t)left_report.h + right_report.h);
left_report.v = pointing_device_hv_clamp((hv_clamp_range_t)left_report.v + right_report.v);
left_report.buttons |= right_report.buttons;
return left_report;
}
Expand Down
14 changes: 12 additions & 2 deletions quantum/pointing_device/pointing_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,21 @@ typedef enum {
#ifdef MOUSE_EXTENDED_REPORT
# define XY_REPORT_MIN INT16_MIN
# define XY_REPORT_MAX INT16_MAX
typedef int32_t clamp_range_t;
typedef int32_t xy_clamp_range_t;
#else
# define XY_REPORT_MIN INT8_MIN
# define XY_REPORT_MAX INT8_MAX
typedef int16_t clamp_range_t;
typedef int16_t xy_clamp_range_t;
#endif

#ifdef WHEEL_EXTENDED_REPORT
# define HV_REPORT_MIN INT16_MIN
# define HV_REPORT_MAX INT16_MAX
typedef int32_t hv_clamp_range_t;
#else
# define HV_REPORT_MIN INT8_MIN
# define HV_REPORT_MAX INT8_MAX
typedef int16_t hv_clamp_range_t;
#endif

void pointing_device_init(void);
Expand Down
10 changes: 5 additions & 5 deletions quantum/pointing_device/pointing_device_drivers.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ const pointing_device_driver_t pointing_device_driver = {
};
#elif defined(POINTING_DEVICE_DRIVER_pimoroni_trackball)

mouse_xy_report_t pimoroni_trackball_adapt_values(clamp_range_t* offset) {
mouse_xy_report_t pimoroni_trackball_adapt_values(xy_clamp_range_t* offset) {
if (*offset > XY_REPORT_MAX) {
*offset -= XY_REPORT_MAX;
return (mouse_xy_report_t)XY_REPORT_MAX;
Expand All @@ -406,10 +406,10 @@ mouse_xy_report_t pimoroni_trackball_adapt_values(clamp_range_t* offset) {
}

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 clamp_range_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 xy_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);
Expand Down
10 changes: 8 additions & 2 deletions tmk_core/protocol/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ typedef int16_t mouse_xy_report_t;
typedef int8_t mouse_xy_report_t;
#endif

#ifdef WHEEL_EXTENDED_REPORT
typedef int16_t mouse_hv_report_t;
#else
typedef int8_t mouse_hv_report_t;
#endif

typedef struct {
#ifdef MOUSE_SHARED_EP
uint8_t report_id;
Expand All @@ -210,8 +216,8 @@ typedef struct {
#endif
mouse_xy_report_t x;
mouse_xy_report_t y;
int8_t v;
int8_t h;
mouse_hv_report_t v;
mouse_hv_report_t h;
} PACKED report_mouse_t;

typedef struct {
Expand Down
24 changes: 19 additions & 5 deletions tmk_core/protocol/usb_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,34 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
# endif
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),

// Vertical wheel (1 byte)
HID_RI_USAGE(8, 0x38), // Wheel
// Vertical wheel (1 or 2 bytes)
HID_RI_USAGE(8, 0x38), // Wheel
# ifndef WHEEL_EXTENDED_REPORT
HID_RI_LOGICAL_MINIMUM(8, -127),
HID_RI_LOGICAL_MAXIMUM(8, 127),
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x08),
# else
HID_RI_LOGICAL_MINIMUM(16, -32767),
HID_RI_LOGICAL_MAXIMUM(16, 32767),
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x10),
# endif
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
// Horizontal wheel (1 byte)
HID_RI_USAGE_PAGE(8, 0x0C), // Consumer
HID_RI_USAGE(16, 0x0238), // AC Pan
// Horizontal wheel (1 or 2 bytes)
HID_RI_USAGE_PAGE(8, 0x0C),// Consumer
HID_RI_USAGE(16, 0x0238), // AC Pan
# ifndef WHEEL_EXTENDED_REPORT
HID_RI_LOGICAL_MINIMUM(8, -127),
HID_RI_LOGICAL_MAXIMUM(8, 127),
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x08),
# else
HID_RI_LOGICAL_MINIMUM(16, -32767),
HID_RI_LOGICAL_MAXIMUM(16, 32767),
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x10),
# endif
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
HID_RI_END_COLLECTION(0),
HID_RI_END_COLLECTION(0),
Expand Down
30 changes: 22 additions & 8 deletions tmk_core/protocol/vusb/vusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,23 +524,37 @@ const PROGMEM uchar shared_hid_report[] = {
# endif
0x81, 0x06, // Input (Data, Variable, Relative)

// Vertical wheel (1 byte)
// Vertical wheel (1 or 2 bytes)
0x09, 0x38, // Usage (Wheel)
# ifndef WHEEL_EXTENDED_REPORT
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x95, 0x01, // Report Count (1)
0x75, 0x08, // Report Size (8)
# else
0x16, 0x01, 0x80, // Logical Minimum (-32767)
0x26, 0xFF, 0x7F, // Logical Maximum (32767)
0x95, 0x01, // Report Count (1)
0x75, 0x10, // Report Size (16)
# endif
0x81, 0x06, // Input (Data, Variable, Relative)
// Horizontal wheel (1 byte)
// Horizontal wheel (1 or 2 bytes)
0x05, 0x0C, // Usage Page (Consumer)
0x0A, 0x38, 0x02, // Usage (AC Pan)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
# ifndef WHEEL_EXTENDED_REPORT
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (127)
0x95, 0x01, // Report Count (1)
0x75, 0x08, // Report Size (8)
# else
0x16, 0x01, 0x80, // Logical Minimum (-32767)
0x26, 0xFF, 0x7F, // Logical Maximum (32767)
0x95, 0x01, // Report Count (1)
0x75, 0x08, // Report Size (8)
0x81, 0x06, // Input (Data, Variable, Relative)
0xC0, // End Collection
0xC0, // End Collection
0x75, 0x10, // Report Size (16)
# endif
0x81, 0x06, // Input (Data, Variable, Relative)
0xC0, // End Collection
0xC0, // End Collection
#endif

#ifdef EXTRAKEY_ENABLE
Expand Down