linux 输入子系统(3)----事件处理(input_handler层)
输入子系统主要设计input_dev、input_handler、input_handle。如下:

【1】每个struct input_dev代表一个输入设备
struct input_dev {
const char *name;//设备名
const char *phys;
const char *uniq;
struct input_id id;//用于匹配事件处理层handler
unsigned long evbit[BITS_TO_LONGS(EV_CNT)];//用于记录支持的事件类型的位图
unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];//记录支持的按键值的位图
unsigned long relbit[BITS_TO_LONGS(REL_CNT)];//记录支持的相对坐标的位图
unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];//记录支持的绝对坐标的位图
unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];//led
unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];//beep
unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
unsigned int keycodemax;//支持的按键值的个数
unsigned int keycodesize;//每个键值的字节数
void *keycode;//存储按键值的数组首地址
int (*setkeycode)(struct input_dev *dev,
unsigned int scancode, unsigned int keycode);//修改键值的函数,可选
int (*getkeycode)(struct input_dev *dev,
unsigned int scancode, unsigned int *keycode);//获取扫描码的键值,可选
struct ff_device *ff;
unsigned int repeat_key;//最近一次按键值,用于连击
struct timer_list timer;//自动连击计时器
int sync;//最后一次同步后没有新的事件置1
int abs[ABS_CNT];//当前各个坐标的值
int rep[REP_MAX + ];//自动连击的参数
unsigned long key[BITS_TO_LONGS(KEY_CNT)];//反映当前按键状态的位图
unsigned long led[BITS_TO_LONGS(LED_CNT)];//反映当前led状态的位图
unsigned long snd[BITS_TO_LONGS(SND_CNT)];//反映当前beep状态的位图
unsigned long sw[BITS_TO_LONGS(SW_CNT)];
/*tp驱动代码里一般使用input_set_abs_params函数设置
函数参数从右往左依次代表输入设备指针、坐标轴、最小值、最大值、分辨率、基准值。
最后两个参数也可以填为0,代表设备非常精确并且总能精确的回到中心位置。*/
int absmax[ABS_CNT];//记录各个坐标的最大值
int absmin[ABS_CNT];//记录各个坐标的最小值
int absfuzz[ABS_CNT];//记录各个坐标的分辨率
int absflat[ABS_CNT];//记录各个坐标的基准值
int absres[ABS_CNT];
int (*open)(struct input_dev *dev);//打开函数
void (*close)(struct input_dev *dev);//关闭函数
int (*flush)(struct input_dev *dev, struct file *file);//断开连接时冲洗数据
int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);//回调函数,可选
struct input_handle *grab;
spinlock_t event_lock;
struct mutex mutex;
unsigned int users;
bool going_away;
struct device dev;
struct list_head h_list;//handle链表
struct list_head node;//input_dev链表
};
struct input_event是事件传送的载体,输入子系统的事件都是包装成struct input_event传给用户空间。各个成员如下所示:
/* include/linux/input.h */
struct input_event {
struct timeval time;//时间戳
__u16 type;//事件类型
__u16 code;//事件代码
__s32 value;//事件值,如坐标的偏移值
};
struct input_dev注册的时候需要跟匹配的hanlder建立连接,匹配的依据就是struct input_dev所包含的struct input_id。
/* include/linux/input.h */
struct input_id {
__u16 bustype;//总线类型
__u16 vendor;//生产商编号
__u16 product;//产品编号
__u16 version;//版本号
};
【2】input_handler这个结构体是事件驱动的主体,每一种处理方式对应一个handler结构体。注册input_handler,其实就是将input_hangler加入到input_handler_list当中。使用input_register_handler注册。
/* include/linux/input.h */
struct input_handler {
//私有数据指针
void *private;
//事件处理函数指针。设备驱动报告的事件最终由这个函数来处理
void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
bool (*match)(struct input_handler *handler, struct input_dev *dev);
//连接handler和input_dev的函数指针
int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
//断开连接函数指针
void (*disconnect)(struct input_handle *handle);
//为给定的handle启动handler函数指针
void (*start)(struct input_handle *handle); //文件操作结构体
const struct file_operations *fops;
//这个handler可以使用的32个次设备号的最小值
int minor;
//此handler的名字
const char *name; //可以处理的input_device_ids列表
const struct input_device_id *id_table;
//需要被忽略的input_device_ids列表
const struct input_device_id *blacklist; //用来连接handle的链表链表节点。每个与此handler相关的handle都放入此链表
struct list_head h_list;
//用来放入全局handler链表的节点
struct list_head node;
};
【3】input_handle这个结构体用来连接input_dev和input_handler。用input_register_handle()注册。
/* include/linux/input.h */
struct input_handle { void *private;//私有数据指针 int open;//记录本设备被打开的次数
const char *name;//创建此handle的handler所赋予的名字 struct input_dev *dev;//指向附着的input_dev
struct input_handler *handler;//指向创建此handle的handler struct list_head d_node;//链表节点,用来加入附着的input_dev
struct list_head h_node;//链表节点,用来加入附着的input_handler
};
input_dev、input_handler、input_handle之间的关系
其中 input_dev_list 为全局输入设备链表、input_handler_list为全局handler处理器链表。

