Linux Gadget的一點研究之HID裝置__Linux

來源:互聯網
上載者:User

接上文,配置編譯gadget HID模組


make modules後在driver/usb/gadget目錄下產生g_hid.ko

執行載入命令:

root@XXX:/mnt# insmod g_hid.ko insmod: can't insert 'g_hid.ko': No such device
提示錯誤。

在TI 技術論壇上看到相關技術回複:

The error message you had before 'error inserting 'g_hid.ko': -1 No such device.' is due to incomplete hid gadget driver. You can followDocumentation/usb/gadget_hid.txt to add your own platform device portion.

For your reference, the following patch is what I tried and it works with the 3.3 kernel from the link I provided above with SD card boot. 下載提及的補丁

From 6363b29be2c2b477a723b74e52025511be280979 Mon Sep 17 00:00:00 2001From: Bin Liu <b-liu@ti.com>Date: Fri, 18 Jan 2013 10:27:57 -0600Subject: [PATCH] patched hid gadget--- drivers/usb/gadget/hid.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 61 insertions(+), 0 deletions(-)diff --git a/drivers/usb/gadget/hid.c b/drivers/usb/gadget/hid.cindex f888c3e..c037039 100644--- a/drivers/usb/gadget/hid.c+++ b/drivers/usb/gadget/hid.c@@ -16,6 +16,8 @@ #include <linux/platform_device.h> #include <linux/list.h> +#include <linux/usb/g_hid.h>+ #define DRIVER_DESC"HID Gadget" #define DRIVER_VERSION"2010/03/16" @@ -49,6 +51,57 @@ struct hidg_func_node {  static LIST_HEAD(hidg_func_list); ++/* hid descriptor for a keyboard */+static struct hidg_func_descriptor my_hid_data = {+.subclass= 0, /* No subclass */+.protocol= 1, /* Keyboard */+.report_length= 8,+.report_desc_length= 63,+.report_desc= {+0x05, 0x01,/* USAGE_PAGE (Generic Desktop)          */+0x09, 0x06,/* USAGE (Keyboard)                       */+0xa1, 0x01,/* COLLECTION (Application)               */+0x05, 0x07,/*   USAGE_PAGE (Keyboard)                */+0x19, 0xe0,/*   USAGE_MINIMUM (Keyboard LeftControl) */+0x29, 0xe7,/*   USAGE_MAXIMUM (Keyboard Right GUI)   */+0x15, 0x00,/*   LOGICAL_MINIMUM (0)                  */+0x25, 0x01,/*   LOGICAL_MAXIMUM (1)                  */+0x75, 0x01,/*   REPORT_SIZE (1)                      */+0x95, 0x08,/*   REPORT_COUNT (8)                     */+0x81, 0x02,/*   INPUT (Data,Var,Abs)                 */+0x95, 0x01,/*   REPORT_COUNT (1)                     */+0x75, 0x08,/*   REPORT_SIZE (8)                      */+0x81, 0x03,/*   INPUT (Cnst,Var,Abs)                 */+0x95, 0x05,/*   REPORT_COUNT (5)                     */+0x75, 0x01,/*   REPORT_SIZE (1)                      */+0x05, 0x08,/*   USAGE_PAGE (LEDs)                    */+0x19, 0x01,/*   USAGE_MINIMUM (Num Lock)             */+0x29, 0x05,/*   USAGE_MAXIMUM (Kana)                 */+0x91, 0x02,/*   OUTPUT (Data,Var,Abs)                */+0x95, 0x01,/*   REPORT_COUNT (1)                     */+0x75, 0x03,/*   REPORT_SIZE (3)                      */+0x91, 0x03,/*   OUTPUT (Cnst,Var,Abs)                */+0x95, 0x06,/*   REPORT_COUNT (6)                     */+0x75, 0x08,/*   REPORT_SIZE (8)                      */+0x15, 0x00,/*   LOGICAL_MINIMUM (0)                  */+0x25, 0x65,/*   LOGICAL_MAXIMUM (101)                */+0x05, 0x07,/*   USAGE_PAGE (Keyboard)                */+0x19, 0x00,/*   USAGE_MINIMUM (Reserved)             */+0x29, 0x65,/*   USAGE_MAXIMUM (Keyboard Application) */+0x81, 0x00,/*   INPUT (Data,Ary,Abs)                 */+0xc0/* END_COLLECTION                         */+}+};++static struct platform_device my_hid = {+.name= "hidg",+.id= 0,+.num_resources= 0,+.resource= 0,+.dev.platform_data= &my_hid_data,+};+ /*-------------------------------------------------------------------------*/  static struct usb_device_descriptor device_desc = {@@ -267,6 +320,13 @@ static int __init hidg_init(void) { int status; +status = platform_device_register(&my_hid);+if (status < 0) {+printk("____ reg failed\n");+platform_device_unregister(&my_hid);+return status;+}+ status = platform_driver_probe(&hidg_plat_driver, hidg_plat_driver_probe); if (status < 0)@@ -283,6 +343,7 @@ module_init(hidg_init); static void __exit hidg_cleanup(void) { platform_driver_unregister(&hidg_plat_driver);+platform_device_unregister(&my_hid); usb_composite_unregister(&hidg_driver); } module_exit(hidg_cleanup);-- 1.7.0.4


繼續嘗試。。。




聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.