69,381
社区成员
发帖
与我相关
我的任务
分享
#include "def1.h"
#include "2440addr.h"
#include "2440lib.h"
#include "config.h"
#define REQCNT 30
#define ADCPRS 9 //YH 0627
#define LOOP 1
void AdcTsAuto(void);
int TouchPanelCnt=0; // 触摸屏次数的记录
struct TouchLocation
{
volatile int x;
volatile int y;
}TPxyLocation = {0,0};
volatile int test_x;
volatile int test_y;
INT8U ts_status;//触摸屏的状态(校准还是测试)
//static U16 ts_lefttop_x,ts_lefttop_y,ts_rightbot_x,ts_rightbot_y,ts_leftbot_x,
//ts_leftbot_y,ts_righttop_x,ts_righttop_y;
struct TouchLocation TestPoint[8] = {0};
extern void AdcTsAuto_Handler(void);
extern OS_EVENT *TP_m_box;
//extern OS_EVENT *Cal_m_box;
//extern OS_EVENT *Lag_m_box;
//unsigned int buf[3][2];
U16 Ptx[6],Pty[6],tmp[6] = {0,0,0,0,0,0};
//U8 index = 0;
void AdcTsAuto(void)
{
int i;
U32 saveAdcdly;
if(rADCDAT0&0x8000)
{
//Uart_Printf("\nStylus Up!!\n");
rADCTSC&=0xff; // Set stylus down interrupt bit
}
//else
// Uart_Printf("\nStylus Down!!\n");
rADCTSC=(1<<3)|(1<<2); //Pull-up disable, Seq. X,Y postion measure.
saveAdcdly=rADCDLY;
rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms
rADCCON|=0x1; //start ADC
for(i=0;i<5;i++)
{
// rADCTSC = (1<<7)|(1<<6)|(0<<5)|(1<<4)|(1<<3)|(1<<2)|(0);
rADCTSC=(1<<3)|(1<<2); //Pull-up disable, Seq. X,Y postion measure.
saveAdcdly=rADCDLY;
rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms
rADCCON |= 0x1; //Start Auto conversion
while(rADCCON & 0x1); //Check if Enable_start is low
while(!(0x8000&rADCCON)); //Check ECFLG
while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit
Pty[i] = (0x3ff&rADCDAT1);
Ptx[i] = (0x3ff&rADCDAT0);
//OSPrintf("----- ========(%04d,%04d)=======\n",Ptx[i], Pty[i]);
}
// buf[3][0] =((buf[0][0] + buf[1][0] + buf[2][0])/3)*10;
//buf[3][1] =((buf[0][1] + buf[1][1] + buf[2][1])/3)*10;
Ptx[5]=(Ptx[0]+Ptx[1]+Ptx[2]+Ptx[3]+Ptx[4])/5;
Pty[5]=(Pty[0]+Pty[1]+Pty[2]+Pty[3]+Pty[4])/5;
OSPrintf(" ========(%04d,%04d)=======\n",Ptx[5], Pty[5]);
//OSPrintf("----- ========(%04d,%04d)=======\n",TPxyLocation.x,TPxyLocation.y);
TPxyLocation.x=Ptx[5]*10;
TPxyLocation.y=Pty[5]*10;
//TPxyLocation.x=TPxyLocation.x*10;
// TPxyLocation.y=TPxyLocation.y*10;
//OSMboxPost(TP_m_box,(void*)1);
//YH 0627, To check Stylus Up Interrupt.
rSUBSRCPND|=BIT_SUB_TC;
ClearPending(BIT_ADC);
rINTSUBMSK&=~(BIT_SUB_TC);
rINTMSK&=~(BIT_ADC);
rADCTSC =0xd3; //Waiting for interrupt
rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal.
while(1) //to check Pen-up state
{
if(rSUBSRCPND & (BIT_SUB_TC)) //check if ADC is finished with interrupt bit
{
//Uart_Printf("Stylus Up Interrupt~!\n");
break; //if Stylus is up(1) state
}
}
//Uart_Printf("count=%03d XP=%04d, YP=%04d\n", TouchPanelCnt++, TPxyLocation.x, TPxyLocation.y); //X-position Conversion data
OSMboxPost(TP_m_box,(void*)1);
rADCDLY=saveAdcdly;
rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal.
rSUBSRCPND|=BIT_SUB_TC;
rINTSUBMSK &=~(BIT_SUB_TC); // Unmask sub interrupt (TC)
ClearPending(BIT_ADC);
}
void Test_Touchpanel(void)
{
//OSPrintf("ADC touch screen test\n");
//OSPrintf("[1] calibration touch screen \n");
// OSPrintf("Please touch the location of left top \n");
//ts_status = TS_JUSTIFY_LEFTTOP;
rADCDLY=50000; //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms
rADCCON=(1<<14) | (ADCPRS<<6);//| (0<<3) | (0<<2) | (0<<1) | (0);
//ADCPRS En, ADCPRS Value
rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En
// pISR_ADC = (uint32)AdcTsAuto_Handler;
pISR_ADC = (int)AdcTsAuto;
rINTMSK &= ~BIT_ADC; //ADC Touch Screen Mask bit clear
rINTSUBMSK &= ~(BIT_SUB_TC);
}