event执行过程:
input_report_key() ------> input_event() -----> input_handle_event() -----> input_pass_event() ====>> handle->handler->event();
如下图:

linux 输入子系统(3)----事件处理(input_handler层)的更多相关文章
- linux输入子系统(input subsystem)之evdev.c事件处理过程
1.代码 input_subsys.drv.c 在linux输入子系统(input subsystem)之按键输入和LED控制的基础上有小改动,input_subsys_test.c不变. input ...
- Linux 输入子系统
Technorati 标签: Kernel 输入子系统 Input 在Linux中,输入设备(如按键.键盘.触摸屏.鼠标等)是典型的字符设备,其一般的工作机理,是底层在按键.触摸时,触发一个 ...
- Linux输入子系统详解
input输入子系统框架 linux输入子系统(linux input subsystem)从上到下由三层实现,分别为:输入子系统事件处理层(EventHandler).输入子系统核心层(Input ...
- linux输入子系统
linux输入子系统(linux input subsystem)从上到下由三层实现,分别为:输入子系统事件处理层(EventHandler).输入子系统核心层(InputCore)和输入子系统设备驱 ...
- linux输入子系统概念介绍
在此文章之前,我们讲解的都是简单的字符驱动,涉及的内容有字符驱动的框架.自动创建设备节点.linux中断.poll机制.异步通知.同步互斥.非阻塞.定时器去抖动. 上一节文章链接:http://blo ...
- 7.Linux 输入子系统分析
为什么要引入输入子系统? 在前面我们写了一些简单的字符设备的驱动程序,我们是怎么样打开一个设备并操作的呢? 一般都是在执行应用程序时,open一个特定的设备文件,如:/dev/buttons .... ...
- Linux输入子系统(转)
Linux输入子系统(Input Subsystem) 1.1.input子系统概述 输入设备(如按键,键盘,触摸屏,鼠标等)是典型的字符设备,其一般的工作机制是低层在按键,触摸等动作发生时产生一个中 ...
- Linux输入子系统框架分析(1)
在Linux下的输入设备键盘.触摸屏.鼠标等都能够用输入子系统来实现驱动.输入子系统分为三层,核心层和设备驱动层.事件层.核心层和事件层由Linux输入子系统本身实现,设备驱动层由我们实现.我们在设备 ...
- linux输入子系统简述【转】
本文转载自:http://blog.csdn.net/xubin341719/article/details/7678035 1,linux输入子系统简述 其实驱动这部分大多还是转载别人的,linux ...
- linux输入子系统(6)-input子系统介绍及结构图
注:本系列转自: http://www.ourunix.org/post/290.html input子系统介绍 输入设备(如按键,键盘,触摸屏,鼠标,蜂鸣器等)是典型的字符设备,其一 ...
随机推荐
- 小白日记29:kali渗透测试之Web渗透-扫描工具-Vega
WEB扫描工具-Vega 纯图形化界面,Java编写的开源web扫描器.两种工作模式:扫描模式和代理模式[主流扫描功能].用于爬站.处理表单,注入测试等.支持SSL:http://vega/ca.cr ...
- 使用在storyBoard之外的xib创建对象
1.在storyBoard之外的xib 要注意的是:TableView的代理一定要设置为FilesOwner 使用: 方式一: 直接创建对象如下,(如果要使用xib里的控件,那么就要将xib里的控件作 ...
- java+mysql实现保存图片到数据库,以及读取数据库存储的图片
一:建表 二:获取数据库连接 1:导入mysql的驱动jar包,mysql-connector-java-5.1.8-bin.jar 2:写代码连接数据库,如下: /** * */ package c ...
- 24小时学通Linux内核--内核探索工具类
寒假闲下来了,可以尽情的做自己喜欢的事情,专心待在实验室里燥起来了,因为大二的时候接触过Linux,只是关于内核方面确实是不好懂,所以十天的时间里还是希望能够补充一下Linux内核相关知识,接下来继续 ...
- hdu 2844 多重背包+单调队列优化
思路:把价值看做体积,而价值的大小还是其本身,那么只需判断1-m中的每个状态最大是否为自己,是就+1: #include<iostream> #include<algorithm&g ...
- CSS3秘笈第三版涵盖HTML5学习笔记9~12章
第9章,装饰网站导航 限制访问,处于隐私方面考虑,浏览器已经开始限制可以对伪类:visited应用哪些CSS属性了.其中包括对已访问过的链接定义color.background-color.borde ...
- Windows下TEX排版论文攻略—CTeX、JabRef使用心得
笔者刚刚接触到TEX排版,相关知识完全空白,用了两天时间学习并完成了一篇论文的完整排版. 期间遇到不少小问题,着实辛苦,分享至上,现将其解决办法总结归纳,共同学习. 一.工具介绍 TeX是一个 ...
- Jquery 模糊匹配ID
[属性名称] 匹配包含给定属性的元素[att=value] 匹配包含给定属性的元素 (大小写区分)[att*=value] 模糊匹配[att!=value] 不能是这个值[att$=value] 结尾 ...
- 设置In_Memery
alter system set inmemory_size=4G scope=spfile; alter table table_name inmemory; alter table table_n ...
- [Bootstrap]全局样式(四)
按钮 1.基本类.btn {display/padding/margin-bottom/font-size/border-radius/border} 作用于< a:role:button &g ...