Linux input子系统学习总结(一)---- 三个重要的结构体
一 、 总体架构 图

上层是图形界面和应用程序,通过监听设备节点,获取用户相应的输入事件,根据输入事件来做出相应的反应;eventX (X从0开始)表示 按键事件,mice 表示鼠标事件
Input core --- input 核心
Input event drivers --- input事件驱动(mousedev 、 evdev、keyboard)
Input device drivers --- input设备驱动(触摸屏、键盘、鼠标)

三个重要的结构体:
代码路径: include\linux\input.h (基于kernel4.0)
struct input_dev { ///代表 input 设备
const char *name; /// 设备名称
const char *phys; ////设备在系统结构中的物理路径
const char *uniq; ///设备的唯一标识符
struct input_id id; ///描述硬件设备属性的 ID
unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];/// INPUT_PROP_CNT--0x20 ,一个long包含32bit,所以 propbit[1]
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)];
unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
unsigned int hint_events_per_packet;
unsigned int keycodemax;
unsigned int keycodesize;
void *keycode;
int (*setkeycode)(struct input_dev *dev,
const struct input_keymap_entry *ke,
unsigned int *old_keycode);
int (*getkeycode)(struct input_dev *dev,
struct input_keymap_entry *ke);
struct ff_device *ff;
unsigned int repeat_key;
struct timer_list timer;
int rep[REP_CNT];
struct input_mt *mt;
struct input_absinfo *absinfo;
unsigned long key[BITS_TO_LONGS(KEY_CNT)];
unsigned long led[BITS_TO_LONGS(LED_CNT)];
unsigned long snd[BITS_TO_LONGS(SND_CNT)];
unsigned long sw[BITS_TO_LONGS(SW_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 __rcu *grab;
spinlock_t event_lock;
struct mutex mutex;
unsigned int users;
bool going_away;
struct device dev;///每个设备的基类
struct list_head h_list;
struct list_head node;
unsigned int num_vals;
unsigned int max_vals;
struct input_value *vals;
bool devres_managed;
};
struct input_handler {///代表输入设备的处理方法
void *private;
void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
void (*events)(struct input_handle *handle,
const struct input_value *vals, unsigned int count);
bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);///
bool (*match)(struct input_handler *handler, struct input_dev *dev);
int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
void (*disconnect)(struct input_handle *handle);
void (*start)(struct input_handle *handle);
bool legacy_minors; ///是否遗留次设备号
int minor;///次设备号
const char *name;///名称
const struct input_device_id *id_table;/// input_device 和 input_handle 通过id_table 进行匹配
struct list_head h_list;
struct list_head node;
};
Match :在设备id 和handler 的id_table 匹配成功的时候调用; (called after comparing device's id with handler's id_table to perform fine-grained matching between device and handler)
Connect : 当一个handle 匹配到一个device 的时候执行(called when attaching a handler to an input device)
Start :当input 核心执行完 connect 以后调用(called by input core right after connect() method)
struct input_handle { //// 用来关联input_dev 和 input_handler (links input device with an input handler)
void *private;///私有成员变量
int open;
const char *name;
struct input_dev *dev;
struct input_handler *handler;
struct list_head d_node;
struct list_head h_node;
};
如图,横轴表示一系列的input 设备,纵轴表示事件驱动event,中间的紫色圆点代表input_handle,通过input_handle来关联设备驱动和事件驱动

