#include #include #include #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "grlib/grlib.h" #include "grlib/widget.h" #include "grlib/canvas.h" #include "grlib/pushbutton.h" #include "drivers/frame.h" #include "drivers/kentec320x240x16_ssd2119.h" #include "drivers/pinout.h" #include "drivers/touch.h" #include "inc/hw_ints.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/interrupt.h" #include "driverlib/timer.h" extern tCanvasWidget g_sBackground; extern tPushButtonWidget g_sPushBtn; extern tPushButtonWidget g_sPushReset; tContext g_sContext; uint32_t g_ui32Flags; const char Counter[6] = "Stoper"; char flagStart = 0; unsigned int msec = 0; unsigned int sec = 0; unsigned int min = 0; unsigned int hrs = 0; char charTime[] = "00:00:00.0 "; void stoperTick(void) { msec++; if (msec == 10){ msec = 0; sec++; } else if (sec == 60){ sec = 0; min++; } else if (min == 60){ min = 0; hrs++; } } //// dfd dfs ds // void Timer0IntHandler(void) { ROM_TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT); // Clear the timer interrupt. if(flagStart == 1){ stoperTick(); // zliczanie ms } } void OnButtonPress(tWidget *psWidget); // The canvas widget acting as the background to the display. void OnButtonReset(tWidget *psWidget); Canvas(g_sBackground, WIDGET_ROOT, 0, &g_sPushBtn, &g_sKentec320x240x16_SSD2119, 10, 25, 300, (240 - 25 -10), CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0); RectangularButton(g_sPushBtn, &g_sBackground, 0, &g_sPushReset, // The button used to hide or display the "Hello World" message. &g_sKentec320x240x16_SSD2119, 40, 140, 80, 40, (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT | PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY), ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite, g_psFontCmss22b, "START", 0, 0, 0, 0, OnButtonPress); RectangularButton(g_sPushReset, &g_sPushBtn, 0, 0, &g_sKentec320x240x16_SSD2119, 180, 140, 80, 40, (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT | PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY), ClrDarkRed, ClrRed, ClrWhite, ClrWhite, g_psFontCmss22b, "RESET", 0, 0, 0, 0, OnButtonReset); //***************************************************************************** //***************************************************************************** // // A global we use to keep track of whether or not the "Hello" widget is // currently visible. // //***************************************************************************** bool g_bHelloVisible = false; //***************************************************************************** // // The error routine that is called if the driver library encounters an error. // //***************************************************************************** #ifdef DEBUG void __error__(char *pcFilename, uint32_t ui32Line) { } #endif //***************************************************************************** // // This function is called by the graphics library widget manager in the // context of WidgetMessageQueueProcess whenever the user releases the // "Press Me!" button. We use this notification to display or hide the // "Hello!" widget. // // This is actually a rather inefficient way to accomplish this but it's // a good example of how to add and remove widgets dynamically. In // normal circumstances, you would likely leave the g_sHello widget // linked into the tree and merely add or remove the text by changing // its style then repainting. // // If using this dynamic add/remove strategy, another useful optimization // is to use a black canvas widget that covers the same area of the screen // as the widgets that you will be adding and removing. If this is the used // as the point in the tree where the subtree is added or removed, you can // repaint just the desired area by repainting the black canvas rather than // repainting the whole tree. // //***************************************************************************** void OnButtonPress(tWidget *psWidget) // funkcja obslugujaca przycisk start { g_bHelloVisible = !g_bHelloVisible; if(g_bHelloVisible) { WidgetRemove((tWidget *)&g_sPushReset); flagStart = 1; PushButtonTextSet(&g_sPushBtn, "STOP"); WidgetPaint(WIDGET_ROOT); } else { WidgetAdd((tWidget *)&g_sPushBtn, (tWidget *)&g_sPushReset); flagStart = 0; PushButtonTextSet(&g_sPushBtn, "START"); WidgetPaint((tWidget *)&g_sPushBtn); } } void OnButtonReset(tWidget *psWidget) // funkcja obslugujaca przycisk reset { flagStart = 0; msec = 0; sec = 0; min = 0; hrs = 0; } int main(void) { // Run from the PLL at 120 MHz. uint32_t ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // Konfiguracja wyswietlacza PinoutSet(); // Configure the device pins. Kentec320x240x16_SSD2119Init(ui32SysClock); // Initialize the display driver. GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // Initialize the graphics context. FrameDraw(&g_sContext, "StOpErEk"); // Draw the application frame. TouchScreenInit(ui32SysClock); // Initialize the touch screen driver. TouchScreenCallbackSet(WidgetPointerMessage); // Set the touch screen event handler. WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground); // Add the compile-time defined widgets to the widget tree. WidgetPaint(WIDGET_ROOT); // Paint the widget tree to make sure they all appear on the display. // Konfiguracja timera ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); ROM_IntMasterEnable(); // Enable processor interrupts. ROM_TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC); // Configure the two 32-bit periodic timers. ROM_TimerLoadSet(TIMER0_BASE, TIMER_A, ui32SysClock/10); ROM_IntEnable(INT_TIMER0A); // Setup the interrupts for the timer timeouts. ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER0_BASE, TIMER_A); // Enable the timers while(1) { usprintf(charTime,"%02u:%02u:%02u.%01u ",hrs,min,sec,msec); // Convert unsigned ints to one char GrStringDraw(&g_sContext, charTime, -1, 140, 55, 1); // Draw a stopwatch result WidgetMessageQueueProcess(); // Process any messages from or for the widgets. } }