一 、 总体架构 图

  

上层是图形界面和应用程序,通过监听设备节点,获取用户相应的输入事件,根据输入事件来做出相应的反应;eventX (X从0开始)表示 按键事件,mice 表示鼠标事件

Input core --- input 核心

Input event drivers --- input事件驱动(mousedev 、 evdev、keyboard)

Input device drivers --- input设备驱动(触摸屏、键盘、鼠标)

三个重要的结构体:

代码路径:include\linux\input.h (基于kernel4.0)

 1 struct input_dev {  ///代表 input 设备 
2 const char *name; /// 设备名称
3 const char *phys; ////设备在系统结构中的物理路径
4 const char *uniq; ///设备的唯一标识符
5 struct input_id id; ///描述硬件设备属性的 ID
6
7 unsigned long propbit[BITS_TO_LONGS(INPUT_PROP_CNT)];/// INPUT_PROP_CNT--0x20 ,一个long包含32bit,所以 propbit[1]
8
9 unsigned long evbit[BITS_TO_LONGS(EV_CNT)]; ///设备支持的事件类型
10 unsigned long keybit[BITS_TO_LONGS(KEY_CNT)];
11 unsigned long relbit[BITS_TO_LONGS(REL_CNT)];
12 unsigned long absbit[BITS_TO_LONGS(ABS_CNT)];
13 unsigned long mscbit[BITS_TO_LONGS(MSC_CNT)];
14 unsigned long ledbit[BITS_TO_LONGS(LED_CNT)];
15 unsigned long sndbit[BITS_TO_LONGS(SND_CNT)];
16 unsigned long ffbit[BITS_TO_LONGS(FF_CNT)];
17 unsigned long swbit[BITS_TO_LONGS(SW_CNT)];
18
19 unsigned int hint_events_per_packet;
20
21 unsigned int keycodemax;
22 unsigned int keycodesize;
23 void *keycode;
24
25 int (*setkeycode)(struct input_dev *dev,
26 const struct input_keymap_entry *ke,
27 unsigned int *old_keycode);
28 int (*getkeycode)(struct input_dev *dev,
29 struct input_keymap_entry *ke);
30
31 struct ff_device *ff;
32
33 unsigned int repeat_key;
34 struct timer_list timer;
35
36 int rep[REP_CNT];
37
38 struct input_mt *mt;
39
40 struct input_absinfo *absinfo;
41
42 unsigned long key[BITS_TO_LONGS(KEY_CNT)];
43 unsigned long led[BITS_TO_LONGS(LED_CNT)];
44 unsigned long snd[BITS_TO_LONGS(SND_CNT)];
45 unsigned long sw[BITS_TO_LONGS(SW_CNT)];
46
47 int (*open)(struct input_dev *dev);///打开设备
48 void (*close)(struct input_dev *dev);
49 int (*flush)(struct input_dev *dev, struct file *file);
50 int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value);
51
52 struct input_handle __rcu *grab;
53
54 spinlock_t event_lock;
55 struct mutex mutex;
56
57 unsigned int users;
58 bool going_away;
59
60 struct device dev;///每个设备的基类
61
62 struct list_head h_list;
63 struct list_head node;
64
65 unsigned int num_vals;
66 unsigned int max_vals;
67 struct input_value *vals;
68
69 bool devres_managed;
70 };

 1 struct input_handler {///代表输入设备的处理方法
2
3 void *private;
4
5 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
6 void (*events)(struct input_handle *handle,
7 const struct input_value *vals, unsigned int count);
8 bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);///
9 bool (*match)(struct input_handler *handler, struct input_dev *dev);
10 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
11 void (*disconnect)(struct input_handle *handle);
12 void (*start)(struct input_handle *handle);
13
14 bool legacy_minors; ///是否遗留次设备号
15 int minor;///次设备号
16 const char *name;///名称
17
18 const struct input_device_id *id_table;/// input_device 和 input_handle 通过id_table 进行匹配
19
20 struct list_head h_list;
21 struct list_head node;
22 };

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

 1 struct input_handle { //// 用来关联input_dev 和 input_handler (links input device with an input handler)
2
3 void *private;///私有成员变量
4
5 int open;
6 const char *name;
7
8 struct input_dev *dev;
9 struct input_handler *handler;
10
11 struct list_head d_node;
12 struct list_head h_node;
13 };

如图,横轴表示一系列的input 设备,纵轴表示事件驱动event,中间的紫色圆点代表input_handle,通过input_handle来关联设备驱动和事件驱动

    

(注:以上图片均来自麦子学院 金鑫老师的课程,在此对其辛勤付出和无私分享表示真挚的感谢!)

更多相关文章

  1. 对linux字符设备的理解(整体架构)
  2. 【原】第一个Linux设备驱动程序hello world!
  3. linux查看硬件信息及驱动设备相关整理
  4. [Linux C]重启设备(系统)
  5. Android usb client mass-storage 多存储设备挂载问题解决
  6. Linux之I2C设备总结
  7. Linux2.6内核下键盘输入设备驱动的实现
  8. Inotify: 高效、实时的Linux文件系统事件监控框架
  9. Linux PCI/PCI-E设备配置空间读取与修改

随机推荐

  1. 对于Fragment的总结
  2. Android之通过shape.xml制作渐变背景色
  3. [Android Samples视频系列之ApiDemos] Ap
  4. Android(安卓)Studio 中文乱码问题
  5. android视图切换动画:ViewAnimator类及其
  6. 创建SqliteDatabase
  7. 【Android Training - Performance】 -
  8. Android如何保存和读取设置
  9. Android中有用笔记
  10. 在Ubuntu上下载编译安装Android最新内核