| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- /* Minimal HID report-descriptor parser for mouse reports.
- *
- * usbhid.c uses this to find a wheel (Generic Desktop usage 0x38) and the
- * exact bit offsets of the mouse fields. A USB boot mouse has no wheel
- * field in its boot report, so a mouse whose report descriptor advertises
- * one is switched to report protocol and decoded through this layout. When
- * the descriptor has no wheel, or the parser cannot make sense of it, the
- * caller keeps the fixed boot-protocol decoder.
- *
- * Only the Input items a mouse needs are interpreted (buttons, X, Y, Wheel);
- * the rest of the descriptor is skipped by its item size. The parser is
- * freestanding and has a host test (make test-hid).
- */
- #ifndef HID_REPORT_H
- #define HID_REPORT_H
- /* A report longer than this cannot be received through the interrupt-IN
- * path (USB_INT_MAX in usb_hcd.h), so the layout is rejected. */
- #define HID_REPORT_MAX 32
- /* Mouse layout flags. */
- #define HID_ML_VALID 0x01u /* X and Y found; layout usable */
- #define HID_ML_HAS_ID 0x02u /* reports start with report_id */
- #define HID_ML_X_SIGNED 0x04u
- #define HID_ML_Y_SIGNED 0x08u
- #define HID_ML_WHEEL_SIGNED 0x10u
- struct hid_mouse_layout {
- unsigned short x_off, y_off, wheel_off; /* bits, after the ID byte */
- unsigned char x_size, y_size, wheel_size;
- unsigned char flags;
- unsigned char report_id;
- unsigned char report_bytes; /* including the ID byte */
- unsigned char btn_bit[8]; /* bit offset + 1, 0 = absent */
- };
- struct hid_mouse_frame {
- unsigned int buttons; /* bit0 left, bit1 right, bit2 middle, ... */
- int dx, dy; /* HID report values: +dy is down */
- int wheel; /* notches, +1 = away from the user */
- };
- /* Parse a report descriptor. Returns 1 and fills `out` when a mouse report
- * with X and Y was found; a layout with wheel_size != 0 also has a wheel.
- * Returns 0 for a descriptor that is not a usable mouse layout. */
- int hid_parse_mouse(const unsigned char *desc, unsigned int len,
- struct hid_mouse_layout *out);
- /* Decode one report-protocol report through `layout`. Returns 1 when the
- * report belongs to the mouse report ID and carries every field the layout
- * needs, 0 otherwise. */
- int hid_mouse_decode(const struct hid_mouse_layout *layout,
- const unsigned char *rep, unsigned int len,
- struct hid_mouse_frame *out);
- #endif
|