在android 4.0上开发触摸设备驱动需要注意的几点

来源:互联网 发布:小鸡手柄连接mac 编辑:程序博客网 时间:2024/05/01 21:45

android 4.0已经渐渐流行,很多方案都已经基于其上,android 4.0的linux内核版本已经更新为linux 3.0,这个变化导致和内核直接接触的驱动需要或多或少的变化,以下描述的是触摸设备驱动的一些小变化:

1.当一个(这时候的情境应该是多点触摸的情况)手指或是触摸工具抬起(UP)时,他应该立即消失在多点出没的同步报告中,当所有的工具或手指抬起,驱动应该立即发送一个“空”同步消息,使用SYN_MT_REPORT其次是SYN_REPORT。

之前的版本是向上报告一个presssure为0的消息,现在新的多点触摸协议已经不再兼容旧的协议了。

2.物理接触或是信号强度将使用ABS_MT_PRESSURE上报。
之前的版本是用ABS_MT_TOUCH_MAJOR上报这个消息,同样,旧的方式也已经不被兼容了。

3.触摸接触面积使用ABS_MT_TOUCH_MAJOR向上报告
旧的版本使用ABS_MT_TOOL_MAJOR向上报告,旧的方式也已经不被兼容了。

触摸设备驱动程序不再需要特定的Android定制。依靠标准的Linux输入协议,Android可以更广泛支持触摸外设,如外部HID多点触摸触摸屏,使用未修改的驱动程序。

example:
static irqreturn_t xxx_ts_irq_handler(int irq, void *dev_id)
{
    struct xxx_ts_data *ts = dev_id;
    struct xxx_ts_finger *finger = ts->finger;
    struct input_dev *input_dev = ts->input_dev;
    int count = 0;
    int i, ret;

    ret = xxx_ts_read_data(ts);
    if (ret < 0)
        goto end;

    /* multi touch protocol */
    for (i = 0; i < MAX_FINGERS; i++) {
        if (!finger[i].is_valid)
            continue;

        input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, finger[i].t);
        input_report_abs(input_dev, ABS_MT_POSITION_X, finger[i].x);
        input_report_abs(input_dev, ABS_MT_POSITION_Y, finger[i].y);
        input_mt_sync(input_dev);
        count++;
    }

    /* SYN_MT_REPORT only if no contact */
    if (!count)
        input_mt_sync(input_dev);

    /* SYN_REPORT */
    input_sync(input_dev);

end:
    return IRQ_HANDLED;
}
原创粉丝点击