usb 接口触摸屏驱动

本文记录了作者在开发USB接口触摸屏驱动时的学习历程,主要涉及USB协议中的HID(Human Interface Device)部分。通过阅读,读者可以了解到如何进行简单的USB驱动编写,特别是针对HID设备的驱动实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

以前写的 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)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值