Goodix汇顶gt9xx触控IC的驱动代码分析_第1页
Goodix汇顶gt9xx触控IC的驱动代码分析_第2页
Goodix汇顶gt9xx触控IC的驱动代码分析_第3页
Goodix汇顶gt9xx触控IC的驱动代码分析_第4页
Goodix汇顶gt9xx触控IC的驱动代码分析_第5页
已阅读5页,还剩7页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、 GTP968(ic)触摸屏调试实际代码的分析触摸屏驱动一.probe函数中处理 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)/若有中断事件,则调用中断处理函数-调用队列工作-调用工作函数goodix_ts_work_func/此处是初始化队列工作,即将ts->work加入到goodix->wq队列中。 INIT_WORK(&ts->work, goodix_ts_work_func); i2c_set_clientdata(client, ts);

2、/1.io 端口初始化 ret = gtp_request_io_port(ts); ret = gtp_i2c_test(client); ret = gtp_read_version(client, &version_info);/2.触摸屏初始化调用(每个触摸屏都会由厂商提供初始化代码) ret = gtp_init_panel(ts);properties_kobj = kobject_create_and_add("board_properties", NULL); if (properties_kobj)

3、/3.gt9xx_properties_attr_group 节点处理虚拟按键(遇到过节点使用前未初始化,造成节点使用错误) ret = sysfs_create_group(properties_kobj,&gt9xx_properties_attr_group);/4.输入设备初始化gtp_request_input_dev(ts);/5.中断初始化ret = gtp_request_irq(ts);二.深入分析细节/1.io 端口初始化void gtp_reset_guitar(struct i2c_client *client, s32 ms)  

4、  GTP_INFO("Guitar reset");    GTP_GPIO_OUTPUT(GTP_RST_PORT, 0);   / begin select I2C slave addr    msleep(ms);                      &#

5、160;  / T2: > 10ms    / HIGH: 0x28/0x29, LOW: 0xBA/0xBB    GTP_GPIO_OUTPUT(GTP_INT_PORT, client->addr = 0x14);    msleep(2);                    

6、      / T3: > 100us    GTP_GPIO_OUTPUT(GTP_RST_PORT, 1);        msleep(6);                        

7、0; / T4: > 5ms    GTP_GPIO_AS_INPUT(GTP_RST_PORT);    / end select I2C slave addr    gtp_int_sync(50);   static s8 gtp_request_io_port(struct goodix_ts_data *ts)    s32 ret = 0;/中断端口    ret = GTP_GPIO_REQUES

8、T(GTP_INT_PORT, "GTP_INT_IRQ");/reset端口    ret = GTP_GPIO_REQUEST(GTP_RST_PORT, "GTP_RST_PORT");/reset端口设置为输入    GTP_GPIO_AS_INPUT(GTP_RST_PORT);/选择i2c地址    gtp_reset_guitar(ts->client, 20);       

9、 if(ret < 0)            GTP_GPIO_FREE(GTP_RST_PORT);        GTP_GPIO_FREE(GTP_INT_PORT);        return ret;2.输入设备初始化/*Function:    Request input device Function.Input:

10、    ts:private data.Output:    Executive outcomes.        0: succeed, otherwise: failed.*/static s8 gtp_request_input_dev(struct goodix_ts_data *ts)    s8 ret = -1;    s8 phys32;#if GTP_HAVE_TOUCH_KEY 

11、;   u8 index = 0;#endif    ts->input_dev = input_allocate_device();    if (ts->input_dev = NULL)            GTP_ERROR("Failed to allocate input device.");      

12、0; return -ENOMEM;    /设置输入设备属于哪类事件    ts->input_dev->evbit0 = BIT_MASK(EV_SYN) | BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS) ;#if GTP_ICS_SLOT_REPORT    _set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);    input_mt_init_slots(ts->

13、;input_dev, 16);     / in case of "out of memory"#else    _set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);    ts->input_dev->keybitBIT_WORD(BTN_TOUCH) = BIT_MASK(BTN_TOUCH);#endif#if GTP_HAVE_TOUCH_KEY    for

