int main() { Clr_BUFFER_FLAG(); alt_video_display Display; TOUCH_HANDLE *pTouch; printf("Hi There !\n"); // Write 0x3C on LED[6:0] through the dedicated custom IP IOWR(LED_CTRL_BASE, 0x0, 0x3C); // TOUCH INITIALIZATION pTouch = Touch_Init(LT24_TOUCH_SPI_BASE, LT24_TOUCH_PENIRQ_N_BASE, LT24_TOUCH_PENIRQ_N_IRQ); if (!pTouch){ printf("Failed to init touch\r\n"); }else{ printf("Init touch successfully\r\n"); } // LCD INITIALIZATION LCD_Init(); // Pattern example //LCD_Pattern_Horizon(); // Sleep 3s //usleep(3*1000*1000); Set_BUFFER_FLAG(); unsigned int X, Y; unsigned int posTamper =0; while(1){ if(Touch_GetXY(pTouch, &X, &Y)){ //printf("X: %d Y: %d\n",X,Y); LCD_WR_DATA(Y); LCD_WR_REG(X); //we can modify the character (the image become progressively red when we touch it), we might do the same for the background IOWR_16DIRECT(PIC_MEM_BASE,posTamper,0xF800); posTamper++; } } // Painter demo /*Clr_BUFFER_FLAG(); Display.interlace = 0; Display.bytes_per_pixel = 2; Display.color_depth = 16; Display.height = SCREEN_HEIGHT; Display.width = SCREEN_WIDTH; GUI(&Display, pTouch);*/ return 0; }
/************************************************ ** Touch_Adjust : ** Code for touch screen calibration ** Get 4 calibration parameters ************************************************/ void Touch_Adjust(void) { u8 i; u16 pos_temp[4][2]; u16 d1,d2; u32 tem1,tem2; float fac; while(1){ for(i=0;i<4;i++){ Refreshes_Screen(); if(i==0){ Drow_Touch_Point(20,20); Touch_GetXY(&pos_temp[0][0],&pos_temp[0][1],1); } else if(i == 1){ Drow_Touch_Point(220,20); Touch_GetXY(&pos_temp[1][0],&pos_temp[1][1],1); } else if(i == 2){ Drow_Touch_Point(20,300); Touch_GetXY(&pos_temp[2][0],&pos_temp[2][1],1); } else { Drow_Touch_Point(220,300); Touch_GetXY(&pos_temp[3][0],&pos_temp[3][1],1); } } tem1=abs(pos_temp[0][0]-pos_temp[1][0]); //x1-x2 tem2=abs(pos_temp[0][1]-pos_temp[1][1]); //y1-y2 tem1*=tem1; tem2*=tem2; d1=sqrt(tem1+tem2); tem1=abs(pos_temp[2][0]-pos_temp[3][0]); //x3-x4 tem2=abs(pos_temp[2][1]-pos_temp[3][1]); //y3-y4 tem1*=tem1; tem2*=tem2; d2=sqrt(tem1+tem2); fac=(float)d1/d2; if(fac<0.95||fac>1.05||d1==0||d2==0) { continue; } tem1=abs(pos_temp[0][0]-pos_temp[2][0]); //x1-x3 tem2=abs(pos_temp[0][1]-pos_temp[2][1]); //y1-y3 tem1*=tem1; tem2*=tem2; d1=sqrt(tem1+tem2); tem1=abs(pos_temp[1][0]-pos_temp[3][0]); //x2-x4 tem2=abs(pos_temp[1][1]-pos_temp[3][1]); //y2-y4 tem1*=tem1; tem2*=tem2; d2=sqrt(tem1+tem2); fac=(float)d1/d2; if(fac<0.95||fac>1.05) { continue; } tem1=abs(pos_temp[1][0]-pos_temp[2][0]); //x1-x3 tem2=abs(pos_temp[1][1]-pos_temp[2][1]); //y1-y3 tem1*=tem1; tem2*=tem2; d1=sqrt(tem1+tem2); tem1=abs(pos_temp[0][0]-pos_temp[3][0]); //x2-x4 tem2=abs(pos_temp[0][1]-pos_temp[3][1]); //y2-y4 tem1*=tem1; tem2*=tem2; d2=sqrt(tem1+tem2); fac=(float)d1/d2; if(fac<0.95||fac>1.05) { continue; } xfac=(float)220/(pos_temp[1][0]-pos_temp[0][0]); xoff=(240-xfac*(pos_temp[1][0]+pos_temp[0][0]))/2; yfac=(float)300/(pos_temp[2][1]-pos_temp[1][1]); yoff=(320-yfac*(pos_temp[2][1]+pos_temp[1][1]))/2; LCD_Clear(BLACK); break; } }