input子系统 KeyPad-Touch上报数据格式与机制
-----------------------------------------------------------------------
本文系本站原创,欢迎转载!
转载请注明出处:http://blog.csdn.net/android_huber
交流邮箱:dp.shao@gmail.com
-----------------------------------------------------------------------
linux drive中input子系统上报信息,调用函数
void input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value),
input子系统最终调用copy_to_user(buffer, event, sizeof(struct input_event))将信息上报给上层,event为struct input_event类型结构体, 中间会有一些处理将 type,code,value值打包成input_event类型的数据。底层上报该结构体给上层。
struct input_event {
struct timeval time;
__u16 type;
__u16 code;
__s32 value;
};
struct timeval {
__kernel_time_t tv_sec; /* seconds */
__kernel_suseconds_t tv_usec; /* microseconds */
};
typedef long __kernel_time_t;
typedef int __kernel_suseconds_t;
对于按键
type为事件类型,按键为EV_KEY,在include/linux/input.h中,
#define EV_KEY 0x01
code为按键的值,value用于标记按键是按下还是弹起,1是按下,0是弹起。
按下和弹起事件只需上报一次。
对于touch
static inline void input_report_abs(struct input_dev *dev, unsigned int code, int value) 为input_event的封装,函数如下
input_event(dev, EV_ABS, code, value);
type为EV_ABS, #define EV_ABS 0X03,
code的值,根据上报属性的不同,分别如下:
(多点触摸)
#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */
#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */
#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
ABS_MT_TOUCH_MAJOR和ABS_MT_PRESSURE实现一个应该就可以了。
(单点触摸)input.h中列举了很多属性,但只需实现以下几种即可。
#define ABS_X 0x00
#define ABS_Y 0x01
#define ABS_Z 0x02 (一般不必实现)
#define ABS_PRESSURE 0x18
下面一个BTN_TOUCH为点击事件,单点触摸中需要上报点击事件
#define BTN_TOUCH 0x14a
touch点上报机制
多点触摸
value为对应属性的值,如code为ABS_MT_POSITION_X,则value的值为就为x轴坐标。
当把一个点的信息发送完毕以后,还需加上input_mt_sync(注意:即使只有一个点也需要加上),这个函数转换成input_event事件为
input_event(dev, EV_SYN, SYN_MT_REPORT, 0);
其中#define EV_SYN 0x00, #define SYN_MT_REPORT 2,
则type为0x00,code为2,value为0。
接着再上报第二个点,第二个点上报结束,依旧要上报input_mt_sync,直至最后一次报点结束,加上input_sync,转换成input_event事件为
input_event(dev, EV_SYN, SYN_REPORT, 0);
其中#define EV_SYN 0x00,#define SYN_REPORT 0,
则type为0x00,code为0,value为0。至此报点结束。
点需要一直上报。
Linux 驱动中的例子
input_report_abs(ssd2531_data.input, ABS_MT_TRACKING_ID, 1);
input_report_abs(ssd2531_data.input, ABS_MT_TOUCH_MAJOR, PRESS_STATUS);
input_report_abs(ssd2531_data.input, ABS_MT_POSITION_X, X_COOR);
input_report_abs(ssd2531_data.input, ABS_MT_POSITION_Y, Y_COOR);
input_mt_sync(ssd2531_data.input);
单点触摸
单点上报同多点上报差不多,只是不需要input_mt_sync了,上报过程中需要
input_event(dev, EV_KEY, BTN_TOUCH, 0/1 ); value为1,代表按下,value为0代表抬起。code值为BTN_TOUCH, #define BTN_TOUCH 0x14a;
同样最后结束需要input_sync。
linux驱动的例子‘
input_report_abs(ts.input, ABS_X, ts.xp);
input_report_abs(ts.input, ABS_Y, ts.yp);
input_report_key(ts.input, BTN_TOUCH, 1);
input_sync(ts.input);
input_event结构体中,有一个成员为struct timeval time;用来记录此刻的墙上时间。
input子系统 KeyPad-Touch上报数据格式与机制的更多相关文章
- input子系统 KeyPad-Touch上报数据格式与机制【转】
转自:https://www.cnblogs.com/0822vaj/p/4185634.html -------------------------------------------------- ...
- Input子系统与多点触摸技术-3【转】
转自:https://blog.csdn.net/u012839187/article/details/77335941 版权声明:本文为博主原创文章,欢迎转载,转载请注明转载地址 https://b ...
- 基于input子系统的sensor驱动调试(一)
要想弄明白世界的本质,就要追根溯源:代码也是一样的道理: 最近调试几个sensor驱动,alps sensor驱动.compass sensor驱动.G-sensor驱动都是一样的架构: 一.基于in ...
- Linux Input子系统浅析(二)-- 模拟tp上报键值【转】
转自:https://blog.csdn.net/xiaopangzi313/article/details/52383226 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...
- Linux--内核Uevent事件机制 与 Input子系统【转】
转自:http://blog.csdn.net/lxl584685501/article/details/46379453 [-] 一Uevent机制 Uevent在kernel中的位置 Uevent ...
- Android驱动之 Linux Input子系统之TP——A/B(Slot)协议
将A/B协议这部分单独拿出来说一方面是因为这部分内容是比较容易忽视的,周围大多数用到input子系统的开发人员也不甚理解:另一方面是由于这部分知识一旦扩展到TP(触摸屏Touch Panel)的多点触 ...
- input子系统事件处理层(evdev)的环形缓冲区【转】
在事件处理层(evdev.c)中结构体evdev_client定义了一个环形缓冲区(circular buffer),其原理是用数组的方式实现了一个先进先出的循环队列(circular queue), ...
- 【驱动】input子系统全面分析
初识linux输入子系统 linux输入子系统(linux input subsystem)从上到下由三层实现,分别为:输入子系统事件处理层(EventHandler).输入子系统核心层(InputC ...
- linux input输入子系统分析《四》:input子系统整体流程全面分析
1 input输入子系统整体流程 本节分析input子系统在内核中的实现,包括输入子系统(Input Core),事件处理层(Event Handler)和设备驱动层.由于上节代码讲解了设备 ...
随机推荐
- mysql 获取季度的第一天 本月的第一天,本周的第一天sql语句(转)
感谢:http://www.111cn.net/database/110/d45124323da8d2d87b80f78319987eda.htm 查看同主题的另一篇博客:http://blog.cs ...
- 你不需要jQuery
http://www.webhek.com/you-do-not-need-jquery
- 【贪心】bzoj 3709:[PA2014]Bohater
3709: [PA2014]Bohater Time Limit: 5 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 653 Solved: ...
- bzoj 2744: [HEOI2012]朋友圈 二分图匹配
2744: [HEOI2012]朋友圈 Time Limit: 30 Sec Memory Limit: 128 MBSubmit: 612 Solved: 174[Submit][Status] ...
- PAT-乙级-1003. 我要通过!(20)
1003. 我要通过!(20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue “答案正确”是自动判题系统给出的最 ...
- uva 437 hdu 1069
dp 将石块按三个面存入队列 按底面积排序 dp就最大高度 按嵌套矩形最长路做做法 #include <iostream> #include <cstdio> #inc ...
- Hadoop将过时了?
http://www.kuqin.com/database/20120715/322528.html Hadoop这个单词如今铺天盖地,几乎成了大数据的代名词.仅仅数年时间,Hadoop从边缘技术迅速 ...
- (转)eclipse快捷键
Eclipse常用快捷键 Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能,能够大大提高开发效率.Eclipse中有如下一些和编辑相关的快捷键. 1. [ALT+/] 此快捷键为用户编 ...
- Servlet课程0424(二) 通过继承GenericServlet来开发Servlet
//这是第二种开发servlet的方法(继承GernericServlet) package com.tsinghua; import javax.servlet.GenericServlet; im ...
- SRM588
250: 有n首歌每首歌有duration和tone,连续唱m首歌会消耗每首歌的duration以及相邻两首歌的tone的差的绝对值的和,给个T,问说在T时间内最对能唱多少歌. 将歌按tone排序后发 ...