Android 的正确 usbHidReportDescriptor 是什么?

问题描述 投票:0回答:1

我正在实现一个 USB 触摸屏界面,它需要在 Android 上工作。

来自https://github.com/denilsonsa/atmega8-magnetometer-usb-mouse/blob/master/firmware/main.c#L159我第一次尝试:

// 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

这在 Ubuntu 16.04 上工作正常,但在 Android 6 上没有任何作用。

然后,从https://www.codeproject.com/Articles/1001891/A-USB-HID-Keyboard-Mouse-Touchscreen-emulator-with“第一个备用触摸屏描述符”我试过:

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)

适用于 Android,只要触摸屏幕就会出现鼠标指针的轻微故障。

Android 的正确 usbHidReportDescriptor 是什么?

更新:

当前的行为是在为按钮发送“3”时看到的,即“Pen Down”和“In Range”。

如果我发送“2”:“在范围内”,我只会得到一个非点击鼠标指针。

如果我发送“1”:“落笔”,我会得到一个非绝对圆形光标。

android usb touch hid
1个回答
1
投票

当您模拟手写笔而不是触摸板时,会出现一个光标。

这条线:

0x09, 0x02,                    // USAGE (Pen)

应该是:

0x09, 0x04,                    // USAGE (Touchscreen)

根据我的实验,我认为样式的 3 种状态是悬停在表面上方 (0)、未显示光标、悬停在表面附近 (1)、显示光标以及单击/触摸 (2)。

有关完整的触摸屏 HID 描述符示例,请参阅 https://learn.microsoft.com/en-us/windows-hardware/design/component-guidelines/touchscreen-sample-report-descriptors?source=recommendations#sample-report-描述符

© www.soinside.com 2019 - 2024. All rights reserved.