14、(index = 0; index < GTP_MAX_KEY_NUM; index+)            input_set_capability(ts->input_dev, EV_KEY, touch_key_arrayindex);      #endif#if GTP_SLIDE_WAKEUP    input_set_capability(ts->input_dev, EV_KEY,

15、 KEY_POWER);#endif#if GTP_WITH_PEN    / pen support    _set_bit(BTN_TOOL_PEN, ts->input_dev->keybit);    _set_bit(INPUT_PROP_DIRECT, ts->input_dev->propbit);    /_set_bit(INPUT_PROP_POINTER, ts->input_dev->propbit);#endif#

16、if GTP_CHANGE_X2Y    GTP_SWAP(ts->abs_x_max, ts->abs_y_max);#endif/设置输入设备:绝对位移事件ABS的具体值    input_set_abs_params(ts->input_dev, ABS_MT_POSITION_X, 0, ts->abs_x_max, 0, 0);    input_set_abs_params(ts->input_dev, ABS_MT_POSITION_Y, 0, ts->a

17、bs_y_max, 0, 0);    input_set_abs_params(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0, 255, 0, 0);    input_set_abs_params(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0, 255, 0, 0);    input_set_abs_params(ts->input_dev, ABS_MT_TRACKING_ID, 0, 255, 0, 0); &#

18、160;  sprintf(phys, "input/ts");    ts->input_dev->name = goodix_ts_name;    ts->input_dev->phys = phys;    ts->input_dev->id.bustype = BUS_I2C;    ts->input_dev->id.vendor = 0xDEAD;   

