//*****************************************************************************
//
//! Performs the sliding menu operation, in response to the "right" button.
//!
//! \param pWidget is a pointer to the slide menu widget to move to the right.
//!
//! This function will respond to the "right" key/button event.  The right
//! button is used to select the next menu level below the current menu item,
//! or a widget that is activated by the menu item.  The effect is that the
//! menu itself slides off to the left, and the new menu or widget slides in
//! from the right.
//!
//! This function repeatedly draws the menu onto the display until the sliding
//! animation is finished and will not return to the caller until then.  This
//! function is usually called from the thread context of
//! WidgetMessageQueueProcess().
//!
//! \return Returns a non-zero value if the menu was moved or was not moved
//! because it is already at the last position.  If a child widget is active
//! then this function does nothing and returns a 0.
//
//*****************************************************************************
static long
SlideMenuRight(tWidget *pWidget)
{
    tSlideMenuWidget *pMenuWidget;
    tSlideMenu *pMenu;
    tSlideMenu *pChildMenu;
    tContext sContext;
    tWidget *pChildWidget;
    unsigned int uX;
    unsigned long ulMenuWidth;

    //
    // If this menu widget has a child widget, that means the child widget
    // is in control of the display, and there is nothing to do here.
    //
    if(pWidget->pChild)
    {
        return(0);
    }

    //
    // Get handy pointers to the menu widget, and the current menu, and the
    // child menu and widget if they exist.
    //
    pMenuWidget = (tSlideMenuWidget *)pWidget;
    pMenu = pMenuWidget->pSlideMenu;
    pChildMenu = pMenu->pSlideMenuItems[pMenu->ulFocusIndex].pChildMenu;
    pChildWidget = pMenu->pSlideMenuItems[pMenu->ulFocusIndex].pChildWidget;

    //
    // Initialize a context for the secondary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, pMenuWidget->pDisplayB);

    //
    // Render the current menu into off-screen buffer B.  This
    // will be the same menu appearance as is already being shown.
    //
    SlideMenuDraw(pMenuWidget, &sContext, 0);

    //
    // Now set up context for drawing into off-screen buffer A
    //
    GrContextInit(&sContext, pMenuWidget->pDisplayA);

    //
    // Process child menu of this menu item
    //
    if(pChildMenu)
    {
        //
        // Switch the active menu for this SlideMenuWidget to be the child
        // menu
        //
        pMenuWidget->pSlideMenu = pChildMenu;

        //
        // Draw the new (child) menu into off-screen buffer A
        //
        SlideMenuDraw(pMenuWidget, &sContext, 0);
    }

    //
    // Process child widget of this menu item.  This only happens if there
    // is no child menu.
    //
    else if(pChildWidget)
    {
        //
        // Call the widget activated callback function.  This will notify
        // the application that a child widget has been activated by the
        // menu system.
        //
        if(pMenuWidget->pfnActive)
        {
            pMenuWidget->pfnActive(pChildWidget,
                                   &pMenu->pSlideMenuItems[pMenu->ulFocusIndex],
                                   1);
        }

        //
        // Link the new child widget into this SlideMenuWidget so
        // it appears as a child to this widget.  Normally the menu widget
        // has no child widget.
        //
        pWidget->pChild = pChildWidget;
        pChildWidget->pParent = pWidget;

        //
        // Fill a rectangle with the new child widget background color.
        // This is done in off-screen buffer A.  When the menu slides off,
        // it will be replaced by a blank background that will then be
        // controlled by the new child widget.
        //
        GrContextForegroundSet(
            &sContext,
            pMenu->pSlideMenuItems[pMenu->ulFocusIndex].ulChildWidgetColor);
        GrRectFill(&sContext, &sContext.sClipRegion);

        //
        // Request a repaint for the child widget so it can draw itself once
        // the menu slide is done.
        //
        WidgetPaint(pChildWidget);
    }

    //
    // There is no child menu or child widget, so there is nothing to change
    // on the display.
    //
    else
    {
        return(1);
    }

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, pWidget->pDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(pWidget->sPosition));

    //
    // Get the width of the menu widget which is used in calculations below
    //
    ulMenuWidth = pMenuWidget->pDisplayA->usWidth;

    //
    // The following loop draws the two off-screen buffers onto the physical
    // display using a right-to-left-wipe.  This will provide an appearance
    // of sliding to the left.  The new child menu, or child widget background
    // will slide in from the right.  The "old" menu is being held in
    // off-screen buffer B and the new one is in buffer A.  So when we are
    // done, the correct image will be in buffer A.
    //
    for(uX = 0; uX <= ulMenuWidth; uX += 8)
    {
        GrImageDraw(&sContext, pMenuWidget->pDisplayB->pvDisplayData,
                    pWidget->sPosition.sXMin - uX, pWidget->sPosition.sYMin);
        GrImageDraw(&sContext, pMenuWidget->pDisplayA->pvDisplayData,
                    pWidget->sPosition.sXMin + ulMenuWidth - uX,
                    pWidget->sPosition.sYMin);
    }

    //
    // Return indication that we handled the key event.
    //
    return(1);
}
Beispiel #2
0
/**
    Task for updating the LCD display every 16ms.
*/
Void _task_LCD(UArg arg0, UArg arg1)
{
	// create the LCD context
	tContext g_sContext;

	// initialize LCD driver
	Kentec320x240x16_SSD2119Init(120000000);

	// initialize graphics context
	GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);

	// draw application frame
	FrameDraw(&g_sContext, "Festo Station");

	uint32_t EventPosted;

	DisplayMessage MessageObject;

	char StringBuffer[100];

	tRectangle ClearRect;
	ClearRect.i16XMax = 320;
	ClearRect.i16XMin = 0;
	ClearRect.i16YMax = 240;
	ClearRect.i16YMin = 0;

	while(1)
	{
		EventPosted = Event_pend(DisplayEvents,
						Event_Id_NONE,
						Event_Id_00,
						10);

		if (EventPosted & Event_Id_00)
		{
			 if (Mailbox_pend(DisplayMailbox, &MessageObject, BIOS_NO_WAIT))
			 {
				GrContextForegroundSet(&g_sContext, 0x00);
				GrRectFill(&g_sContext, &ClearRect);
				if (MessageObject.ScreenID == 0)
				{
					FrameDraw(&g_sContext, "Festo Station - Stopped");

					GrStringDraw(&g_sContext, "Press [Up] to start.", 	-1, 10, 30, 0);
					GrStringDraw(&g_sContext, "Press [Down] to stop.", 	-1, 10, 50, 0);
					GrStringDraw(&g_sContext, "Press [Select] to calibrate.", 	-1, 10, 70, 0);


					//Footer
					sprintf(StringBuffer, "Uptime: %d [s]", MessageObject.uptimeSeconds);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 180, 0);

					sprintf(StringBuffer, "Time: %s", MessageObject.timeString);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 200, 0);
				}

				if (MessageObject.ScreenID == 1)
				{
					FrameDraw(&g_sContext, "Festo Station - Running");

					sprintf(StringBuffer, "Pieces processed = %d", MessageObject.piecesProcessed);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 30, 0);

					sprintf(StringBuffer, "Orange A/R =  %d/%d", MessageObject.orangeAccepted, MessageObject.orangeRejected);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 50, 0);

					sprintf(StringBuffer, "Black A/R =  %d/%d", MessageObject.blackAccepted, MessageObject.blackRejected);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 70, 0);

					sprintf(StringBuffer, "Plastic A/R =  %d/%d", MessageObject.plasticAccepted, MessageObject.plasticRejected);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 90, 0);


					sprintf(StringBuffer, "Metallic Accepted/Rejected =  %d/%d", MessageObject.metalAccepted, MessageObject.metalRejected);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 110, 0);

					sprintf(StringBuffer, "Pieces processed/min =  %.2f [p/min]", (float) 0.01 * MessageObject.piecesProcessedPerSecond);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 130, 0);

					//Footer
					sprintf(StringBuffer, "Uptime: %d [s]", MessageObject.uptimeSeconds);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 180, 0);

					sprintf(StringBuffer, "Time: %s", MessageObject.timeString);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 200, 0);
				}
				if (MessageObject.ScreenID == 2)
				{
					FrameDraw(&g_sContext, "Festo Station - Calibration");

					GrStringDraw(&g_sContext, "Initializing Calibration...", 	-1, 10, 30, 0);

					//Footer
					sprintf(StringBuffer, "Uptime: %d [s]", MessageObject.uptimeSeconds);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 180, 0);

					sprintf(StringBuffer, "Time: %s", MessageObject.timeString);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 200, 0);

				}
				if (MessageObject.ScreenID == 3)
				{
					FrameDraw(&g_sContext, "Festo Station - Calibration");
					//Body
					GrStringDraw(&g_sContext, "Put the standard piece on platform and", 	-1, 10, 30, 0);
					GrStringDraw(&g_sContext, "press [Select].", 	-1, 10, 50, 0);
					//Footer
					sprintf(StringBuffer, "Uptime: %d [s]", MessageObject.uptimeSeconds);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 180, 0);

					sprintf(StringBuffer, "Time: %s", MessageObject.timeString);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 200, 0);


				}
				if (MessageObject.ScreenID == 4)
				{
					FrameDraw(&g_sContext, "Festo Station - Calibration");
					//Body
					GrStringDraw(&g_sContext, "Set the height using [Up] and [Down].", 	-1, 10, 30, 0);
					GrStringDraw(&g_sContext, "When finished, press [Select].", 	-1, 10, 50, 0);
					sprintf(StringBuffer, "Height = %.2f [mm]",  (float) MessageObject.heightCalibrated / 10.0);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 120, 0);
					//Footer
					sprintf(StringBuffer, "Uptime: %d [s]", MessageObject.uptimeSeconds);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 180, 0);

					sprintf(StringBuffer, "Time: %s", MessageObject.timeString);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 200, 0);
				}

				if (MessageObject.ScreenID == 5)
				{
					FrameDraw(&g_sContext, "Festo Station - Calibration");

					//Body
					GrStringDraw(&g_sContext, "Set the upper limit using [Up] and", 	-1, 10, 30, 0);
					GrStringDraw(&g_sContext, "[Down]. When finished, press [Select].", 	-1, 10, 50, 0);
					sprintf(StringBuffer, "Upper Limit = %.2f [mm]", (float) MessageObject.upperHeightCalibrated / 10.0);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 120, 0);

					//Footer
					sprintf(StringBuffer, "Uptime: %d [s]", MessageObject.uptimeSeconds);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 180, 0);

					sprintf(StringBuffer, "Time: %s", MessageObject.timeString);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 200, 0);
				}
				if (MessageObject.ScreenID == 6)
				{
					FrameDraw(&g_sContext, "Festo Station - Calibration");

					//Body
					GrStringDraw(&g_sContext, "Set the lower limit using [Up] and", 	-1, 10, 30, 0);
					GrStringDraw(&g_sContext, "[Down]. When finished, press [Select].", 	-1, 10, 50, 0);
					sprintf(StringBuffer, "Lower Limit = %.2f [mm]", (float) MessageObject.lowerHeightCalibrated / 10.0);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 120, 0);


					//Footer
					sprintf(StringBuffer, "Uptime: %d [s]", MessageObject.uptimeSeconds);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 180, 0);

					sprintf(StringBuffer, "Time: %s", MessageObject.timeString);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 200, 0);
				}
				if (MessageObject.ScreenID == 7)
				{
					FrameDraw(&g_sContext, "Festo Station - Calibration");
					// Body
					GrStringDraw(&g_sContext, "The Festo Station is calibrated!", 	-1, 10, 30, 0);
					//Footer
					sprintf(StringBuffer, "Uptime: %d [s]", MessageObject.uptimeSeconds);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 180, 0);

					sprintf(StringBuffer, "Time: %s", MessageObject.timeString);
					GrStringDraw(&g_sContext, StringBuffer, 	-1, 10, 200, 0);
				}
			 }
		}
		Task_sleep(16);
	}
}
//*****************************************************************************
//
// A simple demonstration of the features of the Stellaris Graphics Library.
//
//*****************************************************************************
int
main(void)
{
    tContext sContext;
    tRectangle sRect;

    //
    // The FPU should be enabled because some compilers will use floating-
    // point registers, even for non-floating-point code.  If the FPU is not
    // enabled this will cause a fault.  This also ensures that floating-
    // point operations could be added to this application and would work
    // correctly and use the hardware floating-point unit.  Finally, lazy
    // stacking is enabled for interrupt handlers.  This allows floating-
    // point instructions to be used within interrupt handlers, but at the
    // expense of extra stack usage.
    //
    FPUEnable();
    FPULazyStackingEnable();

    //
    // Set the clock to 40Mhz derived from the PLL and the external oscillator
    //
    SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 23;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrRectDraw(&sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, &g_sFontCm20);
    GrStringDrawCentered(&sContext, "grlib demo", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 8, 0);

    //
    // Configure and enable uDMA
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
    SysCtlDelay(10);
    uDMAControlBaseSet(&sDMAControlTable[0]);
    uDMAEnable();

    //
    // Initialize the touch screen driver and have it route its messages to the
    // widget tree.
    //
    TouchScreenInit();
    TouchScreenCallbackSet(WidgetPointerMessage);

    //
    // Add the title block and the previous and next buttons to the widget
    // tree.
    //
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle);
    WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext);

    //
    // Add the first panel to the widget tree.
    //
    g_ulPanel = 0;
    WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels);
    CanvasTextSet(&g_sTitle, g_pcPanelNames[0]);

    //
    // Issue the initial paint request to the widgets.
    //
    WidgetPaint(WIDGET_ROOT);

    //
    // Loop forever handling widget messages.
    //
    while(1)
    {
        //
        // Process any messages in the widget message queue.
        //
        WidgetMessageQueueProcess();
    }
}
Beispiel #4
0
//*****************************************************************************
//
// Provides a scribble pad using the display on the Intelligent Display Module.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32SysClock;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "scribble");

    //
    // Print the instructions across the top of the screen in white with a 20
    // point san-serif font.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrContextFontSet(&g_sContext, g_psFontCmss20);
    GrStringDrawCentered(&g_sContext, "Touch the screen to draw", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2,
                         ((GrContextDpyHeightGet(&g_sContext) - 32) / 2) + 14,
                         0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&g_sContext);

    //
    // Set the color index to zero.
    //
    g_ui32ColorIdx = 0;

    //
    // Initialize the message queue we use to pass messages from the touch
    // interrupt handler context to the main loop for processing.
    //
    RingBufInit(&g_sMsgQueue, (uint8_t *)g_psMsgQueueBuffer,
                (MSG_QUEUE_SIZE * sizeof(tScribbleMessage)));

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit(ui32SysClock);

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(TSHandler);

    //
    // Loop forever.  All the drawing is done in the touch screen event
    // handler.
    //
    while(1) {
        //
        // Process any new touchscreen messages.
        //
        ProcessTouchMessages();
    }
}
Beispiel #5
0
//*****************************************************************************
//
// This is the generic callback from host stack.
//
// pvData is actually a pointer to a tEventInfo structure.
//
// This function will be called to inform the application when a USB event has
// occurred that is outside those related to the mouse device.  At this
// point this is used to detect unsupported devices being inserted and removed.
// It is also used to inform the application when a power fault has occurred.
// This function is required when the g_USBGenericEventDriver is included in
// the host controller driver array that is passed in to the
// USBHCDRegisterDrivers() function.
//
//*****************************************************************************
void
USBHCDEvents(void *pvData)
{
    tEventInfo *pEventInfo;
    tRectangle sRect;

    //
    // Fill the bottom rows of the screen with blue to create the status area.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = GrContextDpyHeightGet(&g_sContext) -
                  DISPLAY_BANNER_HEIGHT - 1;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = sRect.i16YMin + DISPLAY_BANNER_HEIGHT;

    GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Set the font for the status message
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);

    //
    // Cast this pointer to its actual type.
    //
    pEventInfo = (tEventInfo *)pvData;

    switch(pEventInfo->ui32Event)
    {
        //
        // New mouse detected.
        //
        case USB_EVENT_CONNECTED:
        {
            //
            // See if this is a HID Mouse.
            //
            if((USBHCDDevClass(pEventInfo->ui32Instance, 0) == USB_CLASS_HID) &&
               (USBHCDDevProtocol(pEventInfo->ui32Instance, 0) ==
                USB_HID_PROTOCOL_MOUSE))
            {
                //
                // Indicate that the mouse has been detected.
                //
                GrStringDrawCentered(&g_sContext, "Mouse Connected", -1,
                                     GrContextDpyWidthGet(&g_sContext) / 2,
                                     sRect.i16YMin + 5, 0);

                //
                // Set initial mouse information.
                //
                GrStringDrawCentered(&g_sContext, "0,0", -1,
                                     GrContextDpyWidthGet(&g_sContext) / 2, 26, 1);
                GrStringDrawCentered(&g_sContext, "000", -1,
                                     GrContextDpyWidthGet(&g_sContext) / 2, 46, 1);

                //
                // Proceed to the STATE_MOUSE_INIT state so that the main loop
                // can finish initialized the mouse since USBHMouseInit()
                // cannot be called from within a callback.
                //
                g_eUSBState = STATE_MOUSE_INIT;
            }

            break;
        }
        //
        // Unsupported device detected.
        //
        case USB_EVENT_UNKNOWN_CONNECTED:
        {
            GrStringDrawCentered(&g_sContext, "Unknown Device", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2,
                                 sRect.i16YMin + 5, 0);
            //
            // An unknown device was detected.
            //
            g_eUSBState = STATE_UNKNOWN_DEVICE;

            break;
        }
        //
        // Device has been unplugged.
        //
        case USB_EVENT_DISCONNECTED:
        {
            //
            // Indicate that the device has been disconnected.
            //
            GrStringDrawCentered(&g_sContext, "No Device", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2,
                                 sRect.i16YMin + 5, 0);

            //
            // Reset the mouse information.
            //
            GrStringDrawCentered(&g_sContext, "   -,-   ", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2, 26, 1);
            GrStringDrawCentered(&g_sContext, "---", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2, 46, 1);

            //
            // Change the state so that the main loop knows that the device is
            // no longer present.
            //
            g_eUSBState = STATE_NO_DEVICE;

            //
            // Reset the button state.
            //
            g_ui32Buttons = 0;

            break;
        }
        //
        // Power Fault has occurred.
        //
        case USB_EVENT_POWER_FAULT:
        {
            //
            // Indicate that there has been a power fault.
            //
            GrStringDrawCentered(&g_sContext, "Power Fault", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2,
                                 sRect.i16YMin + 5, 0);

            //
            // Reset the mouse information.
            //
            GrStringDrawCentered(&g_sContext, "   -,-   ", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2, 26, 1);
            GrStringDrawCentered(&g_sContext, "---", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2, 46, 1);

            //
            // No power means no device is present.
            //
            g_eUSBState = STATE_POWER_FAULT;

            break;
        }

        default:
        {
            break;
        }
    }
}
Beispiel #6
0
//*****************************************************************************
//
// Handles paint requests for the introduction canvas widget.
//
//*****************************************************************************
void
OnIntroPaint(tWidget *psWidget, tContext *psContext)
{
	tRectangle sRect;

	//
    // Display the introduction text in the canvas.
    //
    GrContextFontSet		( psContext, g_psFontCm16);
    GrContextForegroundSet	( psContext, ClrSilver);

    GrStringDraw(psContext, "OUTPUTS", 	-1, 125, LOC_Y_0UTPUTS-50, 0);
    GrStringDraw(psContext, "0", 		-1, LOC_X_0-4, LOC_Y_0UTPUTS-35, 0);
    GrStringDraw(psContext, "1", 		-1, LOC_X_1-4, LOC_Y_0UTPUTS-35, 0);
    GrStringDraw(psContext, "2", 		-1, LOC_X_2-4, LOC_Y_0UTPUTS-35, 0);
    GrStringDraw(psContext, "3", 		-1, LOC_X_3-4, LOC_Y_0UTPUTS-35, 0);
    GrStringDraw(psContext, "4", 		-1, LOC_X_4-4, LOC_Y_0UTPUTS-35, 0);
    GrStringDraw(psContext, "5", 		-1, LOC_X_5-4, LOC_Y_0UTPUTS-35, 0);
    GrStringDraw(psContext, "6", 		-1, LOC_X_6-4, LOC_Y_0UTPUTS-35, 0);
    GrStringDraw(psContext, "7", 		-1, LOC_X_7-4, LOC_Y_0UTPUTS-35, 0);

    WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sPushBtn_0);
    WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sPushBtn_1);
    WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sPushBtn_2);
    WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sPushBtn_3);
    WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sPushBtn_4);
    WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sPushBtn_5);
    WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sPushBtn_6);
    WidgetAdd((tWidget *)&g_sBackground, (tWidget *)&g_sPushBtn_7);


	GrStringDraw(psContext, "INPUTS", 	-1, 130, LOC_Y_INPUTS-50, 0);
    GrStringDraw(psContext, "0", 		-1, LOC_X_0-4, LOC_Y_INPUTS-35, 0);
    GrStringDraw(psContext, "1", 		-1, LOC_X_1-4, LOC_Y_INPUTS-35, 0);
    GrStringDraw(psContext, "2", 		-1, LOC_X_2-4, LOC_Y_INPUTS-35, 0);
    GrStringDraw(psContext, "3", 		-1, LOC_X_3-4, LOC_Y_INPUTS-35, 0);
    GrStringDraw(psContext, "4", 		-1, LOC_X_4-4, LOC_Y_INPUTS-35, 0);
    GrStringDraw(psContext, "5", 		-1, LOC_X_5-4, LOC_Y_INPUTS-35, 0);
    GrStringDraw(psContext, "6", 		-1, LOC_X_6-4, LOC_Y_INPUTS-35, 0);
    GrStringDraw(psContext, "7", 		-1, LOC_X_7-4, LOC_Y_INPUTS-35, 0);	
	
	//Draw all INPUT status circles
	//TBD Cant get a loop to work for this for some reason
	GrContextForegroundSet( psContext, ClrCyan);
    if ( input_status[0] == INPUT_STATUS_IS_ONE ){
    	GrContextForegroundSet( psContext, ClrRed);
    }	
	GrCircleFill( psContext, LOC_X_0, LOC_Y_INPUTS, 15);

	GrContextForegroundSet( psContext, ClrCyan);
    if ( input_status[1] == INPUT_STATUS_IS_ONE ){
    	GrContextForegroundSet( psContext, ClrRed);
    }	
	GrCircleFill( psContext, LOC_X_1, LOC_Y_INPUTS, 15);	

	GrContextForegroundSet( psContext, ClrCyan);
    if ( input_status[2] == INPUT_STATUS_IS_ONE ){
    	GrContextForegroundSet( psContext, ClrRed);
    }	
	GrCircleFill( psContext, LOC_X_2, LOC_Y_INPUTS, 15);

	GrContextForegroundSet( psContext, ClrCyan);
    if ( input_status[3] == INPUT_STATUS_IS_ONE ){
    	GrContextForegroundSet( psContext, ClrRed);
    }	
	GrCircleFill( psContext, LOC_X_3, LOC_Y_INPUTS, 15);	
	
	GrContextForegroundSet( psContext, ClrCyan);
    if ( input_status[4] == INPUT_STATUS_IS_ONE ){
    	GrContextForegroundSet( psContext, ClrRed);
    }	
	GrCircleFill( psContext, LOC_X_4, LOC_Y_INPUTS, 15);

	GrContextForegroundSet( psContext, ClrCyan);
    if ( input_status[5] == INPUT_STATUS_IS_ONE ){
    	GrContextForegroundSet( psContext, ClrRed);
    }	
	GrCircleFill( psContext, LOC_X_5, LOC_Y_INPUTS, 15);	

	GrContextForegroundSet( psContext, ClrCyan);
    if ( input_status[6] == INPUT_STATUS_IS_ONE ){
    	GrContextForegroundSet( psContext, ClrRed);
    }	
	GrCircleFill( psContext, LOC_X_6, LOC_Y_INPUTS, 15);

	GrContextForegroundSet( psContext, ClrCyan);
    if ( input_status[7] == INPUT_STATUS_IS_ONE ){
    	GrContextForegroundSet( psContext, ClrRed);
    }	
	GrCircleFill( psContext, LOC_X_7, LOC_Y_INPUTS, 15);


	GrContextForegroundSet	( psContext, ClrSilver);
	GrStringDraw(psContext, "ANALOG", 	-1, 130, LOC_Y_ANALOG-30, 0);

	//Draw two rectangles, one filled left to right up to the analog value then an empty one to contain the information
    GrContextForegroundSet(psContext, ClrMidnightBlue);
    sRect.i16XMin = 20;
	sRect.i16XMax = 300;
	sRect.i16YMin = LOC_Y_ANALOG-10;
	sRect.i16YMax = LOC_Y_ANALOG+8;
    GrRectFill(psContext, &sRect);

    GrContextForegroundSet(psContext, ClrCyan);
	sRect.i16XMin = 20;
    sRect.i16XMax = num_analog_pixels + sRect.i16XMin;
	sRect.i16YMin = LOC_Y_ANALOG-10;
	sRect.i16YMax = LOC_Y_ANALOG+8;	
    GrRectFill(psContext, &sRect);
	




}
Beispiel #7
0
//*****************************************************************************
//
// A simple application demonstrating use of the boot loader,
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32SysClock;
    tContext sContext;
    tRectangle sRect;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "boot-demo-uart");

    //
    // Print instructions on the screen.
    //
    GrStringDrawCentered(&sContext, "Press the screen to start", -1, 160, 108,
                         false);
    GrStringDrawCentered(&sContext, "the update process", -1, 160, 128, false);

    //
    // Initialize the touch screen driver.
    //
    TouchScreenInit(ui32SysClock);

    //
    // Set the touch screen event handler.
    //
    TouchScreenCallbackSet(TSHandler);

    //
    // Enable the UART that will be used for the firmware update.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure the UART for 115200, 8-N-1.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200,
                            (UART_CONFIG_PAR_NONE | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_WLEN_8));

    //
    // Enable the UART operation.
    //
    ROM_UARTEnable(UART0_BASE);

    //
    // Wait until the screen has been pressed, indicating that the firwmare
    // update should begin.
    //
    while(!g_bFirmwareUpdate)
    {
    }

    //
    // Clear the screen.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = 319;
    sRect.i16YMax = 239;
    GrContextForegroundSet(&sContext, ClrBlack);
    GrRectFill(&sContext, &sRect);

    //
    // Indicate that the firmware update is about to start.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrStringDrawCentered(&sContext, "Update process started...", -1, 160, 98,
                         false);
    GrStringDrawCentered(&sContext, "Using UART0 with", -1, 160, 138, false);
    GrStringDrawCentered(&sContext, "115,200 baud, 8-N-1.", -1, 160, 158,
                         false);

    //
    // Disable all processor interrupts.  Instead of disabling them one at a
    // time, a direct write to NVIC is done to disable all peripheral
    // interrupts.
    //
    HWREG(NVIC_DIS0) = 0xffffffff;
    HWREG(NVIC_DIS1) = 0xffffffff;
    HWREG(NVIC_DIS2) = 0xffffffff;
    HWREG(NVIC_DIS3) = 0xffffffff;
    HWREG(NVIC_DIS4) = 0xffffffff;

    //
    // Call the ROM UART boot loader.
    //
    ROM_UpdateUART();

    //
    // The boot loader should not return.  In the off chance that it does,
    // enter a dead loop.
    //
    while(1)
    {
    }
}
Beispiel #8
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    uint_fast32_t ui32LastTickCount;
    bool bLastSuspend;
    tRectangle sRect;
    tContext sContext;
    int_fast32_t i32CenterX;

    //
    // 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 from the PLL at 50MHz.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Configure the required pins for USB operation.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN);
    ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Erratum workaround for silicon revision A1.  VBUS must have pull-down.
    //
    if(CLASS_IS_BLIZZARD && REVISION_IS_A1)
    {
        HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1;
    }

    //
    // Enable the GPIO that is used for the on-board LED.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTG_BASE, GPIO_PIN_2);
    ROM_GPIOPinWrite(GPIO_PORTG_BASE, GPIO_PIN_2, 0);

    //
    // Initialize the buttons driver
    //
    ButtonsInit();

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context and find the middle X coordinate.
    //
    GrContextInit(&sContext, &g_sCFAL96x64x16);
    i32CenterX = GrContextDpyWidthGet(&sContext) / 2;

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&sContext, "usb-dev-keyboard", -1, i32CenterX, 4, 0);

    //
    // Not configured initially.
    //
    g_bConnected = false;
    g_bSuspended = false;
    bLastSuspend = false;

    //
    // Initialize the USB stack for device mode.
    //
    USBStackModeSet(0, eUSBModeDevice, 0);

    //
    // Pass our device information to the USB HID device class driver,
    // initialize the USB
    // controller and connect the device to the bus.
    //
    USBDHIDKeyboardInit(0, &g_sKeyboardDevice);

    //
    // Set the system tick to fire 100 times per second.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // The main loop starts here.  We begin by waiting for a host connection
    // then drop into the main keyboard handling section.  If the host
    // disconnects, we return to the top and wait for a new connection.
    //
    while(1)
    {
        uint8_t ui8Buttons;
        uint8_t ui8ButtonsChanged;

        //
        // Tell the user what we are doing and provide some basic instructions.
        //
        GrStringDrawCentered(&sContext, "    Waiting    ",
                             -1, i32CenterX, 22, 1);
        GrStringDrawCentered(&sContext, " for host ... ", -1,
                             i32CenterX, 32, 1);

        //
        // Wait here until USB device is connected to a host.
        //
        while(!g_bConnected)
        {
        }

        //
        // Update the status.
        //
        GrStringDrawCentered(&sContext, "     Host     ",
                             -1, i32CenterX, 22, 1);
        GrStringDrawCentered(&sContext, " connected ... ",
                             -1, i32CenterX, 32, 1);

        //
        // Enter the idle state.
        //
        g_eKeyboardState = STATE_IDLE;

        //
        // Assume that the bus is not currently suspended if we have just been
        // configured.
        //
        bLastSuspend = false;

        //
        // Keep transferring characters from the UART to the USB host for as
        // long as we are connected to the host.
        //
        while(g_bConnected)
        {
            //
            // Remember the current time.
            //
            ui32LastTickCount = g_ui32SysTickCount;

            //
            // Has the suspend state changed since last time we checked?
            //
            if(bLastSuspend != g_bSuspended)
            {
                //
                // Yes - the state changed so update the display.
                //
                bLastSuspend = g_bSuspended;
                if(bLastSuspend)
                {
                    GrStringDrawCentered(&sContext, "      Bus      ", -1,
                                         i32CenterX, 22, 1);
                    GrStringDrawCentered(&sContext, " suspended ... ", -1,
                                         i32CenterX, 32, 1);
                }
                else
                {
                    GrStringDrawCentered(&sContext, "     Host     ", -1,
                                         i32CenterX, 22, 1);
                    GrStringDrawCentered(&sContext, " connected ... ",
                                         -1, i32CenterX, 32, 1);
                }
            }

            //
            // See if the button was just pressed.
            //
            ui8Buttons = ButtonsPoll(&ui8ButtonsChanged, 0);
            if(BUTTON_PRESSED(SELECT_BUTTON, ui8Buttons, ui8ButtonsChanged))
            {
                //
                // If the bus is suspended then resume it.  Otherwise, type
                // some "random" characters.
                //
                if(g_bSuspended)
                {
                    USBDHIDKeyboardRemoteWakeupRequest(
                                                   (void *)&g_sKeyboardDevice);
                }
                else
                {
                    SendString("Make the Switch to TI Microcontrollers!");
                }
            }

            //
            // Wait for at least 1 system tick to have gone by before we poll
            // the buttons again.
            //
            while(g_ui32SysTickCount == ui32LastTickCount)
            {
            }
        }
    }
}
Beispiel #9
0
//*****************************************************************************
//
// Demonstrate the use of the boot loader.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_8MHZ);

    //
    // If running on Rev A0 silicon, write the FMPRE[2-3]/FMPPE[2-3] registers
    // to zero.  This is a workaround to allow the mass erase in the ROM-based
    // boot loader to succeed if a locked device recovery has been performed.
    //
    if(REVISION_IS_A0)
    {
        HWREG(FLASH_FMPPE2) = 0;
        HWREG(FLASH_FMPPE3) = 0;
        HWREG(FLASH_FMPRE2) = 0;
        HWREG(FLASH_FMPRE3) = 0;
    }

    //
    // Enable the UART and GPIO modules.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Make the UART pins be peripheral controlled.
    //
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Initialize the display driver.
    //
    Formike128x128x16Init();

    //
    // Turn on the backlight.
    //
    Formike128x128x16BacklightOn();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sFormike128x128x16);

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = 14;
    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_sFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "boot_demo1", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 7, 0);

    //
    // Indicate what is happening.
    //
    GrStringDrawCentered(&g_sContext, "The boot loader is", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 24, 0);
    GrStringDrawCentered(&g_sContext, "now running and", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 32, 0);
    GrStringDrawCentered(&g_sContext, "awaiting an update", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 40, 0);
    GrStringDrawCentered(&g_sContext, "over UART0 at", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 48, 0);
    GrStringDrawCentered(&g_sContext, "115200, 8-N-1.", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 56, 0);

    //
    // Call the boot loader so that it will listen for an update on the UART.
    //
    ROM_UpdateUART();

    //
    // The boot loader should take control, so this should never be reached.
    // Just in case, loop forever.
    //
    while(1)
    {
    }
}
//*****************************************************************************
//
// Demonstrate the use of the USB stick update example.
//
//*****************************************************************************
int
main(void)
{
    uint_fast32_t ui32Count;
    tContext sContext;
    tRectangle sRect;

    //
    // 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 system clock to run at 50MHz from the PLL.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sCFAL96x64x16);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrRectDraw(&sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&sContext, "usb-stick-demo", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 4, 0);

    //
    // Indicate what is happening.
    //
    GrStringDrawCentered(&sContext, "Press the", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, 0);
    GrStringDrawCentered(&sContext, "select button to", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, 0);
    GrStringDrawCentered(&sContext, "start the USB", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, 0);
    GrStringDrawCentered(&sContext, "stick updater.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 50, 0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // Enable the GPIO module which the select button is attached to.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM);

    //
    // Enable the GPIO pin to read the user button.
    //
    ROM_GPIODirModeSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_DIR_MODE_IN);
    MAP_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_4, GPIO_STRENGTH_2MA,
                         GPIO_PIN_TYPE_STD_WPU);

    //
    // Wait for the pullup to take effect or the next loop will exist too soon.
    //
    SysCtlDelay(1000);

    //
    // Wait until the select button has been pressed for ~40ms (in order to
    // debounce the press).
    //
    ui32Count = 0;
    while(1)
    {
        //
        // See if the button is pressed.
        //
        if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) == 0)
        {
            //
            // Increment the count since the button is pressed.
            //
            ui32Count++;

            //
            // If the count has reached 4, then the button has been debounced
            // as being pressed.
            //
            if(ui32Count == 4)
            {
                break;
            }
        }
        else
        {
            //
            // Reset the count since the button is not pressed.
            //
            ui32Count = 0;
        }

        //
        // Delay for approximately 10ms.
        //
        SysCtlDelay(16000000 / (3 * 100));
    }

    //
    // Wait until the select button has been released for ~40ms (in order to
    // debounce the release).
    //
    ui32Count = 0;
    while(1)
    {
        //
        // See if the button is pressed.
        //
        if(ROM_GPIOPinRead(GPIO_PORTM_BASE, GPIO_PIN_4) != 0)
        {
            //
            // Increment the count since the button is released.
            //
            ui32Count++;

            //
            // If the count has reached 4, then the button has been debounced
            // as being released.
            //
            if(ui32Count == 4)
            {
                break;
            }
        }
        else
        {
            //
            // Reset the count since the button is pressed.
            //
            ui32Count = 0;
        }

        //
        // Delay for approximately 10ms.
        //
        SysCtlDelay(16000000 / (3 * 100));
    }

    //
    // Indicate that the updater is being called.
    //
    GrStringDrawCentered(&sContext, "The USB stick", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, true);
    GrStringDrawCentered(&sContext, "updater is now", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, true);
    GrStringDrawCentered(&sContext, "waiting for a", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, true);
    GrStringDrawCentered(&sContext, "USB stick.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 50, true);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // Call the updater so that it will search for an update on a memory stick.
    //
    (*((void (*)(void))(*(uint32_t *)0x2c)))();

    //
    // The updater should take control, so this should never be reached.
    // Just in case, loop forever.
    //
    while(1)
    {
    }
}
Beispiel #11
0
//*****************************************************************************
//
//! Draws a container widget.
//!
//! \param pWidget is a pointer to the container widget to be drawn.
//!
//! This function draws a container widget on the display.  This is called in
//! response to a \b #WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
ContainerPaint(tWidget *pWidget)
{
    tContainerWidget *pContainer;
    long lX1, lX2, lY;
    tContext sCtx;

    //
    // Check the arguments.
    //
    ASSERT(pWidget);

    //
    // Convert the generic widget pointer into a container widget pointer.
    //
    pContainer = (tContainerWidget *)pWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, pWidget->pDisplay);

    //
    // Initialize the clipping region based on the extents of this container.
    //
    GrContextClipRegionSet(&sCtx, &(pWidget->sPosition));

    //
    // See if the container fill style is selected.
    //
    if(pContainer->ulStyle & CTR_STYLE_FILL)
    {
        //
        // Fill the container with the fill color.
        //
        GrContextForegroundSet(&sCtx, pContainer->ulFillColor);
        GrRectFill(&sCtx, &(pWidget->sPosition));
    }

    //
    // See if the container text style is selected.
    //
    if(pContainer->ulStyle & CTR_STYLE_TEXT)
    {
        //
        // Set the font and colors used to draw the container text.
        //
        GrContextFontSet(&sCtx, pContainer->pFont);
        GrContextForegroundSet(&sCtx, pContainer->ulTextColor);
        GrContextBackgroundSet(&sCtx, pContainer->ulFillColor);

        //
        // Get the width of the container text.
        //
        lX2 = GrStringWidthGet(&sCtx, pContainer->pcText, -1);

        //
        // Determine the position of the text.  The position depends on the
        // the width of the string and if centering is enabled.
        //
        if(pContainer->ulStyle & CTR_STYLE_TEXT_CENTER)
        {
            lX1 = (pWidget->sPosition.sXMin +
                   ((pWidget->sPosition.sXMax - pWidget->sPosition.sXMin + 1 -
                     lX2 - 8) / 2));
        }
        else
        {
            lX1 = pWidget->sPosition.sXMin + 4;
        }

        //
        // Draw the container text.
        //
        GrStringDraw(&sCtx, pContainer->pcText, -1, lX1 + 4,
                     pWidget->sPosition.sYMin,
                     pContainer->ulStyle & CTR_STYLE_TEXT_OPAQUE);

        //
        // See if the container outline style is selected.
        //
        if(pContainer->ulStyle & CTR_STYLE_OUTLINE)
        {
            //
            // Get the position of the right side of the string.
            //
            lX2 = lX1 + lX2 + 8;

            //
            // Get the position of the vertical center of the text.
            //
            lY = (pWidget->sPosition.sYMin +
                  (GrFontBaselineGet(pContainer->pFont) / 2));

            //
            // Set the color to draw the outline.
            //
            GrContextForegroundSet(&sCtx, pContainer->ulOutlineColor);

            //
            // Draw the outline around the container widget, leaving a gap
            // where the text reside across the top of the widget.
            //
            GrLineDraw(&sCtx, lX1, lY, pWidget->sPosition.sXMin, lY);
            GrLineDraw(&sCtx, pWidget->sPosition.sXMin, lY,
                       pWidget->sPosition.sXMin, pWidget->sPosition.sYMax);
            GrLineDraw(&sCtx, pWidget->sPosition.sXMin,
                       pWidget->sPosition.sYMax, pWidget->sPosition.sXMax,
                       pWidget->sPosition.sYMax);
            GrLineDraw(&sCtx, pWidget->sPosition.sXMax,
                       pWidget->sPosition.sYMax, pWidget->sPosition.sXMax, lY);
            GrLineDraw(&sCtx, pWidget->sPosition.sXMax, lY, lX2, lY);
        }
    }

    //
    // Otherwise, see if the container outline style is selected.
    //
    else if(pContainer->ulStyle & CTR_STYLE_OUTLINE)
    {
        //
        // Outline the container with the outline color.
        //
        GrContextForegroundSet(&sCtx, pContainer->ulOutlineColor);
        GrRectDraw(&sCtx, &(pWidget->sPosition));
    }
}
//*****************************************************************************
//
// Print "Hello World!" to the display.
//
//*****************************************************************************
int
main(void)
{
    tContext sContext;
    tRectangle sRect;

    //
    // 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);

    //
    // Initialize the UART.
    //
    ConfigureUART();

    UARTprintf("Hello, world!\n");

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sCFAL96x64x16);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 23;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrRectDraw(&sContext, &sRect);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontCm12);
    GrStringDrawCentered(&sContext, "hello", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 10, 0);

    //
    // Say hello using the Computer Modern 40 point font.
    //
    GrContextFontSet(&sContext, g_psFontCm12/*g_psFontFixed6x8*/);
    GrStringDrawCentered(&sContext, "Hello World!", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         ((GrContextDpyHeightGet(&sContext) - 24) / 2) + 24,
                         0);

    //
    // Flush any cached drawing operations.
    //
    GrFlush(&sContext);

    //
    // We are finished. Hang around doing nothing.
    //
    while(1)
    {
    }
}
Beispiel #13
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
static int
main(void)
{
//	tRectangle sRect;
    unsigned int index, i;
	unsigned char *src, *dest;

	 /* Sets up 'Level 1" page table entries.
     * The page table entry consists of the base address of the page
     * and the attributes for the page. The following operation is to
     * setup one-to-one mapping page table for DDR memeory range and set
     * the atributes for the same. The DDR memory range is from 0xC0000000
     * to 0xDFFFFFFF. Thus the base of the page table ranges from 0xC00 to
     * 0xDFF. Cache(C bit) and Write Buffer(B bit) are enabled  only for
     * those page table entries which maps to DDR RAM and internal RAM.
     * All the pages in the DDR range are provided with R/W permissions
     */

#ifdef DMA_MODE
	for(index = 0; index < (4*1024); index++)
    {
         if((index >= 0xC00 && index < 0xE00)|| (index == 0x800))
         {
              pageTable[index] = (index << 20) | 0x00000C1E;
         }
         else
         {
              pageTable[index] = (index << 20) | 0x00000C12;
         }
    }

	/* Configures translation table base register
	* with pagetable base address.
	*/
    CP15TtbSet((unsigned int )pageTable);

    /* Enables MMU */
   	CP15MMUEnable();

	/* Enable Data Cache */
  	CP15DCacheEnable();

	/* Disable Instruction Cache*/
	CP15ICacheDisable();
#endif

#if 0 // No LCD -- ertl-liyixiao
    //
    //configures arm interrupt controller to generate raster interrupt
    //
    SetupIntc();

	//
	//Configures raster to display image
	//
	SetUpLCD();

	/* configuring the base ceiling */
	RasterDMAFBConfig(SOC_LCDC_0_REGS,
					  (unsigned int)(g_pucBuffer+PALETTE_OFFSET),
					  (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET,
					  0);

	RasterDMAFBConfig(SOC_LCDC_0_REGS,
					  (unsigned int)(g_pucBuffer+PALETTE_OFFSET),
					  (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET,
					  1);

	// Copy palette info into buffer
	src = (unsigned char *) palette_32b;
	dest = (unsigned char *) (g_pucBuffer+PALETTE_OFFSET);
	for( i = 4; i < (PALETTE_SIZE+4); i++)
	{
		*dest++ = *src++;
	}

	GrOffScreen16BPPInit(&g_sSHARP480x272x16Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT);

	// Initialize a drawing context.
	GrContextInit(&g_sContext, &g_sSHARP480x272x16Display);

	/* enable End of frame interrupt */
	RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS);

	/* enable raster */
	RasterEnable(SOC_LCDC_0_REGS);
	ConfigRasterDisplayEnable();


    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = DISPLAY_BANNER_HEIGHT;
    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-msc", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 10, 0);

    //
    // Initialize the idle timeout and reset all flags.
    //
    g_ulIdleTimeout = 0;
    g_ulFlags = 0;

    //
    // Initialize the state to idle.
    //
    g_eMSCState = MSC_DEV_IDLE;

    //
    // Draw the status bar and set it to idle.
    //
    UpdateStatus("Idle", 1);
#endif

	//SetupAINTCInt();
	//ConfigureAINTCIntUSB();
	//DelayTimerSetup();

#if 0 // No LCD
	SystickConfigure(SysTickHandler);
	SystickPeriodSet(10);
	SystickEnable();
#endif

    USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice);



#ifdef DMA_MODE
	Cppi41DmaInit(USB_INSTANCE, epInfo, NUMBER_OF_ENDPOINTS);

	for(;g_bufferIndex < NUM_OF_RX_BDs; g_bufferIndex++)
	{
		dataBuffer = (unsigned char *)cppiDmaAllocBuffer();
		doDmaRxTransfer(USB_INSTANCE, USB_MSC_BUFER_SIZE, dataBuffer,
							g_sMSCDevice.psPrivateData->ucOUTEndpoint);
	}
#endif

#if 0 // No LCD -- ertl-liyixiao
	//
    // Drop into the main loop.
    //
     //
    // Drop into the main loop.
	//

    while(1)
    {
        switch(g_eMSCState)
        {
            case MSC_DEV_READ:
            {
                //
                // Update the screen if necessary.
                //
                if(g_ulFlags & FLAG_UPDATE_STATUS)
                {
                    UpdateStatus("Reading", 0);
                    g_ulFlags &= ~FLAG_UPDATE_STATUS;
                }

                //
                // If there is no activity then return to the idle state.
                //
                if(g_ulIdleTimeout == 0)
                {
                    UpdateStatus("Idle     ", 0);
                    g_eMSCState = MSC_DEV_IDLE;
                }

                break;
            }
            case MSC_DEV_WRITE:
            {
                //
                // Update the screen if necessary.
                //
                if(g_ulFlags & FLAG_UPDATE_STATUS)
                {
                    UpdateStatus("Writing ", 0);
                    g_ulFlags &= ~FLAG_UPDATE_STATUS;
                }

                //
                // If there is no activity then return to the idle state.
                //
                if(g_ulIdleTimeout == 0)
                {
                    UpdateStatus("Idle     ", 0);
                    g_eMSCState = MSC_DEV_IDLE;
                }
                break;
            }
            case MSC_DEV_IDLE:
            default:
            {
                break;
            }
        }
    }
#endif

}
//*****************************************************************************
//
//! Performs the sliding menu operation, in response to the "left" button.
//!
//! \param pWidget is a pointer to the slide menu widget to move to the left.
//!
//! This function will respond to the "left" key/button event.  The left
//! button is used to ascend to the next menu up in the menu tree.  The effect
//! is that the current menu, or active widget, slides off to the right, while
//! the parent menu slides in from the left.
//!
//! This function repeatedly draws the menu onto the display until the sliding
//! animation is finished and will not return to the caller until then.  This
//! function is usually called from the thread context of
//! WidgetMessageQueueProcess().
//!
//! \return Returns a non-zero value if the menu was moved or was not moved
//! because it is already at the last position.  If a child widget is active
//! then this function does nothing and returns a 0.
//
//*****************************************************************************
static long
SlideMenuLeft(tWidget *pWidget)
{
    tSlideMenuWidget *pMenuWidget;
    tSlideMenu *pMenu;
    tSlideMenu *pParentMenu;
    tContext sContext;
    unsigned int uX;
    unsigned long ulMenuWidth;

    //
    // Get handy pointers to the menu widget and active menu, and the parent
    // menu if there is one.
    //
    pMenuWidget = (tSlideMenuWidget *)pWidget;
    pMenu = pMenuWidget->pSlideMenu;
    pParentMenu = pMenu->pParent;

    //
    // Initialize a context for the primary off-screen drawing buffer.
    // Clip region is set to entire display by default, which is what we want.
    //
    GrContextInit(&sContext, pMenuWidget->pDisplayB);

    //
    // If this widget has a child, that means that the child widget is in
    // control, and we are requested to go back to the previous menu item.
    // Process the child widget.
    //
    if(pWidget->pChild)
    {
        //
        // Call the widget de-activated callback function.  This notifies the
        // application that the widget is being deactivated.
        //
        if(pMenuWidget->pfnActive)
        {
            pMenuWidget->pfnActive(pWidget->pChild,
                                   &pMenu->pSlideMenuItems[pMenu->ulFocusIndex],
                                   0);
        }

        //
        // Unlink the child widget from the slide menu widget.  The menu
        // widget will now no longer have a child widget.
        //
        pWidget->pChild->pParent = 0;
        pWidget->pChild = 0;

        //
        // Fill a rectangle with the child widget background color.  This will
        // erase everything else that is shown on the widget but leave the
        // background, which will make the change visually less jarring.
        // This is done in off-screen buffer B, which is the buffer that is
        // going to be slid off the screen.
        //
        GrContextForegroundSet(
            &sContext,
            pMenu->pSlideMenuItems[pMenu->ulFocusIndex].ulChildWidgetColor);
        GrRectFill(&sContext, &sContext.sClipRegion);
    }

    //
    // Otherwise there is not a child widget in control, so process the parent
    // menu, if there is one.
    //
    else if(pParentMenu)
    {
        //
        // Render the current menu into the off-screen buffer B.  This will be
        // the same menu appearance that is currently on the display.
        //
        SlideMenuDraw(pMenuWidget, &sContext, 0);

        //
        // Now switch the widget to the parent menu
        //
        pMenuWidget->pSlideMenu = pParentMenu;
    }

    //
    // Otherwise, we are already at the top level menu and there is nothing
    // else to do.
    //
    else
    {
        return(1);
    }

    //
    // Draw the new menu in the second offscreen buffer.  This is the menu
    // that will be on the display when the animation is over.
    //
    GrContextInit(&sContext, pMenuWidget->pDisplayA);
    SlideMenuDraw(pMenuWidget, &sContext, 0);

    //
    // Initialize a drawing context for the display where the widget is to be
    // drawn.  This is the physical display, not an off-screen buffer.
    //
    GrContextInit(&sContext, pWidget->pDisplay);

    //
    // Initialize the clipping region on the physical display, based on the
    // extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(pWidget->sPosition));

    //
    // Get the width of the menu widget.
    //
    ulMenuWidth = pMenuWidget->pDisplayA->usWidth;

    //
    // The following loop draws the two off-screen buffers onto the physical
    // display using a left-to-right.  This will provide an appearance
    // of sliding to the right.  The parent menu will slide in from the left.
    // The "old" child menu is being held in off-screen buffer B and the new
    // one is in buffer A.  So when we are done, the correct image will be in
    // buffer A.
    //
    for(uX = 0; uX <= ulMenuWidth; uX += 8)
    {
        GrImageDraw(&sContext, pMenuWidget->pDisplayB->pvDisplayData,
                    pWidget->sPosition.sXMin + uX, pWidget->sPosition.sYMin);
        GrImageDraw(&sContext, pMenuWidget->pDisplayA->pvDisplayData,
                    pWidget->sPosition.sXMin + uX - ulMenuWidth,
                    pWidget->sPosition.sYMin);
    }

    //
    // Return indication that we handled the key event.
    //
    return(1);
}
Beispiel #15
0
//*****************************************************************************
//
// Draws a JPEG widget.
//
// \param pWidget is a pointer to the JPEG widget to be drawn.
//
// This function draws a JPEG widget on the display.  This is called in
// response to a \b WIDGET_MSG_PAINT message.
//
// \return None.
//
//*****************************************************************************
static void
JPEGWidgetPaint(tWidget *pWidget)
{
    tRectangle sRect;
    tJPEGWidget *pJPEG;
    tContext sCtx;
    unsigned short usWidth, usHeight, usRow;
    unsigned short *pusRow;
    short sSrcX, sSrcY, sDstX, sDstY;

    //
    // Check the arguments.
    //
    ASSERT(pWidget);

    //
    // Convert the generic widget pointer into a JPEG widget pointer.
    //
    pJPEG = (tJPEGWidget *)pWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, pWidget->pDisplay);

    //
    // Initialize the clipping region based on the extents of this rectangular
    // JPEG widget.
    //
    GrContextClipRegionSet(&sCtx, &(pWidget->sPosition));

    //
    // Take a copy of the current widget position.
    //
    sRect=pWidget->sPosition;

    //
    // See if the JPEG widget outline style is selected.
    //
    if(pJPEG->ulStyle & JW_STYLE_OUTLINE)
    {
        unsigned long ulLoop;

        GrContextForegroundSet(&sCtx, pJPEG->ulOutlineColor);

        //
        // Outline the JPEG widget with the outline color.
        //
        for(ulLoop = 0; ulLoop < (unsigned long)pJPEG->ucBorderWidth; ulLoop++)
        {
            GrRectDraw(&sCtx, &sRect);
            sRect.sXMin++;
            sRect.sYMin++;
            sRect.sXMax--;
            sRect.sYMax--;
        }
    }

    //
    // If the fill style is selected fill the widget with the appropriate color.
    //
    if(pJPEG->ulStyle & JW_STYLE_FILL)
    {
        //
        // Fill the JPEG widget with the fill color.
        //
        GrContextForegroundSet(&sCtx, pJPEG->ulFillColor);
        GrRectFill(&sCtx, &(pWidget->sPosition));
    }

    //
    // Does the widget had a decompressed image to draw?
    //
    if(pJPEG->psJPEGInst->pusImage)
    {
        //
        // What is the size of the image area of the widget?
        //
        usWidth = (sRect.sXMax - sRect.sXMin) + 1;
        usHeight = (sRect.sYMax - sRect.sYMin) + 1;

        //
        // Is the display window wider than the image?
        //
        if(usWidth > pJPEG->psJPEGInst->usWidth)
        {
            //
            // The display window is wider so we need to center the image
            // within the window.
            //
            sDstX = sRect.sXMin +
                    (short)(usWidth - pJPEG->psJPEGInst->usWidth) / 2;
            sSrcX = 0;
            usWidth = pJPEG->psJPEGInst->usWidth;
        }
        else
        {
            //
            // The image is wider so we will fill the window (in the x
            // direction) and clip the image accordingly.
            //
            sDstX = sRect.sXMin;
            sSrcX = (pJPEG->psJPEGInst->usWidth - usWidth) / 2 -
                    pJPEG->psJPEGInst->sXOffset;

            //
            // Ensure we don't wrap the image due to an offset that is too
            // large.
            //
            sSrcX = (sSrcX < 0) ? 0 : sSrcX;
        }

        //
        // Is the image highter than the display window?
        //
        if(usHeight > pJPEG->psJPEGInst->usHeight)
        {
            //
            // The display window is higher so we need to center the image
            // within the window.
            //
            sDstY = sRect.sYMin +
                    (short)(usHeight - pJPEG->psJPEGInst->usHeight) / 2;
            sSrcY = 0;
            usHeight = pJPEG->psJPEGInst->usHeight;

        }
        else
        {
            //
            // The image is higher so we will fill the window (in the y
            // direction) and clip the image accordingly.
            //
            sDstY = sRect.sYMin;
            sSrcY = (pJPEG->psJPEGInst->usHeight - usHeight) / 2 -
                    pJPEG->psJPEGInst->sYOffset;

            //
            // Ensure we don't wrap the image due to an offset that is too
            // large.
            //
            sSrcY = (sSrcY < 0) ? 0 : sSrcY;
        }

        //
        // Start at the top left of the visible portion of the image (based on the
        // slider settings).
        //
        pusRow = pJPEG->psJPEGInst->pusImage + sSrcX +
                 (sSrcY * pJPEG->psJPEGInst->usWidth);

        //
        // Draw the rows of image data using direct calls to the display driver.
        //
        for(usRow = 0; usRow < usHeight; usRow++)
        {
            sCtx.pDisplay->pfnPixelDrawMultiple(
                                           sCtx.pDisplay->pvDisplayData,
                                           sDstX, sDstY + usRow, 0, usWidth, 16,
                                           (unsigned char *)pusRow, 0);
            pusRow += pJPEG->psJPEGInst->usWidth;
        }
    }

    //
    // See if the JPEG widget text style is selected.
    //
    if(pJPEG->ulStyle & JW_STYLE_TEXT)
    {
        //
        // Compute the center of the JPEG widget.
        //
        sDstX = (sRect.sXMin + ((sRect.sXMax - sRect.sXMin + 1) / 2));
        sDstY = (sRect.sYMin + ((sRect.sYMax - sRect.sYMin + 1) / 2));

        //
        // Draw the text centered in the middle of the JPEG widget.
        //
        GrContextFontSet(&sCtx, pJPEG->pFont);
        GrContextForegroundSet(&sCtx, pJPEG->ulTextColor);
        GrStringDrawCentered(&sCtx, pJPEG->pcText, -1, sDstX, sDstY, 0);
    }
}
Beispiel #16
0
//*****************************************************************************
//
// Draws the black keys on the display.
//
//*****************************************************************************
static inline void
DrawBlackKeys(tContext *pContext)
{
    uint32_t ui32Key;

    //
    // Loop through the black keys.
    //
    for(ui32Key = 0; ui32Key < NUM_BLACK_KEYS; ui32Key++)
    {
        //
        // Select the color for the top and left edges of the black key.
        //
        GrContextForegroundSet(pContext, ClrBlackBright);

        //
        // Draw the top and left edges of the black key.
        //
        GrLineDraw(pContext,
                   g_psBlackKeys[ui32Key].sOutline.i16XMin,
                   g_psBlackKeys[ui32Key].sOutline.i16YMin,
                   g_psBlackKeys[ui32Key].sOutline.i16XMax,
                   g_psBlackKeys[ui32Key].sOutline.i16YMin);
        GrLineDraw(pContext,
                   g_psBlackKeys[ui32Key].sOutline.i16XMin + 1,
                   g_psBlackKeys[ui32Key].sOutline.i16YMin + 1,
                   g_psBlackKeys[ui32Key].sOutline.i16XMax - 1,
                   g_psBlackKeys[ui32Key].sOutline.i16YMin + 1);
        GrLineDraw(pContext,
                   g_psBlackKeys[ui32Key].sOutline.i16XMin,
                   g_psBlackKeys[ui32Key].sOutline.i16YMin + 1,
                   g_psBlackKeys[ui32Key].sOutline.i16XMin,
                   g_psBlackKeys[ui32Key].sOutline.i16YMax);
        GrLineDraw(pContext,
                   g_psBlackKeys[ui32Key].sOutline.i16XMin + 1,
                   g_psBlackKeys[ui32Key].sOutline.i16YMin + 2,
                   g_psBlackKeys[ui32Key].sOutline.i16XMin + 1,
                   g_psBlackKeys[ui32Key].sOutline.i16YMax - 1);

        //
        // Select the color for the bottom and right edges of the black key.
        //
        GrContextForegroundSet(pContext, ClrBlackDim);

        //
        // Draw the bottom and right edges of the black key.
        //
        GrLineDraw(pContext,
                   g_psBlackKeys[ui32Key].sOutline.i16XMax,
                   g_psBlackKeys[ui32Key].sOutline.i16YMin + 1,
                   g_psBlackKeys[ui32Key].sOutline.i16XMax,
                   g_psBlackKeys[ui32Key].sOutline.i16YMax);
        GrLineDraw(pContext,
                   g_psBlackKeys[ui32Key].sOutline.i16XMax - 1,
                   g_psBlackKeys[ui32Key].sOutline.i16YMin + 2,
                   g_psBlackKeys[ui32Key].sOutline.i16XMax - 1,
                   g_psBlackKeys[ui32Key].sOutline.i16YMax - 1);
        GrLineDraw(pContext,
                   g_psBlackKeys[ui32Key].sOutline.i16XMin + 1,
                   g_psBlackKeys[ui32Key].sOutline.i16YMax,
                   g_psBlackKeys[ui32Key].sOutline.i16XMax - 1,
                   g_psBlackKeys[ui32Key].sOutline.i16YMax);
        GrLineDraw(pContext,
                   g_psBlackKeys[ui32Key].sOutline.i16XMin + 2,
                   g_psBlackKeys[ui32Key].sOutline.i16YMax - 1,
                   g_psBlackKeys[ui32Key].sOutline.i16XMax - 2,
                   g_psBlackKeys[ui32Key].sOutline.i16YMax - 1);

        //
        // Fill in the black key with the default color.
        //
        FillBlackKey(pContext, ui32Key, ClrBlackKey);
    }
}
Beispiel #17
0
//*****************************************************************************
//
// The main code for the application.  It sets up the peripherals, displays the
// splash screens, and then manages the interaction between the game and the
// screen saver.
//
//*****************************************************************************
int
main(void)
{
	tRectangle sRect;
#ifndef _TMS320C6X
    unsigned int index;
#endif
	
    SetupIntc();

	
	/* Configuring UART2 instance for serial communication. */
    UARTStdioInit();

#ifdef _TMS320C6X
    CacheEnableMAR((unsigned int)0xC0000000, (unsigned int)0x20000000);
    CacheEnable(L1PCFG_L1PMODE_32K | L1DCFG_L1DMODE_32K | L2CFG_L2MODE_256K);
#else
    /* Sets up 'Level 1" page table entries. 
     * The page table entry consists of the base address of the page
     * and the attributes for the page. The following operation is to
     * setup one-to-one mapping page table for DDR memeory range and set
     * the atributes for the same. The DDR memory range is from 0xC0000000
     * to 0xDFFFFFFF. Thus the base of the page table ranges from 0xC00 to 
     * 0xDFF. Cache(C bit) and Write Buffer(B bit) are enabled  only for
     * those page table entries which maps to DDR RAM and internal RAM.
     * All the pages in the DDR range are provided with R/W permissions
     */
    for(index = 0; index < (4*1024); index++)
    {
         if((index >= 0xC00 && index < 0xE00)|| (index == 0x800))
         {             
              pageTable[index] = (index << 20) | 0x00000C1E;
         }
         else
         {
              pageTable[index] = (index << 20) | 0x00000C12;
         }
    }
     
    /* Configures translation table base register
     * with pagetable base address.
     */
    CP15TtbSet((unsigned int )pageTable);

    /* Enables MMU */
    CP15MMUEnable();
   
	/* Enable Instruction Cache */
    CP15ICacheEnable();

    /* Enable Data Cache */
    CP15DCacheEnable();
#endif

    SetUpLCD();
	
	ConfigureFrameBuffer();
		
	GrOffScreen16BPPInit(&g_sSHARP480x272x16Display0, (unsigned char *)g_pucBuffer0, LCD_WIDTH, LCD_HEIGHT);
	GrOffScreen16BPPInit(&g_sSHARP480x272x16Display1, (unsigned char *)g_pucBuffer1, LCD_WIDTH, LCD_HEIGHT);
	
	// Initialize a drawing context.
	GrContextInit(&sContext0, &g_sSHARP480x272x16Display0);
	GrContextInit(&sContext1, &g_sSHARP480x272x16Display1);

    /* enable End of frame interrupt */
    RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS);

    /* enable raster */
    RasterEnable(SOC_LCDC_0_REGS);

	PeripheralsSetup();
	I2C0IntRegister(4);
    AIC31Init();
    ToneLoopInit();
	/* Start playing the tone */
    ToneLoopStart();
	
    // TS init	
	TouchInit();
	
	GrContextForegroundSet(&sContext0, ClrBlack);
	GrContextForegroundSet(&sContext1, ClrBlack);
    sRect.sXMin = GAME_X - 1;
    sRect.sYMin = GAME_Y - 1;
    sRect.sXMax = GAME_X + GAME_W;
    sRect.sYMax = GAME_Y + GAME_H;
    GrRectFill(&sContext0, &sRect);
    GrRectFill(&sContext1, &sRect);

    GrImageDraw(&sContext0, g_pucTILogo128x96, GAME_X, GAME_Y);
	GrImageDraw(&sContext1, g_pucTILogo128x96, GAME_X, GAME_Y);
	
	Delay(0x5FFFFF);
	
	// Confiure and start timer2
	Timer2Config();
	Timer2Start();

    // Loop forever.
    while(1)
    {
        // Display the main screen.
        if(MainScreen())
        {
            // The button was pressed, so start the game.
            PlayGame();
        }
        else
        {
            // The button was not pressed during the timeout period, so start
            // the screen saver.
            ScreenSaver();
        }
    }
}
Beispiel #18
0
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    tContext sContext;

    //
    // 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_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sCFAL96x64x16);

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&sContext, "uart-echo", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 4, 0);

    //
    // Initialize the display and write some instructions.
    //
    GrStringDrawCentered(&sContext, "Connect a", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 20, false);
    GrStringDrawCentered(&sContext, "terminal", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 30, false);
    GrStringDrawCentered(&sContext, "to UART0.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 40, false);
    GrStringDrawCentered(&sContext, "115000,N,8,1", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 50, false);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Enable processor interrupts.
    //
    ROM_IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART0);
    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Prompt for text to be entered.
    //
    UARTSend((uint8_t *)"Enter text: ", 12);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
    }
}
Beispiel #19
0
static void OnDraw(tContext *pContext)
{
  char buf[20];
  // clear screen
  GrContextForegroundSet(pContext, ClrBlack);
  GrContextBackgroundSet(pContext, ClrWhite);
  GrRectFill(pContext, &fullscreen_clip);

  // draw table title
  GrContextForegroundSet(pContext, ClrWhite);
  GrContextBackgroundSet(pContext, ClrBlack);
  const tRectangle rect = {0, 27, 255, 41};
  GrRectFill(pContext, &rect);

  // draw the title bar
  GrContextFontSet(pContext, &g_sFontGothic18b);
  sprintf(buf, "%s %d", toMonthName(month, 1), year);
  GrStringDrawCentered(pContext, buf, -1, LCD_WIDTH / 2, 15, 0);

  GrContextForegroundSet(pContext, ClrBlack);
  GrContextBackgroundSet(pContext, ClrWhite);
  GrContextFontSet(pContext, &g_sFontGothic18);
  for(int i = 0; i < 7; i++)
  {
    GrStringDrawCentered( pContext, week_shortname[i], -1, i * 20 + 11, 35, 0);
    // draw line in title bar
    GrLineDrawV(pContext, i * 20, 28, 42);
  }

  GrContextFontSet(pContext, &g_sFontGothic18);
  GrContextForegroundSet(pContext, ClrWhite);
  GrContextBackgroundSet(pContext, ClrBlack);

  // get the start point of this month
  uint8_t weekday = rtc_getweekday(year, month, 1) - 1; // use 0 as index
  uint8_t maxday = rtc_getmaxday(year, month);
  uint8_t y = 50;

  for(int day = 1; day <= maxday; day++)
  {
    sprintf(buf, "%d", day);

    uint8_t today = now_year == year && now_month == month && now_day == day;
    if (today)
    {
      const tRectangle rect = {weekday * 20 + 1, y - 7, 20 + weekday * 20 - 1, y + 7};
      GrRectFill(pContext, &rect);
      GrContextForegroundSet(pContext, ClrBlack);
      GrContextBackgroundSet(pContext, ClrWhite);
    }
    GrStringDrawCentered( pContext, buf, -1, weekday * 20 + 11, y, 0);
    if (today)
    {
      const tRectangle rect2 = {weekday * 20 + 16, y - 5, weekday * 20 + 17, y - 4};
      GrRectFill(pContext, &rect2);

      GrContextForegroundSet(pContext, ClrWhite);
      GrContextBackgroundSet(pContext, ClrBlack);
    }

    if (weekday != 6)
      GrLineDrawV(pContext, (weekday + 1 ) * 20, 42, y + 7);

    weekday++;
    if (weekday == 7)
    {
      GrLineDrawH(pContext, 0, LCD_WIDTH, y + 8);

      weekday = 0;
      y += 20;
    }
  }

  GrLineDrawH(pContext, 0, weekday * 20, y + 8);

  // draw the buttons
  if (month == 1)
    sprintf(buf, "%s %d", toMonthName(12, 0), year - 1);
  else
    sprintf(buf, "%s %d", toMonthName(month - 1, 0), year);
  window_button(pContext, KEY_ENTER, buf);

  if (month == 12)
    sprintf(buf, "%s %d", toMonthName(1, 0), year + 1);
  else
    sprintf(buf, "%s %d", toMonthName(month + 1, 0), year);
  window_button(pContext, KEY_DOWN, buf);
}
Beispiel #20
0
//*****************************************************************************
//
//! Draws a slider.
//!
//! \param pWidget is a pointer to the slider widget to be drawn.
//! \param pDirty is the subrectangle of the widget which is to be redrawn.
//! This is expressed in screen coordinates.
//!
//! This function draws a slider on the display.  This is called in response to
//! a \b #WIDGET_MSG_PAINT message or when the slider position changes.
//!
//! \return None.
//
//*****************************************************************************
static void
SliderPaint(tWidget *pWidget, tRectangle *pDirty)
{
    tRectangle sClipRect, sValueRect, sEmptyRect, sActiveClip;
    tSliderWidget *pSlider;
    tContext sCtx;
    unsigned lX, lY, bIntersect;
    short sPos;

    //
    // Convert the generic widget pointer into a slider widget pointer.
    //
    pSlider = (tSliderWidget *)pWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, pWidget->pDisplay);

    //
    // Initialize the clipping region based on the update rectangle passed.
    //
    bIntersect = GrRectIntersectGet(pDirty, &(pSlider->sBase.sPosition),
                                    &sClipRect);
    GrContextClipRegionSet(&sCtx, &sClipRect);

    //
    // Draw the control outline if necessary.
    //
    if(pSlider->ulStyle & SL_STYLE_OUTLINE)
    {
        //
        // Outline the slider with the outline color.
        //
        GrContextForegroundSet(&sCtx, pSlider->ulOutlineColor);
        GrRectDraw(&sCtx, &(pWidget->sPosition));

        //
        // Adjust the clipping rectangle to prevent the outline from being
        // corrupted later.
        //
        if(sClipRect.sXMin == pWidget->sPosition.sXMin)
        {
            sClipRect.sXMin++;
        }

        if(sClipRect.sYMin == pWidget->sPosition.sYMin)
        {
            sClipRect.sYMin++;
        }

        if(sClipRect.sXMax == pWidget->sPosition.sXMax)
        {
            sClipRect.sXMax--;
        }

        if(sClipRect.sYMax == pWidget->sPosition.sYMax)
        {
            sClipRect.sYMax--;
        }
    }

    //
    // Determine the position associated with the current slider value.
    //
    sPos = SliderValueToPosition(pSlider, pSlider->lValue);

    //
    // Remember this so that the dirty rectangle code in the click handler
    // draws the correct thing the first time it is called.
    //
    pSlider->sPos = sPos;

    //
    // Determine the rectangles for the active and empty portions of the
    // widget.
    //
    if(pSlider->ulStyle & SL_STYLE_VERTICAL)
    {
        //
        // Determine the rectangle corresponding to the bottom (value) portion
        // of the slider.
        //
        sValueRect.sXMin = pWidget->sPosition.sXMin;
        sValueRect.sXMax = pWidget->sPosition.sXMax;
        sValueRect.sYMin = sPos;
        sValueRect.sYMax = pWidget->sPosition.sYMax;

        //
        // Determine the rectangle corresponding to the top (empty) portion
        // of the slider.
        //
        sEmptyRect.sXMin = pWidget->sPosition.sXMin;
        sEmptyRect.sXMax = pWidget->sPosition.sXMax;
        sEmptyRect.sYMin = pWidget->sPosition.sYMin;
        sEmptyRect.sYMax = max(sEmptyRect.sYMin, sValueRect.sYMin - 1);
    }
    else
    {
        //
        // Determine the rectangle corresponding to the bottom (value) portion
        // of the slider.
        //
        sValueRect.sYMin = pWidget->sPosition.sYMin;
        sValueRect.sYMax = pWidget->sPosition.sYMax;
        sValueRect.sXMin = pWidget->sPosition.sXMin;
        sValueRect.sXMax = sPos;

        //
        // Determine the rectangle corresponding to the top (empty) portion
        // of the slider.
        //
        sEmptyRect.sYMin = pWidget->sPosition.sYMin;
        sEmptyRect.sYMax = pWidget->sPosition.sYMax;
        sEmptyRect.sXMax = pWidget->sPosition.sXMax;
        sEmptyRect.sXMin = min(sEmptyRect.sXMax, sValueRect.sXMax + 1);
    }

    //
    // Compute the center of the slider.  This will be needed later if drawing
    // text or an image.
    //
    lX = (pWidget->sPosition.sXMin +
          ((pWidget->sPosition.sXMax - pWidget->sPosition.sXMin + 1) / 2));
    lY = (pWidget->sPosition.sYMin +
          ((pWidget->sPosition.sYMax - pWidget->sPosition.sYMin + 1) / 2));

    //
    // Get the required clipping rectangle for the active/value part of
    // the slider.
    //
    bIntersect = GrRectIntersectGet(&sClipRect, &sValueRect, &sActiveClip);

    //
    // Does any part of the value rectangle intersect with the region we are
    // supposed to be redrawing?
    //
    if(bIntersect)
    {
        //
        // Yes - we have something to draw.
        //

        //
        // Set the new clipping rectangle.
        //
        GrContextClipRegionSet(&sCtx, &sActiveClip);

        //
        // Do we need to fill the active area with a color?
        //
        if(pSlider->ulStyle & SL_STYLE_FILL)
        {
            GrContextForegroundSet(&sCtx, pSlider->ulFillColor);
            GrRectFill(&sCtx, &sValueRect);
        }

        //
        // Do we need to draw an image in the active area?
        //
        if(pSlider->ulStyle & SL_STYLE_IMG)
        {
            GrContextForegroundSet(&sCtx, pSlider->ulTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ulFillColor);
            GrImageDraw(&sCtx, pSlider->pucImage,
                        lX - (GrImageWidthGet(pSlider->pucImage) / 2),
                        lY - (GrImageHeightGet(pSlider->pucImage) / 2));
        }

        //
        // Do we need to render a text string over the top of the active area?
        //
        if(pSlider->ulStyle & SL_STYLE_TEXT)
        {
            GrContextFontSet(&sCtx, pSlider->pFont);
            GrContextForegroundSet(&sCtx, pSlider->ulTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ulFillColor);
            GrStringDrawCentered(&sCtx, pSlider->pcText, -1, lX, lY,
                                 pSlider->ulStyle & SL_STYLE_TEXT_OPAQUE);
        }
    }

    //
    // Now get the required clipping rectangle for the background portion of
    // the slider.
    //
    bIntersect = GrRectIntersectGet(&sClipRect, &sEmptyRect, &sActiveClip);

    //
    // Does any part of the background rectangle intersect with the region we
    // are supposed to be redrawing?
    //
    if(bIntersect)
    {
        //
        // Yes - we have something to draw.
        //

        //
        // Set the new clipping rectangle.
        //
        GrContextClipRegionSet(&sCtx, &sActiveClip);

        //
        // Do we need to fill the active area with a color?
        //
        if(pSlider->ulStyle & SL_STYLE_BACKG_FILL)
        {
            GrContextForegroundSet(&sCtx, pSlider->ulBackgroundFillColor);
            GrRectFill(&sCtx, &sEmptyRect);
        }

        //
        // Do we need to draw an image in the active area?
        //
        if(pSlider->ulStyle & SL_STYLE_BACKG_IMG)
        {
            GrContextForegroundSet(&sCtx, pSlider->ulBackgroundTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ulBackgroundFillColor);
            GrImageDraw(&sCtx, pSlider->pucBackgroundImage,
                    lX - (GrImageWidthGet(pSlider->pucBackgroundImage) / 2),
                    lY - (GrImageHeightGet(pSlider->pucBackgroundImage) / 2));
        }

        //
        // Do we need to render a text string over the top of the active area?
        //
        if(pSlider->ulStyle & SL_STYLE_BACKG_TEXT)
        {
            GrContextFontSet(&sCtx, pSlider->pFont);
            GrContextForegroundSet(&sCtx, pSlider->ulBackgroundTextColor);
            GrContextBackgroundSet(&sCtx, pSlider->ulBackgroundFillColor);
            GrStringDrawCentered(&sCtx, pSlider->pcText, -1, lX, lY,
                                 pSlider->ulStyle & SL_STYLE_BACKG_TEXT_OPAQUE);
        }
    }
}
Beispiel #21
0
//*****************************************************************************
//
// The main loop handler for touch screen events from the touch screen driver.
//
//*****************************************************************************
int32_t
TSMainHandler(uint32_t ui32Message, int32_t i32X, int32_t i32Y)
{
    tRectangle sRect;

    //
    // See which event is being sent from the touch screen driver.
    //
    switch(ui32Message) {
        //
        // The pen has just been placed down.
        //
        case WIDGET_MSG_PTR_DOWN: {
            //
            // Erase the drawing area.
            //
            GrContextForegroundSet(&g_sContext, ClrBlack);
            sRect.i16XMin = 0;
            sRect.i16YMin = 0;
            sRect.i16XMax = 319;
            sRect.i16YMax = 239;
            GrRectFill(&g_sContext, &sRect);

            //
            // Flush any cached drawing operations.
            //
            GrFlush(&g_sContext);

            //
            // Set the drawing color to the current pen color.
            //
            GrContextForegroundSet(&g_sContext, g_pui32Colors[g_ui32ColorIdx]);

            //
            // Save the current position.
            //
            g_i32X = i32X;
            g_i32Y = i32Y;

            //
            // This event has been handled.
            //
            break;
        }

        //
        // Then pen has moved.
        //
        case WIDGET_MSG_PTR_MOVE: {
            //
            // Draw a line from the previous position to the current position.
            //
            GrLineDraw(&g_sContext, g_i32X, g_i32Y, i32X, i32Y);

            //
            // Flush any cached drawing operations.
            //
            GrFlush(&g_sContext);

            //
            // Save the current position.
            //
            g_i32X = i32X;
            g_i32Y = i32Y;

            //
            // This event has been handled.
            //
            break;
        }

        //
        // The pen has just been picked up.
        //
        case WIDGET_MSG_PTR_UP: {
            //
            // Draw a line from the previous position to the current position.
            //
            GrLineDraw(&g_sContext, g_i32X, g_i32Y, i32X, i32Y);

            //
            // Flush any cached drawing operations.
            //
            GrFlush(&g_sContext);

            //
            // Increment to the next drawing color.
            //
            g_ui32ColorIdx++;
            if(g_ui32ColorIdx ==
                    (sizeof(g_pui32Colors) / sizeof(g_pui32Colors[0]))) {
                g_ui32ColorIdx = 0;
            }

            //
            // This event has been handled.
            //
            break;
        }
    }

    //
    // Success.
    //
    return(1);
}
Beispiel #22
0
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;

    //
    // Set the clocking to run directly from the crystal.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_8MHZ);

    //
    // Initialize the display driver.
    //
    Formike128x128x16Init();

    //
    // Turn on the backlight.
    //
    Formike128x128x16BacklightOn();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sFormike128x128x16);

    //
    // Fill the top 15 rows of the screen with blue to create the banner.
    //
    sRect.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = 14;
    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_sFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "uart_echo", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 7, 0);

    //
    // Initialize the CSTN display and write status.
    //
    GrStringDraw(&g_sContext, "Port:   Uart 0",       -1, 12, 24, 0);
    GrStringDraw(&g_sContext, "Baud:   115,200 bps",  -1, 12, 32, 0);
    GrStringDraw(&g_sContext, "Data:   8 Bit",        -1, 12, 40, 0);
    GrStringDraw(&g_sContext, "Parity: None",         -1, 12, 48, 0);
    GrStringDraw(&g_sContext, "Stop:   1 Bit",        -1, 12, 56, 0);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

    //
    // Enable processor interrupts.
    //
    IntMasterEnable();

    //
    // Set GPIO A0 and A1 as UART pins.
    //
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Configure the UART for 115,200, 8-N-1 operation.
    //
    ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
                            (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
                             UART_CONFIG_PAR_NONE));

    //
    // Enable the UART interrupt.
    //
    ROM_IntEnable(INT_UART0);
    ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Prompt for text to be entered.
    //
    UARTSend((unsigned char *)"Ingrese un Texto: ", 18);

    //
    // Loop forever echoing data through the UART.
    //
    while(1)
    {
    }
}
Beispiel #23
0
//*****************************************************************************
//
// Run the hibernate example.  Use a loop to put the microcontroller into
// hibernate mode, and to wake up based on time. Also allow the user to cause
// it to hibernate and/or wake up based on button presses.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32Idx;
    uint32_t ui32Status = 0;
    uint32_t ui32HibernateCount = 0;
    tContext sContext;
    tRectangle sRect;

    //
    // 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_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Initialize the UART.
    //
    ConfigureUART();

    //
    // Initialize the OLED display
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sCFAL96x64x16);

    //
    // Fill the top 24 rows of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = 9;
    GrContextForegroundSet(&sContext, ClrDarkBlue);
    GrRectFill(&sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&sContext, ClrWhite);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&sContext, "hibernate", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 4, 0);

    //
    // Initialize the buttons driver
    //
    ButtonsInit();

    //
    // Set up systick to generate interrupts at 100 Hz.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100);
    ROM_SysTickIntEnable();
    ROM_SysTickEnable();

    //
    // Enable the Hibernation module.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE);

    //
    // Print wake cause message on display.
    //
    GrStringDrawCentered(&sContext, "Wake due to:", -1,
                         GrContextDpyWidthGet(&sContext) / 2, Row(2) + 4,
                         true);

    //
    // Check to see if Hibernation module is already active, which could mean
    // that the processor is waking from a hibernation.
    //
    if(HibernateIsActive())
    {
        //
        // Read the status bits to see what caused the wake.
        //
        ui32Status = HibernateIntStatus(0);
        HibernateIntClear(ui32Status);

        //
        // Wake was due to the push button.
        //
        if(ui32Status & HIBERNATE_INT_PIN_WAKE)
        {
            GrStringDrawCentered(&sContext, "BUTTON", -1,
                                 GrContextDpyWidthGet(&sContext) / 2,
                                 Row(3) + 4, true);
        }

        //
        // Wake was due to RTC match
        //
        else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0)
        {
            GrStringDrawCentered(&sContext, "TIMEOUT", -1,
                                 GrContextDpyWidthGet(&sContext) / 2,
                                 Row(3) + 4, true);
        }

        //
        // Wake is due to neither button nor RTC, so it must have been a hard
        // reset.
        //
        else
        {
            GrStringDrawCentered(&sContext, "RESET", -1,
                                 GrContextDpyWidthGet(&sContext) / 2,
                                 Row(3) + 4, true);
        }

        //
        // If the wake is due to button or RTC, then read the first location
        // from the battery backed memory, as the hibernation count.
        //
        if(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0))
        {
            HibernateDataGet(&ui32HibernateCount, 1);
        }
    }

    //
    // Enable the Hibernation module.  This should always be called, even if
    // the module was already enabled, because this function also initializes
    // some timing parameters.
    //
    HibernateEnableExpClk(ROM_SysCtlClockGet());

    //
    // If the wake was not due to button or RTC match, then it was a reset.
    //
    if(!(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0)))
    {
        //
        // Configure the module clock source.
        //
        HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE);

        //
        // Finish the wake cause message.
        //
        GrStringDrawCentered(&sContext, "RESET", -1,
                             GrContextDpyWidthGet(&sContext) / 2,
                             Row(3) + 4, true);

        //
        // Wait a couple of seconds in case we need to break in with the
        // debugger.
        //
        SysTickWait(3 * 100);

        //
        // Allow time for the crystal to power up.  This line is separated from
        // the above to make it clear this is still needed, even if the above
        // delay is removed.
        //
        SysTickWait(15);
    }

    //
    // Print the count of times that hibernate has occurred.
    //
    usnprintf(g_pcBuf, sizeof(g_pcBuf), "Hib count=%4u", ui32HibernateCount);
    GrStringDrawCentered(&sContext, g_pcBuf, -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(1) + 4, true);

    //
    // Print messages on the screen about hibernation.
    //
    GrStringDrawCentered(&sContext, "Select to Hib", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(4) + 4, true);
    GrStringDrawCentered(&sContext, "Wake in 5 s,", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(5) + 4, true);
    GrStringDrawCentered(&sContext, "or press Select", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(6) + 4, true);
    GrStringDrawCentered(&sContext, "for immed. wake.", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(7) + 4, true);

    //
    // Clear the button pressed flag, in case it was held down at the
    // beginning.
    //
    bSelectPressed = 0;

    //
    // Wait for user to press the button.
    //
    while(!bSelectPressed)
    {
        //
        // Wait a bit before looping again.
        //
        SysTickWait(10);
    }

    //
    // Tell user to release the button.
    //
    GrStringDrawCentered(&sContext, "                ", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(4) + 4, true);
    GrStringDrawCentered(&sContext, "   Release the  ", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(5) + 4, true);
    GrStringDrawCentered(&sContext, "     button.    ", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(6) + 4, true);
    GrStringDrawCentered(&sContext, "                ", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         Row(7) + 4, true);

    //
    // Wait for user to release the button.
    //
    while(bSelectPressed)
    {
    }

    //
    // If hibernation count is very large, it may be that there was already
    // a value in the hibernate memory, so reset the count.
    //
    ui32HibernateCount = (ui32HibernateCount > 10000) ? 0 : ui32HibernateCount;

    //
    // Increment the hibernation count, and store it in the battery backed
    // memory.
    //
    ui32HibernateCount++;
    HibernateDataSet(&ui32HibernateCount, 1);

    //
    // Clear and enable the RTC and set the match registers to 5 seconds in the
    // future. Set both to same, though they could be set differently, the
    // first to match will cause a wake.
    //
    HibernateRTCSet(0);
    HibernateRTCEnable();
    HibernateRTCMatchSet(0, 5);

    //
    // Set wake condition on pin or RTC match.  Board will wake when 5 seconds
    // elapses, or when the button is pressed.
    //
    HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC);

    //
    // Request hibernation.
    //
    HibernateRequest();

    //
    // Give it time to activate, it should never get past this wait.
    //
    SysTickWait(100);

    //
    // Should not have got here, something is wrong.  Print an error message to
    // the user.
    //
    sRect.i16XMin = 0;
    sRect.i16XMax = 95;
    sRect.i16YMin = 0;
    sRect.i16YMax = 63;
    GrContextForegroundSet(&sContext, ClrBlack);
    GrRectFill(&sContext, &sRect);
    GrContextForegroundSet(&sContext, ClrWhite);
    ui32Idx = 0;
    while(g_pcErrorText[ui32Idx])
    {
        GrStringDraw(&sContext, g_pcErrorText[ui32Idx], -1, Col(0),
                     Row(ui32Idx), true);
        ui32Idx++;
    }

    //
    // Wait for the user to press the button, then restart the app.
    //
    bSelectPressed = 0;
    while(!bSelectPressed)
    {
    }

    //
    // Reset the processor.
    //
    ROM_SysCtlReset();

    //
    // Finished.
    //
    while(1)
    {
    }
}
Beispiel #24
0
//*****************************************************************************
//
//! Paints the clock set widget on the display.
//!
//! \param psWidget is a pointer to the clock setting widget to be drawn.
//!
//! This function draws the date and time fields of the clock setting widget
//! onto the display.  One of the fields can be highlighted.  This is
//! called in response to a \b WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
ClockSetPaint(tWidget *psWidget)
{
    tClockSetWidget *psClockWidget;
    tContext sContext;
    tRectangle sRect, sRectSel;
    struct tm *psTime;
    char pcBuf[8];
    int32_t i32X, i32Y, i32Width, i32Height;
    uint32_t ui32Idx, ui32FontHeight, ui32FontWidth, ui32SelWidth;

    //
    // Check the arguments.
    //
    ASSERT(psWidget);
    ASSERT(psWidget->psDisplay);

    //
    // Convert the generic widget pointer into a clock set widget pointer.
    //
    psClockWidget = (tClockSetWidget *)psWidget;
    ASSERT(psClockWidget->psTime);

    //
    // Get pointer to the time structure
    //
    psTime = psClockWidget->psTime;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sContext, psWidget->psDisplay);

    //
    // Initialize the clipping region based on the extents of this widget.
    //
    GrContextClipRegionSet(&sContext, &(psWidget->sPosition));

    //
    // Set the font for the context, and get font height and width - they
    // are used a lot later.
    //
    GrContextFontSet(&sContext, psClockWidget->psFont);
    ui32FontHeight = GrFontHeightGet(psClockWidget->psFont);
    ui32FontWidth = GrFontMaxWidthGet(psClockWidget->psFont);

    //
    // Fill the widget with the background color.
    //
    GrContextForegroundSet(&sContext, psClockWidget->ui32BackgroundColor);
    GrRectFill(&sContext, &sContext.sClipRegion);

    //
    // Draw a border around the widget
    //
    GrContextForegroundSet(&sContext, psClockWidget->ui32ForegroundColor);
    GrContextBackgroundSet(&sContext, psClockWidget->ui32BackgroundColor);
    GrRectDraw(&sContext, &sContext.sClipRegion);

    //
    // Compute a rectangle for the screen title.  Put it at the top of
    // the widget display, and sized to be the height of the font, plus
    // a few pixels of space.
    //
    sRect.i16XMin = sContext.sClipRegion.i16XMin;
    sRect.i16XMax = sContext.sClipRegion.i16XMax;
    sRect.i16YMin = sContext.sClipRegion.i16YMin;
    sRect.i16YMax = ui32FontHeight * 2;
    GrRectDraw(&sContext, &sRect);

    //
    // Print a title for the widget
    //
    GrContextFontSet(&sContext, psClockWidget->psFont);
    GrStringDrawCentered(&sContext, "CLOCK SET", -1,
                         (1 + sRect.i16XMax - sRect.i16XMin) / 2,
                         (1 + sRect.i16YMax - sRect.i16YMin) / 2, 1);

    //
    // Reset the rectangle to cover the non-title area of the display
    //
    sRect.i16YMin = sRect.i16YMax + 1;
    sRect.i16YMax = sContext.sClipRegion.i16YMax;

    //
    // Compute the width and height of the area remaining for showing the
    // clock fields.
    //
    i32Width = 1 + (sRect.i16XMax - sRect.i16XMin);
    i32Height = 1 + (sRect.i16YMax - sRect.i16YMin);

    //
    // Compute the X and Y starting point for the row that will show the
    // date.
    //
    i32X = sRect.i16XMin + (i32Width - (ui32FontWidth * 10)) / 2;
    i32Y = sRect.i16YMin + ((i32Height * 1) / 6) - (ui32FontHeight / 2);

    //
    // Draw the date field separators on the date row.
    //
    GrStringDraw(&sContext, "/", -1, i32X + (ui32FontWidth * 4), i32Y, 0);
    GrStringDraw(&sContext, "/", -1, i32X + (ui32FontWidth * 7), i32Y, 0);

    //
    // Compute the X and Y starting point for the row that will show the
    // time.
    //
    i32X = sRect.i16XMin + (i32Width - (ui32FontWidth * 5)) / 2;
    i32Y = sRect.i16YMin + ((i32Height * 3) / 6) - (ui32FontHeight / 2);

    //
    // Draw the time field separators on the time row.
    //
    GrStringDraw(&sContext, ":", -1, i32X + (ui32FontWidth * 2), i32Y, 0);

    //
    // Process each of the fields to be shown on the widget
    //
    for(ui32Idx = 0; ui32Idx < NUM_FIELDS; ui32Idx++)
    {
        //
        // Compute the X and Y for the text for each field, and print the
        // text into a buffer.
        //
        switch(ui32Idx)
        {
            //
            // Year
            //
            case FIELD_YEAR:
            {
                usnprintf(pcBuf, sizeof(pcBuf), "%4u", psTime->tm_year+1900);
                i32X = sRect.i16XMin + (i32Width - (ui32FontWidth * 10)) / 2;
                i32Y = sRect.i16YMin + ((i32Height * 1) / 6) -
                       (ui32FontHeight / 2);
                ui32SelWidth = 4;
                break;
            }

            //
            // Month
            //
            case FIELD_MONTH:
            {
                usnprintf(pcBuf, sizeof(pcBuf), "%02u", psTime->tm_mon + 1);
                i32X += ui32FontWidth * 5;
                ui32SelWidth = 2;
                break;
            }

            //
            // Day
            //
            case FIELD_DAY:
            {
                usnprintf(pcBuf, sizeof(pcBuf), "%02u", psTime->tm_mday);
                i32X += ui32FontWidth * 3;
                ui32SelWidth = 2;
                break;
            }

            //
            // Hour
            //
            case FIELD_HOUR:
            {
                usnprintf(pcBuf, sizeof(pcBuf), "%02u", psTime->tm_hour);
                i32X = sRect.i16XMin + (i32Width - (ui32FontWidth * 5)) / 2;
                i32Y = sRect.i16YMin + ((i32Height * 3) / 6) -
                       (ui32FontHeight / 2);
                ui32SelWidth = 2;
                break;
            }

            //
            // Minute
            //
            case FIELD_MINUTE:
            {
                usnprintf(pcBuf, sizeof(pcBuf), "%02u", psTime->tm_min);
                i32X += ui32FontWidth * 3;
                ui32SelWidth = 2;
                break;
            }

            //
            // OK
            //
            case FIELD_OK:
            {
                usnprintf(pcBuf, sizeof(pcBuf), "OK");
                i32X = (i32Width - (ui32FontWidth * 9)) / 2;
                i32X += sRect.i16XMin;
                i32Y = ((i32Height * 5) / 6) - (ui32FontHeight / 2);
                i32Y += sRect.i16YMin;
                ui32SelWidth = 2;
                break;
            }

            //
            // CANCEL (default case is purely to keep the compiler from
            // issuing a warning that ui32SelWidth may be used ininitialized).
            //
            case FIELD_CANCEL:
            default:
            {
                usnprintf(pcBuf, sizeof(pcBuf), "CANCEL");
                i32X += ui32FontWidth * 3;
                ui32SelWidth = 6;
                break;
            }
        }


        //
        // If the current field index is the highlighted field, then this
        // text field will be drawn with highlighting.
        //
        if(ui32Idx == psClockWidget->ui32Highlight)
        {
            //
            // Compute a rectangle for the highlight area.
            //
            sRectSel.i16XMin = i32X;
            sRectSel.i16XMax = (ui32SelWidth * ui32FontWidth) + i32X;
            sRectSel.i16YMin = i32Y - 2;
            sRectSel.i16YMax = ui32FontHeight + i32Y + 2;

            //
            // Set the foreground color to the text color, and then fill the
            // highlight rectangle.  The text field will be highlighted by
            // inverting the normal colors.
            // Then draw the highlighting rectangle.
            //
            GrContextForegroundSet(&sContext,
                                   psClockWidget->ui32ForegroundColor);
            GrRectFill(&sContext, &sRectSel);

            //
            // Change the foreground color to the normal background color.
            // This will be used for drawing the text for the highlighted
            // field, which has the colors inverted (FG <--> BG)
            //
            GrContextForegroundSet(&sContext,
                                   psClockWidget->ui32BackgroundColor);
        }
        else
        {
            //
            // This text field is not highlighted so just set the normal
            // foreground color.
            //
            GrContextForegroundSet(&sContext,
                                   psClockWidget->ui32ForegroundColor);
        }

        //
        // Print the text from the buffer to the display at the computed
        // location.
        //
        GrStringDraw(&sContext, pcBuf, -1, i32X, i32Y, 0);
    }
}
Beispiel #25
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;

    //
    // Set the clocking to run from the PLL at 50MHz.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                       SYSCTL_XTAL_16MHZ);

    //
    // Initialize the display driver.
    //
    CFAL96x64x16Init();

    //
    // Initialize the graphics context.
    //
    GrContextInit(&g_sContext, &g_sCFAL96x64x16);

    //
    // Fill the top part of the screen with blue to create the banner.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = (DISPLAY_BANNER_HEIGHT) - 1;
    GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG);
    GrRectFill(&g_sContext, &sRect);

    //
    // Change foreground for white text.
    //
    GrContextForegroundSet(&g_sContext, DISPLAY_TEXT_FG);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "usb-host-mouse", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);

    //
    // Display default information about the mouse
    //
    GrStringDrawCentered(&g_sContext, "Position:", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 16, 0);
    GrStringDrawCentered(&g_sContext, "-,-", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 26, 1);
    GrStringDrawCentered(&g_sContext, "Buttons:", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 36, 0);
    GrStringDrawCentered(&g_sContext, "---", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 46, 1);

    //
    // Fill the bottom rows of the screen with blue to create the status area.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = GrContextDpyHeightGet(&g_sContext) -
                  DISPLAY_BANNER_HEIGHT - 1;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = sRect.i16YMin + DISPLAY_BANNER_HEIGHT;

    GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG);
    GrRectFill(&g_sContext, &sRect);

    //
    // Put a white box around the banner.
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrRectDraw(&g_sContext, &sRect);

    //
    // Print a no device message a placeholder for the message printed
    // during an event.
    //
    GrStringDrawCentered(&g_sContext, "No Device", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2,
                         sRect.i16YMin + 5, 0);

    //
    // Configure SysTick for a 100Hz interrupt.
    //
    ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND);
    ROM_SysTickEnable();
    ROM_SysTickIntEnable();

    //
    // Enable Clocking to the USB controller.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0);

    //
    // Configure the required pins for USB operation.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN);
    ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Initially wait for device connection.
    //
    g_eUSBState = STATE_NO_DEVICE;

    //
    // Initialize the USB stack mode and pass in a mode callback.
    //
    USBStackModeSet(0, eUSBModeOTG, ModeCallback);

    //
    // Register the host class drivers.
    //
    USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers);

    //
    // Initialized the cursor.
    //
    g_ui32Buttons = 0;
    g_i32CursorX = 0;
    g_i32CursorY = 0;

    //
    // Open an instance of the mouse driver.  The mouse does not need
    // to be present at this time, this just saves a place for it and allows
    // the applications to be notified when a mouse is present.
    //
    g_psMouseInstance =
        USBHMouseOpen(MouseCallback, g_pui8Buffer, MOUSE_MEMORY_SIZE);

    //
    // Initialize the power configuration. This sets the power enable signal
    // to be active high and does not enable the power fault.
    //
    USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER);

    //
    // Initialize the USB controller for OTG operation with a 2ms polling
    // rate.
    //
    USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE);

    //
    // The main loop for the application.
    //
    while(1)
    {
        //
        // Tell the OTG state machine how much time has passed in
        // milliseconds since the last call.
        //
        USBOTGMain(GetTickms());

        switch(g_eUSBState)
        {
            //
            // This state is entered when the mouse is first detected.
            //
            case STATE_MOUSE_INIT:
            {
                //
                // Initialize the newly connected mouse.
                //
                USBHMouseInit(g_psMouseInstance);

                //
                // Proceed to the mouse connected state.
                //
                g_eUSBState = STATE_MOUSE_CONNECTED;

                break;
            }

            case STATE_MOUSE_CONNECTED:
            {
                //
                // Nothing is currently done in the main loop when the mouse
                // is connected.
                //
                break;
            }

            case STATE_NO_DEVICE:
            {
                //
                // The mouse is not connected so nothing needs to be done here.
                //
                break;
            }

            default:
            {
                break;
            }
        }
    }
}
Beispiel #26
0
//*****************************************************************************
//
//! Draws the contents of a canvas.
//!
//! \param pWidget is a pointer to the canvas widget to be drawn.
//!
//! This function draws the contents of a canvas on the display.  This is
//! called in response to a \b #WIDGET_MSG_PAINT message.
//!
//! \return None.
//
//*****************************************************************************
static void
CanvasPaint(tWidget *pWidget)
{
    tCanvasWidget *pCanvas;
    tContext sCtx;
    long lX, lY, lSize;

    //
    // Check the arguments.
    //
    ASSERT(pWidget);

    //
    // Convert the generic widget pointer into a canvas widget pointer.
    //
    pCanvas = (tCanvasWidget *)pWidget;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sCtx, pWidget->pDisplay);

    //
    // Initialize the clipping region based on the extents of this canvas.
    //
    GrContextClipRegionSet(&sCtx, &(pWidget->sPosition));

    //
    // See if the canvas fill style is selected.
    //
    if(pCanvas->ulStyle & CANVAS_STYLE_FILL)
    {
        //
        // Fill the canvas with the fill color.
        //
        GrContextForegroundSet(&sCtx, pCanvas->ulFillColor);
        GrRectFill(&sCtx, &(pWidget->sPosition));
    }

    //
    // See if the canvas outline style is selected.
    //
    if(pCanvas->ulStyle & CANVAS_STYLE_OUTLINE)
    {
        //
        // Outline the canvas with the outline color.
        //
        GrContextForegroundSet(&sCtx, pCanvas->ulOutlineColor);
        GrRectDraw(&sCtx, &(pWidget->sPosition));
    }

    //
    // See if the canvas text or image style is selected.
    //
    if(pCanvas->ulStyle & (CANVAS_STYLE_TEXT | CANVAS_STYLE_IMG))
    {
        //
        // Compute the center of the canvas.
        //
        lX = (pWidget->sPosition.sXMin +
              ((pWidget->sPosition.sXMax - pWidget->sPosition.sXMin + 1) / 2));
        lY = (pWidget->sPosition.sYMin +
              ((pWidget->sPosition.sYMax - pWidget->sPosition.sYMin + 1) / 2));

        //
        // If the canvas outline style is selected then shrink the clipping
        // region by one pixel on each side so that the outline is not
        // overwritten by the text or image.
        //
        if(pCanvas->ulStyle & CANVAS_STYLE_OUTLINE)
        {
            sCtx.sClipRegion.sXMin++;
            sCtx.sClipRegion.sYMin++;
            sCtx.sClipRegion.sXMax--;
            sCtx.sClipRegion.sYMax--;
        }

        //
        // See if the canvas image style is selected.
        //
        if(pCanvas->ulStyle & CANVAS_STYLE_IMG)
        {
            //
            // Set the foreground and background colors to use for 1 BPP
            // images.
            //
            GrContextForegroundSet(&sCtx, pCanvas->ulTextColor);
            GrContextBackgroundSet(&sCtx, pCanvas->ulFillColor);

            //
            // Draw the image centered in the canvas.
            //
            GrImageDraw(&sCtx, pCanvas->pucImage,
                        lX - (GrImageWidthGet(pCanvas->pucImage) / 2),
                        lY - (GrImageHeightGet(pCanvas->pucImage) / 2));
        }

        //
        // See if the canvas text style is selected.
        //
        if(pCanvas->ulStyle & CANVAS_STYLE_TEXT)
        {
            //
            // Set the relevant font and colors.
            //
            GrContextFontSet(&sCtx, pCanvas->pFont);
            GrContextForegroundSet(&sCtx, pCanvas->ulTextColor);
            GrContextBackgroundSet(&sCtx, pCanvas->ulFillColor);

            //
            // Determine the drawing position for the string based on the
            // text alignment style.  First consider the horizontal case.  We
            // enter this section with lX set to the center of the widget.
            //

            //
            // How wide is the string?
            //
            lSize = GrStringWidthGet(&sCtx, pCanvas->pcText, -1);

            if(pCanvas->ulStyle & CANVAS_STYLE_TEXT_LEFT)
            {
                //
                // The string is to be aligned with the left edge of
                // the widget.  Use the clipping rectangle as reference
                // since this will ensure that the string doesn't
                // encroach on any border that is set.
                //
                lX = sCtx.sClipRegion.sXMin;
            }
            else
            {
                if(pCanvas->ulStyle & CANVAS_STYLE_TEXT_RIGHT)
                {
                    //
                    // The string is to be aligned with the right edge of
                    // the widget.  Use the clipping rectangle as reference
                    // since this will ensure that the string doesn't
                    // encroach on any border that is set.
                    //
                    lX = sCtx.sClipRegion.sXMax - lSize;
                }
                else
                {
                    //
                    // We are centering the string horizontally so adjust
                    // the position accordingly to take into account the
                    // width of the string.
                    //
                    lX -= (lSize / 2);
                }
            }

            //
            // Now consider the horizontal case.  We enter this section with lY
            // set to the center of the widget.
            //
            // How tall is the string?
            //
            lSize = GrStringHeightGet(&sCtx);

            if(pCanvas->ulStyle & CANVAS_STYLE_TEXT_TOP)
            {
                //
                // The string is to be aligned with the top edge of
                // the widget.  Use the clipping rectangle as reference
                // since this will ensure that the string doesn't
                // encroach on any border that is set.
                //
                lY = sCtx.sClipRegion.sYMin;
            }
            else
            {
                if(pCanvas->ulStyle & CANVAS_STYLE_TEXT_BOTTOM)
                {
                    //
                    // The string is to be aligned with the bottom edge of
                    // the widget.  Use the clipping rectangle as reference
                    // since this will ensure that the string doesn't
                    // encroach on any border that is set.
                    //
                    lY = sCtx.sClipRegion.sYMax - lSize;
                }
                else
                {
                    //
                    // We are centering the string vertically so adjust
                    // the position accordingly to take into account the
                    // height of the string.
                    //
                    lY -= (lSize / 2);
                }
            }

            //
            // Now draw the string.
            //
            GrStringDraw(&sCtx, pCanvas->pcText, -1, lX, lY,
                         pCanvas->ulStyle & CANVAS_STYLE_TEXT_OPAQUE);
        }
    }

    //
    // See if the application-drawn style is selected.
    //
    if(pCanvas->ulStyle & CANVAS_STYLE_APP_DRAWN)
    {
        //
        // Call the application-supplied function to draw the canvas.
        //
        pCanvas->pfnOnPaint(pWidget, &sCtx);
    }
}
Beispiel #27
0
//*****************************************************************************
//
// Handles paint requests for the primitives canvas widget.
//
//*****************************************************************************
void
OnPrimitivePaint(tWidget *pWidget, tContext *pContext)
{
    uint32_t ulIdx;
    tRectangle sRect;

    //
    // Draw a vertical sweep of lines from red to green.
    //
    for(ulIdx = 0; ulIdx <= 8; ulIdx++)
    {
        GrContextForegroundSet(pContext,
                               (((((10 - ulIdx) * 255) / 10) << ClrRedShift) |
                                (((ulIdx * 255) / 10) << ClrGreenShift)));
        GrLineDraw(pContext, 115, 120, 5, 120 - (11 * ulIdx));
    }

    //
    // Draw a horizontal sweep of lines from green to blue.
    //
    for(ulIdx = 1; ulIdx <= 10; ulIdx++)
    {
        GrContextForegroundSet(pContext,
                               (((((10 - ulIdx) * 255) / 10) <<
                                 ClrGreenShift) |
                                (((ulIdx * 255) / 10) << ClrBlueShift)));
        GrLineDraw(pContext, 115, 120, 5 + (ulIdx * 11), 29);
    }

    //
    // Draw a filled circle with an overlapping circle.
    //
    GrContextForegroundSet(pContext, ClrBrown);
    GrCircleFill(pContext, 185, 69, 40);
    GrContextForegroundSet(pContext, ClrSkyBlue);
    GrCircleDraw(pContext, 205, 99, 30);

    //
    // Draw a filled rectangle with an overlapping rectangle.
    //
    GrContextForegroundSet(pContext, ClrSlateGray);
    sRect.i16XMin = 20;
    sRect.i16YMin = 100;
    sRect.i16XMax = 75;
    sRect.i16YMax = 160;
    GrRectFill(pContext, &sRect);
    GrContextForegroundSet(pContext, ClrSlateBlue);
    sRect.i16XMin += 40;
    sRect.i16YMin += 40;
    sRect.i16XMax += 30;
    sRect.i16YMax += 28;
    GrRectDraw(pContext, &sRect);

    //
    // Draw a piece of text in fonts of increasing size.
    //
    GrContextForegroundSet(pContext, ClrSilver);
    GrContextFontSet(pContext, &g_sFontCm14);
    GrStringDraw(pContext, "Strings", -1, 125, 110, 0);
    GrContextFontSet(pContext, &g_sFontCm18);
    GrStringDraw(pContext, "Strings", -1, 145, 124, 0);
    GrContextFontSet(pContext, &g_sFontCm22);
    GrStringDraw(pContext, "Strings", -1, 165, 142, 0);
    GrContextFontSet(pContext, &g_sFontCm24);
    GrStringDraw(pContext, "Strings", -1, 185, 162, 0);

    //
    // Draw an image.
    //
    GrImageDraw(pContext, g_pucLogo, 270, 80);
}
Beispiel #28
0
//*****************************************************************************
//
// This example decrypts blocks of plaintext using TDES in CBC mode.  It
// does the decryption first without uDMA and then with uDMA.  The results
// are checked after each operation.
//
//*****************************************************************************
int
main(void)
{
    uint32_t pui32PlainText[16], ui32Errors, ui32Idx, ui32SysClock;
    tContext sContext;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Configure the device pins.
    //
    PinoutSet();

    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

    //
    // Initialize the graphics context.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "tdes-cbc-decrypt");

    //
    // Show some instructions on the display
    //
    GrContextFontSet(&sContext, g_psFontCm20);
    GrContextForegroundSet(&sContext, ClrWhite);
    GrStringDrawCentered(&sContext, "Connect a terminal to", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 60, false);
    GrStringDrawCentered(&sContext, "UART0 (115200,N,8,1)", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 80, false);
    GrStringDrawCentered(&sContext, "for more information.", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 100, false);

    //
    // Initialize local variables.
    //
    ui32Errors = 0;
    for(ui32Idx = 0; ui32Idx < 16; ui32Idx++)
    {
        pui32PlainText[ui32Idx] = 0;
    }

    //
    // Enable stacking for interrupt handlers.  This allows floating-point
    // instructions to be used within interrupt handlers, but at the expense of
    // extra stack usage.
    //
    ROM_FPUStackingEnable();

    //
    // Enable DES interrupts.
    //
    ROM_IntEnable(INT_DES0);

    //
    // Enable debug output on UART0 and print a welcome message.
    //
    ConfigureUART();
    UARTprintf("Starting TDES CBC decryption demo.\n");
    GrStringDrawCentered(&sContext, "Starting demo...", -1,
                         GrContextDpyWidthGet(&sContext) / 2, 140, false);

    //
    // Enable the uDMA module.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);

    //
    // Setup the control table.
    //
    ROM_uDMAEnable();
    ROM_uDMAControlBaseSet(g_psDMAControlTable);

    //
    // Initialize the CCM and DES modules.
    //
    if(!DESInit())
    {
        UARTprintf("Initialization of the DES module failed.\n");
        ui32Errors |= 0x00000001;
    }

    //
    // Perform the decryption without uDMA.
    //
    UARTprintf("Performing decryption without uDMA.\n");
    TDESCBCDecrypt(g_pui32TDESCipherText, pui32PlainText, g_pui32TDESKey,
                   64, g_pui32TDESIV, false);

    //
    // Check the result.
    //
    for(ui32Idx = 0; ui32Idx < 16; ui32Idx++)
    {
        if(pui32PlainText[ui32Idx] != g_pui32TDESPlainText[ui32Idx])
        {
            UARTprintf("Plaintext mismatch on word %d. Exp: 0x%x, Act: "
                       "0x%x\n", ui32Idx, g_pui32TDESPlainText[ui32Idx],
                       pui32PlainText[ui32Idx]);
            ui32Errors |= (ui32Idx << 16) | 0x00000002;
        }
    }

    //
    // Clear the array containing the plaintext.
    //
    for(ui32Idx = 0; ui32Idx < 16; ui32Idx++)
    {
        pui32PlainText[ui32Idx] = 0;
    }

    //
    // Perform the decryption with uDMA.
    //
    UARTprintf("Performing decryption with uDMA.\n");
    TDESCBCDecrypt(g_pui32TDESCipherText, pui32PlainText, g_pui32TDESKey,
                   64, g_pui32TDESIV, true);

    //
    // Check the result.
    //
    for(ui32Idx = 0; ui32Idx < 16; ui32Idx++)
    {
        if(pui32PlainText[ui32Idx] != g_pui32TDESPlainText[ui32Idx])
        {
            UARTprintf("Plaintext mismatch on word %d. Exp: 0x%x, Act: "
                       "0x%x\n", ui32Idx, g_pui32TDESPlainText[ui32Idx],
                       pui32PlainText[ui32Idx]);
            ui32Errors |= (ui32Idx << 16) | 0x00000004;
        }
    }

    //
    // Finished.
    //
    if(ui32Errors)
    {
        UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors);
        GrStringDrawCentered(&sContext, "Demo failed.", -1,
                             GrContextDpyWidthGet(&sContext) / 2, 180, false);
    }
    else
    {
        UARTprintf("Demo completed successfully.\n");
        GrStringDrawCentered(&sContext, "Demo passed.", -1,
                             GrContextDpyWidthGet(&sContext) / 2, 180, false);
    }

    while(1)
    {
    }
}
Beispiel #29
0
void main(void){

    WDT_A_hold(WDT_A_BASE); // Stop WDT

    boardInit(); // Basic GPIO initialization

    clockInit(8000000); // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz

    Sharp96x96_LCDInit(); // Set up the LCD


    GrContextInit(&g_sContext, &g_sharp96x96LCD);
  	GrContextForegroundSet(&g_sContext, ClrBlack);
  	GrContextBackgroundSet(&g_sContext, ClrWhite);
  	GrContextFontSet(&g_sContext, &g_sFontFixed6x8);
  	GrClearDisplay(&g_sContext);
  	GrFlush(&g_sContext);

	while(1){
		// Intro Screen
		GrClearDisplay(&g_sContext);
		GrStringDrawCentered(&g_sContext,
							 "How to use",
							 AUTO_STRING_LENGTH,
							 48,
							 15,
							 TRANSPARENT_TEXT);
		GrStringDrawCentered(&g_sContext,
							 "the MSP430",
							 AUTO_STRING_LENGTH,
							 48,
							 35,
							 TRANSPARENT_TEXT);
		GrStringDraw(&g_sContext,
					 "Graphics Library",
					 AUTO_STRING_LENGTH,
					 1,
					 51,
					 TRANSPARENT_TEXT);
		GrStringDrawCentered(&g_sContext,
							 "Primitives",
							 AUTO_STRING_LENGTH,
							 48,
							 75,
							 TRANSPARENT_TEXT);

		GrFlush(&g_sContext);
		Delay();
		GrClearDisplay(&g_sContext);

		// Draw pixels and lines on the display
		GrStringDrawCentered(&g_sContext,
							 "Draw Pixels",
							 AUTO_STRING_LENGTH,
							 48,
							 5,
							 TRANSPARENT_TEXT);
		GrStringDrawCentered(&g_sContext,
							 "& Lines",
							 AUTO_STRING_LENGTH,
							 48,
							 15,
							 TRANSPARENT_TEXT);
		GrPixelDraw(&g_sContext, 30, 30);
		GrPixelDraw(&g_sContext, 30, 32);
		GrPixelDraw(&g_sContext, 32, 32);
		GrPixelDraw(&g_sContext, 32, 30);
		GrLineDraw(&g_sContext, 35, 35, 90, 90);
		GrLineDraw(&g_sContext, 5, 80, 80, 20);
		GrLineDraw(&g_sContext,
				   0,
				   GrContextDpyHeightGet(&g_sContext) - 1,
				   GrContextDpyWidthGet(&g_sContext) - 1,
				   GrContextDpyHeightGet(&g_sContext) - 1);
		GrFlush(&g_sContext);
		Delay();
		GrClearDisplay(&g_sContext);

		// Draw circles on the display
		GrStringDraw(&g_sContext,
					 "Draw Circles",
					 AUTO_STRING_LENGTH,
					 10,
					 5,
					 TRANSPARENT_TEXT);
		GrCircleDraw(&g_sContext,
					 30,
					 70,
					 20);
		GrCircleFill(&g_sContext,
					 60,
					 50,
					 30);
		GrFlush(&g_sContext);
		Delay();
		GrClearDisplay(&g_sContext);

		// Draw rectangles on the display
		GrStringDrawCentered(&g_sContext,
							 "Draw Rectangles",
							 AUTO_STRING_LENGTH,
							 48,
							 5,
							 TRANSPARENT_TEXT);
		GrRectDraw(&g_sContext, &myRectangle1);
		GrRectFill(&g_sContext, &myRectangle2);
		// Text below won't be visible on screen due to transparency
		// (foreground colors match)
		GrStringDrawCentered(&g_sContext,
							 "Normal Text",
							 AUTO_STRING_LENGTH,
							 50,
							 50,
							 TRANSPARENT_TEXT);
		// Text below draws foreground and background for opacity
		GrStringDrawCentered(&g_sContext,
							 "Opaque Text",
							 AUTO_STRING_LENGTH,
							 50,
							 65,
							 OPAQUE_TEXT);
		GrContextForegroundSet(&g_sContext, ClrWhite);
		GrContextBackgroundSet(&g_sContext, ClrBlack);
		GrStringDrawCentered(&g_sContext,
							 "Invert Text",
							 AUTO_STRING_LENGTH,
							 50,
							 80,
							 TRANSPARENT_TEXT);
		GrFlush(&g_sContext);
		Delay();

		// Invert the foreground and background colors
		GrContextForegroundSet(&g_sContext, ClrBlack);
		GrContextBackgroundSet(&g_sContext, ClrWhite);
		GrRectFill(&g_sContext, &myRectangle3);
		GrContextForegroundSet(&g_sContext, ClrWhite);
		GrContextBackgroundSet(&g_sContext, ClrBlack);
		GrStringDrawCentered(&g_sContext,
							 "Invert Colors",
							 AUTO_STRING_LENGTH,
							 48,
							 5,
							 TRANSPARENT_TEXT);
		GrRectDraw(&g_sContext, &myRectangle1);
		GrRectFill(&g_sContext, &myRectangle2);
		// Text below won't be visible on screen due to
		// transparency (foreground colors match)
		GrStringDrawCentered(&g_sContext,
							 "Normal Text",
							 AUTO_STRING_LENGTH,
							 50,
							 50,
							 TRANSPARENT_TEXT);
		// Text below draws foreground and background for opacity
		GrStringDrawCentered(&g_sContext,
							 "Opaque Text",
							 AUTO_STRING_LENGTH,
							 50,
							 65,
							 OPAQUE_TEXT);
		// Text below draws with inverted foreground color to become visible
		GrContextForegroundSet(&g_sContext, ClrBlack);
		GrContextBackgroundSet(&g_sContext, ClrWhite);
		GrStringDrawCentered(&g_sContext,
							 "Invert Text",
							 AUTO_STRING_LENGTH,
							 50,
							 80,
							 TRANSPARENT_TEXT);
		GrFlush(&g_sContext);
		Delay();
		GrContextForegroundSet(&g_sContext, ClrBlack);
		GrContextBackgroundSet(&g_sContext, ClrWhite);
		GrClearDisplay(&g_sContext);

		// Draw Images on the display
		GrImageDraw(&g_sContext, &LPRocket_96x37_1BPP_UNCOMP, 3, 28);
		GrFlush(&g_sContext);
		Delay();
		GrClearDisplay(&g_sContext);
		GrImageDraw(&g_sContext, &TI_Logo_69x64_1BPP_UNCOMP, 15, 15);
		GrFlush(&g_sContext);
		Delay();
		// __bis_SR_register(LPM0_bits+GIE); //enter low power mode 0 with interrupts
	}
}
//*****************************************************************************
//
//! Draws the current menu into a drawing context, off-screen buffer.
//!
//! \param pMenuWidget points at the SlideMenuWidget being processed.
//! \param pContext points to the context where all drawing should be done.
//! \param lOffsetY is the Y offset for drawing the menu.
//!
//! This function renders a menu (set of menu items), into a drawing context.
//! It assumes that the drawing context is an off-screen buffer, and that
//! the entire buffer belongs to this widget.  The vertical position of the
//! menu can be adjusted by using the parameter lOffsetY.  This value can be
//! positive or negative and can cause the menu to be rendered above or below
//! the normal position in the display.
//!
//! \return None.
//
//*****************************************************************************
void
SlideMenuDraw(tSlideMenuWidget *pMenuWidget, tContext *pContext, long lOffsetY)
{
    tSlideMenu *pMenu;
    unsigned long ulIdx;
    tRectangle sRect;

    //
    // Check the arguments
    //
    ASSERT(pMenuWidget);
    ASSERT(pContext);

    //
    // Set the foreground color for the rectangle fill to match what we want
    // as the menu background.
    //
    GrContextForegroundSet(pContext, pMenuWidget->ulColorBackground);
    GrRectFill(pContext, &pContext->sClipRegion);

    //
    // Get the current menu that is being displayed
    //
    pMenu = pMenuWidget->pSlideMenu;

    //
    // Set the foreground to the color we want for the menu item boundaries
    // and text color, text font.
    //
    GrContextForegroundSet(pContext, pMenuWidget->ulColorForeground);
    GrContextFontSet(pContext, pMenuWidget->pFont);

    //
    // Set the rectangle bounds for the first menu item.
    // The starting Y value is calculated based on which menu item is currently
    // centered.  Y coordinates are subtracted to find the Y start location
    // of the first menu item, which could even be off the display.
    //
    // Set the X coords of the menu item to the extents of the display
    //
    sRect.sXMin = 0;
    sRect.sXMax = pContext->sClipRegion.sXMax;

    //
    // Find the Y coordinate of the centered menu item
    //
    sRect.sYMin = (pContext->pDisplay->usHeight / 2) -
                  (pMenuWidget->ulMenuItemHeight / 2);

    //
    // Adjust to find Y coordinate of first menu item
    //
    sRect.sYMin -= pMenu->ulCenterIndex * pMenuWidget->ulMenuItemHeight;

    //
    // Now adjust for the offset that was passed in by caller.  This allows
    // for drawing menu items above or below the main display.
    //
    sRect.sYMin += lOffsetY;

    //
    // Find the ending Y coordinate of first menu item
    //
    sRect.sYMax = sRect.sYMin + pMenuWidget->ulMenuItemHeight - 1;

    //
    // Start the index at the first menu item.  It is possible that this
    // menu item is off the display.
    //
    ulIdx = 0;

    //
    // Loop through all menu items, drawing on the display.  Note that some
    // may not be on the screen, but they will be clipped.
    //
    while(ulIdx < pMenu->ulItems)
    {
        //
        // If this index is the one that is highlighted, then change the
        // background
        //
        if(ulIdx == pMenu->ulFocusIndex)
        {
            //
            // Set the foreground to the highlight color, and fill the
            // rectangle of the background of this menu item.
            //
            GrContextForegroundSet(pContext, pMenuWidget->ulColorHighlight);
            GrRectFill(pContext, &sRect);

            //
            // Set the new foreground to the normal foreground color, and
            // set the background to the highlight color.  This is so
            // remaining drawing operations will have the correct background
            // and foreground colors for this highlighted menu item cell.
            //
            GrContextForegroundSet(pContext, pMenuWidget->ulColorForeground);
            GrContextBackgroundSet(pContext, pMenuWidget->ulColorHighlight);

            //
            // If this menu has a parent, then draw a left arrow icon on the
            // focused menu item.
            //
            if(pMenu->pParent)
            {
                GrImageDraw(pContext, g_ucLtArrow, sRect.sXMin + 4,
                            sRect.sYMin +
                            (pMenuWidget->ulMenuItemHeight / 2) - 4);
            }

            //
            // If this menu has a child menu or child widget, then draw a
            // right arrow icon on the focused menu item.
            //
            if(pMenu->pSlideMenuItems[ulIdx].pChildMenu ||
                    pMenu->pSlideMenuItems[ulIdx].pChildWidget)
            {
                GrImageDraw(pContext, g_ucRtArrow, sRect.sXMax - 8,
                            sRect.sYMin +
                            (pMenuWidget->ulMenuItemHeight / 2) - 4);
            }
        }

        //
        // Otherwise this is a normal, non-highlighted menu item cell,
        // so set the normal background color.
        //
        else
        {
            GrContextBackgroundSet(pContext, pMenuWidget->ulColorBackground);
        }

        //
        // If the current menu is multi-selectable, then draw a checkbox on
        // the menu item.  Draw a checked or unchecked box depending on whether
        // the item has been selected.
        //
        if(pMenu->bMultiSelectable)
        {
            if(pMenu->ulSelectedFlags & (1 << ulIdx))
            {
                GrImageDraw(pContext, g_ucChecked, sRect.sXMax - 12,
                            sRect.sYMin +
                            (pMenuWidget->ulMenuItemHeight / 2) - 4);
            }
            else
            {
                GrImageDraw(pContext, g_ucUnchecked, sRect.sXMax - 12,
                            sRect.sYMin +
                            (pMenuWidget->ulMenuItemHeight / 2) - 4);
            }

        }

        //
        // Draw the rectangle representing the menu item
        //
        GrRectDraw(pContext, &sRect);

        //
        // Draw the text for this menu item in the middle of the menu item
        // rectangle (cell).
        //
        GrStringDrawCentered(pContext, pMenu->pSlideMenuItems[ulIdx].pcText,
                             -1, pMenuWidget->sBase.pDisplay->usWidth / 2,
                             sRect.sYMin +
                             (pMenuWidget->ulMenuItemHeight / 2) - 1, 0);

        //
        // Advance to the next menu item, and update the menu item rectangle
        // bounds to the next position
        //
        ulIdx++;
        sRect.sYMin += pMenuWidget->ulMenuItemHeight;
        sRect.sYMax += pMenuWidget->ulMenuItemHeight;

        //
        // Note that this may attempt to render menu items that run off the
        // bottom of the drawing area, but these will just be clipped and a
        // little bit of processing time is wasted.
        //
    }
}