这个驱动参考usb-skeleton.c写的,直接以原始USB设备形式挂载,不向input或者HID注册。以下是驱动代码: #include <linux/kernel.h> #include <linux/errno.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/kref.h> #include <linux/uaccess.h> #include <linux/usb.h> #include <linux/mutex.h> // Define these values to match your devices //joystick: VENDOR_ID 0x0E8F, PRODUCT_ID 0X0002 //icbc: VENDOR_ID 0x096E, PRODUCT_ID 0X0010 #define USB_JOYSTICK_VENDOR_ID 0x0E8F #define USB_JOYSTICK_PRODUCT_ID 0x0003 /* table of devices that work with this driver */ static struct usb_device_id joystick_table[] = { { USB_DEVICE(USB_JOYSTICK_VENDOR_ID, USB_JOYSTICK_PRODUCT_ID) }, { } /* Terminating entry */ }; MODULE_DEVICE_TABLE(usb, joystick_table); //masks for each key, see file KEY_MASK for more details #define KEYMASK_UP 0x00 #define KEYMASK_DOWN 0xFF #define KEYMASK_LEFT 0x00 #define KEYMASK_RIGHT 0xFF #define KEYMASK_L1 0x01 #define KEYMASK_L2 0x04 #define KEYMASK_R1 0x02 #define KEYMASK_R2 0x08 #define KEYMASK_Y 0x1F #define KEYMASK_A 0x4F #define KEYMASK_X 0x8F #define KEYMASK_B 0x2F #define KEYMASK_SELECT 0x10 #define KEYMASK_START 0x20 #define INTERV_MILLI(ms) (ms*HZ/1000) static struct fasync_struct *fasync_queue; static char *gb_data; // Get a minor range for your devices from the usb maintainer #define USB_JOYSTICK_MINOR_BASE 192 // Structure to hold all of our device specific stuff struct usb_joystick { struct usb_device *udev; /* the usb device for this device */ struct usb_interface *interface; /* the interface for this device */ struct semaphore limit_sem; /* limiting the number of writes in progress */ struct urb *in_urb; /* the urb to read data with */ unsigned char *in_buffer; /* the buffer to receive data */ size_t in_buffer_size; /* the size of the receive buffer */ char *data; dma_addr_t data_dma; __u8 in_endpointAddr; /* the address of the bulk in endpoint */ __u8 out_endpointAddr; /* the address of the bulk out endpoint */ struct kref kref; }; static int joystick_fasync(int fd, struct file *file, int on); static int joystick_open(struct inode *inode, struct file *file) { printk("joystick open./n"); return 0; } static int joystick_release(struct inode *inode, struct file *file) { printk("joystick release./n"); joystick_fasync(-1, file, 0); return 0; } static ssize_t joystick_read(struct file *file, char *buf, size_t count, loff_t *ppos) { //printk("joystick read./n"); copy_to_user(buf, gb_data, 8); return 0; } static ssize_t joystick_write(struct file *file, const char *buf, size_t count, loff_t *ppos) { printk("joystick write./n"); return 0; } static int joystick_fasync(int fd, struct file *file, int on) { int retval; printk("joystick fasynchroni