Chinaunix首页 | 论坛 | 博客
  • 博客访问: 708589
  • 博文数量: 118
  • 博客积分: 1437
  • 博客等级: 上尉
  • 技术积分: 1155
  • 用 户 组: 普通用户
  • 注册时间: 2009-02-22 20:23
文章分类

全部博文(118)

文章存档

2022年(32)

2017年(3)

2014年(4)

2013年(1)

2011年(2)

2010年(16)

2009年(60)

我的朋友

分类: LINUX

2009-04-08 10:33:00

用了将近半个月的时间粗略明白了,s3c2410触摸屏响应的流程,以及数据在驱动中的流动。
觉得有用的几个网页,和大家分享。
http://blog.chinaunix.net/u2/66024/showart_674037.html理解输入子系统的工作原理
http://www.cublog.cn/u1/51562/showart_1090628.html
粗略的理解:
键盘,鼠标,触摸屏在内核有统一的接口,他们都可以产生事件(按键,相对坐标,绝对坐标等)汇报给内核的输入子系统,输入子系统统一处理这些事件,并进行相应的处理,将数据送往用户空间。
简单的数据流向:
触摸屏有按下,中断响应产生数据data0,data1;数据传递给ts.xp,ts.yp;然后向输入子系统汇报产生的事件input_report_abs();ts_event()根据事件的类型,进行处理;然后copy_to_user()将数据传递给用户空间,供应用程序使用。
重要的文件:
1.添加drivers/input/touchscreen/s3c2410ts.c
这个文件网上一般都有代码,可以直接复制。
这个文件是驱动的框架,主要完成硬件的设置,实现中断处理函数和注销。
2.在arch/arm/mach-s3c2410/mach-smdk2410.c文件,包括了触摸屏需要设置的参数。
3.最重要的文件drivers/input/tsdev.c,里面实现了触摸屏设备的操作函数(open,read等)。可以在tsdev_read()中用几个printk看看设备驱动向用户空间返回的数据。
4.两个头文件include/linux/platform_device.h和include/linux/input.h包含了一些重要的数据结构。
重要的结构体:
1.struct ts_event {
    short pressure;
    short x;
    short y;
    short millisecs;
};触摸事件的数据结构,从内核空间向数据空间就是传递的这个数据结构。
2.struct platform_driver {
    int (*probe)(struct platform_device *);
    int (*remove)(struct platform_device *);
    void (*shutdown)(struct platform_device *);
    int (*suspend)(struct platform_device *, pm_message_t state);
    int (*suspend_late)(struct platform_device *, pm_message_t state);
    int (*resume_early)(struct platform_device *);
    int (*resume)(struct platform_device *);
    struct device_driver driver;
};在s3c2410ts.c中的数据机构,主要是有.probe函数。
3.struct s3c2410ts {
    struct input_dev *dev;
    long xp;
    long yp;
    int count;
    int shift;
};输入设备在s3c2410ts.c文件中,又包含重要结构体input_dev
4.
struct ts_calibration {
    int xscale;
    int xtrans;
    int yscale;
    int ytrans;
    int xyswap;
};

struct tsdev {
    int exist;
    int open;
    int minor;
    char name[8];
    wait_queue_head_t wait;
    struct list_head client_list;
    struct input_handle handle;
    int x, y, pressure;
    struct ts_calibration cal;
};

struct tsdev_client {
    struct fasync_struct *fasync;
    struct list_head node;
    struct tsdev *tsdev;
    int head, tail;
    struct ts_event event[TSDEV_BUFFER_SIZE];
    int raw;
};输入子系统里和handle相关的几个函数,没看太懂,不过也很重要。
重要的函数
input_report_key(ts.dev, BTN_TOUCH, 0);向输入子系统报告按键事件
input_report_abs(ts.dev, ABS_PRESSURE, 0);向输入子系统报告压力状态
input_report_abs(ts.dev, ABS_X, ts.xp);向输入子系统报告x绝对坐标
input_report_abs(ts.dev, ABS_Y, ts.yp)向输入子系统报告y绝对坐标
input_register_device(ts.dev);向输入子系统注册设备
tsdev_event(struct input_handle *handle, unsigned int type,
            unsigned int code, int value)输入系统中用来处理各个事件的函数
tsdev_read()在用户程序read()设备文件时调用的函数
copy_to_user (buffer + retval, client->event + client->tail,
                  sizeof (struct ts_event)
将内核空间的ts_event数据传递到用户空间
重要的文件
crw-rw-rw-    1 0        0         13, 128 Jan  1  1970 ts0   
一定要在/dev/input下有这个文件ts0,否则出错。

阅读(819) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~