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子系统介绍 输入设备(如按键,键盘,触摸屏,鼠标,蜂鸣器等)是典型的字符设备,其一 ...
随机推荐
- Spring3之Security
1.spring security介绍 Spring Security原来叫做Acegi Security,可用于加强任何Java应用的安全,但是最常用于基于Web的应用.下面首先理解几个安全术语: ...
- .NET自动识别HttpWebResponse的编码及是否压缩
请求和响应头 POST的数据 最近项目使用HttpWebRequest请求网页,处理HttpWebResponse返回消息体,发现网页可能是有GZIP压缩等,所得数据乱码,所以相处了解决方案,大家共同 ...
- 【安卓面试题】在一个Activity启动另一个Activity和在Service中启动一个Activity有什么区别
在Activity中可以直接使用Intent启动另一个Activity 显式Intent intent = new Intent(context, activity.class) 隐式 Intent ...
- php核心知识要点
Php:脚本语言,网站建设,服务器端运行 PHP定义:一种服务器端的 HTML 脚本/编程语言,是一种简单的.面向对象的.解释型的.健壮的.安全的.性能非常之高的.独立于架构的.可移植的.动态的脚本语 ...
- [需再总结]SSH整合代码生成器
package cn.itcast.invoice.util.generator; import java.io.BufferedWriter; import java.io.File; import ...
- 1、关于Boolean(2015年05月30日)
背景:刚在看Effective Java,看到一段关于Boolean提供一个返回实例的静态方法的例子,便去看了下Boolean的源码,发现有些内容是之前没注意到的,于是便有了下面这些. 1. Bool ...
- Commons Math - Primes
org.apache.commons.math3.primes.Primes 是关于质数操作的工具类. 1. public static boolean isPrime(int n) 判断 n 是否为 ...
- django 学习-4 模板标签
1.第一个标签是 if 标签 vim learn/home.html <!DOCTYPE html><html><head> <title&g ...
- React-Native错误笔记-EPERM
运行react-native run-android时出现错误 EPERM:operation not permitted,lstat .............. 解决办法:用Android Stu ...
- sqlserver 测试sql语句执行时间
查看sql语句执行时间/测试sql语句性能 写程序的人,往往需要分析所写的SQL语句是否已经优化过了,服务器的响应时间有多快,这个时候就需要用到SQL的STATISTICS状态值来查看了. 通过设置S ...