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)和设备驱动层.由于上节代码讲解了设备 ...
随机推荐
- 使用Redis构建简单的ORM
Reids相关的资料引用 http://www.tuicool.com/articles/bURJRj [Reids各种数据类型的应用场景] https://github.com/antirez/re ...
- asp 文件上传(无组件上传)
文件1.上传界面文件 upload.htm<html><head><meta http-equiv="Content-Language" conten ...
- spoj 394
每段可以连续的串的可能性是个Fibonacci数列 但是直接dp更好吧~~ #include <cstdio> #include <cstring> using names ...
- 重新学struct,边界对齐,声明……与Union的区别
在内存中,编译器按照成员列表顺序分别为每个结构体变量成员分配内存,当存储过程中需要满足边界对齐的要求时,编译器会在成员之间留下额外的内存空间. 如果想确认结构体占多少存储空间,则使用关键字sizeof ...
- 深入理解计算机各种类型大小(sizeof)
深入理解计算机各种类型大小(sizeof) // Example of the sizeof keyword size_t i = sizeof( int ); struct align_dep ...
- hdu 3400 Line belt 三分法
思路:要求最短时间从A到D,则走的路线一定是AB上的一段,CD上的一段,AB与CD之间的一段. 那么可以先三分得到AB上的一个点,在由这个点三分CD!! 代码如下: #include<iostr ...
- Eclipse不能自动编译 java文件的解决方案
前段时间出现了eclipse 不自动编译java文件的问题,在网上找了好长时间,总算把问题解决了,现在把这个问题的解决方法总结一下. 1,看看project -- Build Automaticall ...
- [模拟]ZOJ3480 Duck Typing
题意:给了一坨...按题目意思输出就好了... 给一组案例 begin class d class c:d class b:c class a:b def d.m def d.n call a.m e ...
- 李洪强iOS开发之XMPP
XMPP历史 这个xmpp框架在2008年开始,不过是一个简单地RFC实现.提供一个最小的代理去接受三种xmpp的基本类型presence.message.iq.因为framwork只提供了最小的 ...
- Mac OS X 启用 Web 服务器
转载: http://note.rpsh.net/posts/2013/11/26/osx-apache-server-php-mysql/