[国嵌攻略][141][触摸屏驱动编程]

开启XY坐标转换,并上报

触摸屏驱动文件在/drivers/input/touchscreen/s3c2410_ts.c

 

static void touch_timer_fire(unsigned long data)
{
      unsigned long data0;
      unsigned long data1;
    int updown;

      data0 = ioread32(base_addr+S3C2410_ADCDAT0);
      data1 = ioread32(base_addr+S3C2410_ADCDAT1);

     updown = (!(data0 & S3C2410_ADCDAT0_UPDOWN)) && (!(data1 & S3C2410_ADCDAT0_UPDOWN));

     if (updown) {
        //判断上报事件
        if(count != 0){   //如果是第四次采样,那么提交上报事件
            //交换坐标
            long tmp;
            
            tmp = xp;
            xp = yp;
            yp = tmp;
            
            //平均处理
            xp >>= 2;
            yp >>= 2;
            
            //上报事件
            input_report_abs(dev, ABS_X, xp);
            input_report_abs(dev, ABS_Y, yp);
            
            input_report_abs(dev, ABS_PRESSURE, 1);
            input_report_key(dev, BTN_TOUCH, 1);
            
            //同步上报
            input_sync(dev);
            
            //显示坐标
            printk("x = %d, y = %d\n", xp, yp);
        }
        
        //清零转换坐标
        xp = 0;
        yp = 0;
        count = 0;
        
         //启动坐标转换
        iowrite32(1<<2, base_addr + S3C2410_ADCTSC);                                            //设置自动转换模式
        iowrite32(ioread32(base_addr + S3C2410_ADCCON) | (1<<0), base_addr + S3C2410_ADCCON);   //开启坐标转换
     } else {
         count = 0;

         input_report_key(dev, BTN_TOUCH, 0);
         input_report_abs(dev, ABS_PRESSURE, 0);
         input_sync(dev);

         iowrite32(WAIT4INT(0), base_addr+S3C2410_ADCTSC);
        if (OwnADC) {
            OwnADC = 0;
            up(&ADC_LOCK);
        }
     }
}

 

posted @ 2016-03-13 09:47  盛夏夜  阅读(270)  评论(0编辑  收藏  举报