完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
RK1808虚拟成自定义HID设备的实现
1、内核配置 cd kernel make menuconfig 配置如下: Device Drivers USB support USB Gadget Support 2、修改kernel/drivers/u***/gadget/ legacy/hid.c 修改如下: diff --git a/kernel/drivers/u***/gadget/legacy/hid.c b/kernel/drivers/u***/gadget/legacy/hid.c old mode 100644 new mode 100755 index 7e5d2c484..addffae56 --- a/kernel/drivers/u***/gadget/legacy/hid.c +++ b/kernel/drivers/u***/gadget/legacy/hid.c @@ -31,6 +31,56 @@ /*-------------------------------------------------------------------------*/ +/*--------------------------add by guchunqi begin--------------------------*/ +static struct hidg_func_descriptor my_hid_data = +{ + .subclass = 0, /* No subclass */ + .protocol = 0, /* Keyboard */ + .report_length = 8, + .report_desc_length = 52, + .report_desc = + { + 0x06, 0xA0, 0xFF, //用法页(FFA0h, vendor defined) + 0x09, 0x01, //用法(vendor defined) + 0xA1, 0x01, //集合(Application) + 0x09, 0x02, //用法(vendor defined) + 0xA1, 0x00, //集合(Physical) + 0x06, 0xA1, 0xFF, //用法页(vendor defined) +//输入报告 + 0x09, 0x03, //用法(vendor defined) + 0x09, 0x04, //用法(vendor defined) + 0x15, 0x80, //逻辑最小值(0x80 or -128) + 0x25, 0x7F, //逻辑最大值(0x7F or 127) + 0x35, 0x00, //物理最小值(0) + 0x45, 0xFF, //物理最大值(255) + 0x75, 0x08, //报告长度Report size (8位) + 0x95, 0x40, //报告数值(64 fields) + 0x81, 0x02, //输入(data, variable, absolute) +//输出报告 + 0x09, 0x05, //用法(vendor defined) + 0x09, 0x06, //用法(vendor defined) + 0x15, 0x80, //逻辑最小值(0x80 or -128) + 0x25, 0x7F, //逻辑最大值(0x7F or 127) + 0x35, 0x00, //物理最小值(0) + 0x45, 0xFF, //物理最大值(255) + 0x75, 0x08, //报告长度(8位) + 0x95, 0x40, //报告数值(64 fields) + 0x91, 0x02, //输出(data, variable, absolute) + 0xC0, //集合结束(Physical) + 0xC0 //集合结束(Application) + } +}; + +static struct platform_device my_hid = +{ + .name = "hidg", + .id = 0, + .num_resources = 0, + .resource = 0, + .dev.platform_data = &my_hid_data, +}; +/*--------------------------add by guchunqi end----------------------------*/ + struct hidg_func_node { struct u***_function_instance *fi; struct u***_function *f; @@ -280,6 +330,15 @@ static int __init hidg_init(void) { int status; +/*--------------------add by guchunqi begin------------------------*/ + printk("********************enter hid**********************rn"); + status = platform_device_register(&my_hid); + if (status < 0) + { + return status; + } +/*--------------------add by guchunqi end--------------------------*/ + status = platform_driver_probe(&hidg_plat_driver, hidg_plat_driver_probe); if (status < 0) @@ -297,5 +356,11 @@ static void __exit hidg_cleanup(void) { u***_composite_unregister(&hidg_driver); platform_driver_unregister(&hidg_plat_driver); + +/*--------------------add by guchunqi begin------------------------*/ + platform_device_unregister(&my_hid); + printk("********************out hid************************rn"); +/*--------------------add by guchunqi end--------------------------*/ + } module_exit(hidg_cleanup); 修改完成后重新编译内核将在kernel/drivers/u***/gadget生成的ko文件 3、拷贝ko到开发 为了防止modprobe加载驱动的时候,相关依赖的ko找不到,把kernel/drivers/u***/gadget下的所有ko拷贝到板/lib/modules/4.4.194下面(注意: 4.4.194.194 可能没有自己创建文件(特别是4.4.194,使用uname-r确认当然) 4、加载HID驱动 执行命令,完成加载驱动: depmod modprobe libcomposite.ko modprobe u***_f_hid.ko modprobe g_hid.ko 加载成功打印以下: [root@rk1808:/lib/modules/4.4.194]# modprobe libcomposite.ko [root@rk1808:/lib/modules/4.4.194]# modprobe u***_f_hid.ko [root@rk1808:/lib/modules/4.4.194]# modprobe g_hid.ko [ 77.820449] *******************************enter hid************************************* [ 77.822072] g_hid gadget: HID Gadget, version: 2010/03/16 [ 77.822114] g_hid gadget: g_hid ready [root@rk1808:/lib/modules/4.4.194]# [ 81.956406] g_hid gadget: high-speed config #1: HID Gadget [ 281.935604] rockchip-dwc3 u***: USB unconnected [ 300.223501] phy phy-fe010000.syscon:u***2-phy@100.2: charger = USB_SDP_CHARGER [ 300.224768] rockchip-dwc3 u***: USB peripheral connected [ 309.200718] g_hid gadget: high-speed config #1: HID Gadget 加载成功后将开发板连接到windows PC在设备管理器中可以看到HID设备: 加载成功后将开发板连接到linux PC或者开发板使用lsu***可以看到HID设备: lsu*** Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 003 Device 004: ID 0e0f:0002 VMware, Inc. Virtual USB Hub Bus 003 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub Bus 003 Device 042: ID 0525:a4ac Netchip Technology, Inc. Bus 003 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub 上面的“Bus 003 Device 042: ID 0525:a4ac Netchip Technology, Inc.”就是插入的开发板 可以使用lsu*** -v查看详细的描述符信息: lsu*** -v Bus 003 Device 042: ID 0525:a4ac Netchip Technology, Inc. Couldn't open device, some information will be missing Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.10 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x0525 Netchip Technology, Inc. idProduct 0xa4ac bcdDevice 4.04 iManufacturer 1 iProduct 2 iSerial 0 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 41 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0xc0 Self Powered MaxPower 500mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 3 Human Interface Device bInterfaceSubClass 0 No Subclass bInterfaceProtocol 0 None iInterface 4 HID Device Descriptor: bLength 9 bDescriptorType 33 bcdHID 1.01 bCountryCode 0 Not supported bNumDescriptors 1 bDescriptorType 34 Report wDescriptorLength 63 Report Descriptors: ** UNAVAILABLE ** Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x81 EP 1 IN bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0008 1x 8 bytes bInterval 4 Endpoint Descriptor: bLength 7 bDescriptorType 5 bEndpointAddress 0x01 EP 1 OUT bmAttributes 3 Transfer Type Interrupt Synch Type None Usage Type Data wMaxPacketSize 0x0008 1x 8 bytes bInterval 4 上面的“bInterfaceClass 3 Human Interface Device”表明这是一个HID设备 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1988 浏览 1 评论
synopsys 的design ware:DW_fpv_div,浮点数除法器,默认32位下,想提升覆盖率(TMAX),如果用功能case去提升覆盖率呢?
2490 浏览 1 评论
RK3588 GStreamer调试四路鱼眼摄像头四宫格显示报错
5272 浏览 1 评论
【飞凌嵌入式OK3576-C开发板体验】RKNN神经网络-YOLO图像识别
254 浏览 0 评论
【飞凌嵌入式OK3576-C开发板体验】SSH远程登录网络配置及CAN通讯
1336 浏览 0 评论
浏览过的版块 |
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 08:12 , Processed in 0.746154 second(s), Total 73, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号