//***************************************************************************** // // hello.c - Simple hello world example. // // Maciej Kucia July 2013 // // Texas Instruments (TI) is supplying this software for use solely and // exclusively on TI's microcontroller products. The software is owned by // TI and/or its suppliers, and is protected under applicable copyright // laws. You may not combine this software with "viral" open-source // software in order to form a larger program. // // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL // DAMAGES, FOR ANY REASON WHATSOEVER. // // This is part of revision 1.0 of the EK-LM4F232 Firmware Package. // //***************************************************************************** #include #include #include #include "inc/hw_memmap.h" //Memory mapping of the used device (maps all the pins ports etc. to specific numbers) #include "driverlib/fpu.h" //Routines for manipulating the floating-point unit in the Cortex-M processor. #include "driverlib/sysctl.h" //Driver for the system controller #include "driverlib/rom.h" //Macros to facilitate calling functions in the ROM #include "driverlib/pin_map.h" //Mapping of peripherals to pins for all parts #include "driverlib/uart.h" // Driver for the UART #include "grlib/grlib.h" //Prototypes for the low level primitives provided by the graphics library #include "drivers/ili9341_240x320x262K.h" //Display driver for the MULTI-INNO TECHNOLOGY // MI0283QT-9 TFT display with an ILI9341 controller. #include "utils/uartstdio.h" //Prototypes for the UART console functions. #include "inc/hw_types.h" #include "inc/hw_gpio.h" #include "driverlib/gpio.h" #include "driverlib/systick.h" #include "drivers/touch.h" #define GPIO_PINS_ALL GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3|GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7 #define WIDGET_MSG_PTR_DOWN 0x00000002 #define WIDGET_MSG_PTR_UP 0x00000004 //***************************************************************************** // // Global system tick counter holds elapsed time since the application started // expressed in 100ths of a second. // //***************************************************************************** volatile uint32_t g_ui32SysTickCount; int_fast32_t i32CenterX, i32CenterY; //int i32CenterX_temp = 100; //int i32CenterY_temp = 100; tContext sContext; tRectangle sRect; tRectangle sRect1; tRectangle sRect2; tRectangle sRect3; //***************************************************************************** // // This is the interrupt handler for the SysTick interrupt. It is used to // update our local tick count which, in turn, is used to check for transmit // timeouts. // //***************************************************************************** void SysTickIntHandler(void) { g_ui32SysTickCount++; } //***************************************************************************** // //! Callback for calibration process //! //! \param X - x coordinate of point to check //! \param Y - y coordinate of point to check //! \param cX - x coordinate of circle center //! \param cY - y coordinate of circle center //! \param radius - circle radius //! //! \return boolean true if coordinates are within circle // //***************************************************************************** inline bool IsInCircle(int32_t X,int32_t Y,int32_t cX,int32_t cY,int32_t radius) { return ( (X-cX)*(X-cX) + (Y-cY)*(Y-cY) < (radius*radius) ); } //***************************************************************************** // //! Callback for calibration process //! //! \param ulMessage is type of event //! \param lX is a x location of touch //! \param lY is a y location of cross center //! //! \return None. // //***************************************************************************** int32_t TouchCallback(uint32_t ulMessage, int32_t lX, int32_t lY) { i32CenterX = lX; i32CenterY = lY; if (ulMessage == WIDGET_MSG_PTR_DOWN && lX>20 && lX<140 && lY>20 && lY<100) { sRect.i16XMin = 20; sRect.i16YMin = 20; sRect.i16XMax = 140; sRect.i16YMax = 100; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrGreen); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrWhite); GrContextFontSet(&sContext, g_psFontCmsc18); GrStringDrawCentered(&sContext, "Pole D", -1,60,60,0); } if (ulMessage == WIDGET_MSG_PTR_UP && lX>50 && lX<150 && lY>50 && lY<120) { sRect.i16XMin = 20; sRect.i16YMin = 20; sRect.i16XMax = 140; sRect.i16YMax = 100; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrBlack); GrRectFill(&sContext, &sRect); } if (ulMessage == WIDGET_MSG_PTR_DOWN && lX>180 && lX<300 && lY>20 && lY<100) { sRect1.i16XMin = 180; sRect1.i16YMin = 20; sRect1.i16XMax = 300; sRect1.i16YMax = 100; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrBlue); GrRectFill(&sContext, &sRect); } if (ulMessage == WIDGET_MSG_PTR_UP && lX>180 && lX<300 && lY>20 && lY<100) { sRect1.i16XMin = 180; sRect1.i16YMin = 20; sRect1.i16XMax = 300; sRect1.i16YMax = 100; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrBlack); GrRectFill(&sContext, &sRect); } if (ulMessage == WIDGET_MSG_PTR_DOWN && lX>180 && lX<300 && lY>140 && lY<220) { sRect2.i16XMin = 180; sRect2.i16YMin = 140; sRect2.i16XMax = 300; sRect2.i16YMax = 220; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrRed); GrRectFill(&sContext, &sRect); } if (ulMessage == WIDGET_MSG_PTR_UP && lX>180 && lX<300 && lY>140 && lY<220) { sRect2.i16XMin = 180; sRect2.i16YMin = 140; sRect2.i16XMax = 300; sRect2.i16YMax = 220; GrContextBackgroundSet(&sContext, ClrWhite); GrContextForegroundSet(&sContext, ClrBlack); GrRectFill(&sContext, &sRect); } /* int32_t ctrX = GrContextDpyWidthGet(&sContext)/2; int32_t ctrY = GrContextDpyHeightGet(&sContext)/2; int32_t ctrDisX = lX - ctrX ; int32_t ctrDisY = lY - ctrY; int32_t corX = lX*0.18; int32_t corY = lY*0.18; char fullText[30]; sprintf(fullText,"Pressed from center %d %d",ctrDisX, ctrDisY); GrContextForegroundSet(&sContext, ClrGreen); GrStringDrawCentered(&sContext, fullText, -1, i32CenterX, i32CenterY-25, 0); sprintf(fullText,"Pressed from corner (in mm) %d %d",corX, corY); GrContextForegroundSet(&sContext, ClrGreen); GrStringDrawCentered(&sContext, fullText, -1, i32CenterX, i32CenterY+25, 0); SysCtlDelay(SysCtlClockGet()/50); sprintf(fullText,"Pressed from center %d %d",ctrDisX, ctrDisY); GrContextForegroundSet(&sContext, ClrWhite); GrStringDrawCentered(&sContext, fullText, -1, i32CenterX, i32CenterY-25, 0); sprintf(fullText,"Pressed from corner (in mm) %d %d",corX, corY); GrContextForegroundSet(&sContext, ClrWhite); GrStringDrawCentered(&sContext, fullText, -1, i32CenterX, i32CenterY+25, 0); */ return 0; } int main(void) { // // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | // SYSCTL_OSC_MAIN); ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the display driver. // ILI9341_240x320x262K_Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sILI9341_240x320x262K); // // Initialize touchscreen driver // tContext sContext; tRectangle sRect; tRectangle sRect1; tRectangle sRect2; tRectangle sRect3; ROM_FPULazyStackingEnable(); ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); ILI9341_240x320x262K_Init(); GrContextInit(&sContext, &g_sILI9341_240x320x262K); //GrContextForegroundSet(&sContext, ClrWhite); //GrContextFontSet(&sContext, g_psFontFixed6x8); //GrStringDraw(&sContext, "Texas", -1,218,222,0); // // Flush any cached drawing operations. // GrFlush(&sContext); // // We are finished. Hang around doing nothing. // unsigned long ii = 1; //while(1) //{ // // Draw RGB rectangles // sRect.i16XMin = 20; sRect.i16YMin = 20; sRect.i16XMax = 140; sRect.i16YMax = 100; sRect1.i16XMin = 180; sRect1.i16YMin = 20; sRect1.i16XMax = 300; sRect1.i16YMax = 100; sRect2.i16XMin = 180; sRect2.i16YMin = 140; sRect2.i16XMax = 300; sRect2.i16YMax = 220; sRect3.i16XMin = 20; sRect3.i16YMin = 140; sRect3.i16XMax = 140; sRect3.i16YMax = 220; // unsigned long temp_color = ColorTranslate(void *pvDisplayData, ii); ii=ii+0.01; GrContextForegroundSet(&sContext, ClrRed); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrWhite); GrContextFontSet(&sContext, g_psFontCm14); GrStringDraw(&sContext, "Texas", -1,60,60,0); //ROM_SysCtlDelay(ROM_SysCtlClockGet()/2); GrContextForegroundSet(&sContext, ClrGreen); GrRectFill(&sContext, &sRect1); GrContextForegroundSet(&sContext, ClrWhite); GrContextFontSet(&sContext, g_psFontCmsc14); GrStringDraw(&sContext, "Texas", -1,220,60,0); //ROM_SysCtlDelay(ROM_SysCtlClockGet()/2); GrContextForegroundSet(&sContext, ClrBlue); GrRectFill(&sContext, &sRect2); GrContextForegroundSet(&sContext, ClrWhite); GrContextFontSet(&sContext, g_psFontCmss14); GrStringDraw(&sContext, "Texas", -1,220,180,0); //ROM_SysCtlDelay(ROM_SysCtlClockGet()/2); GrContextForegroundSet(&sContext, ClrYellow); GrRectFill(&sContext, &sRect3); GrContextForegroundSet(&sContext, ClrBlack); GrContextFontSet(&sContext, g_psFontCmss14i); GrStringDraw(&sContext, "Texas", -1,60,180,0); //ROM_SysCtlDelay(ROM_SysCtlClockGet()/2); //} TouchScreenInit(); //TouchScreenCalibrate(&sContext); TouchScreenCallbackSet(TouchCallback); GrContextFontSet(&sContext, g_psFontCm12); while(1) { } }