虽然能正常通信 但不速度太慢 默认只有控制端点IN/OUT和中断端点IN 而控制传输最大传输数据为64字节 基本上速度在300K左右 如果增加一个中断端点OUT默认数据就会出中断端点传输 中断端点高速设备最大传输为1024字节 相关说明在下面的参考文章中有详细的说明. 下面我说就来增加一个中断端点. 这个是在4418 linux3.4.39上增加的 其它linux版本 增加类似 先保证自定义hid设备能正常通信 然后开始增加 主要修改文件为内核drivers/usb/gadget/f_hid.c 和drivers/usb/gadget/hid.c
首先来看下f_hid.c
struct f_hidg {
/* configuration */
unsigned charbInterfaceSubClass;
unsigned charbInterfaceProtocol;
unsigned shortreport_desc_length;
char*report_desc;
unsigned shortreport_length;
/* recv report */
char*set_report_buff;
unsigned shortset_report_length;
spinlock_tspinlock;
wait_queue_head_tread_queue;
/* send report */
struct mutexlock;
boolwrite_pending;
wait_queue_head_twrite_queue;
struct usb_request*req;
intminor;
struct cdevcdev;
struct usb_functionfunc;
struct usb_ep*in_ep;
#ifdef CONFIG_INTOUT
struct usb_ep*out_ep;
wait_queue_head_t read_wq;
unsigned short rx_length;
struct usb_request*rx_req;
#endif
};首先修改f_hidg结构增加#ifdef CONFIG_INTOUT中,中断OUT需要的参数.
修改struct usb_interface_descriptor hidg_interface_desc中bNumEndpoints
#ifdef CONFIG_INTOUT
.bNumEndpoints= 2,
#else
.bNumEndpoints= 1,
#endif增加了中断OUT 端点数就变成了2
修改struct hid_descriptor hidg_desc中
.bcdHID= 0x0200,usb 2.0协议对应bcdhid是0x0200
增加高速度中断OUT端点描述符
#ifdef CONFIG_INTOUT
static struct usb_endpoint_descriptor hidg_hs_out_ep_desc = {
.bLength= USB_DT_ENDPOINT_SIZE,
.bDescriptorType= USB_DT_ENDPOINT,
.bEndpointAddress= USB_DIR_OUT,
.bmAttributes= USB_ENDPOINT_XFER_INT,
/*.wMaxPacketSize= DYNAMIC */
.bInterval= 1, /* FIXME: Add this field in the
* HID gadget configuration?
* (struct hidg_func_descriptor)
*/
};
#endif这里bInterval是主机轮询时间1表示125us
修改struct usb_descriptor_header *hidg_hs_descriptors[]加上刚刚增加的endpoint
static struct usb_descriptor_header *hidg_hs_descriptors[] = {
(struct usb_descriptor_header *)&hidg_interface_desc,
(struct usb_descriptor_header *)&hidg_desc,
(struct usb_descriptor_header *)&hidg_hs_in_ep_desc,
#ifdef CONFIG_INTOUT
(struct usb_descriptor_header *)&hidg_hs_out_ep_desc,
#endif
NULL,
};hs也相应的加上中断out端点
#ifdef CONFIG_INTOUT
static struct usb_endpoint_descriptor hidg_fs_out_ep_desc = {
.bLength= USB_DT_ENDPOINT_SIZE,
.bDescriptorType= USB_DT_ENDPOINT,
.bEndpointAddress= USB_DIR_OUT,
.bmAttributes= USB_ENDPOINT_XFER_INT,
/*.wMaxPacketSize= DYNAMIC */
.bInterval= 1, /* FIXME: Add t