usb触摸屏驱动

源码在/drivers/input/touchscreen/usbtouchscreen.c中static int __init usbtouch_init(void) //入口函数{ return usb_register(&usbtouch_driver); //注册usb触摸屏驱动}module_init(usbtouch_init);看usbtouch_driver的定义s
摘要由CSDN通过智能技术生成
源码在/drivers/input/touchscreen/usbtouchscreen.c中
static int __init usbtouch_init(void)	//入口函数
{
	return usb_register(&usbtouch_driver);	//注册usb触摸屏驱动
}
module_init(usbtouch_init);

看usbtouch_driver的定义

static struct usb_driver usbtouch_driver = {
	.name		= "usbtouchscreen",
	.probe		= usbtouch_probe,	//usb触摸屏探测到
	.disconnect	= usbtouch_disconnect,
	.suspend	= usbtouch_suspend,
	.resume		= usbtouch_resume,
	.reset_resume	= usbtouch_reset_resume,
	.id_table	= usbtouch_devices,
	.supports_autosuspend = 1,
};

当有设备匹配的时候会调用probe方法,也就是usbtouch_probe

在static const struct usb_device_id usbtouch_devices[]中定义了的usb设备插入就会匹配并触发probe

可以用宏USB_DEVICE简化设置usb设备id信息,如下:

{USB_DEVICE(0x3823, 0x0001), .driver_info = DEVTYPE_EGALAX},

driver_info是驱动类型,有一下选择

enum {
	DEVTYPE_IGNORE = -1,
	DEVTYPE_EGALAX,
	DEVTYPE_PANJIT,
	DEVTYPE_3M,
	DEVTYPE_ITM,
	DEVTYPE_ETURBO,
	DEVTYPE_GUNZE,
	DEVTYPE_DMC_TSC10,
	DEVTYPE_IRTOUCH,
	DEVTYPE_IDEALTEK,
	DEVTYPE_GENERAL_TOUCH,
	DEVTYPE_GOTOP,
	DEVTYPE_JASTEC,
	DEVTYPE_E2I,
	DEVTYPE_ZYTRONIC,
	DEVTYPE_TC45USB,
	DEVTYPE_NEXIO,
};

没有选择也可以自己添加一个在枚举体后面
(0x3823,0x0001)这两个分别是usb设备的厂商id和产品id
下面代码是我插拔usb触摸屏的打印信息

usb 1-1.1: new full speed USB device using musb-hdrc and address 9
usb 1-1.1: New USB device found, idVendor=0408, idProduct=3001
usb 1-1.1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1.1: Product: HCTouch    
usb 1-1.1: Manufacturer: HC
input: HC HCTouch     as /devices/platform/omap/ti81xx-usbss/musb-hdrc.0/usb1/1-1/1-1.1/1-1.1:1.0/input/input6
input: HC HCTouch     as /devices/platform/omap/ti81xx-usbss/musb-hdrc.0/usb1/1-1/1-1.1/1-1.1:1.1/input/input7

作为我的设备,我就把idVendor=0408, idProduct=3001添加进USB_DEVICE宏就行

{USB_DEVICE(0x0408, 0x3001), .driver_info = DEVTYPE_HCTOUCH},

OK!插上设备就会匹配的

input: HC HCTouch     as /devices/platform/omap/ti81xx-usbss/musb-hdrc.0/usb1/1-1/1-1.1/1-1.1:1.0/input/input6
input: HC HCTouch     as /devices/platform/omap/ti81xx-usbss/musb-hdrc.0/usb1/1-1/1-1.1/1-1.1:1.1/input/input7

这个就是匹配后的打印信息

接着就是probe方法了

static int usbtouch_probe(struct usb_interface *intf,const struct usb_device_id *id)
{
	struct usbtouch_usb *usbtouch;
	struct input_dev *input_dev;
	struct usb_endpoint_descriptor *endpoint;
	struct usb_device *udev = interface_to_usbdev(intf);
	struct usbtouch_device_info *type;
	int err = -ENOMEM;

	/* some devices are ignored */
	if (id->driver_info == DEVTYPE_IGNORE)	//忽略的设备类型
		return -ENODEV;

	endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);	//获取端点描述符数组指针
	if (!endpoint)
		return -ENXIO;

	usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);	//分配usbtouch_usb结构体对象内存
	input_dev = input_allocate_device();	//分配输入设备对象内存
	if (!usbtouch || !input_dev)	//分配不成功退出
		goto out_free;

	type = &usbtouch_dev_info[id->driver_info];	//根据id的driver_info信息获取全局usbtouch_dev_info数组项
	usbtouch->type = type;	//指定usbtouch_dev_info
	if (!type->process_pkt)	//若usbtouch_dev_info不存在process_pkt方法
		type->process_pkt = usbtouch_process_pkt;	//则默认设置为usbtouch_process_pkt

	usbtouch->data = usb_alloc_coherent(udev, type->rept_size,GFP_KERNEL, &usbtouch->data_dma);	//分配缓冲区
	if (!usbtouch->data)
		goto out_free;

	if
  • 2
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
ilitek2510 是一款常见的 USB 触摸屏控制器芯片,Linux 平台下可以使用 HID 触摸屏驱动来支持 ilitek2510 触摸屏。 以下是步骤: 1. 确保系统已经加载了 hid-multitouch 驱动,可以使用以下命令来检查: ``` lsmod | grep hid_multitouch ``` 如果没有输出,则需要加载该驱动: ``` sudo modprobe hid-multitouch ``` 2. 连接 ilitek2510 触摸屏,并用以下命令来检测是否能够识别: ``` dmesg | grep input ``` 如果能够识别,则会输出如下信息: ``` input: ILITEK ILITEK-TP as /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/0003:22B8:2E82.0001/input/input3 hid-generic 0003:22B8:2E82.0001: input,hidraw0: USB HID v1.10 Pointer [ILITEK ILITEK-TP] on usb-0000:00:14.0-3/input0 ``` 其中,hidraw0 就是触摸屏的设备号。 3. 安装 xinput 工具,可以使用以下命令进行安装: ``` sudo apt-get install xinput ``` 4. 使用以下命令来调整触摸屏的参数: ``` xinput set-prop <device id> "Device Accel Velocity Scaling" <value> ``` 其中,device id 就是之前获取到的 hidraw 设备号,value 是一个浮点数,代表加速度的值。可以根据实际情况进行调整。 5. 如果需要在系统启动时自动加载 hid-multitouch 驱动和设置触摸屏参数,可以将以下脚本保存为 /etc/init.d/touchscreen,并授予可执行权限: ``` #!/bin/bash ### BEGIN INIT INFO # Provides: touchscreen # Required-Start: $local_fs $remote_fs $syslog # Required-Stop: $local_fs $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start touchscreen # Description: Enable support for ilitek2510 touchscreen on boot ### END INIT INFO case "$1" in start) modprobe hid-multitouch xinput set-prop <device id> "Device Accel Velocity Scaling" <value> ;; stop) ;; *) echo "Usage: $0 {start|stop}" exit 1 esac exit 0 ``` 然后使用以下命令将脚本添加到启动项中: ``` sudo update-rc.d touchscreen defaults ``` 以上就是在 Linux 平台下使用 ilitek2510 触摸屏驱动方法。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值