linux内核打开VDBG,linux 自定义hid速度优化

本文介绍了如何在Linux内核中为自定义HID设备增加中断端点以提高传输速度。通过修改`f_hid.c`和`hid.c`中的相关结构和描述符,实现了高速中断端点,从而将传输速率提升到约900KB/s。主要修改包括结构体`f_hidg`的扩展、接口和端点描述符的更新,以及`hidg_bind`和`hidg_set_alt`函数的调整。
摘要由CSDN通过智能技术生成

虽然能正常通信 但不速度太慢 默认只有控制端点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

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值