Facebook
From Corrupt Tortoise, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 324
  1. //*****************************************************************************
  2. //
  3. // hello.c - Simple hello world example.
  4. //
  5. // Maciej Kucia July 2013
  6. //
  7. // Texas Instruments (TI) is supplying this software for use solely and
  8. // exclusively on TI's microcontroller products. The software is owned by
  9. // TI and/or its suppliers, and is protected under applicable copyright
  10. // laws. You may not combine this software with "viral" open-source
  11. // software in order to form a larger program.
  12. //
  13. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  14. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  15. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  16. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  17. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  18. // DAMAGES, FOR ANY REASON WHATSOEVER.
  19. //
  20. // This is part of revision 1.0 of the EK-LM4F232 Firmware Package.
  21. //
  22. //*****************************************************************************
  23.  
  24. #include <stdint.h>
  25. #include <stdio.h>
  26. #include <stdbool.h>
  27. #include "inc/hw_memmap.h" //Memory mapping of the used device (maps all the pins ports etc. to specific numbers)
  28. #include "driverlib/fpu.h" //Routines for manipulating the floating-point unit in the Cortex-M processor.
  29. #include "driverlib/sysctl.h" //Driver for the system controller
  30. #include "driverlib/rom.h"              //Macros to facilitate calling functions in the ROM
  31. #include "driverlib/pin_map.h" //Mapping of peripherals to pins for all parts
  32. #include "driverlib/uart.h"     // Driver for the UART
  33. #include "grlib/grlib.h"        //Prototypes for the low level primitives provided by the graphics library
  34. #include "drivers/ili9341_240x320x262K.h" //Display driver for the MULTI-INNO TECHNOLOGY
  35.                                                                                 // MI0283QT-9 TFT display with an ILI9341 controller.
  36. #include "utils/uartstdio.h"            //Prototypes for the UART console functions.
  37. #include "inc/hw_types.h"
  38. #include "inc/hw_gpio.h"
  39. #include "driverlib/gpio.h"
  40. #include "driverlib/systick.h"
  41. #include "drivers/touch.h"
  42.  
  43.  
  44.  
  45. #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
  46. #define WIDGET_MSG_PTR_DOWN 0x00000002
  47. #define WIDGET_MSG_PTR_UP 0x00000004
  48.  
  49.  
  50.  
  51. //*****************************************************************************
  52. //
  53. // Global system tick counter holds elapsed time since the application started
  54. // expressed in 100ths of a second.
  55. //
  56. //*****************************************************************************
  57. volatile uint32_t g_ui32SysTickCount;
  58.  
  59.  
  60.  
  61. int_fast32_t i32CenterX, i32CenterY;
  62. //int i32CenterX_temp = 100;
  63. //int i32CenterY_temp = 100;
  64. tContext sContext;
  65. tRectangle sRect;
  66. tRectangle sRect1;
  67. tRectangle sRect2;
  68. tRectangle sRect3;
  69.  
  70.  
  71.  
  72. //*****************************************************************************
  73. //
  74. // This is the interrupt handler for the SysTick interrupt.  It is used to
  75. // update our local tick count which, in turn, is used to check for transmit
  76. // timeouts.
  77. //
  78. //*****************************************************************************
  79. void
  80. SysTickIntHandler(void)
  81. {
  82.     g_ui32SysTickCount++;
  83. }
  84.  
  85.  
  86. //*****************************************************************************
  87. //
  88. //! Callback for calibration process
  89. //!
  90. //! \param X - x coordinate of point to check
  91. //! \param Y - y coordinate of point to check
  92. //! \param cX - x coordinate of circle center
  93. //! \param cY - y coordinate of circle center
  94. //! \param radius - circle radius
  95. //!
  96. //! \return boolean true if coordinates are within circle
  97. //
  98. //*****************************************************************************
  99. inline bool IsInCircle(int32_t X,int32_t Y,int32_t cX,int32_t cY,int32_t radius)
  100. {
  101.         return ( (X-cX)*(X-cX) + (Y-cY)*(Y-cY) < (radius*radius) );
  102. }
  103.  
  104.  
  105.  
  106. //*****************************************************************************
  107. //
  108. //! Callback for calibration process
  109. //!
  110. //! \param ulMessage is type of event
  111. //! \param lX is a x location of touch
  112. //! \param lY is a y location of cross center
  113. //!
  114. //! \return None.
  115. //
  116. //*****************************************************************************
  117.  
  118. int32_t TouchCallback(uint32_t ulMessage, int32_t lX, int32_t lY)
  119. {
  120.  
  121.         i32CenterX = lX;
  122.         i32CenterY = lY;
  123.  
  124.  
  125.         if (ulMessage == WIDGET_MSG_PTR_DOWN && lX>20 && lX<140 && lY>20 && lY<100)
  126.         {
  127.                                         sRect.i16XMin = 20;
  128.                                         sRect.i16YMin = 20;
  129.                                         sRect.i16XMax = 140;
  130.                                         sRect.i16YMax = 100;
  131.                                 GrContextBackgroundSet(&sContext, ClrWhite);
  132.                                 GrContextForegroundSet(&sContext, ClrGreen);
  133.                                 GrRectFill(&sContext, &sRect);
  134.  
  135.                                 GrContextForegroundSet(&sContext, ClrWhite);
  136.                                 GrContextFontSet(&sContext, g_psFontCmsc18);
  137.                                 GrStringDrawCentered(&sContext, "Pole D", -1,60,60,0);
  138.  
  139.  
  140.         }
  141.  
  142.         if (ulMessage == WIDGET_MSG_PTR_UP && lX>50 && lX<150 && lY>50 && lY<120)
  143.                 {
  144.                                                 sRect.i16XMin = 20;
  145.                                         sRect.i16YMin = 20;
  146.                                         sRect.i16XMax = 140;
  147.                                         sRect.i16YMax = 100;
  148.                                         GrContextBackgroundSet(&sContext, ClrWhite);
  149.                                         GrContextForegroundSet(&sContext, ClrBlack);
  150.                                         GrRectFill(&sContext, &sRect);
  151.  
  152.  
  153.  
  154.  
  155.                 }
  156.  
  157.  
  158.         if (ulMessage == WIDGET_MSG_PTR_DOWN && lX>180 && lX<300 && lY>20 && lY<100)
  159.                 {
  160.                                         sRect1.i16XMin = 180;
  161.                                         sRect1.i16YMin = 20;
  162.                                         sRect1.i16XMax = 300;
  163.                                         sRect1.i16YMax = 100;
  164.                                 GrContextBackgroundSet(&sContext, ClrWhite);
  165.                                 GrContextForegroundSet(&sContext, ClrBlue);
  166.                                 GrRectFill(&sContext, &sRect);
  167.  
  168.  
  169.  
  170.                 }
  171.  
  172.         if (ulMessage == WIDGET_MSG_PTR_UP && lX>180 && lX<300 && lY>20 && lY<100)
  173.                 {
  174.                                         sRect1.i16XMin = 180;
  175.                                         sRect1.i16YMin = 20;
  176.                                         sRect1.i16XMax = 300;
  177.                                         sRect1.i16YMax = 100;
  178.                                 GrContextBackgroundSet(&sContext, ClrWhite);
  179.                                 GrContextForegroundSet(&sContext, ClrBlack);
  180.                                 GrRectFill(&sContext, &sRect);
  181.  
  182.  
  183.  
  184.                 }
  185.  
  186.         if (ulMessage == WIDGET_MSG_PTR_DOWN && lX>180 && lX<300 && lY>140 && lY<220)
  187.                 {
  188.                                 sRect2.i16XMin = 180;
  189.                         sRect2.i16YMin = 140;
  190.                         sRect2.i16XMax = 300;
  191.                         sRect2.i16YMax = 220;
  192.                                 GrContextBackgroundSet(&sContext, ClrWhite);
  193.                                 GrContextForegroundSet(&sContext, ClrRed);
  194.                                 GrRectFill(&sContext, &sRect);
  195.  
  196.  
  197.  
  198.                 }
  199.  
  200.  
  201.         if (ulMessage == WIDGET_MSG_PTR_UP && lX>180 && lX<300 && lY>140 && lY<220)
  202.                         {
  203.                                 sRect2.i16XMin = 180;
  204.                         sRect2.i16YMin = 140;
  205.                         sRect2.i16XMax = 300;
  206.                         sRect2.i16YMax = 220;
  207.                                 GrContextBackgroundSet(&sContext, ClrWhite);
  208.                                 GrContextForegroundSet(&sContext, ClrBlack);
  209.                                 GrRectFill(&sContext, &sRect);
  210.  
  211.  
  212.  
  213.                         }
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229. /*
  230.         int32_t ctrX = GrContextDpyWidthGet(&sContext)/2;
  231.         int32_t ctrY = GrContextDpyHeightGet(&sContext)/2;
  232.  
  233.         int32_t ctrDisX = lX - ctrX ;
  234.         int32_t ctrDisY = lY - ctrY;
  235.  
  236.         int32_t corX = lX*0.18;
  237.         int32_t corY = lY*0.18;
  238.  
  239.  
  240.         char fullText[30];
  241.  
  242.         sprintf(fullText,"Pressed from center %d %d",ctrDisX, ctrDisY);
  243.         GrContextForegroundSet(&sContext, ClrGreen);
  244.         GrStringDrawCentered(&sContext, fullText, -1, i32CenterX, i32CenterY-25, 0);
  245.         sprintf(fullText,"Pressed from corner (in mm) %d %d",corX, corY);
  246.         GrContextForegroundSet(&sContext, ClrGreen);
  247.         GrStringDrawCentered(&sContext, fullText, -1, i32CenterX, i32CenterY+25, 0);
  248.  
  249.         SysCtlDelay(SysCtlClockGet()/50);
  250.  
  251.         sprintf(fullText,"Pressed from center %d %d",ctrDisX, ctrDisY);
  252.         GrContextForegroundSet(&sContext, ClrWhite);
  253.         GrStringDrawCentered(&sContext, fullText, -1, i32CenterX, i32CenterY-25, 0);
  254.         sprintf(fullText,"Pressed from corner (in mm) %d %d",corX, corY);
  255.         GrContextForegroundSet(&sContext, ClrWhite);
  256.         GrStringDrawCentered(&sContext, fullText, -1, i32CenterX, i32CenterY+25, 0);
  257.  
  258.  
  259. */
  260.  
  261.  
  262.  
  263.  
  264.  
  265.         return 0;
  266. }
  267.  
  268.  
  269.  
  270. int
  271. main(void)
  272. {
  273.  
  274.     //
  275.     //
  276.     // Enable lazy stacking for interrupt handlers.  This allows floating-point
  277.     // instructions to be used within interrupt handlers, but at the expense of
  278.     // extra stack usage.
  279.     //
  280.     ROM_FPULazyStackingEnable();
  281.  
  282.     //
  283.     // Set the clocking to run directly from the crystal.
  284.     //
  285. //    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
  286. //                       SYSCTL_OSC_MAIN);
  287.  
  288.     ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
  289.                        SYSCTL_XTAL_8MHZ);
  290.  
  291.     //
  292.     // Initialize the display driver.
  293.     //
  294.     ILI9341_240x320x262K_Init();
  295.  
  296.     //
  297.     // Initialize the graphics context.
  298.     //
  299.     GrContextInit(&sContext, &g_sILI9341_240x320x262K);
  300.  
  301.     //
  302.     // Initialize touchscreen driver
  303.     //
  304.  
  305.  
  306.  
  307.  
  308.         tContext sContext;
  309.         tRectangle sRect;
  310.         tRectangle sRect1;
  311.         tRectangle sRect2;
  312.         tRectangle sRect3;
  313.  
  314.         ROM_FPULazyStackingEnable();
  315.  
  316.         ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
  317.  
  318.         ILI9341_240x320x262K_Init();
  319.  
  320.         GrContextInit(&sContext, &g_sILI9341_240x320x262K);
  321.  
  322.  
  323.  
  324.         //GrContextForegroundSet(&sContext, ClrWhite);
  325.         //GrContextFontSet(&sContext, g_psFontFixed6x8);
  326.         //GrStringDraw(&sContext, "Texas", -1,218,222,0);
  327.  
  328.         //
  329.         // Flush any cached drawing operations.
  330.         //
  331.         GrFlush(&sContext);
  332.  
  333.         //
  334.         // We are finished. Hang around doing nothing.
  335.         //
  336.         unsigned long ii = 1;
  337.         //while(1)
  338.         //{
  339.         //
  340.         // Draw RGB rectangles
  341.         //
  342.         sRect.i16XMin = 20;
  343.         sRect.i16YMin = 20;
  344.         sRect.i16XMax = 140;
  345.         sRect.i16YMax = 100;
  346.  
  347.         sRect1.i16XMin = 180;
  348.         sRect1.i16YMin = 20;
  349.         sRect1.i16XMax = 300;
  350.         sRect1.i16YMax = 100;
  351.  
  352.         sRect2.i16XMin = 180;
  353.         sRect2.i16YMin = 140;
  354.         sRect2.i16XMax = 300;
  355.         sRect2.i16YMax = 220;
  356.  
  357.         sRect3.i16XMin = 20;
  358.         sRect3.i16YMin = 140;
  359.         sRect3.i16XMax = 140;
  360.         sRect3.i16YMax = 220;
  361.  
  362.         //      unsigned long temp_color = ColorTranslate(void *pvDisplayData, ii);
  363.         ii=ii+0.01;
  364.  
  365.         GrContextForegroundSet(&sContext, ClrRed);
  366.         GrRectFill(&sContext, &sRect);
  367.  
  368.         GrContextForegroundSet(&sContext, ClrWhite);
  369.         GrContextFontSet(&sContext, g_psFontCm14);
  370.         GrStringDraw(&sContext, "Texas", -1,60,60,0);
  371.  
  372.         //ROM_SysCtlDelay(ROM_SysCtlClockGet()/2);
  373.  
  374.         GrContextForegroundSet(&sContext, ClrGreen);
  375.         GrRectFill(&sContext, &sRect1);
  376.  
  377.         GrContextForegroundSet(&sContext, ClrWhite);
  378.         GrContextFontSet(&sContext, g_psFontCmsc14);
  379.         GrStringDraw(&sContext, "Texas", -1,220,60,0);
  380.         //ROM_SysCtlDelay(ROM_SysCtlClockGet()/2);
  381.  
  382.         GrContextForegroundSet(&sContext, ClrBlue);
  383.         GrRectFill(&sContext, &sRect2);
  384.  
  385.         GrContextForegroundSet(&sContext, ClrWhite);
  386.         GrContextFontSet(&sContext, g_psFontCmss14);
  387.         GrStringDraw(&sContext, "Texas", -1,220,180,0);
  388.  
  389.         //ROM_SysCtlDelay(ROM_SysCtlClockGet()/2);
  390.  
  391.         GrContextForegroundSet(&sContext, ClrYellow);
  392.         GrRectFill(&sContext, &sRect3);
  393.  
  394.         GrContextForegroundSet(&sContext, ClrBlack);
  395.         GrContextFontSet(&sContext, g_psFontCmss14i);
  396.         GrStringDraw(&sContext, "Texas", -1,60,180,0);
  397.  
  398.                 //ROM_SysCtlDelay(ROM_SysCtlClockGet()/2);
  399.  
  400.         //}
  401.  
  402.                 TouchScreenInit();
  403.             //TouchScreenCalibrate(&sContext);
  404.             TouchScreenCallbackSet(TouchCallback);
  405.             GrContextFontSet(&sContext, g_psFontCm12);
  406.  
  407.     while(1)
  408.     {
  409.  
  410.     }
  411.  
  412. }
  413.