一 、 总体架构 图

  

上层是图形界面和应用程序,通过监听设备节点,获取用户相应的输入事件,根据输入事件来做出相应的反应;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子系统学习总结(一)---- 三个重要的结构体的更多相关文章

  1. Linux input子系统学习总结(三)----Input设备驱动

    Input 设备驱动 ---操作硬件获取硬件寄存器中设备输入的数据,并把数据交给核心层: 一 .设备驱动的注册步骤: 1.分配一个struct  input_dev :          struct ...

  2. Linux input子系统学习总结(二)----Input事件驱动

    Input 事件驱动:  (主要文件 :drivers/input/evdev.c  .  drivers/input/input.h)基于kernel 4.0  一. 关键函数调用顺序: 1.inp ...

  3. Linux input子系统分析

    输入输出是用户和产品交互的手段,因此输入驱动开发在Linux驱动开发中很常见.同时,input子系统的分层架构思想在Linux驱动设计中极具代表性和先进性,因此对Linux input子系统进行深入分 ...

  4. Linux防火墙iptables学习笔记(三)iptables命令详解和举例[转载]

     Linux防火墙iptables学习笔记(三)iptables命令详解和举例 2008-10-16 23:45:46 转载 网上看到这个配置讲解得还比较易懂,就转过来了,大家一起看下,希望对您工作能 ...

  5. Linux input子系统 io控制字段【转】

    转自:http://www.cnblogs.com/leaven/archive/2011/02/12/1952793.html http://blog.csdn.net/guoshaobei/arc ...

  6. input子系统学习笔记六 按键驱动实例分析下【转】

    转自:http://blog.chinaunix.net/uid-20776117-id-3212095.html 本文接着input子系统学习笔记五 按键驱动实例分析上接续分析这个按键驱动实例! i ...

  7. Linux Input子系统浅析(二)-- 模拟tp上报键值【转】

    转自:https://blog.csdn.net/xiaopangzi313/article/details/52383226 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...

  8. Linux Input子系统

    先贴代码: //input.c int input_register_handler(struct input_handler *handler) { //此处省略很多代码 list_for_each ...

  9. Linux input子系统简介

    1.前言 本文主要对Linux下的input子系统进行介绍 2. 软件架构 图 input子系统结构图 input子系统主要包括三个部分:设备驱动层.核心层和事件层.我们可以分别理解为:具体的输入设备 ...

随机推荐

  1. 【2018CCPC秦皇岛】

    递推式的线段树可以用矩阵维护.

  2. Luogu 3385 负环 | 我有特别的SPFA技巧

    这样似乎跑得快: 初始化所有的dis是0,然后枚举每个点作为起点,用DFS更新所有点的dis: 如果更新到一个栈中节点,那么有负环. #include <cstdio> #include ...

  3. 【bzoj1095】 ZJOI2007—捉迷藏

    http://www.lydsy.com/JudgeOnline/problem.php?id=1095 (题目链接) 题意 一棵树,求最远的两黑点之间的距离,每次可以将黑点染白或者将白点染黑. So ...

  4. 【bzoj3527】 Zjoi2014—力

    http://www.lydsy.com/JudgeOnline/problem.php?id=3527 (题目链接) 题意 $${F_i=\sum_{j<i} {\frac{q_iq_j}{( ...

  5. Xpack集成LDAP

    支持两种配置方式: The ldap realm supports two modes of operation, a user search mode and a mode with specifi ...

  6. android studio gradle dependencies 包存放在哪儿?

    在AndroidStudio中的"External Libraries"下有引用的library的列表, 选择某个library右键->"Library Prope ...

  7. Gym 101933

    Gym 101933 B. Baby Bites水题直接模拟即可 #include <cstdio> #include <cstring> #include <queue ...

  8. Nginx Configuration 免费HTTPS加密证书

    Linux就该这么学 2018-05-11 实验环境:CentOS Linux release 7.3.1611 (Core) 内核版本:Linux version 3.10.0-514.el7.x8 ...

  9. tp5.1 入口文件即报错

    ---------------------------------------------------------------[ 2018-10-10T10:51:49+08:00 ] 218.93. ...

  10. ubuntu内核及系统升级

    升级之前,需要先确认ubuntu当前系统版本,使用操作: root@Dy-JXQ-ubuntu-101:~# lsb_release -a No LSB modules are available. ...