以前写的 USB 接口的触摸屏驱动,那段时间简单的看了下 USB 协议的一些东西,主要是 HID 相关的,代码记录:
/*
Created by_fire 2012.2.13
*/
#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>
#include <linux/input.h>
#include <linux/usb/input.h>
#define DEBUG 0
#if DEBUG
#define usb_ts_dbg(fmt, arg...) printk(fmt, ##arg)
#else
#define usb_ts_dbg(arg...)
#endif
/* Define these values to match your devices */
#define USB_SKEL_VENDOR_ID 0x0eef
#define USB_SKEL_PRODUCT_ID 0x0001
/* table of devices that work with this driver */
static const struct usb_device_id usb_ts_table[] = {
{ USB_DEVICE(USB_SKEL_VENDOR_ID, USB_SKEL_PRODUCT_ID) },
{ } /* Terminating entry */
};
MODULE_DEVICE_TABLE(usb, usb_ts_table);
static int swap_xy;
module_param(swap_xy, bool, 0644);
MODULE_PARM_DESC(swap_xy, "If set X and Y axes are swapped.");
struct usb_ts;
struct usb_ts_device_info {
int min_xc, max_xc;
int min_yc, max_yc;
int min_press, max_press;
int rept_size;
/*
* Always service the USB devices irq not just when the input device is
* open. This is useful when devices have a watchdog which prevents us
* from periodically polling the device. Leave this unset unless your
* touchscreen device requires it, as it does consume more of the USB
* bandwidth.
*/
bool irq_always;
void (*process_pkt) (struct usb_ts *usbtouch, unsigned char *pkt, int len);
/*
* used to get the packet len. possible return values:
* > 0: packet len
* = 0: skip one byte
* < 0: -return value more bytes needed
*/
int (*get_pkt_len) (unsigned char *pkt, int len);
int (*read_data) (struct usb_ts *usbtouch, unsigned char *pkt);
int (*init) (struct usb_ts *usbtouch);
void (*exit) (struct usb_ts *usbtouch);
};
/* a usbtouch device */
struct usb_ts {
unsigned char *data;
dma_addr_t data_dma;
unsigned char *buffer;
int buf_len;
struct urb *int_urb;
struct usb_interface *interface;
struct input_dev *input;
struct usb_ts_device_info *dev_info;
char name[128];
char phys[64];
void *priv;
int x, y;
int touch, press;
};
static int usb_ts_read_data(struct usb_ts *dev, unsigned char *pkt)