/* ** This function tells if a touch is detected. */ bool TouchIdle(LcdTouch_t* structure) { #ifdef UseWatchdog WDR(); #endif if(!structure) return false; //TouchScreen_Data_t* TouchReport = &structure->TouchResponse; unsigned char State1 = Cursor_NoAction; bool Return = false; signed int TouchX = -1, TouchY = -1; if(IsTSPress) { if(ignore_cnt > 1) { IsTSPress = 0; State1 = Cursor_Move; TouchCoOrdGet(structure, &TouchX, &TouchY); structure->TouchResponse.x1 = TouchX; structure->TouchResponse.y1 = TouchY; Return = true; }else { ignore_cnt++; IsTSPress = 0; } }else ignore_cnt = 0; if(structure->LastState1 == Cursor_NoAction && State1 == Cursor_Move) { structure->LastState1 = Cursor_Down; structure->TouchResponse.touch_event1 = Cursor_Down; } else if((structure->LastState1 == Cursor_Down || structure->LastState1 == Cursor_Move) && State1 == Cursor_Move) { structure->LastState1 = Cursor_Move; structure->TouchResponse.touch_event1 = Cursor_Move; } else if((structure->LastState1 == Cursor_Down || structure->LastState1 == Cursor_Move) && State1 == Cursor_NoAction) { structure->LastState1 = Cursor_Up; structure->TouchResponse.touch_event1 = Cursor_Up; ignored_touch = analog_touch_filter_level; dbidx = 0; } else if(structure->LastState1 == Cursor_Up && State1 == Cursor_NoAction) { structure->LastState1 = Cursor_NoAction; structure->TouchResponse.touch_event1 = Cursor_NoAction; ignored_touch = analog_touch_filter_level; dbidx = 0; structure->TouchResponse.x1 = -1; structure->TouchResponse.y1 = -1; } return Return; }
int main(void) { tRectangle sRect; unsigned int i = 0; unsigned char *src = (unsigned char *) palette_32b; unsigned char *dest = (unsigned char *) (g_pucBuffer+4); MMUConfigAndEnable(); // //Enable USB module clock // USB0ModuleClkConfig(); // //Enable DM timer 3 module clock // DMTimer3ModuleClkConfig(); // //Enbale touch screen module colock // TSCADCModuleClkConfig(); // //Enable touch screen ADC pinmux // TSCADCPinMuxSetUp(); // //Enbale USB interrupts // USBInterruptEnable(); // //Switch ON LCD back light // LCDBackLightEnable(); // //UDP Pin control // UPDNPinControl(); // //Delay timer setup // DelayTimerSetup(); // //Configures raster to display image // SetUpLCD(); // //Register touch scren interrupt // TouchIntRegister(); IntSystemEnable(SYS_INT_TINT3); IntPrioritySet(SYS_INT_TINT3, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_ADC_TSC_GENINT); IntPrioritySet(SYS_INT_ADC_TSC_GENINT, 0, AINTC_HOSTINT_ROUTE_IRQ); RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int)(g_pucBuffer+PALETTE_OFFSET), (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET, FRAME_BUFFER_0); RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int)(g_pucBuffer+PALETTE_OFFSET), (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET, FRAME_BUFFER_1); src = (unsigned char *) palette_32b; dest = (unsigned char *) (g_pucBuffer+PALETTE_OFFSET); // Copy palette info into buffer for( i = PALETTE_OFFSET; i < (PALETTE_SIZE+PALETTE_OFFSET); i++) { *dest++ = *src++; } GrOffScreen24BPPInit(&g_s35_480x272x24Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT); // Initialize a drawing context. GrContextInit(&g_sContext, &g_s35_480x272x24Display); /* enable End of frame interrupt */ RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS); /* enable raster */ RasterEnable(SOC_LCDC_0_REGS); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = 23; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, &g_sFontCm20); GrStringDrawCentered(&g_sContext, "usb-dev-mouse", -1, GrContextDpyWidthGet(&g_sContext) / 2, 10, 0); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 25; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = GrContextDpyHeightGet(&g_sContext) - BUTTON_HEIGHT - 2; GrContextForegroundSet(&g_sContext, ClrDarkGray); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrRed); GrRectDraw(&g_sContext, &sRect); // // Draw the buttons in their initial (unpressed)state. // UpdateDisplay(g_ucButtons, true); // //Initialize touch screen // TouchInit(); // //Touch screen Interrupt enbale // TouchIntEnable(); // //Touch Screen Enable // TouchEnable(); // // Initialize the mouse // USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); // // Drop into the main loop. // while(1) { // // Wait for USB configuration to complete. // while(!bConnected) { } // //Wait till someone touches the screen // while(!g_iTouch) { g_iTouch = TouchDetect(); } // //Loop here as long as someone moving the finger/stylus on the touch screen // do { // //If so, read the x and Y vlaue and give it to touch handler // TouchCoOrdGet(&g_lScreenX, &g_lScreenY); // //Call touch handler // TouchHandler(); }while(TouchDetect()); // //Touch is released // g_released = 1; // //Reset the button status // g_ucButtons = 0; // //Call the touch handler to update the release status // TouchHandler(); // //Reset the touch flag // g_iTouch = 0; } }
/* ** This function tells if a touch is detected. */ bool microe_touch_idle(LcdTouch_t* Touch) { if(!Touch) return false; MicroeTouch_t *MikroeTouch = Touch->UsrData; #ifdef UseWatchdog WDR(); #endif bool Return = false; if(MikroeTouch->touch_conv_finish) { MikroeTouch->touch_conv_finish = false; unsigned char State1 = Cursor_NoAction; signed int TouchX = -1, TouchY = -1; if(MikroeTouch->IsTSPress) { if(MikroeTouch->ignore_cnt > 1) { MikroeTouch->IsTSPress = 0; State1 = Cursor_Move; TouchCoOrdGet(Touch, &TouchX, &TouchY); Touch->TouchResponse.x1 = TouchX; Touch->TouchResponse.y1 = TouchY; if(Touch->pDisplay->LcdTimings->orientation == LCD_ORIENTATION_LANDSCAPE || Touch->pDisplay->LcdTimings->orientation == LCD_ORIENTATION_LANDSCAPE_FLIP) { Touch->TouchResponse.y1 = Touch->pDisplay->LcdTimings->X - Touch->TouchResponse.y1; signed int x1_Back = Touch->TouchResponse.x1; Touch->TouchResponse.x1 = Touch->TouchResponse.y1; Touch->TouchResponse.y1 = x1_Back; Touch->TouchResponse.x1 = Touch->pDisplay->LcdTimings->X - Touch->TouchResponse.x1; Touch->TouchResponse.y1 = Touch->pDisplay->LcdTimings->Y - Touch->TouchResponse.y1; } if(Touch->pDisplay->LcdTimings->orientation == LCD_ORIENTATION_PORTRAIT_FLIP || Touch->pDisplay->LcdTimings->orientation == LCD_ORIENTATION_LANDSCAPE_FLIP) { Touch->TouchResponse.x1 = Touch->pDisplay->LcdTimings->X - Touch->TouchResponse.x1; Touch->TouchResponse.y1 = Touch->pDisplay->LcdTimings->Y - Touch->TouchResponse.y1; } if(Touch->pDisplay->LcdTimings->orientation == LCD_ORIENTATION_LANDSCAPE || Touch->pDisplay->LcdTimings->orientation == LCD_ORIENTATION_LANDSCAPE_FLIP) { Touch->TouchResponse.x1 = Touch->pDisplay->LcdTimings->X - Touch->TouchResponse.x1; Touch->TouchResponse.y1 = Touch->pDisplay->LcdTimings->Y - Touch->TouchResponse.y1; } if(Touch->flip_x) Touch->TouchResponse.x1 = Touch->pDisplay->LcdTimings->X - Touch->TouchResponse.x1; if(Touch->flip_y) Touch->TouchResponse.y1 = Touch->pDisplay->LcdTimings->Y - Touch->TouchResponse.y1; Return = true; }else { MikroeTouch->ignore_cnt++; MikroeTouch->IsTSPress = 0; } }else MikroeTouch->ignore_cnt = 0; if(Touch->LastState1 == Cursor_NoAction && State1 == Cursor_Move) { Touch->LastState1 = Cursor_Down; Touch->TouchResponse.touch_event1 = Cursor_Down; } else if((Touch->LastState1 == Cursor_Down || Touch->LastState1 == Cursor_Move) && State1 == Cursor_Move) { Touch->LastState1 = Cursor_Move; Touch->TouchResponse.touch_event1 = Cursor_Move; } else if((Touch->LastState1 == Cursor_Down || Touch->LastState1 == Cursor_Move) && State1 == Cursor_NoAction) { Touch->LastState1 = Cursor_Up; Touch->TouchResponse.touch_event1 = Cursor_Up; MikroeTouch->ignored_touch = ANALOG_TOUCH_FILTER_LEVEL; MikroeTouch->dbidx = 0; } else if(Touch->LastState1 == Cursor_Up && State1 == Cursor_NoAction) { Touch->LastState1 = Cursor_NoAction; Touch->TouchResponse.touch_event1 = Cursor_NoAction; MikroeTouch->ignored_touch = ANALOG_TOUCH_FILTER_LEVEL; MikroeTouch->dbidx = 0; Touch->TouchResponse.x1 = -1; Touch->TouchResponse.y1 = -1; } } return Return; }