input子系统 KeyPad-Touch上报数据格式与机制

-----------------------------------------------------------------------
本文系本站原创,欢迎转载!
转载请注明出处:http://blog.csdn.net/android_huber
交流邮箱:dp.shao@gmail.com
-----------------------------------------------------------------------

linux driveinput子系统上报信息,调用函数

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))将信息上报给上层,eventstruct input_event类型结构体, 中间会有一些处理将 typecodevalue值打包成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);

typeEV_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_MAJORABS_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为对应属性的值,如codeABS_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

type0x00code2value0

接着再上报第二个点,第二个点上报结束,依旧要上报input_mt_sync,直至最后一次报点结束,加上input_sync,转换成input_event事件为

input_event(dev, EV_SYN, SYN_REPORT, 0)

其中#define EV_SYN  0x00#define SYN_REPORT 0

type0x00code0value0。至此报点结束。

点需要一直上报。

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 );  value1,代表按下,value0代表抬起。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;用来记录此刻的墙上时间。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值