LPCOpen Mouse Example from 8-bit X/Y Inputs to 16-bit

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPCOpen Mouse Example from 8-bit X/Y Inputs to 16-bit

334 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by esheets on Wed Nov 25 10:20:52 MST 2015
As you can see below, I changed HID_USAGE_GENERIC_X to -32767 and HID_USAGE_GENERIC_Y to 32767 to get the greatest possible value range for a 16 bit variable. I also changed HID_ReportSize to 16 rather than 8. I read that wMaxPacketSize must be greater than the number of packets to be sent, which it should be since that value is set to 8. I believe regarding the USB desc file, I have everything set the way it should be.


So with the original working 8-bit code, I am using a `uint8_t report[report_size]`. When I changed it, I increased the report size to 5 where it was 3 before. My understanding is that: `report[0] = mouse buttons, report[1] = lower 8 bits of X, report[2] = upper 8 bits of X, report[3] = lower 8 bits of Y, report[4] = upper 8 bits of Y`. Is this the correct implementation of a 16 bit X/Y 16-bit variable? I've looked online for something that may help, but nothing seems to be very thorough with what needs to be done. I'm sure there must be something in the hid_mouse.c code that I need to change other than increasing the mouse report size and making X and Y variables 16 bit instead of 8 bit.
                
    /**
     * HID Mouse Report Descriptor
     */
     const uint8_t Mouse_ReportDescriptor[] = {
    HID_UsagePage(HID_USAGE_PAGE_GENERIC),
    HID_Usage(HID_USAGE_GENERIC_MOUSE),
    HID_Collection(HID_Application),
    HID_Usage(HID_USAGE_GENERIC_POINTER),
    HID_Collection(HID_Physical),
    HID_UsagePage(HID_USAGE_PAGE_BUTTON),
    HID_UsageMin(1),
    HID_UsageMax(3),
    HID_LogicalMin(0),
    HID_LogicalMax(1),
    HID_ReportCount(3),
    HID_ReportSize(1),
    HID_Input(HID_Data | HID_Variable | HID_Absolute),
    HID_ReportCount(1),
    HID_ReportSize(5),
    HID_Input(HID_Constant),
    HID_UsagePage(HID_USAGE_PAGE_GENERIC),
    HID_Usage(HID_USAGE_GENERIC_X),
    HID_Usage(HID_USAGE_GENERIC_Y),
    HID_LogicalMin( (uint16_t) -32767),     //was -127
    HID_LogicalMax(32767),                  //was 127
    HID_ReportSize(16),            //Was 8
    HID_ReportCount(2),
    HID_Input(HID_Data | HID_Variable | HID_Relative),
    HID_EndCollection,
    HID_EndCollection,
    };
    const uint16_t Mouse_ReportDescSize = sizeof(Mouse_ReportDescriptor);

    /**
     * USB Standard Device Descriptor
     */
    ALIGNED(4) const uint8_t USB_DeviceDescriptor[] = {
    USB_DEVICE_DESC_SIZE,/* bLength */
    USB_DEVICE_DESCRIPTOR_TYPE,/* bDescriptorType */
    WBVAL(0x0200),/* bcdUSB : 2.00*/
    0x00,/* bDeviceClass */
    0x00,/* bDeviceSubClass */
    0x00,/* bDeviceProtocol */
    USB_MAX_PACKET0,/* bMaxPacketSize0 */
    WBVAL(0x1FC9),/* idVendor */
    WBVAL(0x0085),/* idProduct */
    WBVAL(0x0100),/* bcdDevice : 1.00 */
    0x01,/* iManufacturer */
    0x02,/* iProduct */
    0x03,/* iSerialNumber */
    0x01/* bNumConfigurations */
    };

    /**
     * USB FSConfiguration Descriptor
     * All Descriptors (Configuration, Interface, Endpoint, Class, Vendor)
     */
    ALIGNED(4) uint8_t USB_FsConfigDescriptor[] = {
    /* Configuration 1 */
    USB_CONFIGURATION_DESC_SIZE,/* bLength */
    USB_CONFIGURATION_DESCRIPTOR_TYPE,/* bDescriptorType */
    WBVAL(/* wTotalLength */
    USB_CONFIGURATION_DESC_SIZE   +
    USB_INTERFACE_DESC_SIZE       +
    HID_DESC_SIZE                 +
    USB_ENDPOINT_DESC_SIZE
    ),
    0x01,/* bNumInterfaces */
    0x01,/* bConfigurationValue */
    0x00,/* iConfiguration */
    USB_CONFIG_SELF_POWERED,/* bmAttributes */
    USB_CONFIG_POWER_MA(2),    /* bMaxPower */

    /* Interface 0, Alternate Setting 0, HID Class */
    USB_INTERFACE_DESC_SIZE,/* bLength */
    USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType */
    0x00,/* bInterfaceNumber */
    0x00,/* bAlternateSetting */
    0x01,/* bNumEndpoints */
    USB_DEVICE_CLASS_HUMAN_INTERFACE,/* bInterfaceClass */
    HID_SUBCLASS_BOOT,/* bInterfaceSubClass */
    HID_PROTOCOL_MOUSE,/* bInterfaceProtocol */
    0x04,/* iInterface */
    /* HID Class Descriptor */
    /* HID_DESC_OFFSET = 0x0012 */
    HID_DESC_SIZE,/* bLength */
    HID_HID_DESCRIPTOR_TYPE,/* bDescriptorType */
    WBVAL(0x0111),/* bcdHID : 1.11*/
    0x00,/* bCountryCode */
    0x01,/* bNumDescriptors */
    HID_REPORT_DESCRIPTOR_TYPE,/* bDescriptorType */
    WBVAL(sizeof(Mouse_ReportDescriptor)),/* wDescriptorLength */
    /* Endpoint, HID Interrupt In */
    USB_ENDPOINT_DESC_SIZE,/* bLength */
    USB_ENDPOINT_DESCRIPTOR_TYPE,/* bDescriptorType */
    HID_EP_IN,/* bEndpointAddress */
    USB_ENDPOINT_TYPE_INTERRUPT,/* bmAttributes */
    WBVAL(0x0008),/* wMaxPacketSize */
    HID_MOUSE_REPORT_INTERVAL,/* bInterval */
    /* Terminator */
    0/* bLength */
    };
Labels (1)
0 Kudos
0 Replies