kernel input device

源码:

  android-5.0.2\linux-3.0.86\drivers\input\touchscreen\Ft5x06_ts.c

功能:

  input device驱动code,该篇只阐述input device驱动框架,其他文章将描述input子系统

  1:注册input_device

  2:上报事件

源码分析:

  只关注input device相关code

注册input device

static int ft5x0x_ts_probe(struct i2c_client *client, const struct i2c_device_id *id)
    // 1:申请
    input_dev = input_allocate_device();
    // 2:设置
// 2.1 上报何种类型事件
set_bit(EV_SYN, input_dev->evbit); set_bit(EV_ABS, input_dev->evbit); set_bit(EV_KEY, input_dev->evbit); // 这里涉及A类/B类报点协议,A类算法识别多点轨迹,B类硬件支持识别 // type B set_bit(ABS_MT_TRACKING_ID, input_dev->absbit); set_bit(ABS_MT_TOUCH_MAJOR, input_dev->absbit); set_bit(ABS_MT_WIDTH_MAJOR, input_dev->absbit); set_bit(ABS_MT_POSITION_X, input_dev->absbit); set_bit(ABS_MT_POSITION_Y, input_dev->absbit); // 2.2 各类型的数据范围 input_set_abs_params(input_dev, ABS_MT_POSITION_X, 0, ts->screen_max_x, 0, 0); input_set_abs_params(input_dev, ABS_MT_POSITION_Y, 0, ts->screen_max_y, 0, 0); input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, 0, ts->pressure_max, 0, 0); input_set_abs_params(input_dev, ABS_MT_WIDTH_MAJOR, 0, 200, 0, 0); input_set_abs_params(input_dev, ABS_MT_TRACKING_ID, 0, FT5X0X_PT_MAX, 0, 0); input_dev->name = FT5X0X_NAME; input_dev->phys = "input(mt)"; input_dev->id.bustype = BUS_I2C; input_dev->id.vendor = 0x12FA; input_dev->id.product = 0x2143; input_dev->id.version = 0x0100; // 3:注册 input_register_device(input_dev);

上报事件

static void ft5x0x_ts_report(struct ft5x0x_ts_data *ts) {
    for (i = 0; i < event->touch_point; i++) {
        input_report_abs(ts->input_dev, ABS_MT_POSITION_X, x);
        input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, y);

        input_report_abs(ts->input_dev, ABS_MT_PRESSURE, event->pressure);
        input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, event->pressure);
        input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, i);

        input_mt_sync(ts->input_dev);
    }

    input_sync(ts->input_dev);
}
posted @ 2018-01-18 15:54  __千里之行  阅读(337)  评论(0编辑  收藏  举报