diff --git a/src/hid_report.c b/src/hid_report.c index abd1bc9..31e1e1e 100644 --- a/src/hid_report.c +++ b/src/hid_report.c @@ -166,6 +166,14 @@ void extract_data(hid_interface_t *iface, report_val_t *val) { .dst = &iface->mouse.wheel, .id = &iface->mouse.report_id}, + {.usage_page = HID_USAGE_PAGE_CONSUMER, + .global_usage = HID_USAGE_DESKTOP_MOUSE, + .usage = HID_USAGE_CONSUMER_AC_PAN, + .handler = _store, + .receiver = process_mouse_report, + .dst = &iface->mouse.pan, + .id = &iface->mouse.report_id}, + {.usage_page = HID_USAGE_PAGE_KEYBOARD, .global_usage = HID_USAGE_DESKTOP_KEYBOARD, .handler = handle_keyboard_descriptor_values, @@ -293,4 +301,4 @@ int32_t extract_kbd_data( /* This is something completely different, look at the report */ return _extract_kbd_other(raw_report, len, iface, report); -} \ No newline at end of file +} diff --git a/src/include/hid_parser.h b/src/include/hid_parser.h index 0926ee5..35c397b 100644 --- a/src/include/hid_parser.h +++ b/src/include/hid_parser.h @@ -98,6 +98,7 @@ typedef struct { report_val_t move_x; report_val_t move_y; report_val_t wheel; + report_val_t pan; uint8_t report_id; diff --git a/src/include/main.h b/src/include/main.h index dc6882d..a44d844 100644 --- a/src/include/main.h +++ b/src/include/main.h @@ -177,7 +177,7 @@ typedef struct { #define KEYARRAY_BIT_OFFSET 16 #define KEYS_IN_USB_REPORT 6 #define KBD_REPORT_LENGTH 8 -#define MOUSE_REPORT_LENGTH 7 +#define MOUSE_REPORT_LENGTH 8 #define CONSUMER_CONTROL_LENGTH 4 #define SYSTEM_CONTROL_LENGTH 1 #define MODIFIER_BIT_LENGTH 8 @@ -345,6 +345,7 @@ typedef struct TU_ATTR_PACKED { int16_t x; int16_t y; int8_t wheel; + int8_t pan; uint8_t mode; } mouse_report_t; @@ -460,7 +461,7 @@ int32_t extract_bit_variable(uint32_t, uint32_t, uint8_t *, int, uint8_t *); int32_t extract_kbd_data(uint8_t *, int, uint8_t, hid_interface_t *, hid_keyboard_report_t *); /********* Mouse **********/ -bool tud_mouse_report(uint8_t mode, uint8_t buttons, int16_t x, int16_t y, int8_t wheel); +bool tud_mouse_report(uint8_t mode, uint8_t buttons, int16_t x, int16_t y, int8_t wheel, int8_t pan); void process_mouse_report(uint8_t *, int, uint8_t, hid_interface_t *); void parse_report_descriptor(hid_interface_t *, uint8_t const *, int); diff --git a/src/include/usb_descriptors.h b/src/include/usb_descriptors.h index e32a45e..65f1ed4 100644 --- a/src/include/usb_descriptors.h +++ b/src/include/usb_descriptors.h @@ -98,6 +98,15 @@ HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\ HID_REPORT_SIZE ( 8 ) ,\ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\ \ + /* Horizontal wheel (AC Pan) */ \ + HID_USAGE_PAGE ( HID_USAGE_PAGE_CONSUMER ) ,\ + HID_LOGICAL_MIN ( 0x81 ) ,\ + HID_LOGICAL_MAX ( 0x7f ) ,\ + HID_REPORT_COUNT( 1 ) ,\ + HID_REPORT_SIZE ( 8 ) ,\ + HID_USAGE_N ( HID_USAGE_CONSUMER_AC_PAN, 2 ) ,\ + HID_INPUT ( HID_DATA | HID_VARIABLE | HID_RELATIVE ) ,\ + \ /* Mouse mode (0 = absolute, 1 = relative) */ \ HID_REPORT_COUNT( 1 ), \ HID_REPORT_SIZE ( 8 ), \ diff --git a/src/mouse.c b/src/mouse.c index 79a9198..7e8e30e 100644 --- a/src/mouse.c +++ b/src/mouse.c @@ -219,6 +219,7 @@ void extract_report_values(uint8_t *raw_report, device_t *state, mouse_values_t values->move_x = mouse_report->x; values->move_y = mouse_report->y; values->wheel = mouse_report->wheel; + values->pan = mouse_report->pan; values->buttons = mouse_report->buttons; return; } @@ -230,6 +231,7 @@ void extract_report_values(uint8_t *raw_report, device_t *state, mouse_values_t values->move_x = get_report_value(raw_report, &iface->mouse.move_x); values->move_y = get_report_value(raw_report, &iface->mouse.move_y); values->wheel = get_report_value(raw_report, &iface->mouse.wheel); + values->pan = get_report_value(raw_report, &iface->mouse.pan); values->buttons = get_report_value(raw_report, &iface->mouse.buttons); } @@ -239,6 +241,7 @@ mouse_report_t create_mouse_report(device_t *state, mouse_values_t *values) { .x = state->pointer_x, .y = state->pointer_y, .wheel = values->wheel, + .pan = values->pan, .mode = ABSOLUTE, }; @@ -296,7 +299,8 @@ void process_mouse_queue_task(device_t *state) { return; /* Try sending it to the host, if it's successful */ - bool succeeded = tud_mouse_report(report.mode, report.buttons, report.x, report.y, report.wheel); + bool succeeded + = tud_mouse_report(report.mode, report.buttons, report.x, report.y, report.wheel, report.pan); /* ... then we can remove it from the queue */ if (succeeded) diff --git a/src/usb_descriptors.c b/src/usb_descriptors.c index 278e3ae..2f02594 100644 --- a/src/usb_descriptors.c +++ b/src/usb_descriptors.c @@ -81,10 +81,10 @@ uint8_t const *tud_hid_descriptor_report_cb(uint8_t instance) { } } -bool tud_mouse_report(uint8_t mode, uint8_t buttons, int16_t x, int16_t y, int8_t wheel) { - mouse_report_t report = {.buttons = buttons, .wheel = wheel, .x = x, .y = y, .mode = mode}; uint8_t instance = ITF_NUM_HID; uint8_t report_id = REPORT_ID_MOUSE; +bool tud_mouse_report(uint8_t mode, uint8_t buttons, int16_t x, int16_t y, int8_t wheel, int8_t pan) { + mouse_report_t report = {.buttons = buttons, .wheel = wheel, .x = x, .y = y, .mode = mode, .pan = pan}; if (mode == RELATIVE) { instance = ITF_NUM_HID_REL_M;