From c7a762ae67ff8ab316caaa1ff090783dd4ed0a60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Wed, 2 Mar 2016 00:28:15 +0100 Subject: [PATCH] Add a mouse report descriptor that have wheel usages. --- right/usb_descriptor_mouse_report.c | 79 ++++++++++++++++++++++++++++- right/usb_descriptor_mouse_report.h | 8 ++- right/usb_interface_mouse.c | 14 +++-- right/usb_interface_mouse.h | 10 +++- 4 files changed, 105 insertions(+), 6 deletions(-) diff --git a/right/usb_descriptor_mouse_report.c b/right/usb_descriptor_mouse_report.c index ab8ffd2..29cd645 100644 --- a/right/usb_descriptor_mouse_report.c +++ b/right/usb_descriptor_mouse_report.c @@ -1,6 +1,7 @@ #include +#include "usb_report_item_macros.h" #include "usb_descriptor_mouse_report.h" - +/* uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH] = { 0x05U, 0x01U, // Usage Page (Generic Desktop) 0x09U, 0x02U, // Usage (Mouse) @@ -35,4 +36,80 @@ uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH] = { 0x81U, 0x06U, // Input (Data, Variable, Relative), 3 position bytes (X & Y & Z) 0xC0U, // End collection, Close Pointer collection 0xC0U // End collection, Close Mouse collection + +}; +*/ + +uint8_t UsbMouseReportDescriptor[USB_MOUSE_REPORT_DESCRIPTOR_LENGTH] = { + HID_RI_USAGE_PAGE(8, 0x01), + HID_RI_USAGE(8, 0x02), + HID_RI_COLLECTION(8, 0x01), + HID_RI_USAGE(8, 0x01), + HID_RI_COLLECTION(8, 0x00), + HID_RI_USAGE_PAGE(8, 0x09), + HID_RI_USAGE_MINIMUM(8, 0x01), + HID_RI_USAGE_MAXIMUM(8, USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS), + HID_RI_LOGICAL_MINIMUM(8, 0x00), + HID_RI_LOGICAL_MAXIMUM(8, 0x01), + HID_RI_REPORT_COUNT(8, USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS), + HID_RI_REPORT_SIZE(8, 0x01), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE), + + HID_RI_REPORT_COUNT(8, 0x01), + HID_RI_REPORT_SIZE(8, (USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS % 8) ? (8 - (USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS % 8)) : 0), + HID_RI_INPUT(8, HID_IOF_CONSTANT), + + HID_RI_USAGE_PAGE(8, 0x01), + HID_RI_USAGE(8, 0x30), + HID_RI_USAGE(8, 0x31), + HID_RI_LOGICAL_MINIMUM(16, USB_MOUSE_REPORT_DESCRIPTOR_MIN_AXIS_VALUE), + HID_RI_LOGICAL_MAXIMUM(16, USB_MOUSE_REPORT_DESCRIPTOR_MAX_AXIS_VALUE), + HID_RI_PHYSICAL_MINIMUM(16, USB_MOUSE_REPORT_DESCRIPTOR_MIN_AXIS_PHYSICAL_VALUE), + HID_RI_PHYSICAL_MAXIMUM(16, USB_MOUSE_REPORT_DESCRIPTOR_MAX_AXIS_PHYSICAL_VALUE), //50 + HID_RI_REPORT_COUNT(8, 0x02), + HID_RI_REPORT_SIZE(8, (((USB_MOUSE_REPORT_DESCRIPTOR_MIN_AXIS_VALUE >= -128) && (USB_MOUSE_REPORT_DESCRIPTOR_MAX_AXIS_VALUE <= 127)) ? 8 : 16)), + HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE), + + 0xa1, 0x02, // COLLECTION (Logical) + // ------------------------------ Vertical wheel res multiplier + 0x09, 0x48, // USAGE (Resolution Multiplier) + 0x15, 0x00, // LOGICAL_MINIMUM (0) + 0x25, 0x01, // LOGICAL_MAXIMUM (1) + 0x35, 0x01, // PHYSICAL_MINIMUM (1) + 0x45, 0x04, // PHYSICAL_MAXIMUM (4) + 0x75, 0x02, // REPORT_SIZE (2) + 0x95, 0x01, // REPORT_COUNT (1) + 0xa4, // PUSH + 0xb1, 0x02, // FEATURE (Data,Var,Abs) + + // ------------------------------ Vertical wheel + 0x09, 0x38, // USAGE (Wheel) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical + 0x45, 0x00, // PHYSICAL_MAXIMUM (0) + 0x75, 0x08, // REPORT_SIZE (8) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION // 90 + + 0xa1, 0x02, // COLLECTION (Logical) + // ------------------------------ Horizontal wheel res multiplier + 0x09, 0x48, // USAGE (Resolution Multiplier) + 0xb4, // POP + 0xb1, 0x02, // FEATURE (Data,Var,Abs) + // ------------------------------ Padding for Feature report + 0x35, 0x00, // PHYSICAL_MINIMUM (0) - reset physical + 0x45, 0x00, // PHYSICAL_MAXIMUM (0) + 0x75, 0x04, // REPORT_SIZE (4) + 0xb1, 0x03, // FEATURE (Cnst,Var,Abs) + // ------------------------------ Horizontal wheel + 0x05, 0x0c, // USAGE_PAGE (Consumer Devices) + 0x0a, 0x38, 0x02, // USAGE (AC Pan) + 0x15, 0x81, // LOGICAL_MINIMUM (-127) + 0x25, 0x7f, // LOGICAL_MAXIMUM (127) + 0x75, 0x08, // REPORT_SIZE (8) + 0x81, 0x06, // INPUT (Data,Var,Rel) + 0xc0, // END_COLLECTION + HID_RI_END_COLLECTION(0), + HID_RI_END_COLLECTION(0) }; diff --git a/right/usb_descriptor_mouse_report.h b/right/usb_descriptor_mouse_report.h index be52e20..3994a75 100644 --- a/right/usb_descriptor_mouse_report.h +++ b/right/usb_descriptor_mouse_report.h @@ -3,7 +3,13 @@ // Macros: - #define USB_MOUSE_REPORT_DESCRIPTOR_LENGTH (52U) + #define USB_MOUSE_REPORT_DESCRIPTOR_LENGTH (121U) + + #define USB_MOUSE_REPORT_DESCRIPTOR_MIN_AXIS_VALUE -4096 + #define USB_MOUSE_REPORT_DESCRIPTOR_MAX_AXIS_VALUE 4096 + #define USB_MOUSE_REPORT_DESCRIPTOR_MIN_AXIS_PHYSICAL_VALUE -4096 + #define USB_MOUSE_REPORT_DESCRIPTOR_MAX_AXIS_PHYSICAL_VALUE 4096 + #define USB_MOUSE_REPORT_DESCRIPTOR_BUTTONS 8 // Variables: diff --git a/right/usb_interface_mouse.c b/right/usb_interface_mouse.c index dfe8df9..8e328ab 100644 --- a/right/usb_interface_mouse.c +++ b/right/usb_interface_mouse.c @@ -15,10 +15,18 @@ static usb_device_hid_mouse_struct_t UsbMouseDevice; static usb_status_t UsbMouseAction(void) { - UsbMouseDevice.buffer[1] = 0U; - UsbMouseDevice.buffer[2] = 0U; + //usb_device_wheeled_mouse_struct_t *wheeledMouse = (usb_device_wheeled_mouse_struct_t*)&(UsbMouseDevice.buffer); + UsbMouseDevice.buffer[0] = 0; + UsbMouseDevice.buffer[1] = 0; + UsbMouseDevice.buffer[2] = 0; + UsbMouseDevice.buffer[3] = 0; + UsbMouseDevice.buffer[4] = 0; + UsbMouseDevice.buffer[5] = 0; + UsbMouseDevice.buffer[6] = 0; if (!GPIO_ReadPinInput(BOARD_SW2_GPIO, BOARD_SW2_GPIO_PIN)) { - UsbMouseDevice.buffer[2] = 1U; + UsbMouseDevice.buffer[1] = 1; + //wheeledMouse->x = 32767; + //wheeledMouse->y = 32767; } return USB_DeviceHidSend(UsbCompositeDevice.mouseHandle, USB_MOUSE_ENDPOINT_ID, UsbMouseDevice.buffer, USB_MOUSE_REPORT_LENGTH); diff --git a/right/usb_interface_mouse.h b/right/usb_interface_mouse.h index 01b04e8..d48f320 100644 --- a/right/usb_interface_mouse.h +++ b/right/usb_interface_mouse.h @@ -3,7 +3,7 @@ // Macros: - #define USB_MOUSE_REPORT_LENGTH (0x04U) + #define USB_MOUSE_REPORT_LENGTH (0x07U) // Typedefs: @@ -12,6 +12,14 @@ uint8_t idleRate; } usb_device_hid_mouse_struct_t; + typedef struct usb_device_wheeled_mouse_struct { + uint8_t button; + int16_t x; + int16_t y; + int8_t verticalWheelMovement; + int8_t horizontalWheelMovement; + } usb_device_wheeled_mouse_struct_t; + // Functions: extern usb_status_t UsbMouseCallback(class_handle_t handle, uint32_t event, void *param);