19、ts->input_dev->duct = 0xBEEF;    ts->input_dev->id.version = 10427;        ret = input_register_device(ts->input_dev);    if (ret)            GTP_ERROR("Regist

20、er %s input device failed", ts->input_dev->name);        return -ENODEV;        #ifdef CONFIG_HAS_EARLYSUSPEND    ts->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN + 1;    ts-&g

21、t;early_suspend.suspend = goodix_ts_early_suspend;    ts->early_suspend.resume = goodix_ts_late_resume;    register_early_suspend(&ts->early_suspend);#endif    return 0;3.中断初始化static s8 gtp_request_irq(struct goodix_ts_data *ts)   

22、; s32 ret = -1;    const u8 irq_table = GTP_IRQ_TAB;    GTP_DEBUG_FUNC();    GTP_DEBUG("INT trigger type:%x", ts->int_trigger_type);/请求中断,并设定中断触发方式    ret  = request_irq(ts->client->irq,     

23、                   goodix_ts_irq_handler,                       irq_tablets->int_trigger_type,

24、60;                      ts->client->name,                       ts); 

25、0;  if (ret)            GTP_ERROR("Request IRQ failed!ERRNO:%d.", ret);        GTP_GPIO_AS_INPUT(GTP_INT_PORT);        GTP_GPIO_FREE(GTP_INT_PORT);   

26、     hrtimer_init(&ts->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);        ts->timer.function = goodix_ts_timer_handler;hrtimer_start(&ts->timer, ktime_set(1, 0), HRTIMER_MODE_REL);        return

27、 -1;        else             gtp_irq_disable(ts);        ts->use_irq = 1;        return 0;    三.当有中断发生时,调用中断处理函数/*Function:

28、0;   Timer interrupt service routine for polling mode.Input:    timer: timer struct pointerOutput:    Timer work mode.         HRTIMER_NORESTART: no restart mode*/static enum hrtimer_restart goodix_ts_timer_handler(struc

29、t hrtimer *timer)    struct goodix_ts_data *ts = container_of(timer, struct goodix_ts_data, timer);    GTP_DEBUG_FUNC();/调用goodix_wq队列中的ts->work工作    queue_work(goodix_wq, &ts->work);    hrtimer_start(&ts->timer, ktime_set(

30、0, (GTP_POLL_TIME+6)*1000000), HRTIMER_MODE_REL);    return HRTIMER_NORESTART;四.调用ts->work的工作函数goodix_ts_work_func此函数主要是读取手指数及各个手指的坐标,并上报event事件。static void goodix_ts_work_func(struct work_struct *work)    u8  end_cmd3 = GTP_READ_COOR_ADDR >> 8, GTP_READ_C

31、OOR_ADDR & 0xFF, 0;    u8  point_data2 + 1 + 8 * GTP_MAX_TOUCH + 1=GTP_READ_COOR_ADDR >> 8, GTP_READ_COOR_ADDR & 0xFF;    u8  touch_num = 0;    u8  finger = 0;    static u16 pre_touch = 0;    stat

32、ic u8 pre_key = 0;    u8  key_value = 0;    u8* coor_data = NULL;    s32 input_x = 0;    s32 input_y = 0;    s32 input_w = 0;    s32 id = 0;    s32 i  = 0;    s32 ret = -

33、1;    struct goodix_ts_data *ts = NULL;    GTP_DEBUG_FUNC();    ts = container_of(work, struct goodix_ts_data, work);    if (ts->enter_update)            return;    /从触摸屏I2

34、C 读取数据    ret = gtp_i2c_read(ts->client, point_data, 12);    if (ret < 0)            GTP_ERROR("I2C transfer error. errno:%dn ", ret);        goto exit_work_func; &

35、#160;      finger = point_dataGTP_ADDR_LENGTH;       if(finger & 0x80) = 0)            goto exit_work_func;    /对手指数的判断    touch_num = finger & 0x0f;  &

36、#160; if (touch_num > GTP_MAX_TOUCH)            goto exit_work_func;        if (touch_num > 1)            u8 buf8 * GTP_MAX_TOUCH = (GTP_READ_COOR_ADDR + 10) >&g

37、t; 8, (GTP_READ_COOR_ADDR + 10) & 0xff;        ret = gtp_i2c_read(ts->client, buf, 2 + 8 * (touch_num - 1);         memcpy(&point_data12, &buf2, 8 * (touch_num - 1);    /上报虚拟按键的值(虚拟按键上报有两种方式:1.按键

38、上报,2.坐标上报,所以才有判断)#if GTP_HAVE_TOUCH_KEY    key_value = point_data3 + 8 * touch_num;    if(key_value | pre_key)        #ifndef VKEY_SYS        for (i = 0; i < GTP_MAX_KEY_NUM; i+)    

39、                input_report_key(ts->input_dev, touch_key_arrayi, key_value & (0x01<<i);           #else  if (key_value = 1)    input_x = 80;&

40、#160;  input_y = 898;  else if (key_value = 2)    input_x = 240;   input_y = 898;  else if (key_value = 4)    input_x = 400;   input_y = 898;    blocking_notifier_call_chain(&touch_key_n

41、otifier, 0, NULL);  input_report_abs(ts->input_dev, ABS_MT_POSITION_X, input_x);  input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, input_y);  if(key_value)    input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 8);   in

42、put_report_key(ts->input_dev, BTN_TOUCH, 1);   /printk("lht-%s-touch key_value=%d-touch_num=%d-downn", _func_, key_value, touch_num);  else    input_report_abs(ts, ABS_MT_TOUCH_MAJOR, 0);   input_report_key(ts->input_dev, BTN_TOU

43、CH, 0);   /printk("lht-%s-touch key_value=%d-touch_num=%d-upn", _func_, key_value, touch_num);    input_mt_sync(ts->input_dev); #endif        touch_num = 0;        pre_touch = 0

44、;        pre_key = key_value;    GTP_DEBUG("pre_touch:%02x, finger:%02x.", pre_touch, finger);    input_report_key(ts->input_dev, BTN_TOUCH, (touch_num | key_value); /printk("lht-%s-touch_num=%d-key_value=%d-n",

45、_func_, touch_num, key_value); down_up_flag = touch_num | key_value;/各个手指坐标的读取    if (touch_num)            for (i = 0; i < touch_num; i+)               

46、;     coor_data = &point_datai * 8 + 3;            id = coor_data0 & 0x0F;            input_x  = coor_data1 | (coor_data2 << 8);    

47、;        input_y  = coor_data3 | (coor_data4 << 8);            input_w  = coor_data5 | (coor_data6 << 8);/上报坐标值及w值            gtp_tou

48、ch_down(ts, id, input_x, input_y, input_w);                else if (pre_touch)            GTP_DEBUG("Touch Release!");/释放手指        gtp_touch_up(ts, 0);        pre_touch = touch_num;#endif    input_sync(ts->inp

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论