linux驱动编写(触摸屏驱动)

【 声明:版权所有,欢迎转载,请勿用于商业用途。 联系信箱:feixiaoxing @163.com


    早在诺基亚手机还比较流行的时候,那时候触摸屏用的还不多。但是随着触摸屏手机、即智能手机的流行,触摸屏基本成了手机的标配。所以,今天可以看看触摸屏驱动在linux上是如何进行的。


1、驱动目录

drivers/input


2、看看这个目录的Makefile如何设计

obj-$(CONFIG_INPUT)		+= input-core.o
input-core-y := input.o input-compat.o input-mt.o ff-core.o

obj-$(CONFIG_INPUT_TOUCHSCREEN)	+= touchscreen/


3、除了input-core.o这个文件外,只需要看touchscreen目录就可以了

config TOUCHSCREEN_S3C2410
	tristate "Samsung S3C2410/generic touchscreen input driver"
	depends on ARCH_S3C24XX || SAMSUNG_DEV_TS
	depends on S3C_ADC
	help
	  Say Y here if you have the s3c2410 touchscreen.

	  If unsure, say N.

	  To compile this driver as a module, choose M here: the
	  module will be called s3c2410_ts.


4、看懂了Kconfig之后,再阅读Makefile,注意S3C_ADC宏可以参考arch/arm/plat-samsung/adc.c

obj-$(CONFIG_TOUCHSCREEN_S3C2410)	+= s3c2410_ts.o

5、继续阅读s3c2410_ts.c文件

static const struct platform_device_id s3cts_driver_ids[] = {
	{ "s3c2410-ts", 0 },
	{ "s3c2440-ts", 0 },
	{ "s3c64xx-ts", FEAT_PEN_IRQ },
	{ }
};
MODULE_DEVICE_TABLE(platform, s3cts_driver_ids);

static struct platform_driver s3c_ts_driver = {
	.driver         = {
		.name   = "samsung-ts",
#ifdef CONFIG_PM
		.pm	= &s3c_ts_pmops,
#endif
	},
	.id_table	= s3cts_driver_ids,
	.probe		= s3c2410ts_probe,
	.remove		= s3c2410ts_remove,
};
module_platform_driver(s3c_ts_driver);


6、根据probe函数,看看有什么需要注意的内容

	ts.client = s3c_adc_register(pdev, s3c24xx_ts_select,
				     s3c24xx_ts_conversion, 1);
	if (IS_ERR(ts.client)) {
		dev_err(dev, "failed to register adc client\n");
		ret = PTR_ERR(ts.client);
		goto err_iomap;
	}


7、接着,查看是否有中断函数被注册

	ret = request_irq(ts.irq_tc, stylus_irq, 0,
			  "s3c2410_ts_pen", ts.input);

8、最后

    很明显,触摸屏驱动本质上还是由TOUCHSCREEN_S3C2410和S3C_ADC两个macro一起完成的。


猜你喜欢

转载自blog.csdn.net/feixiaoxing/article/details/79885954