有个项目要求平板作为一个扫描枪的hid设备让电脑失败,根据usb设备的文件描述符设置为对应的设备,如下是补丁。
diff --git a/drivers/usb/gadget/android.c b/drivers/usb/gadget/android.c
index f126474..14568c4 100755
--- a/drivers/usb/gadget/android.c
+++ b/drivers/usb/gadget/android.c
@@ -36,6 +36,7 @@
#include "f_mass_storage.c"
#include "f_mtp.c"
#include "f_accessory.c"
+#include "f_hid.c"
#define USB_ETH_RNDIS y
#include "f_rndis.c"
#include "rndis.c"
@@ -1009,6 +1010,81 @@ static struct android_usb_function midi_function = {
.attributes = midi_function_attributes,
};
+static struct hidg_func_descriptor ghid_data = {
+ .subclass = 0,
+ .protocol = 1,
+ .report_length = 8,
+ .report_desc_length = 63,
+ .report_desc = {
+ 0x05, 0x01,
+ 0x09, 0x06,
+ 0xa1, 0x01,
+ 0x05, 0x07,
+ 0x19, 0xe0,
+ 0x29, 0xe7,
+ 0x15, 0x00,
+ 0x25, 0x01,
+ 0x75, 0x01,
+ 0x95, 0x08,
+ 0x81, 0x02,
+ 0x95, 0x01,
+ 0x75, 0x08,
+ 0x81, 0x03,
+ 0x95, 0x05,
+ 0x75, 0x01,
+ 0x05, 0x08,
+ 0x19, 0x01,
+ 0x29, 0x05,
+ 0x91, 0x02,
+ 0x95, 0x01,
+ 0x75, 0x03,
+ 0x91, 0x03,
+ 0x95, 0x06,
+ 0x75, 0x08,
+ 0x15, 0x00,
+ 0x25, 0x65,
+ 0x05, 0x07,
+ 0x19, 0x00,
+ 0x29, 0x65,
+ 0x81, 0x00,
+ 0xc0
+ }
+};
+
+static int hidg_function_init(struct android_usb_function *f,
+ struct usb_composite_dev *cdev)
+{
+ ghid_setup(cdev->gadget, 2);
+ return 0;
+}
+
+static void hidg_function_cleanup(struct android_usb_function *f)
+{
+ ghid_cleanup();
+ return;
+}
+
+static int hidg_function_bind_config(struct android_usb_function *f,
+ struct usb_configuration *c)
+{
+ if(ghid_data.report_desc_length)
+ hidg_bind_config(c, &ghid_data, 0);
+ return 0;
+}
+static void hidg_function_unbind_config(struct android_usb_function *f,
+ struct usb_configuration *c)
+{
+ return;
+}
+
+static struct android_usb_function hidg_function = {
+ .name = "hidg",
+ .init = hidg_function_init,
+ .cleanup = hidg_function_cleanup,
+ .bind_config = hidg_function_bind_config,
+ .unbind_config = hidg_function_unbind_config,
+};
+
static struct android_usb_function *supported_functions[] = {
&ffs_function,
&acm_function,
@@ -1019,6 +1095,7 @@ static struct android_usb_function *supported_functions[] = {
&accessory_function,
&audio_source_function,
&midi_function,
+ &hidg_function,
NULL
};
diff --git a/drivers/usb/gadget/f_hid.c b/drivers/usb/gadget/f_hid.c
index 6e69a8e..d7205b6 100644
--- a/drivers/usb/gadget/f_hid.c
+++ b/drivers/usb/gadget/f_hid.c
@@ -560,7 +560,7 @@ const struct file_operations f_hidg_fops = {
.llseek = noop_llseek,
};
-static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)
+static int hidg_bind(struct usb_configuration *c, struct usb_function *f)
{
struct usb_ep *ep;
struct f_hidg *hidg = func_to_hidg(f);
@@ -689,8 +689,8 @@ static struct usb_gadget_strings *ct_func_strings[] = {
/*-------------------------------------------------------------------------*/
/* usb_configuration */
-int __init hidg_bind_config(struct usb_configuration *c,
- struct hidg_func_descriptor *fdesc, int index)
+int hidg_bind_config(struct usb_configuration *c,
+ struct hidg_func_descriptor *fdesc, int index)
{
struct f_hidg *hidg;
int status;
@@ -743,7 +743,7 @@ int __init hidg_bind_config(struct usb_configuration *c,
return status;
}
-int __init ghid_setup(struct usb_gadget *g, int count)
+int ghid_setup(struct usb_gadget *g, int count)
{
int status;
dev_t dev;
diff --git a/init.rk30board.usb.rc b/init.rk30board.usb.rc
old mode 100644
new mode 100755
index 6640910..613f3f9
--- a/init.rk30board.usb.rc
+++ b/init.rk30board.usb.rc
@@ -139,4 +139,12 @@ on property:sys.usb.config=rndis,dm
write /sys/class/android_usb/android0/functions ${sys.usb.config}
write /sys/class/android_usb/android0/enable 1
setprop sys.usb.state ${sys.usb.config}
+
+on property:sys.usb.config=hidg
+ write /sys/class/android_usb/android0/enable 0
+ write /sys/class/android_usb/android0/idVendor 0471
+ write /sys/class/android_usb/android0/idProduct e002
+ write /sys/class/android_usb/android0/functions ${sys.usb.config}
+ write /sys/class/android_usb/android0/enable 1
+ setprop sys.usb.state ${sys.usb.config}
diff --git a/ueventd.rockchip.rc b/ueventd.rockchip.rc
index cc1f393..3428fcf 100644
--- a/ueventd.rockchip.rc
+++ b/ueventd.rockchip.rc
@@ -49,13 +49,13 @@
+/dev/hidg0 0666 radio radio
+/dev/ttyACM0 0666 radio radio