static irqreturn_t adc_irq(int irq, void *dev_id) { static int cnt = 0; static int x[4], y[4]; int adcdat0, adcdat1; /* 优化措施2: 如果ADC完成时, 发现触摸笔已经松开, 则丢弃此次结果 */ adcdat0 = s3c_ts_regs->adcdat0; adcdat1 = s3c_ts_regs->adcdat1; if (s3c_ts_regs->adcdat0 & (1<<15)) { /* 已经松开 */ cnt = 0; input_report_abs(s3c_ts_dev, ABS_PRESSURE, 0); input_report_key(s3c_ts_dev, BTN_TOUCH, 0); input_sync(); enter_wait_pen_down_mode(); } else { // printk("adc_irq cnt = %d, x = %d, y = %d\n", ++cnt, adcdat0 & 0x3ff, adcdat1 & 0x3ff); /* 优化措施3: 多次测量求平均值 */ x[cnt] = adcdat0 & 0x3ff; y[cnt] = adcdat1 & 0x3ff; ++cnt; if (cnt == 4) { /* 优化措施4: 软件过滤 */ if (s3c_filter_ts(x, y)) { //printk("x = %d, y = %d\n", (x[0]+x[1]+x[2]+x[3])/4, (y[0]+y[1]+y[2]+y[3])/4); input_report_abs(s3c_ts_dev, ABS_X, (x[0]+x[1]+x[2]+x[3])/4); input_report_abs(s3c_ts_dev, ABS_Y, (y[0]+y[1]+y[2]+y[3])/4); input_report_abs(s3c_ts_dev, ABS_PRESSURE, 1); input_report_key(s3c_ts_dev, BTN_TOUCH, 1); input_sync(); } cnt = 0; enter_wait_pen_up_mode(); /* 启动定时器处理长按/滑动的情况 */ mod_timer(&ts_timer, jiffies + HZ/100); } else { enter_measure_xy_mode(); start_adc(); } } return IRQ_HANDLED; }
static irqreturn_t stylus_action(int irq, void *dev_id) { static int cnt = 0; long int adcdat0, adcdat1; static long int x[4], y[4]; /* * Extra: Optimization 2 * After the ADC interrupt is finished, if the stylus is up, then discards this results */ adcdat0 = s3c_ts_regs->ADCDAT0; adcdat1 = s3c_ts_regs->ADCDAT1; if(s3c_ts_regs->ADCDAT0 & (1<<15)) { /* Stylus is already up */ cnt = 0; wait4IntMode_Down(); }else { //printk("stylus_action cnt = %d, (x,y) = (%ld,%ld)\n", ++cnt, adcdat0 & 0x3FF, adcdat1 & 0x3FF); /* * Extra: Optimization 3 * Measure many times and calculate the average value */ x[cnt] = adcdat0 & 0x3FF; y[cnt] = adcdat1 & 0x3FF; ++cnt; if(4 == cnt) { /* * Extra: Optimization 4 * Software filter */ if(s3c_filter_ts(x, y)) { printk("(x,y) = (%ld,%ld)\n", AVG_TS(x[0],x[1],x[2],x[3]), AVG_TS(y[0],y[1],y[2],y[3])); } cnt = 0; wait4IntMode_Up(); /* Start timer for handling the slither */ mod_timer(&ts_timer, jiffies + HZ/100); /* HZ/100 = 10ms since HZ = 1s */ }else { measure_xy_mode(); start_adc(); } }
static irqreturn_t adc_irq(int irq, void *dev_id) { static int cnt = 0; int adcdat0, adcdat1; static int x[4], y[4]; int updown; enter_no_operation_mode(); #if 1 /* 优化措施2: 如果ADC完成时, 发现触摸笔已经松开, 则丢弃此次结果 */ adcdat0 = s3c_ts_regs->adcdat0; adcdat1 = s3c_ts_regs->adcdat1; /* dat0和dat1中bit15都是0, updown才是0, 0是down state */ updown =! (!(adcdat0 & (1<<15))) && (!(adcdat1 & (1<<15))); if (updown) /* 已经松开 */ { cnt = 0; enter_wait_pen_down_mode(); /* 进入等待按下模式 */ } else /* 已经按下 */ { // printk("adc_irq cnt = %d, x = %d, y = %d\n", ++cnt, adcdat0 & 0xfff, adcdat1 & 0xfff); // enter_wait_pen_up_mode(); /* 优化措施3: 多次测量求平均值 */ x[cnt] = adcdat0 & 0xfff; y[cnt] = adcdat1 & 0xfff; ++cnt; if (cnt == 4) { cnt = 0; /* 优化措施4: 软件过滤 */ if (s3c_filter_ts(x, y)) { printk("x = %d, y = %d\n", (x[0]+x[1]+x[2]+x[3])/4, (y[0]+y[1]+y[2]+y[3])/4); } enter_wait_pen_up_mode(); /* 进入等待弹起模式 */ /* 启动定时器处理长按/滑动的情况 */ mod_timer(&ts_timer, jiffies + HZ/100); } else { enter_measure_xy_mode(); start_adc(); } } #endif #if 0 printk("adc_irq cnt = %d, x = %d, y = %d\n", ++cnt,(int) (s3c_ts_regs->adcdat0 & 0xfff), (int) (s3c_ts_regs->adcdat1 & 0xfff)); enter_wait_pen_up_mode(); #endif return IRQ_HANDLED; }