没有合适的资源?快使用搜索试试~ 我知道了~
按键拦截
资源详情
资源评论
资源推荐
1. Linux Input子系统
内核中的输入子系统自底向上分为设备驱动层,输入核心层,事件处理层。由于每种输入的设备上报的事件都各有不同,
所以为了应用层能够很好识别上报的事件,内核中也为应用层封装了标准的接口来描述一个事件。
· 设备驱动层是具体硬件相关的实现,也是驱动开发中主要完成的部分,
· 输入核心层主要提供一些API供设备驱动层调用,通过这些API设备驱动层上报的数据就可以传递到事件处理层,
· 事件处理层负责创建设备文件以及将上报的事件传递到用户空间
· 设备驱动层和事务处理层在注册时,会将相对应的设备驱动层与事件处理层建立连接。设备驱动层当有事件发生,就会由
与之对应的事件处理层处理上报到用户空间。
1.1 Input Core初始化
Kernel启动时执行subsys_initcall(input_init);
class_register:注册class类,在/sys/class 里创建一个 input类
input_proc_init:在/proc创建 bus/input/devices 及handlers
|
proc_mkdir:创建proc/bus/input目录
proc_create:创建的proc/bus/input/devices(/handlers)目录及相应的操作
register_chrdev:创建"input"设备
/linux/linux-4.14/drivers/input/ input.c
/* 在kernel启动时候加载,进入input_init函数*/
1 subsys_initcall(input_init);
2
3 static int __init input_init(void)
4 {
5 int err;
6
7 err = class_register(&input_class); /*注册class类*/
8 if (err) {
9 pr_err("unable to register input_dev class\n");
10 return err;
11 }
12 err = class_create_file(&input_class, &class_attr_input_event_type_filter);
13 if(err) {
14 pr_err("unable to create class file\n");
15 goto fail0;
16 }
17
18 err = input_proc_init();/* 在/proc创建 bus/input/devices handlers */
19 if (err)
20 goto fail1;
21
22 err = register_chrdev_region(MKDEV(INPUT_MAJOR, 0), /* 注册input字符设备 */
23 INPUT_MAX_CHAR_DEVICES, "input");
24 if (err) {
25 pr_err("unable to register char major %d", INPUT_MAJOR);
26 goto fail2;
27 }
28
29 err = class_create_file(&input_class, &class_attr_input_intercept_add_event);
30 if(err) {
31 pr_err("unable to create class file for intercept function\n");
32 goto fail3;
33 }
34
35 err = class_create_file(&input_class, &class_attr_input_intercept_remove_event);
36 if(err) {
37 pr_err("unable to create class file for intercept function\n");
38 goto fail4;
39 }
40
41 err = class_create_file(&input_class, &class_attr_input_event_gen);
42 if(err) {
43 pr_err("unable to create class file for intercept function\n");
44 goto fail5;
45 }
46
47 err = class_create_file(&input_class, &class_attr_input_event_fuction_enable);
48 if(err) {
49 pr_err("unable to create class file for intercept function\n");
50 goto fail6;
51 }
52
53 input_init_intercept_event_list(&g_intercept_event_list);
54 return 0;
55 ……
56 }
1 static int __init input_proc_init(void)
2 {
3 struct proc_dir_entry *entry;
4
5 proc_bus_input_dir = proc_mkdir("bus/input", NULL); /*proc_bus_input_dir pro
6 if (!proc_bus_input_dir)
7 return -ENOMEM;
8
9 entry = proc_create("devices", 0, proc_bus_input_dir, /*entry 和上面proc_bus_
10 &input_devices_fileops); /*input_devices_fi
11 if (!entry)
12 goto fail1;
13
/* 查看创建的input设备*/
BeyondTV:/sys/class # ls -l
total 0
……
drwxr-xr-x 2 root root 0 2019-08-13 12:05 i2c-dev
drwxr-xr-x 2 root root 0 2019-08-13 12:05 ieee80211
drwxr-xr-x 2 root root 0 2019-08-12 18:07 input
drwxr-xr-x 2 root root 0 2019-08-13 12:05 irrp
drwxr-xr-x 2 root root 0 2019-08-13 12:05 mdio_bus
14 entry = proc_create("handlers", 0, proc_bus_input_dir, /*entry 和上面proc_bus_
15 &input_handlers_fileops);
16 if (!entry)
17 goto fail2;
18
19 return 0;
20
21 fail2: remove_proc_entry("devices", proc_bus_input_dir);
22 fail1: remove_proc_entry("bus/input", NULL);
23 return -ENOMEM;
24 }
25
26 static const struct file_operations input_devices_fileops = {
27 .owner = THIS_MODULE,
28 .open = input_proc_devices_open,
29 .poll = input_proc_devices_poll,
30 .read = seq_read,
31 .llseek = seq_lseek,
32 .release = seq_release,
33 };
34
35 static const struct file_operations input_handlers_fileops = {
36 .owner = THIS_MODULE,
37 .open = input_proc_handlers_open,
38 .read = seq_read,
39 .llseek = seq_lseek,
40 .release = seq_release,
41 };
……
/* 查看linux系统已经注册的input设备信息*/
BeyondTV:/ # cat /proc/bus/input/devices
I: Bus=0000 Vendor=0000 Product=0000 Version=0000
N: Name="mtkinp"
P: Phys=venus/input0
S: Sysfs=/devices/virtual/input/input0
U: Uniq=
H: Handlers=event0
B: PROP=0
B: EV=2000017
B: KEY=7ff00000 0 0 b0 f1000800 7fff40f c60aa82e 0 20 840180 3ff80c 128fcb12 821460c0 0
0 70c00 ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe
B: REL=103
B: MSC=10
I: Bus=0006 Vendor=0000 Product=0001 Version=0001
N: Name="rtk_keypad"
P: Phys=rtkTV/input1
S: Sysfs=/devices/virtual/input/input1
U: Uniq=
H: Handlers=event1
B: PROP=0
B: EV=3
B: KEY=70000 0 c0000 0 0 100000 0 0 0
I: Bus=0000 Vendor=0019 Product=0001 Version=0000
N: Name="sim-kb"
P: Phys=
S: Sysfs=/devices/virtual/input/input3
U: Uniq=
H: Handlers=event2
B: PROP=0
B: EV=3
B: KEY=3 3f c00fffff 0 20 8001ff ffffffff ffffffff ffffffff fffffbff ffffffff ffffffff ffffffff ffffffff ffffffff
ffffffff ffffffff ffffffff ffffffff fffffffe
剩余61页未读,继续阅读
但汉俣
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0