This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

HID USB support 16 bit X-axis and Y-axis

I came across the SDK document below:
For the mouse protocol, one 4-byte input report is defined:
BYTE[0]: Button state bit field.
BYTE[1]: Signed 8-bit X-axis offset since the last position.
BYTE[2]: Signed 8-bit Y-axis offset since the last position.
BYTE[3]: signed 8-bit Wheel offset since the last position.

By using the Generic HID USB instance how do I extend this 4 bytes to 6 bytes reporting to support 16 bit X-axis and Y-axis?

Parents
  • It is working now after I have made the change in the Report Descriptor per your advice on the typo.

    /**
     * @brief Reuse HID mouse report descriptor for HID generic class    modified chanhock 9/1/2019
     */
    #define HID_GENERIC_REP_DESCRIPTOR {                            \
    0x05, 0x01,       /* Usage Page (Generic Desktop),       */     \
    0x09, 0x02,       /* Usage (Mouse),                      */     \
    0xA1, 0x01,       /*  Collection (Application),          */     \
    0x85, 0x01,                        /*     Report Id 1  Mouse Motion   */     \
    0x09, 0x01,       /*   Usage (Pointer),                  */     \
    0xA1, 0x00,       /*  Collection (Physical),             */     \
    0x05, 0x09,       /*     Usage Page (Buttons),           */     \
    0x19, 0x01,       /*     Usage Minimum (01),             */     \
    0x29, 0x03,       /*     Usage Maximum (03),  3 buttons  */     \
    0x15, 0x00,       /*     Logical Minimum (0),            */     \
    0x25, 0x01,       /*     Logical Maximum (1),            */     \
    0x75, 0x01,       /*     Report Size (1),                */     \
    0x95, 0x03,       /*     Report Count (3),               */     \
    0x81, 0x02,       /*     Input (Data, Variable, Absolute)*/     \
    0x75, 0x05,       /*     Report Size (5), 5 bit padding  */     \
    0x95, 0x01,       /*     Report Count (1),               */     \
    0x81, 0x01,       /*     Input (Constant),               */     \
    0x05, 0x01,       /*     Usage Page (Generic Desktop),   */     \
    0x09, 0x30,       /*     Usage (X),                      */     \
    0x09, 0x31,       /*     Usage (Y),                      */     \
    0x16, 0x01, 0x80, /*     Logical Minimum (-32767),       */     \
    0x26, 0xFF, 0x7F, /*     Logical Maximum (32767),        */     \
    0x75, 0x10,       /*     Report Size (16),                */     \
    0x95, 0x02,       /*     Report Count (2),               */     \
    0x81, 0x06,       /*     Input (Data, Variable, Relative)*/     \
    0x09, 0x38,       /*     Usage (Scroll),                 */     \
    0x15,0x81,        /*     Logical Minimum(-127)           */     \
    0x25,0x7F,        /*     Logical Maximum(127)            */     \
    0x75,0x08,        /*     Report Size(8)                  */     \
    0x95,0x01,        /*     Report Count(1)                 */     \
    0x81,0x06,        /*     Input(Data,Var,Rel)             */     \
    0x95,0x02,        /*     Report Count(1) dummy padding for 1 byte as standard 8 byte USB max size        */     \
    0x75,0x08,        /*     Report Size(8)                  */     \
    0x81,0x01,        /*     Input(Data,Var,Rel)             */     \
    0xC0,             /*  End Collection,                    */     \
    0xC0,             /* End Collection                      */     \
    }

    However, noticed that would need to add the additional line below to report 1st byte of Motion ID 0x01.

    0x85, 0x01,                        /*     Report Id 1  Mouse Motion   */     \

    Thank you so much for your prompt. This really helps in my development work. Appreciate it so much!

  • Hi Bernard,

    I tried the same thing and found that when I sent mouse offset data (X/Y axes) at the same time as wheel offset data, Android reported only the mouse offset data -- that is, MotionEvent with action ACTION_MOVE. The scroll event (ACTION_xSCROLL) and data is lost. Do you see the same issue? Thanks.

Reply Children
No Data
Related