static BOOL TSP_GetXY(int *px, int *py) { int i,j,k; int temp; int x[TSP_SAMPLE_NUM], y[TSP_SAMPLE_NUM]; int dx, dy; int TimeOut = 100; // about 100ms EnterCriticalSection(&g_csTouchADC); for (i = 0; i < TSP_SAMPLE_NUM; i++) { g_pADCReg->ADCTSC = ADCTSC_AUTO_ADC; // Auto Conversion g_pADCReg->ADCCON |= ENABLE_START_EN; // ADC Conversion Start while (g_pADCReg->ADCCON & ENABLE_START_EN) { // Wait for Start Bit Cleared if(TimeOut-- < 0) { RETAILMSG(ZONE_ERROR,(TEXT("ADC cannot start\n"))); goto ADCfails; } Sleep(1); } TimeOut = 100; // about 100ms while (!(g_pADCReg->ADCCON & ECFLG_END)) { // Wait for ADC Conversion Ended if(TimeOut-- < 0) { RETAILMSG(ZONE_ERROR,(TEXT("ADC Conversion cannot be done\n"))); goto ADCfails; } Sleep(1); } x[i] = D_XPDATA_MASK(g_pADCReg->ADCDAT0); y[i] = D_YPDATA_MASK(g_pADCReg->ADCDAT1); } ADCfails: LeaveCriticalSection(&g_csTouchADC); for (j = 0; j < TSP_SAMPLE_NUM -1; ++j) { for (k = j+1; k < TSP_SAMPLE_NUM; ++k) { if(x[j]>x[k]) { temp = x[j]; x[j]=x[k]; x[k]=temp; } if(y[j]>y[k]) { temp = y[j]; y[j]=y[k]; y[k]=temp; } } } #ifdef DETAIL_SAMPLING // 8 samples Interpolation (weighted 4 samples) *px = (x[2] + ((x[3]+x[4])<<1) + (x[3]+x[4]) + x[5]); *py = (y[2] + ((y[3]+y[4])<<1) + (y[3]+y[4]) + y[5]); if ((*px & 0x7) > 3) *px = (*px>>3) + 1; else *px = *px>>3;
static BOOL TSP_GetXY(int *px, int *py) { int i,j,k; int temp; int x[TSP_SAMPLE_NUM], y[TSP_SAMPLE_NUM]; int dx, dy; EnterCriticalSection(&g_csTouchADC); for (i = 0; i < TSP_SAMPLE_NUM; i++) { g_pADCReg->ADCTSC = ADCTSC_AUTO_ADC; // Auto Conversion g_pADCReg->ADCCON |= ENABLE_START_EN; // ADC Conversion Start while (g_pADCReg->ADCCON & ENABLE_START_EN) { // Wait for Start Bit Cleared Sleep(1); } while (!(g_pADCReg->ADCCON & ECFLG_END)) { // Wait for ADC Conversion Ended Sleep(1); } x[i] = D_XPDATA_MASK(g_pADCReg->ADCDAT0); y[i] = D_YPDATA_MASK(g_pADCReg->ADCDAT1); } LeaveCriticalSection(&g_csTouchADC); for (j = 0; j < TSP_SAMPLE_NUM -1; ++j) { for (k = j+1; k < TSP_SAMPLE_NUM; ++k) { if(x[j]>x[k]) { temp = x[j]; x[j]=x[k]; x[k]=temp; } if(y[j]>y[k]) { temp = y[j]; y[j]=y[k]; y[k]=temp; } } } *px = (x[1]+x[2])>>1; *py = (y[1]+y[2])>>1; #if 0 TSPMSG((_T("[TSP] TSP_GetXY() : (%d, %d)\r\n"), *px, *py)); TSPMSG((_T("[TSP] TSP_GetXY() : 1st (%d, %d)\r\n"), x[0], y[0])); TSPMSG((_T("[TSP] TSP_GetXY() : 2nd (%d, %d)\r\n"), x[1], y[1])); TSPMSG((_T("[TSP] TSP_GetXY() : 3rd (%d, %d)\r\n"), x[2], y[2])); TSPMSG((_T("[TSP] TSP_GetXY() : 4th (%d, %d)\r\n"), x[3], y[3])); #endif dx = x[2]-x[1]; dy = y[2]-y[1]; if ((dx > TSP_INVALIDLIMIT) || (dy > TSP_INVALIDLIMIT)) { return FALSE; } else { return TRUE; } }