触摸屏驱动一关键函数

来源:互联网 发布:浙大gpa算法 编辑:程序博客网 时间:2024/05/01 00:27
  1. PUBLIC VOID  
  2. DdsiTouchPanelGetPoint(TOUCH_PANEL_SAMPLE_FLAGS * pTipStateFlags,  
  3.                        INT  * pUncalX,  
  4.                        INT  * pUncalY)  
  5. {  
  6.     static INT x, y;  
  7.   
  8.     //DEBUGMSG(1, (TEXT("::: DdsiTouchPanelGetPoint()/r/n")));  
  9.       
  10.     if (v_pINTregs->SUBSRCPND & (1<<IRQ_SUB_TC))        /* SYSINTR_TOUCH Interrupt Case                */  
  11.     {   //触点中断(INT_TC)  
  12.         *pTipStateFlags = TouchSampleValidFlag;  
  13.         //读取ADC Conversion DATA Register, 1-Stylus down state 0-Stylus up state  
  14.         if ( (v_pADCregs->ADCDAT0 & (1 << 15)) |  
  15.              (v_pADCregs->ADCDAT1 & (1 << 15)) )  
  16.         {  
  17.             //Stylus up state  
  18.             bTSP_DownFlag = FALSE;  
  19.   
  20.             DEBUGMSG(ZONE_TIPSTATE, (TEXT("up/r/n")));  
  21.             //重新设置ADC TOUCH SCREEN CONTROL REGISTER  
  22.             v_pADCregs->ADCTSC &= 0xff;  
  23.             //读取上次的坐标值  
  24.             *pUncalX = x;  
  25.             *pUncalY = y;  
  26.             //停止取样(停止Timer3 PWM)  
  27.             TSP_SampleStop();  
  28.             //停止取样后忽略TIMER3中断  
  29.             /* At this point SYSINTR_TOUCH_CHANGED (timer3) interrupt could also be pending (and masked). 
  30.                Since we do not care about the timer3 interrupt after calling TSP_SampleStop, signal it Done. 
  31.                If we do not signal done and it was indeed pending and masked, IRQ_TIMER3 will not be unmasked 
  32.                and won't fire again unless unmasked */  
  33.             if (v_pINTregs->SRCPND & (1<<IRQ_TIMER3))  
  34.                 InterruptDone(gIntrTouchChanged);  
  35.         }  
  36.         else  
  37.         {  
  38.               //Stylus down state  
  39.             bTSP_DownFlag = TRUE;  
  40.             //读触摸屏AD数据  
  41.             if (!TSP_GetXY(&x, &y))  
  42.                 *pTipStateFlags = TouchSampleIgnore;  
  43.             //转换成LCD上的坐标  
  44.             TSP_TransXY(&x, &y);  
  45.   
  46.             *pUncalX = x;  
  47.             *pUncalY = y;  
  48.   
  49.             *pTipStateFlags |= TouchSampleDownFlag;  
  50.               
  51.             DEBUGMSG(ZONE_TIPSTATE, (TEXT("down %x %x/r/n"), x, y));  
  52.             //启动Timer3 PWM  
  53.             TSP_SampleStart();  
  54.         }  
  55.         //屏蔽触摸屏中断,清除中断标志  
  56.         v_pINTregs->SUBSRCPND  =  (1<<IRQ_SUB_TC);  
  57.         v_pINTregs->INTSUBMSK &= ~(1<<IRQ_SUB_TC);  
  58.         //通知系统中断处理完成  
  59.         InterruptDone(gIntrTouch);  
  60.     }  
  61.     else        /* SYSINTR_TOUCH_CHANGED Interrupt Case     */  
  62.     {  
  63. //      TSP_SampleStart();  
  64.         //Timer3 PWM中断发生  
  65.         if (bTSP_DownFlag)  
  66.         {  
  67.               //触摸笔还处于down状态  
  68.             INT  tx, ty;  
  69.             INT  dx, dy;  
  70.             //读取触摸屏AD数据  
  71.             if (!TSP_GetXY(&tx, &ty))  
  72.                 *pTipStateFlags = TouchSampleIgnore;  
  73.             else  
  74.             {   //读到的是坏数据,进行相应处理,如不能修正则忽略该数据  
  75.                 TSP_TransXY(&tx, &ty);  
  76. // insert by mostek@dstcorp.com  
  77. #define X_ERRV  0x3bf  
  78. #define Y_ERRV  0x4ff  
  79.   
  80. // Subsequent info: If the ADC provides a bad reading, this catches it and  
  81. // skips over it. Instead, it should be fixed at the source  
  82. // so as not to provide a bad reading.  
  83.   
  84.                 if ((tx == X_ERRV) || (ty == Y_ERRV))  
  85.                 {  
  86.                     tx = x;  
  87.                     ty = y;  
  88.                 }  
  89. // =================== mostek  
  90.                 dx = (tx > x) ? (tx - x) : (x - tx);  
  91.                 dy = (ty > y) ? (ty - y) : (y - ty);  
  92.   
  93.                 if (dx > TSP_CHANGE || dy > TSP_CHANGE)  
  94.                 {  
  95.                     *pUncalX = x = tx;  
  96.                     *pUncalY = y = ty;  
  97.   
  98.                     DEBUGMSG(ZONE_TIPSTATE, (TEXT("down-c-v %x %x/r/n"), x, y));  
  99.   
  100.                     *pTipStateFlags = TouchSampleValidFlag | TouchSampleDownFlag;  
  101.                 }  
  102.                 else  
  103.                 {  
  104.                     *pUncalX = x;  
  105.                     *pUncalY = y;  
  106.   
  107.                     DEBUGMSG(ZONE_TIPSTATE, (TEXT("down-c %x %x/r/n"), x, y));  
  108.   
  109.                     *pTipStateFlags = TouchSampleIgnore;  
  110.                 }  
  111.             }  
  112.         }  
  113.         else  
  114.         {  
  115.             *pTipStateFlags = TouchSampleIgnore;  
  116.   
  117.             TSP_SampleStop();  
  118.         }  
  119.   
  120.         InterruptDone(gIntrTouchChanged);  
  121.     }  
原创粉丝点击