linux下i2c接口的电容触摸屏驱动开发

在创建和配置I2C 设备linux-2.6.32.2/arch/arm/mach-s3c2440/mach-mini2440.c中,应添加代码为:
#include <linux/i2c.h>

/*I2C touch screen devices*/
/*bus configuration*/
static struct s3c2410_platform_i2c i2c_ts_cfg __initdata = {
.flags   = 0,
.slave_addr = 0x02, // 7 bit address
.frequency = 100*1000, // 100 kHz
.sda_delay = 2,
};

/* I2C device name is "cypress_ts", 7 bits address is 0x02, interruput is eint20 */
static struct i2c_board_info i2c_ts_devices[] __initdata = {
// I2C_BOARD_INFO("cypress_ts", 0x02),
{
.type = "cypress_ts",
.addr = 0x02,
.irq = IRQ_EINT20, },
{ }

};

在如下初始化函数中初始化I2C设备,注册I2C触摸屏
static void __init mini2440_machine_init(void)
{
………………
/* i2c touch screen devices */
s3c_i2c0_set_platdata(&i2c_ts_cfg);
i2c_register_board_info(0, i2c_ts_devices, ARRAY_SIZE(i2c_ts_devices));
/****************************/
………………
}
c) Input子系统简单介绍如下:参见文章《linux内核input子系统解析》原文链接为:http://www.embedu.org/Column/Column289.htm 同时可以分析2.6.32系统内核源文件。上文只讲述了子系统的结构和工作原理,但是对于多点触摸input子系统没有过多解释,参考linux自带的document Multi-touch (MT) Protocol可知,本系统的多点触摸的上报机制应该如下所示:
1.      ABS_MT_TRACKING_ID
2.      ABS_MT_POSITION_X
3.      ABS_MT_POSITION_Y
4.      SYN_MT_REPORT
5.      ABS_MT_TRACKING_ID
6.      ABS_MT_POSITION_X
7.      ABS_MT_POSITION_Y
8.      SYN_MT_REPORT
9.      SYN_REPORT
参考文档《29内核输入子系统多点上报机制实现》
http://blog.csdn.net/tjd0227/archive/2010/06/13/5669620.aspx
d) 附录四会给出修改好的 cypress_ts.c 源文件,即为I2C触摸屏的设备驱动。除此之外,还需要修改Kconfig文件和Makefile文件以使得能够在menuconfig中选中我们的I2C触摸屏驱动并编译生成模块或者直接编译进内核。具体操作为:修改linux-2.6.32.2/drivers/input/touchscreen/Kconfig文件,添加如下代码:
   config TOUCHSCREEN_CYPRESS
     tristate "Cypress I2C touchscreen"
     depends on I2C
     help
       Say Y here to enable cypress i2c touchscreen support.
      If unsure, say N.
      To compile this driver as a module, choose M here: the
       module will be called cypress_ts.
修改linux-2.6.32.2/drivers/input/touchscreen/Makefile文件,添加如下代码:
   obj-$(CONFIG_TOUCHSCREEN_CYPRESS) += cypress_ts.o
e) 连接I2C触摸屏到mini2440上,利用GPIO口或者CAMERA接口(CON20)的 I2C信号线即可。在此利用CON20,连接SCL到I2CSCL,SDA到I2CSDA,VCC到VDD3.3V,GND到GND,连接INT到EINT20(利用20号中断,在i2c_ts_devices[] __initdata中定义了设备名,器件地址,中断号)
f) 重新编译内核,拷贝生成的模块文件 cypress_ts.ko 到开发板下执行,即可以在开发板上创建设备 /dev/input/event1 给I2C电容触摸屏。编写测试程序,读取触摸屏上报给event1的数据值。简单程序为:
static int fd_cypress_ts = -1;
static struct input_event ev_ts;
fd_cypress_ts = open(“/dev/input/event1”, O_RDONLY);
read(fd_cypress_ts, &ev_ts, sizeof(ev_ts));
while(1){
printf(“%d %d %d”, ev_ts.type, ev_ts.code, ev_ts.value);
}

 

posted @ 2012-11-22 12:54  莫回头  阅读(889)  评论(0编辑  收藏  举报