FT5406(添加XXX供应商TP5306支持)

来源:互联网 发布:织梦cms 视频播放 编辑:程序博客网 时间:2024/04/30 08:48

修改只需要在FT5406_touch.c的基础上进行解单的修改就可以了,他们用的芯片都是同一款芯片,只是产品型号上有些出入。只需要做简单的修改就可以进行调试:


第一个需要修改的就是

static void ft5406_ts_work_func(struct work_struct * work)
{
        struct ft5406_ts * ts = container_of(work, struct ft5406_ts, work);
        uint8_t buf[32] = { 0 };
        unsigned int X, Y,oldx,oldy;
        unsigned int x, y, event, id;
        int i;


        ft5406_read_coordinates(ts->client, buf, 32);


        for(i = 0; i < 5; i++)
        {
                X = (buf[i*6 + 3])<<8 | buf[i*6 + 4];
                Y = (buf[i*6 + 5])<<8 | buf[i*6 + 6];


                y = X & 0xfff;
                x = Y & 0xfff;
//打印出来的坐标x,y值刚好与我们所需的刚好相反,数值正确。所以下面做了x,y值得交换;

                oldx = y;
                oldy = x;
                //x = (x * SCREEN_MAX_WIDTH / TOUCH_MAX_WIDTH);
                //x = SCREEN_MAX_WIDTH - x;
                //y = (y * SCREEN_MAX_HEIGHT / TOUCH_MAX_HEIGHT);          注释的此3行代码是因为此前屏做了270度的调转
                x = x ^ y;
                y = x ^ y;
                x = x ^ y;




                event = (X >> 14) & 0x3;
                id = (Y >> 12) & 0xf;


                if(id >= 0 && id <= 4)
                {
                        ts->node[id].x = x;
                        ts->node[id].y = y;


                        if((event == 0) || (event == 0x02))
                        {
                                input_report_abs(ts->input_dev, ABS_MT_POSITION_X, ts->node[id].x);
                                input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, ts->node[id].y);
                                input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1);
                                input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 1);
                                input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
                                input_mt_sync(ts->input_dev);


                                //printk("[%d]down: x = %4d, y = %4d\n", id, ts->node[id].x, ts->node[id].y);
                        }
                        else if(event == 0x01)
                        {
                                input_report_abs(ts->input_dev, ABS_MT_POSITION_X, ts->node[id].x);
                                input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, ts->node[id].y);
                        input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
                                input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
                                input_report_abs(ts->input_dev,ABS_MT_TRACKING_ID, id);
                                input_mt_sync(ts->input_dev);

static void ft5406_ts_work_func(struct work_struct * work)
{
        struct ft5406_ts * ts = container_of(work, struct ft5406_ts, work);
        uint8_t buf[32] = { 0 };
        unsigned int X, Y,oldx,oldy;
        unsigned int x, y, event, id;
        int i;


        ft5406_read_coordinates(ts->client, buf, 32);


        for(i = 0; i < 5; i++)
        {
                X = (buf[i*6 + 3])<<8 | buf[i*6 + 4];
                Y = (buf[i*6 + 5])<<8 | buf[i*6 + 6];


                y = X & 0xfff;
                x = Y & 0xfff;


                oldx = y;
                oldy = x;
                //x = (x * SCREEN_MAX_WIDTH / TOUCH_MAX_WIDTH);
                //x = SCREEN_MAX_WIDTH - x;
                //y = (y * SCREEN_MAX_HEIGHT / TOUCH_MAX_HEIGHT);
                x = x ^ y;
                y = x ^ y;
                x = x ^ y;




                event = (X >> 14) & 0x3;
                id = (Y >> 12) & 0xf;


                if(id >= 0 && id <= 4)
                {
                        ts->node[id].x = x;
                        ts->node[id].y = y;


                        if((event == 0) || (event == 0x02))
                        {
                                input_report_abs(ts->input_dev, ABS_MT_POSITION_X, ts->node[id].x);
                                input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, ts->node[id].y);
                                input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 1);
                                input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 1);
                                input_report_abs(ts->input_dev, ABS_MT_TRACKING_ID, id);
                                input_mt_sync(ts->input_dev);


                                //printk("[%d]down: x = %4d, y = %4d\n", id, ts->node[id].x, ts->node[id].y);
                        }
                        else if(event == 0x01)
                        {
                                input_report_abs(ts->input_dev, ABS_MT_POSITION_X, ts->node[id].x);
                                input_report_abs(ts->input_dev, ABS_MT_POSITION_Y, ts->node[id].y);
                        input_report_abs(ts->input_dev, ABS_MT_TOUCH_MAJOR, 0);
                                input_report_abs(ts->input_dev, ABS_MT_WIDTH_MAJOR, 0);
                                input_report_abs(ts->input_dev,ABS_MT_TRACKING_ID, id);
                                input_mt_sync(ts->input_dev);

                          }

                        ft5406_process_key(ts->input_dev, oldx, oldy, event, id);
                }
        }


        input_sync(ts->input_dev);
        enable_irq(ts->client->irq);
}


下面我们可是修改按键所涉及的变量:
static void ft5406_process_key(struct input_dev * dev, int x, int y, int event, int id)
{
        static uint8_t key_old = 0x0;
        uint8_t key, keyup, keydown;


        // printk("x=%d, y=%d, event=%d, id=%d\n", x, y, event, id);


        if( y > 1024 + 20 )
        {
                key = 0;

                if(g_vendorID == 0x79)
                {
                        if((x >570) && (x < 600))
                        {
                                if((event == 0) || (event == 0x02))
                                        key |= 0x8;
                                else if(event == 0x01)
                                        key &= ~0x8;
                        }
                        else if((x > 510) && (x < 540))
                        {
                                if((event == 0) || (event == 0x02))
                                        key |= 0x4;
                                else if(event == 0x01)
                                        key &= ~0x4;
                        }
                        else if((x > 450) && (x < 480))
                        {
                                if((event == 0) || (event == 0x02))
                                        key |= 0x2;
                                else if(event == 0x01)
                                        key &= ~0x2;
                        }
                        else if((x > 400) && (x < 430))
                        {
                                if((event == 0) || (event == 0x02))
                                        key |= 0x1;
                                else if(event == 0x01)
                                        key &= ~0x1;
                        }
                }

       }
        else
        {
                return;
        }


        if(key != key_old)
        {
                keyup = (key ^ key_old) & key_old;
                keydown = (key ^ key_old) & key;
                key_old = key;


                if(keyup)
                {
                        if(keyup & 0x1)
                                input_report_key(dev, K_SEARCH, 0);
                        else if(keyup & 0x2)
                                input_report_key(dev, K_MENU, 0);
                        else if(keyup & 0x4)
                                input_report_key(dev, K_HOME, 0);
                        else if(keyup & 0x8)
                                input_report_key(dev, K_BACK, 0);
                }


                if(keydown)
                {
                        if(keydown & 0x1)
                                input_report_key(dev, K_SEARCH, 0);
                        else if(keydown & 0x2)
                                input_report_key(dev, K_MENU, 1);
                        else if(keydown & 0x4)
                                input_report_key(dev, K_HOME, 1);
                        else if(keydown & 0x8)
                                input_report_key(dev, K_BACK, 1);


                        gpio_enable_ext(50);
                }
        }
}
  


按照g_vendorID获取到你值进行判断使用的是那款屏,然后通过打印出来的X,Y值来设置BACK,HOME,MENU,SEARCH的键值范围并进行事件上报;




我的工作也就完成了.O(∩_∩)O哈哈~