问题
I am implementing a USB touchscreen interface, which needs to work on Android.
From https://github.com/denilsonsa/atmega8-magnetometer-usb-mouse/blob/master/firmware/main.c#L159 I first tried:
// Mouse
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x02, // USAGE (Mouse)
0xa1, 0x01, // COLLECTION (Application)
0x85, 0x02, // REPORT_ID (2)
0x09, 0x01, // USAGE (Pointer)
0xa1, 0x00, // COLLECTION (Physical)
// X, Y movement
0x09, 0x30, // USAGE (X)
0x09, 0x31, // USAGE (Y)
0x26, 0xff, 0x7f, // LOGICAL_MAXIMUM (32767)
0x75, 0x10, // REPORT_SIZE (16)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x42, // INPUT (Data,Var,Abs,Null)
0xc0, // END_COLLECTION
// Buttons
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x03, // USAGE_MAXIMUM (Button 3)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x03, // REPORT_COUNT (3)
0x81, 0x02, // INPUT (Data,Var,Abs)
// Padding for the buttons
0x95, 0x05, // REPORT_COUNT (5)
0x81, 0x03, // INPUT (Cnst,Var,Abs)
0xc0 // END_COLLECTION
This worked correctly on Ubuntu 16.04, but did nothing on Android 6.
Then, from https://www.codeproject.com/Articles/1001891/A-USB-HID-Keyboard-Mouse-Touchscreen-emulator-with "First alternate Touchscreen Descriptor" I tried:
0x05, 0x0d, // USAGE_PAGE (Digitizer)
0x09, 0x02, // USAGE (Pen)
0xa1, 0x01, // COLLECTION (Application)
// declare a finger collection
0x09, 0x20, // Usage (Stylus)
0xA1, 0x00, // Collection (Physical)
// Declare a finger touch (finger up/down)
0x09, 0x42, // Usage (Tip Switch)
0x09, 0x32, // USAGE (In Range)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x02, // REPORT_COUNT (2)
0x81, 0x02, // INPUT (Data,Var,Abs)
// Declare the remaining 6 bits of the first data byte as constant -> the driver will ignore them
0x75, 0x01, // REPORT_SIZE (1)
0x95, 0x06, // REPORT_COUNT (6)
0x81, 0x01, // INPUT (Cnst,Ary,Abs)
// Define absolute X and Y coordinates of 16 bit each (percent values multiplied with 100)
// http://www.usb.org/developers/hidpage/Hut1_12v2.pdf
// Chapter 16.2 says: "In the Stylus collection a Pointer physical collection will contain the axes reported by the stylus."
0x05, 0x01, // Usage Page (Generic Desktop)
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x16, 0x00, 0x00, // Logical Minimum (0)
0x26, 0x10, 0x27, // Logical Maximum (10000)
0x36, 0x00, 0x00, // Physical Minimum (0)
0x46, 0x10, 0x27, // Physical Maximum (10000)
0x66, 0x00, 0x00, // UNIT (None)
0x75, 0x10, // Report Size (16),
0x95, 0x02, // Report Count (2),
0x81, 0x02, // Input (Data,Var,Abs)
0xc0, // END_COLLECTION
0xc0, // END_COLLECTION
0xc0 // END_COLLECTION
// With this declaration a data packet must be sent as:
// byte 1 -> "touch" state (bit 0 = pen up/down, bit 1 = In Range)
// byte 2,3 -> absolute X coordinate (0...10000)
// byte 4,5 -> absolute Y coordinate (0...10000)
Which worked on Android, with the slight niggle of a mouse pointer appearing whenever the screen was touched.
What is a correct usbHidReportDescriptor for Android?
Update:
The current behaviour is seen when sending "3" for buttons, i.e. "Pen Down" and "In Range".
If I send "2":"In Range" I get just a non-clicking mouse pointer.
If I send "1":"Pen Down" I get a non-absolute circular cursor.
来源:https://stackoverflow.com/questions/46033581/what-is-a-correct-usbhidreportdescriptor-for-android