Learning USB HID in Linux Part 6 - Understanding Mouse Report Descriptor and reports

jamal@ubuntu:~/hidrd$ sudo usbhid-dump -d 0458:003a | tail -n +2 | xxd -r -p | hidrd-convert -o spec
Usage Page (Desktop),               ; Generic desktop controls (01h)
Usage (Mouse),                      ; Mouse (02h, application collection)
Collection (Application),
    Usage Page (Button),            ; Button (09h)
    Usage Minimum (01h),
    Usage Maximum (03h),
    Logical Minimum (0),
    Logical Maximum (1),
    Report Count (3),
    Report Size (1),
    Input (Variable),
    Report Count (1),
    Report Size (5),
    Input (Constant, Variable),
    Usage Page (Desktop),           ; Generic desktop controls (01h)
    Usage (Pointer),                ; Pointer (01h, physical collection)
    Collection (Physical),
        Usage (X),                  ; X (30h, dynamic value)
        Usage (Y),                  ; Y (31h, dynamic value)
        Logical Minimum (-127),
        Logical Maximum (127),
        Report Size (8),
        Report Count (2),
        Input (Variable, Relative),
    End Collection,
    Usage (Wheel),                  ; Wheel (38h, dynamic value)
    Logical Minimum (-127),
    Logical Maximum (127),
    Report Size (8),
    Report Count (1),
    Input (Variable, Relative),
End Collection

The report descriptor says it has 3 buttons and with 1 bit size and data is variable
 Usage Page (Button),            ; Button (09h)
    Usage Minimum (01h),
    Usage Maximum (03h),
    Logical Minimum (0),
    Logical Maximum (1),
    Report Count (3),
    Report Size (1),
    Input (Variable),

Next 5 bits are constant, 
 Report Count (1),
 Report Size (5),
 Input (Constant, Variable),

So total 1 byte in which 3 bits are for button and the next five bits are unused(constant).

Next two bytes contain x and y value each one byte.

 Usage Page (Desktop),           ; Generic desktop controls (01h)
    Usage (Pointer),                ; Pointer (01h, physical collection)
    Collection (Physical),
    Usage (X),                  ; X (30h, dynamic value)
    Usage (Y),                  ; Y (31h, dynamic value)
    Logical Minimum (-127),
    Logical Maximum (127),
    Report Size (8),
    Report Count (2),
    Input (Variable, Relative),

Next one byte is for the scrolling wheel,
Usage (Wheel),                  ; Wheel (38h, dynamic value)
    Logical Minimum (-127),
    Logical Maximum (127),
    Report Size (8),
    Report Count (1),
    Input (Variable, Relative),

So total the report contains 4 bytes:
First byte signifying three buttons
Second and third byte for x and y coordinate
Fourth byte for scrolling wheel.

Let's look at the report and try to do some button presses and mouse movements.


Pressing left click the value of first byte became 01 and then on release it became 00
Pressing right click the value of first byte became 02 and then on release it became 00


Scrolling down the value of 4th byte became 0xff when scrolled up it became 0x01

Similarly the second and third byte changes when mouse is moved towards x and y coordinates.



Comments

Popular posts from this blog

bb.utils.contains yocto

Difference between RDEPENDS and DEPENDS in Yocto

make config vs oldconfig vs defconfig vs menuconfig vs savedefconfig