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子系统介绍 输入设备(如按键,键盘,触摸屏,鼠标,蜂鸣器等)是典型的字符设备,其一 ...
随机推荐
- JavaScript之对数组中元素进行增删改
JavaScript中数据类型无非是:简单类型+复杂类型,什么是简单什么又是复杂.从电脑物理存储上讲,简单就是所见即所得,你看见什么,电脑里面存的就只是什么,并不会因为一些关系(比如引用)而多出一部分 ...
- Linux kill -9 和 kill -15 的区别
“我的天呀!”,网页编辑没有自动保存草稿的功能.害的我昨天写的东西都没有了.算了,不计较这些了.反正也没写多少. 嘻嘻. 大家对kill -9 肯定非常熟悉,在工作中也经常用到.特别是你去重启tomc ...
- centos6.4搭建lnmp服务(转载)
1.配置防火墙,开启80端口.3306端口vi /etc/sysconfig/iptables-A INPUT -m state --state NEW -m tcp -p tcp --dport 8 ...
- RestEasy传值方式
一.@pathparam @PathParam 是一个参数注解,可以将一个 URL 上的参数映射到方法的参数上,它可以映射到方法参数的类型有基本类型.字符串.或者任何有一个字符串作为构造方法参数 ...
- 浅谈 Data URI 与 BASE 64 编码
前言(废话):鼓捣 Stylish 的时候发现了这么个奇怪的代码行: Data:image/gif;BASE64,R0lGODlhEAAQAKEAAEKF9NPi/AAAAAAAACH5BAEAAAI ...
- 【转】android 安卓APP获取手机设备信息和手机号码的代码示例
http://blog.csdn.net/changemyself/article/details/7421476 下面我从安卓开发的角度,简单写一下如何获取手机设备信息和手机号码 准备条件:一部安卓 ...
- Redis - HyperLogLogs
A HyperLogLog is a probabilistic data structure used in order to count unique things (technically th ...
- IIS服务器应用程序不可用的解决办法
转载:http://www.cnblogs.com/caicainiao/archive/2010/11/29/1891085.html 这个问题见了好几次,在.net下 Microsoft visu ...
- 使用iTextSharp来填充PDF模板文件
需求简介: 遇到了这样一个需求:某公司需要为所有用户的培训生成一个培训记录,过程如下: (1)用户在培训完之后会进入到一个填写信息的界面. (2)用户填写信息. (3) ...
- SQL按照日、周、月、年统计数据
写sql语句分别按日,星期,月,季度,年统计销售额 --按日 select sum(consume),day([date]) from consume_record where year([date] ...