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)和设备驱动层.由于上节代码讲解了设备 ...
随机推荐
- Bypass Preventing CSRF
CSRF在过去的n年(n>2)一直都火,在bh/defcon/owasp等会议上多次探讨CSRF的攻防[具体你可以看看以往的那些pp].前 段时间PLAYHACK.net上发表了一个总结性的pp ...
- MyEclipse下查看Java API帮助文档
每次重装JDK或者升级JDK时,都会忘了如何使MyEclipse关联帮助文档.然后,再花十几分钟重新google搜索,麻烦! 首先下载Javadoc api帮助文档,google搜一下就行了. MyE ...
- SQLite入门与分析(三)---内核概述(2)
写在前面:本节是前一节内容的后续部分,这两节都是从全局的角度SQLite内核各个模块的设计和功能.只有从全局上把握SQLite,才会更容易的理解SQLite的实现.SQLite采用了层次化,模块化的设 ...
- WinAPI你知道多少?!(上千个,好多都没见过)
http://www.cnblogs.com/vanver/archive/2013/06/13/NO-2013_06_13pm.html 播客开篇,讲讲废话:本篇播客只是推荐给热与钻研的同学们... ...
- 组策略限制添加用户作为服务登录导致ITAtomcat服务无法启动(log on as a service)
[故障类型]:ITA tomcat服务器无法启动. [关 键 词]:Logon as a service 作为服务登录 tomcat loggeter [适用版本]:FusionCloud So ...
- 221. Maximal Square
题目: Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ...
- foreman1.3安装
一.环境: centos 6.3 64bit 二.安装yum源: rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release ...
- Oracle DBA常用SQL
监控SQL 1.监控事例的等待: select event,sum(decode(wait_time,0,0,1)) prev, sum(decode(wait_time,0,1,0)) curr,c ...
- Java实现文件复制
import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; /** * & ...
- 推荐:ThoughtWorks(中国)程序员读书雷达
部分转自张逸的博客:http://agiledon.github.io/blog/2013/04/17/thoughtworks-developer-reading-radar/ 长久以来一直对程序员 ...