(注:以上图片均来自麦子学院 金鑫老师的课程,在此对其辛勤付出和无私分享表示真挚的感谢!)
Linux input子系统学习总结(一)---- 三个重要的结构体的更多相关文章
- Linux input子系统学习总结(三)----Input设备驱动
Input 设备驱动 ---操作硬件获取硬件寄存器中设备输入的数据,并把数据交给核心层: 一 .设备驱动的注册步骤: 1.分配一个struct input_dev : struct ...
- Linux input子系统学习总结(二)----Input事件驱动
Input 事件驱动: (主要文件 :drivers/input/evdev.c . drivers/input/input.h)基于kernel 4.0 一. 关键函数调用顺序: 1.inp ...
- Linux input子系统分析
输入输出是用户和产品交互的手段,因此输入驱动开发在Linux驱动开发中很常见.同时,input子系统的分层架构思想在Linux驱动设计中极具代表性和先进性,因此对Linux input子系统进行深入分 ...
- Linux防火墙iptables学习笔记(三)iptables命令详解和举例[转载]
Linux防火墙iptables学习笔记(三)iptables命令详解和举例 2008-10-16 23:45:46 转载 网上看到这个配置讲解得还比较易懂,就转过来了,大家一起看下,希望对您工作能 ...
- Linux input子系统 io控制字段【转】
转自:http://www.cnblogs.com/leaven/archive/2011/02/12/1952793.html http://blog.csdn.net/guoshaobei/arc ...
- input子系统学习笔记六 按键驱动实例分析下【转】
转自:http://blog.chinaunix.net/uid-20776117-id-3212095.html 本文接着input子系统学习笔记五 按键驱动实例分析上接续分析这个按键驱动实例! i ...
- Linux Input子系统浅析(二)-- 模拟tp上报键值【转】
转自:https://blog.csdn.net/xiaopangzi313/article/details/52383226 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...
- Linux Input子系统
先贴代码: //input.c int input_register_handler(struct input_handler *handler) { //此处省略很多代码 list_for_each ...
- Linux input子系统简介
1.前言 本文主要对Linux下的input子系统进行介绍 2. 软件架构 图 input子系统结构图 input子系统主要包括三个部分:设备驱动层.核心层和事件层.我们可以分别理解为:具体的输入设备 ...
随机推荐
- 只会java,参加acm如何?
作者:董适链接:https://www.zhihu.com/question/31213070/answer/51054677来源:知乎著作权归作者所有,转载请联系作者获得授权. 当然合适,有什么不合 ...
- Chapter 5(串)
1.kmp #include <stdio.h> #include <stdlib.h> #include <stdbool.h> #include <str ...
- Redis3未授权访问漏洞导致服务器被入侵
今天在腾讯云上搭的开发环境里的一台机器cpu load飚升老高,然后还能登陆上去,top后发现两个可疑进程./root/目录下有修改过的文件./opt目录被干掉了, 后经分析,这台机器上有redis外 ...
- 关于.Net开源并跨平台的思考
开源的意义: 关于开源,我个人觉得有两个提高(勿喷). 一方面开源提高了生产力,另一方面开源也是信任的一种体现.为什么这么说呢,在当下的互联网时代,开源是一种核心价值观.人与人沟通交流合作之下,降低成 ...
- Kubernetes--kubectl
一.Kubectl命令行说明 类型 命令 描述 基础命令 create 通过文件名或标准输入创建资源 expose 将一个资源公开为一个新的kubernetes服务 run 创建并运行一个特定的镜 ...
- Zabbix应用一:Zabbix安装
1.准备zabbix依赖环境:LNMP 依赖包安装参考http://www.osyunwei.com/archives/10057.html. cmake安装mysql: cmake . -DCMAK ...
- Casting a Classifier into a Fully Convolutional Network将带全连接的网络做成全卷积网络
详见:http://nbviewer.jupyter.org/github/BVLC/caffe/blob/master/examples/net_surgery.ipynb 假设使用标准的caffe ...
- bzoj千题计划121:bzoj1033: [ZJOI2008]杀蚂蚁antbuster
http://www.lydsy.com/JudgeOnline/problem.php?id=1033 经半个下午+一个晚上+半个晚上 的 昏天黑地调代码 最终成果: codevs.洛谷.tyvj上 ...
- CS20 D LCA
给出一棵树,许多询问,每次询问A,B,C三点,求一点使到三点距离最小,输出该点和最小值. 很明显就是求LCA,三种组合都求一次LCA,然后在里面选个距离和最小的就行了. 官方题解里面的代码求LCA是在 ...
- php设计模式之工厂设计模式
概念: 工厂设计模式提供获取某个对象的新实例的一个接口,同时使调用代码避免确定实际实例化基类步骤. 很多高级模式都是依赖于工厂模式. 好处: PHP中能够创建基于变量内容 ...