
本文共 3169 字,大约阅读时间需要 10 分钟。
hexdump: 查看文件的内容,比如二进制文件中包含的某些字符串,通常用来调试驱动用
描述:
我们以event1为例,当我们insmod挂载了键盘驱动后,出现一个event1设备,
此时没有按键按下,所以event1里面的数据是没有的,那么数据又是从来哪里来?
通过键盘驱动的read函数,若有按键按下,就会上传按键数据给用户层hexdump
因为键盘驱动的input_handler 是:evdev_handler
所以键盘驱动的read函数是: evdev_handler->evdev_fops->evdev_read
进入evdev_read()函数,如下图所示:
evdev_event_to_user()这个函数从字面上来看,显然就是用来上传给用户层的函数,其中buffer是函数参数,指向用户层,
所以数据就是event.
我们来看看event的结构体:input_event
struct input_event {struct timeval time; //事件发生的时间__u16 type; // 哪类事件, 比如键盘事件__u16 code; // 对应的事件里支持的哪个变量,比如按键K__s32 value; // 对应的变量里的数值, 比如松开按键则是1,反之为0};
把 time里的成员展开如下:
struct input_event {long tv_sec; /* seconds */ //秒long tv_usec; /* microseconds */ //微妙__u16 type; // 哪类事件, 比如键盘事件__u16 code; // 对应的事件里支持的哪个变量,比如按键K__s32 value; // 对应的变量里的数值, 比如松开按键则是1,反之为0};
所以我们hexdump调试任何输入子系统event XX驱动时,有信息就会打印上面数据
1.调试键盘驱动
(键盘驱动代码:)
以按开发板的按键 KEY_L,为例(因为数据是从低到高打印的,所以数据是反的):
# hexdump /dev/event1 //按键键盘驱动/*按下时:*///hexdump序列号 秒 微妙 键盘事件 code=KEY_L value=1(按下) 0000000 07c6 0000 faa2 000b 0001 0026 0001 0000//hexdump序列号 秒 微妙 同步事件 code value=0 0000010 07c6 0000 faac 000b 0000 0000 0000 0000/*松开时:*///hexdump序列号 秒 微妙 键盘事件 code=0x26 value=0(松开) 0000020 07c6 0000 cf67 000d 0001 0026 0000 0000//hexdump序列号 秒 微妙 同步事件 code value=0 0000030 07c6 0000 cf70 000d 0000 0000 0000 0000
2.调试触摸屏驱动
(触摸屏驱动代码: )
/dev/event0 //触摸屏驱动# hexdump /dev/event0 //hexdump序列号 秒 微妙 绝对坐标事件 code=ABS_X X坐标值 0000000 0412 0000 6ef0 000c 0003 0000 0239 0000//hexdump序列号 秒 微妙 绝对坐标事件 code=ABS_Y Y坐标值0000010 0412 0000 6f08 000c 0003 0001 01ae 0000//hexdump序列号 秒 微妙 绝对坐标事件 code=压力 压力值0000020 0412 0000 6f0c 000c 0003 0018 0001 0000//hexdump序列号 秒 微妙 键盘事件 code=触摸按键 value=1(按下)0000030 0412 0000 6f10 000c 0001 014a 0001 0000//hexdump序列号 秒 微妙 同步事件 0000040 0412 0000 6f13 000c 0000 0000 0000 0000//hexdump序列号 秒 微妙 绝对坐标事件 code=压力 压力值00000b0 023b 0000 872d 000c 0003 0018 0000 0000//hexdump序列号 秒 微妙 键盘事件 code=触摸按键 value=0(松开)00000b0 0412 0000 1f5b 000d 0001 014a 0000 0000//hexdump序列号 秒 微妙 同步事件 00000c0 0412 0000 1f70 000d 0000 0000 0000 0000
也可以使用getevent 命令,用于获取 input 输入事件,比如获取按键上报信息、获取触摸屏上报信息等。
示例:
格式输出为event type、event code、event value
比如 EV_KEY 330 0 表示: 按键事件的BTN_TOUCH触摸按键(ox14a) 松开了(0)
EV_ABS 1 72 表示: 绝对坐标事件的ABS_Y(1)坐标位于72
这些定义都在input.h里,比如EV_ABS的code有:
发表评论
最新留言
关于作者
