Пример #1
0
/******************************************************************************
*																			  *
* \brief  Shows the status string on the color STN display.                   *
*																			  *
* \param psContext is a pointer to the graphics context representing the      *
*        display.                                                             *
*																		      *
* \param pcStatus is a pointer to the string to be shown.                     *
*																		      *
* \return none.                                                               *
*                                                                             *
******************************************************************************/
void DisplayStatus(tContext *psContext, char *pcStatus)
{
    tRectangle rectLine;
    int lY;

    /* Calculate the Y coordinate of the top left of the character cell
       for our line of text.
    */
    lY = (GrContextDpyHeightGet(psContext) / 8) -
         (GrFontHeightGet(TEXT_FONT) / 2);

    /* Determine the bounding rectangle for this line of text. We add 4 pixels
       to the height just to ensure that we clear a couple of pixels above and
       below the line of text.
    */
    rectLine.sXMin = 0;
    rectLine.sXMax = GrContextDpyWidthGet(psContext) - 1;
    rectLine.sYMin = lY;
    rectLine.sYMax = lY + GrFontHeightGet(TEXT_FONT) + 3;

    /* Clear the line with black. */
    
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrRectFill(psContext, &rectLine);
    
    /* Draw the new status string */
    
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrStringDrawCentered(psContext, pcStatus, -1,
                         GrContextDpyWidthGet(psContext) / 2,
                         GrContextDpyHeightGet(psContext) / 8 , false);
}
Пример #2
0
//*****************************************************************************
//
// The touch screen driver calls this function to report all state changes.
//
//*****************************************************************************
static long
WatchdogTouchCallback(unsigned long ulMessage, long lX,  long lY)
{
    //
    // If the screen is tapped, we will receive a PTR_DOWN then a PTR_UP
    // message. We pick one (pretty much at random) to use as the trigger to
    // stop feeding the watchdog.
    //
    if(ulMessage == WIDGET_MSG_PTR_UP)
    {
        //
        // Let the user know that the tap has been registered and that the
        // watchdog is being starved.
        //
        GrContextFontSet(&g_sContext, g_pFontCmss20);
        GrStringDrawCentered(&g_sContext, "Watchdog is not being fed!", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2 ,
                             (GrContextDpyHeightGet(&g_sContext) / 2), 1);
        GrContextFontSet(&g_sContext, g_pFontCmss14);
        GrStringDrawCentered(&g_sContext,
                             "           System will reset shortly.           ",
                             -1, GrContextDpyWidthGet(&g_sContext) / 2 ,
                             (GrContextDpyHeightGet(&g_sContext) / 2) + 20, 1);

        //
        // Set the flag that tells the interrupt handler not to clear the
        // watchdog interrupt.
        //
        g_bFeedWatchdog = false;
    }

    return(0);
}
Пример #3
0
//*****************************************************************************
//
// The touch screen driver calls this function to report all state changes.
//
//*****************************************************************************
static int32_t
WatchdogTouchCallback(uint32_t ui32Message, int32_t i32X, int32_t i32Y)
{
    //
    // If the screen is tapped, we will receive a PTR_DOWN then a PTR_UP
    // message.  Use PTR_UP as the trigger to stop feeding the watchdog.
    //
    if(ui32Message == WIDGET_MSG_PTR_UP)
    {
        //
        // See if the left or right side of the screen was touched.
        //
        if(i32X <= (GrContextDpyWidthGet(&g_sContext) / 2))
        {
            //
            // Let the user know that the tap has been registered and that the
            // watchdog0 is being starved.
            //
            GrContextFontSet(&g_sContext, g_psFontCmss20);
            GrContextForegroundSet(&g_sContext, ClrRed);
            GrStringDrawCentered(&g_sContext,
                                 "Watchdog 0 starved, reset shortly", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2 ,
                                 (GrContextDpyHeightGet(&g_sContext) / 2) + 40,
                                 1);
            GrContextForegroundSet(&g_sContext, ClrWhite);

            //
            // Set the flag that tells the interrupt handler not to clear the
            // watchdog0 interrupt.
            //
            g_bFeedWatchdog0 = false;
        }
        else
        {
            //
            // Let the user know that the tap has been registered and that the
            // watchdog1 is being starved.
            //
            GrContextFontSet(&g_sContext, g_psFontCmss20);
            GrContextForegroundSet(&g_sContext, ClrRed);
            GrStringDrawCentered(&g_sContext,
                                 "Watchdog 1 starved, reset shortly", -1,
                                 GrContextDpyWidthGet(&g_sContext) / 2 ,
                                 (GrContextDpyHeightGet(&g_sContext) / 2) + 60,
                                 1);
            GrContextForegroundSet(&g_sContext, ClrWhite);

            //
            // Set the flag that tells the interrupt handler not to clear the
            // watchdog1 interrupt.
            //
            g_bFeedWatchdog1 = false;
        }
    }

    return(0);
}
Пример #4
0
//*****************************************************************************
//
// Shows the status string on the color STN display.
//
// \param psContext is a pointer to the graphics context representing the
// display.
// \param pcStatus is a pointer to the string to be shown.
//
// This implementation assumes we are using a 6 pixel wide font, giving us
// space for 16 characters across the display.
//
//*****************************************************************************
void
DisplayStatus(tContext *psContext, char *pcStatus)
{
    tRectangle sRectLine;

    //
    // Determine the bounding rectangle for this line of text.
    //
    sRectLine.i16XMin = 0;
    sRectLine.i16XMax = GrContextDpyWidthGet(psContext) - 1;
    sRectLine.i16YMin = GrContextDpyHeightGet(psContext) - (TEXT_HEIGHT + 2);
    sRectLine.i16YMax = sRectLine.i16YMin + GrFontHeightGet(TEXT_FONT) + 1;

    //
    // Clear the line with black.
    //
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrRectFill(psContext, &sRectLine);

    //
    // Draw the new status string
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrStringDrawCentered(psContext, pcStatus, -1,
                         GrContextDpyWidthGet(psContext) / 2,
                         sRectLine.i16YMin + (TEXT_HEIGHT / 2), false);
}
Пример #5
0
//*****************************************************************************
//
// This hook is called by FreeRTOS when an stack overflow error is detected.
//
//*****************************************************************************
void
vApplicationStackOverflowHook(xTaskHandle *pxTask, signed char *pcTaskName)
{
    tContext sContext;

    //
    // A fatal FreeRTOS error was detected, so display an error message.
    //
    GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);
    GrContextForegroundSet(&sContext, ClrRed);
    GrContextBackgroundSet(&sContext, ClrBlack);
    GrContextFontSet(&sContext, g_psFontCm20);
    GrStringDrawCentered(&sContext, "Fatal FreeRTOS error!", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         (((GrContextDpyHeightGet(&sContext) - 24) / 2) +
                          24), 1);

    //
    // This function can not return, so loop forever.  Interrupts are disabled
    // on entry to this function, so no processor interrupts will interrupt
    // this loop.
    //
    while(1)
    {
    }
}
//*****************************************************************************
//
// This hook is called by SafeRTOS when an error is detected.
//
//*****************************************************************************
static void
SafeRTOSErrorHook(xTaskHandle xHandleOfTaskWithError,
                  signed portCHAR *pcNameOfTaskWithError,
                  portBASE_TYPE xErrorCode)
{
    tContext sContext;

    //
    // A fatal SafeRTOS error was detected, so display an error message.
    //
    GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119);
    GrContextForegroundSet(&sContext, ClrRed);
    GrContextBackgroundSet(&sContext, ClrBlack);
    GrContextFontSet(&sContext, g_pFontCm20);
    GrStringDrawCentered(&sContext, "Fatal SafeRTOS error!", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         (((GrContextDpyHeightGet(&sContext) - 24) / 2) +
                          24), 1);

    //
    // This function can not return, so loop forever.  Interrupts are disabled
    // on entry to this function, so no processor interrupts will interrupt
    // this loop.
    //
    while(1)
    {
    }
}
Пример #7
0
void Timer1IntHandler(void)
{
	//debugled(10);
    ROM_TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

    //debugled(3);
    int angle=0;
    if(max2>0 && max1>0 && abs(maxi1-maxi2)<PULSE_SAMPLE)
    {
    //float dt=abs(maxi1-maxi2)/SAMPLING_FREQUENCY;
    //angle=asin(dt*lambda/distance)*180/3.1412;
    angle=abs(maxi1-maxi2);
    }
    //debugled(3);
    acount++;
    //rcount=0;
    //ROM_IntMasterDisable();

	snprintf(text,sizeof(text),"%3ld,%3ld",rcount,g_ulADCCount);


    GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    GrRectFill(&sDisplayContext, &sRect1);
    GrContextForegroundSet(&sDisplayContext, ClrWhite);
    //GrRectDraw(&sDisplayContext, &sRect1);
    GrContextFontSet(&sDisplayContext, g_pFontCm12);
    GrStringDrawCentered(&sDisplayContext,text, -1,
                         GrContextDpyWidthGet(&sDisplayContext) / 2, 10, 0);

    GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    GrRectFill(&sDisplayContext, &sRect2);
    GrContextForegroundSet(&sDisplayContext, ClrWhite);
    sprintf(text,"%4d,%4d",buffer_increment,rem);
    GrContextFontSet(&sDisplayContext, g_pFontCm12/*g_pFontFixed6x8*/);
    GrStringDrawCentered(&sDisplayContext, text, -1,
                         GrContextDpyWidthGet(&sDisplayContext) / 2,
                         ((GrContextDpyHeightGet(&sDisplayContext) - 24) / 2) + 24,
                         0);
//    GrFlush(&sDisplayContext);
    max1=0;
    max2=0;
    res=0;
    res1=0;
    maxi1=0;
    maxi2=0;
    buffer_index=0;
    for(i=0;i<buffer_size;i++)
    {
    	buffer[0][i]=0;
    	buffer[1][i]=0;
    }
    i=0;
    j=0;
    ind2=buffer_index-buffer_increment+1;




}
Пример #8
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
void
HostMain(void)
{
    switch(iUSBState)
    {
        //
        // This state is entered when the mouse is first detected.
        //
        case eStateMouseInit:
        {
            //
            // Initialize the newly connected mouse.
            //
            USBHMouseInit(g_psMouseInstance);

            //
            // Proceed to the mouse connected state.
            //
            iUSBState = eStateMouseConnected;

            //
            // Update the status on the screen.
            //
            UpdateStatus(0, 0, true);

            //
            // Update the cursor on the screen.
            //
            UpdateCursor(GrContextDpyWidthGet(&g_sContext) / 2,
                         GrContextDpyHeightGet(&g_sContext)/ 2);

            break;
        }
        case eStateMouseConnected:
        {
            //
            // Nothing is currently done in the main loop when the mouse
            // is connected.
            //
            break;
        }
        case eStateNoDevice:
        {
            //
            // The mouse is not connected so nothing needs to be done here.
            //
            break;
        }
        default:
        {
            break;
        }
    }

    //
    // Periodically call the main loop for the Host controller driver.
    //
    USBHCDMain();
}
Пример #9
0
//*****************************************************************************
//
// Initialize the application interface.
//
//*****************************************************************************
void
UIInit(uint32_t ui32SysClock)
{
    //
    // Initialize the display driver.
    //
    Kentec320x240x16_SSD2119Init(ui32SysClock);

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

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "usb-host-keyboard");

    //
    // Set the font for the application.
    //
    GrContextFontSet(&g_sContext, g_psFontFixed6x8);

    //
    // Calculate the number of characters that will fit on a line.
    // Make sure to leave a small border for the text box.
    //
    g_ui32CharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 16) /
                         GrFontMaxWidthGet(g_psFontFixed6x8);

    //
    // Calculate the number of lines per usable text screen.  This requires
    // taking off space for the top and bottom banners and adding a small bit
    // for a border.
    //
    g_ui32LinesPerScreen = (GrContextDpyHeightGet(&g_sContext) -
                            (2*(DISPLAY_BANNER_HEIGHT + 1)) -
                            BUTTON_HEIGHT) / GrFontHeightGet(g_psFontFixed6x8);

    //
    // Set up the text scrolling variables.
    //
    g_ui32CurrentLine = 0;
    g_ui32EntryLine = 0;

    //
    // Draw the initial prompt on the screen.
    //
    DrawPrompt();

    //
    // Initial update of the screen.
    //
    UIUpdateStatus();
}
Пример #10
0
//*****************************************************************************
//
// This function will update the small mouse button indicators in the status
// bar area of the screen.  This can be called on its own or it will be called
// whenever UpdateStatus() is called as well.
//
//*****************************************************************************
void
UpdateButtons(void)
{
    tRectangle sRect, sRectInner;
    int iButton;

    //
    // Initialize the button indicator position.
    //
    sRect.i16XMin = GrContextDpyWidthGet(&g_sContext) - 36;
    sRect.i16YMin = GrContextDpyHeightGet(&g_sContext) - 18;
    sRect.i16XMax = sRect.i16XMin + 6;
    sRect.i16YMax = sRect.i16YMin + 8;
    sRectInner.i16XMin = sRect.i16XMin + 1;
    sRectInner.i16YMin = sRect.i16YMin + 1;
    sRectInner.i16XMax = sRect.i16XMax - 1;
    sRectInner.i16YMax = sRect.i16YMax - 1;

    //
    // Check all three buttons.
    //
    for(iButton = 0; iButton < 3; iButton++)
    {
        //
        // Draw the button indicator red if pressed and black if not pressed.
        //
        if(g_ui32Buttons & (1 << iButton))
        {
            GrContextForegroundSet(&g_sContext, ClrRed);
        }
        else
        {
            GrContextForegroundSet(&g_sContext, ClrBlack);
        }

        //
        // Draw the back of the  button indicator.
        //
        GrRectFill(&g_sContext, &sRectInner);

        //
        // Draw the border on the button indicator.
        //
        GrContextForegroundSet(&g_sContext, ClrWhite);
        GrRectDraw(&g_sContext, &sRect);

        //
        // Move to the next button indicator position.
        //
        sRect.i16XMin += 8;
        sRect.i16XMax += 8;
        sRectInner.i16XMin += 8;
        sRectInner.i16XMax += 8;
    }
}
//*****************************************************************************
//
// Print "Hello World!" to the display on the Intelligent Display Module.
//
//*****************************************************************************
int
main(void)
{
    tContext sContext;
    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(&sContext, &g_sKentec320x240x16_SSD2119);

    //
    // Draw the application frame.
    //
    FrameDraw(&sContext, "hello");

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

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

    //
    // We are finished. Hang around doing nothing.
    //
    while(1)
    {
    }
}
//*****************************************************************************
//
// Shows the status string on the color STN display.
//
// \param psContext is a pointer to the graphics context representing the
// display.
// \param pcStatus is a pointer to the string to be shown.
//
//*****************************************************************************
void
DisplayStatus(tContext *psContext, char *pcStatus)
{
    tRectangle rectLine;
    int32_t i32Y;

    //
    // Calculate the Y coordinate of the top left of the character cell
    // for our line of text.
    //
    i32Y = (GrContextDpyHeightGet(psContext) / 4) -
           (GrFontHeightGet(TEXT_FONT) / 2);

    //
    // Determine the bounding rectangle for this line of text. We add 4 pixels
    // to the height just to ensure that we clear a couple of pixels above and
    // below the line of text.
    //
    rectLine.i16XMin = 0;
    rectLine.i16XMax = GrContextDpyWidthGet(psContext) - 1;
    rectLine.i16YMin = i32Y;
    rectLine.i16YMax = i32Y + GrFontHeightGet(TEXT_FONT) + 3;

    //
    // Clear the line with black.
    //
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrRectFill(psContext, &rectLine);

    //
    // Draw the new status string
    //
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrStringDrawCentered(psContext, pcStatus, -1,
                         GrContextDpyWidthGet(psContext) / 2,
                         GrContextDpyHeightGet(psContext) / 4 , false);
}
Пример #13
0
/**
 * Show the Text for the Bootscreen
 */
void vShowBootText(char* text)
{

	/* Header Rectangle */
	tRectangle sRect;

	if (g_sContext.pDisplay == 0)
	{
		GrContextInit(&g_sContext, DISPLAY_DRIVER);
	}

	//
	// Fill the top 24 rows of the screen with blue to create the banner.
	//
	sRect.sXMin = 0;
	sRect.sYMin = 0;
	sRect.sXMax = GrContextDpyWidthGet(&g_sContext);
	sRect.sYMax = GrContextDpyHeightGet(&g_sContext);

	GrContextForegroundSet(&g_sContext, DISPLAY_BOOT_SCREEN_BACKGROUND_COLOR);
	GrContextBackgroundSet(&g_sContext, DISPLAY_BOOT_SCREEN_BACKGROUND_COLOR);
	GrRectFill(&g_sContext, &sRect);

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

	GrContextForegroundSet(&g_sContext, DISPLAY_BOOT_SCREEN_COLOR);
	//
	// Put the application name in the middle of the banner.
	//
	GrContextFontSet(&g_sContext, DISPLAY_BOOT_SCREEN_FONT);
	GrStringDrawCentered(&g_sContext, text, -1,
			GrContextDpyWidthGet(&g_sContext) / 2, GrContextDpyHeightGet(&g_sContext) / 2, 0);
}
//*****************************************************************************
//
// Shows the status string on the color STN display.
//
// \param psContext is a pointer to the graphics context representing the
// display.
// \param pcStatus is a pointer to the string to be shown.
//
//*****************************************************************************
void
DisplayStatus(tContext *psContext, char *pcStatus)
{
    tRectangle rectLine;
    long lY;

    //
    // Calculate the Y coordinate of the top left of the character cell
    // for our line of text.
    //
    lY = (GrContextDpyHeightGet(psContext) / 4) -
         (GrFontHeightGet(TEXT_FONT) / 2);

    //
    // Determine the bounding rectangle for this line of text.
    //
    rectLine.sXMin = 0;
    rectLine.sXMax = GrContextDpyWidthGet(psContext) - 1;
    rectLine.sYMin = lY;
    rectLine.sYMax = lY + GrFontHeightGet(TEXT_FONT) - 1;

    //
    // Clear the line with black.
    //
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrRectFill(psContext, &rectLine);

    //
    // Draw the new status string
    //
    DEBUG_PRINT("%s\n", pcStatus);
    GrContextForegroundSet(&g_sContext, ClrWhite);
    GrStringDrawCentered(psContext, pcStatus, -1,
                         GrContextDpyWidthGet(psContext) / 2,
                         GrContextDpyHeightGet(psContext) / 4 , false);
}
//*****************************************************************************
//
// This function updates the status area of the screen.  It uses the current
// state of the application to print the status bar.
//
//*****************************************************************************
void
UpdateStatus(char *pcString, tBoolean bClrBackground)
{
    tRectangle sRect;

    //
    // Fill the bottom rows of the screen with blue to create the status area.
    //
    sRect.sXMin = 0;
    sRect.sYMin = GrContextDpyHeightGet(&g_sContext) -
                  DISPLAY_BANNER_HEIGHT - 1;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = sRect.sYMin + DISPLAY_BANNER_HEIGHT;

    //
    //
    //
    GrContextBackgroundSet(&g_sContext, DISPLAY_BANNER_BG);

    if(bClrBackground)
    {
        //
        // Draw the background of the banner.
        //
        GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG);
        GrRectFill(&g_sContext, &sRect);

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

    //
    // Write the current state to the left of the status area.
    //
    GrContextFontSet(&g_sContext, g_pFontFixed6x8);

    //
    // Update the status on the screen.
    //
    if(pcString != 0)
    {
        GrStringDraw(&g_sContext, pcString, -1, 4, sRect.sYMin + 4, 1);
    }
}
Пример #16
0
//*****************************************************************************
//
// This function clears the main application screen area.
//
//*****************************************************************************
void
ClearMainWindow(void)
{
    tRectangle sRect;

    //
    // Initialize the button indicator.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = DISPLAY_BANNER_HEIGHT + 1;
    sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.i16YMax = GrContextDpyHeightGet(&g_sContext) - DISPLAY_BANNER_HEIGHT;

    GrContextForegroundSet(&g_sContext, DISPLAY_MOUSE_BG);
    GrRectFill(&g_sContext, &sRect);
    GrContextForegroundSet(&g_sContext, DISPLAY_MOUSE_FG);
}
Пример #17
0
//*****************************************************************************
//
// Fill either the whole screen (psRect == NULL) or a subrectangle (psRect !=
// NULL) with the supplied color.
//
//*****************************************************************************
void
GraphicsDemoCls(tRectangle *psRect, unsigned long ulColor)
{
    tContext sContext;
    tRectangle sRect;

    //
    // Initialize a drawing context.
    //
    GrContextInit(&sContext, &g_sFormike240x320x16_ILI9320);

    //
    // Are we being asked to fill the whole screen or a subrectangle?
    //
    if(!psRect)
    {
        //
        // Get the full screen dimensions.
        //
        sRect.sXMin = 0;
        sRect.sYMin = 0;
        sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1;
        sRect.sYMax = GrContextDpyHeightGet(&sContext) - 1;
    }
    else
    {
        //
        // Filling a subrectangle so just copy the rectangle passed.
        //
        sRect = *psRect;
    }

    //
    // Set the foreground color.
    //
    GrContextForegroundSet(&sContext, ulColor);

    //
    // Fill the screen with the required background color.
    //
    GrRectFill(&sContext, &sRect);

}
Пример #18
0
/**
 * Initialize the ParentWidget (=root for Drawing) with the Definitions of displayStyle.h
 */
void vInitializeParentWidget(void)
{
	xParentWidget.pFont = NULL;
	xParentWidget.pcText = NULL;
	xParentWidget.pucImage = NULL;
	xParentWidget.sBase.lSize = sizeof(tPushButtonWidget);
	xParentWidget.sBase.pChild = NULL;
	xParentWidget.sBase.pDisplay = DISPLAY_DRIVER;
	xParentWidget.sBase.pNext = NULL;
	xParentWidget.sBase.pParent = NULL;
	xParentWidget.sBase.pfnMsgProc = CanvasMsgProc;
	xParentWidget.sBase.sPosition.sXMax = GrContextDpyWidthGet(&g_sContext);
	xParentWidget.sBase.sPosition.sXMin = 0;
	xParentWidget.sBase.sPosition.sYMax = GrContextDpyHeightGet(&g_sContext);
	xParentWidget.sBase.sPosition.sYMin = 0;
	xParentWidget.ulFillColor = ClrBlack;
	xParentWidget.ulOutlineColor = ClrBlack;
	xParentWidget.ulStyle = CANVAS_STYLE_FILL;
	xParentWidget.ulTextColor = ClrBlack;
}
Пример #19
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    unsigned int i;
    unsigned char *src, *dest;

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

    //
    // Set the banner background.
    //
    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);

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

    //
    //Setup the interrupt controller
    //
#ifdef _TMS320C6X
    SetupDSPINTCInt();
    ConfigureDSPINTCIntUSB();
#else
    SetupAINTCInt(); 
    ConfigureAINTCIntUSB();
#endif
    
    DelayTimerSetup();
    
    //
    // Calculate the number of characters that will fit on a line.
    // Make sure to leave a small border for the text box.
    //
    g_ulCharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 4) /
                        GrFontMaxWidthGet(&g_sFontCm20);

    //
    // Calculate the number of lines per usable text screen.  This requires
    // taking off space for the top and bottom banners and adding a small bit
    // for a border.
    //
    g_ulLinesPerScreen = (GrContextDpyHeightGet(&g_sContext) -
                          (2*(DISPLAY_BANNER_HEIGHT + 1)))/
                          GrFontHeightGet(&g_sFontCm20);


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

    // Open an instance of the keyboard driver.  The keyboard does not need
    // to be present at this time, this just save a place for it and allows
    // the applications to be notified when a keyboard is present.
    //
    g_ulKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pucBuffer,
                                            KEYBOARD_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);

    //
    // Initialize the host controller stack.
    //
    USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE);

    //
    // Call the main loop for the Host controller driver.
    //
    USBHCDMain();

    //
    // Initial update of the screen.
    //
    UpdateStatus();

    //
    // The main loop for the application.
    //
    while(1)
    {
        switch(g_eUSBState)
        {
            //
            // This state is entered when they keyboard is first detected.
            //
            case STATE_KEYBOARD_INIT:
            {
                //
                // Initialized the newly connected keyboard.
                //
                USBHKeyboardInit(g_ulKeyboardInstance);

                //
                // Proceed to the keyboard connected state.
                //
                g_eUSBState = STATE_KEYBOARD_CONNECTED;

                //
                // Update the screen now that the keyboard has been
                // initialized.
                //
                UpdateStatus();

                break;
            }
            case STATE_KEYBOARD_UPDATE:
            {
                //
                // If the application detected a change that required an
                // update to be sent to the keyboard to change the modifier
                // state then call it and return to the connected state.
                //
                g_eUSBState = STATE_KEYBOARD_CONNECTED;

                USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers);

                break;
            }
            case STATE_KEYBOARD_CONNECTED:
            {
                //
                // Nothing is currently done in the main loop when the keyboard
                // is connected.
                //
                break;
            }
            case STATE_UNKNOWN_DEVICE:
            {
                //
                // Nothing to do as the device is unknown.
                //
                break;
            }
            case STATE_NO_DEVICE:
            {
                //
                // Nothing is currently done in the main loop when the keyboard
                // is not connected.
                //
                break;
            }
            default:
            {
                break;
            }
        }

        //
        // Periodic call the main loop for the Host controller driver.
        //
        USBHCDMain();
    }
}
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;
    tUSBMode eLastMode;
    char *pcString;

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

    //
    // Initially wait for device connection.
    //
    g_eUSBState = STATE_NO_DEVICE;
    eLastMode = USB_MODE_OTG;
    g_eCurrentUSBMode = USB_MODE_OTG;

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

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

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

    //
    // Enable clocking to the UART and associated GPIO
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);

    //
    // Configure the relevant pins such that UART0 owns them.
    //
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Open UART0 for debug output.
    //
    UARTStdioInit(0);

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

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

    //
    // Open an instance of the keyboard driver.  The keyboard does not need
    // to be present at this time, this just save a place for it and allows
    // the applications to be notified when a keyboard is present.
    //
    g_ulKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pucBuffer,
                                            KEYBOARD_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_pHCDPool, HCD_MEMORY_SIZE);

    //
    // 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.sXMin = 0;
    sRect.sYMin = 0;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = (2 * 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_pFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "usb-host-", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 4, 0);
    GrStringDrawCentered(&g_sContext, "keyboard", -1,
                             GrContextDpyWidthGet(&g_sContext) / 2, 14, 0);


    //
    // Calculate the number of characters that will fit on a line.
    // Make sure to leave a small border for the text box.
    //
    g_ulCharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 4) /
                        GrFontMaxWidthGet(g_pFontFixed6x8);

    //
    // Calculate the number of lines per usable text screen.  This requires
    // taking off space for the top and bottom banners and adding a small bit
    // for a border.
    //
    g_ulLinesPerScreen = (GrContextDpyHeightGet(&g_sContext) -
                          (3*(DISPLAY_BANNER_HEIGHT + 1)))/
                          GrFontHeightGet(g_pFontFixed6x8);

    //
    // Open and instance of the keyboard class driver.
    //
    UARTprintf("Host Keyboard Application\n");

    //
    // Initial update of the screen.
    //
    UpdateStatus();

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

        //
        // Has the USB mode changed since last time we checked?
        //
        if(g_eCurrentUSBMode != eLastMode)
        {
            //
            // Remember the new mode.
            //
            eLastMode = g_eCurrentUSBMode;

            switch(eLastMode)
            {
                case USB_MODE_HOST:
                    pcString = "HOST";
                    break;

                case USB_MODE_DEVICE:
                    pcString = "DEVICE";
                    break;

                case USB_MODE_NONE:
                    pcString = "NONE";
                    break;

                default:
                    pcString = "UNKNOWN";
                    break;
            }

            UARTprintf("USB mode changed to %s\n", pcString);
        }

        switch(g_eUSBState)
        {
            //
            // This state is entered when they keyboard is first detected.
            //
            case STATE_KEYBOARD_INIT:
            {
                //
                // Initialized the newly connected keyboard.
                //
                USBHKeyboardInit(g_ulKeyboardInstance);

                //
                // Proceed to the keyboard connected state.
                //
                g_eUSBState = STATE_KEYBOARD_CONNECTED;

                //
                // Update the screen now that the keyboard has been
                // initialized.
                //
                UpdateStatus();

                USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers);

                break;
            }
            case STATE_KEYBOARD_UPDATE:
            {
                //
                // If the application detected a change that required an
                // update to be sent to the keyboard to change the modifier
                // state then call it and return to the connected state.
                //
                g_eUSBState = STATE_KEYBOARD_CONNECTED;

                USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers);

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

            case STATE_UNKNOWN_DEVICE:
            {
                //
                // Nothing to do as the device is unknown.
                //
                break;
            }

            case STATE_NO_DEVICE:
            {
                //
                // Nothing is currently done in the main loop when the keyboard
                // is not connected.
                //
                break;
            }
            default:
            {
                break;
            }
        }
    }
}
//*****************************************************************************
//
// This function updates the status area of the screen.  It uses the current
// state of the application to print the status bar.
//
//*****************************************************************************
void
UpdateStatus(void)
{
    tRectangle sRect;

    //
    // Fill the bottom rows of the screen with blue to create the status area.
    //
    sRect.sXMin = 0;
    sRect.sYMin = GrContextDpyHeightGet(&g_sContext) -
                  DISPLAY_BANNER_HEIGHT - 1;
    sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1;
    sRect.sYMax = sRect.sYMin + 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);

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_pFontFixed6x8);

    //
    // Update the status on the screen.
    //
    if(g_eUSBState == STATE_NO_DEVICE)
    {
        //
        // Keyboard is currently disconnected.
        //
        GrStringDrawCentered(&g_sContext, "no device", -1, 
                             GrContextDpyWidthGet(&g_sContext) / 2, 
                             sRect.sYMin + 5, 0);
    }
    else if(g_eUSBState == STATE_UNKNOWN_DEVICE)
    {
        //
        // Unknown device is currently connected.
        //
        GrStringDrawCentered(&g_sContext, "unknown device", -1, 
                             GrContextDpyWidthGet(&g_sContext) / 2, 
                             sRect.sYMin + 5, 0);
    }
    else if(g_eUSBState == STATE_POWER_FAULT)
    {
        //
        // Something caused a power fault.
        //
        GrStringDrawCentered(&g_sContext, "power fault", -1, 
                             GrContextDpyWidthGet(&g_sContext) / 2, 
                             sRect.sYMin + 5, 0);
    }
    else if((g_eUSBState == STATE_KEYBOARD_CONNECTED) ||
            (g_eUSBState == STATE_KEYBOARD_UPDATE))
    {
        //
        // Keyboard is connected.
        //
        GrStringDrawCentered(&g_sContext, "connected", -1, 
                             GrContextDpyWidthGet(&g_sContext) / 2, 
                             sRect.sYMin + 5, 0);

        //
        // Update the CAPS Lock status.
        //
        if(g_ulModifiers & HID_KEYB_CAPS_LOCK)
        {
            GrStringDrawCentered(&g_sContext, "C", 
                                 GrContextDpyWidthGet(&g_sContext) / 2, 
                                 sRect.sXMax - 10,
                                 sRect.sYMin + 5, 0);
        }
    }
}
//*****************************************************************************
//
// This function prints the character out the UART and into the text area of
// the screen.
//
// \param ucChar is the character to print out.
//
// This function handles all of the detail of printing a character to both the
// UART and to the text area of the screen on the evaluation board.  The text
// area of the screen will be cleared any time the text goes beyond the end
// of the text area.
//
// \return None.
//
//*****************************************************************************
void
PrintChar(const char ucChar)
{
    tRectangle sRect;

    //
    // If both the line and column have gone to zero then clear the screen.
    //
    if((g_ulLine == 0) && (g_ulColumn == 0))
    {
        //
        // Form the rectangle that makes up the text box.
        //
        sRect.sXMin = 0;
        sRect.sYMin = (2 * DISPLAY_BANNER_HEIGHT) + DISPLAY_TEXT_BORDER;
        sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - DISPLAY_TEXT_BORDER;
        sRect.sYMax = GrContextDpyHeightGet(&g_sContext) -
                      DISPLAY_BANNER_HEIGHT - DISPLAY_TEXT_BORDER;

        //
        // Change the foreground color to black and draw black rectangle to
        // clear the screen.
        //
        GrContextForegroundSet(&g_sContext, DISPLAY_TEXT_BG);
        GrRectFill(&g_sContext, &sRect);

        //
        // Reset the foreground color to the text color.
        //
        GrContextForegroundSet(&g_sContext, DISPLAY_TEXT_FG);
    }

    //
    // Send the character to the UART.
    //
    UARTprintf("%c", ucChar);

    //
    // Allow new lines to cause the column to go back to zero.
    //
    if(ucChar != '\n')
    {
        //
        // Did we get a backspace character?
        //
        if(ucChar != ASCII_BACKSPACE)
        {
            //
            // This is not a backspace so print the character to the screen.
            //
            GrStringDraw(&g_sContext, &ucChar, 1,
                         GrFontMaxWidthGet(g_pFontFixed6x8) * g_ulColumn,
                         (2 * DISPLAY_BANNER_HEIGHT) + DISPLAY_TEXT_BORDER +
                         (g_ulLine * GrFontHeightGet(g_pFontFixed6x8)), 0);
        }
        else
        {
            //
            // We got a backspace.  If we are at the top left of the screen,
            // return since we don't need to do anything.
            //
            if(g_ulColumn || g_ulLine)
            {
                //
                // Adjust the cursor position to erase the last character.
                //
                if(g_ulColumn)
                {
                    g_ulColumn--;
                }
                else
                {
                    g_ulColumn = g_ulCharsPerLine;
                    g_ulLine--;
                }

                //
                // Print a space at this position then return without fixing up
                // the cursor again.
                //
                GrStringDraw(&g_sContext, " ", 1,
                             GrFontMaxWidthGet(g_pFontFixed6x8) * g_ulColumn,
                             (2 * DISPLAY_BANNER_HEIGHT) + DISPLAY_TEXT_BORDER +
                             (g_ulLine * GrFontHeightGet(g_pFontFixed6x8)),
                             true);
            }
            return;
        }
    }
    else
    {
        //
        // This will allow the code below to properly handle the new line.
        //
        g_ulColumn = g_ulCharsPerLine;
    }

    //
    // Update the text row and column that the next character will use.
    //
    if(g_ulColumn < g_ulCharsPerLine)
    {
        //
        // No line wrap yet so move one column over.
        //
        g_ulColumn++;
    }
    else
    {
        //
        // Line wrapped so go back to the first column and update the line.
        //
        g_ulColumn = 0;
        g_ulLine++;

        //
        // The line has gone past the end so go back to the first line.
        //
        if(g_ulLine >= g_ulLinesPerScreen)
        {
            g_ulLine = 0;
        }
    }
}
//*****************************************************************************
//
// Performs calibration of the touch screen.
//
//*****************************************************************************
int
main(void)
{
    int32_t i32Idx, i32X1, i32Y1, i32X2, i32Y2, i32Count, ppi32Points[3][4];
    uint32_t ui32SysClock;
    char pcBuffer[32];
    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, "calibrate");

    //
    // Print the instructions across the middle of the screen in white with a
    // 20 point small-caps font.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrContextFontSet(&sContext, g_psFontCmsc20);
    GrStringDrawCentered(&sContext, "Touch the box", -1,
                         GrContextDpyWidthGet(&sContext) / 2,
                         (GrContextDpyHeightGet(&sContext) / 2) - 10, 0);

    //
    // Set the points used for calibration based on the size of the screen.
    //
    ppi32Points[0][0] = GrContextDpyWidthGet(&sContext) / 10;
    ppi32Points[0][1] = (GrContextDpyHeightGet(&sContext) * 2) / 10;
    ppi32Points[1][0] = GrContextDpyWidthGet(&sContext) / 2;
    ppi32Points[1][1] = (GrContextDpyHeightGet(&sContext) * 9) / 10;
    ppi32Points[2][0] = (GrContextDpyWidthGet(&sContext) * 9) / 10;
    ppi32Points[2][1] = GrContextDpyHeightGet(&sContext) / 2;

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

    //
    // Loop through the calibration points.
    //
    for(i32Idx = 0; i32Idx < 3; i32Idx++)
    {
        //
        // Fill a white box around the calibration point.
        //
        GrContextForegroundSet(&sContext, ClrWhite);
        sRect.i16XMin = ppi32Points[i32Idx][0] - 5;
        sRect.i16YMin = ppi32Points[i32Idx][1] - 5;
        sRect.i16XMax = ppi32Points[i32Idx][0] + 5;
        sRect.i16YMax = ppi32Points[i32Idx][1] + 5;
        GrRectFill(&sContext, &sRect);

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

        //
        // Initialize the raw sample accumulators and the sample count.
        //
        i32X1 = 0;
        i32Y1 = 0;
        i32Count = -5;

        //
        // Loop forever.  This loop is explicitly broken out of when the pen is
        // lifted.
        //
        while(1)
        {
            //
            // Grab the current raw touch screen position.
            //
            i32X2 = g_i16TouchX;
            i32Y2 = g_i16TouchY;

            //
            // See if the pen is up or down.
            //
            if((i32X2 < g_i16TouchMin) || (i32Y2 < g_i16TouchMin))
            {
                //
                // The pen is up, so see if any samples have been accumulated.
                //
                if(i32Count > 0)
                {
                    //
                    // The pen has just been lifted from the screen, so break
                    // out of the controlling while loop.
                    //
                    break;
                }

                //
                // Reset the accumulators and sample count.
                //
                i32X1 = 0;
                i32Y1 = 0;
                i32Count = -5;

                //
                // Grab the next sample.
                //
                continue;
            }

            //
            // Increment the count of samples.
            //
            i32Count++;

            //
            // If the sample count is greater than zero, add this sample to the
            // accumulators.
            //
            if(i32Count > 0)
            {
                i32X1 += i32X2;
                i32Y1 += i32Y2;
            }
        }

        //
        // Save the averaged raw ADC reading for this calibration point.
        //
        ppi32Points[i32Idx][2] = i32X1 / i32Count;
        ppi32Points[i32Idx][3] = i32Y1 / i32Count;

        //
        // Erase the box around this calibration point.
        //
        GrContextForegroundSet(&sContext, ClrBlack);
        GrRectFill(&sContext, &sRect);
    }

    //
    // Clear the screen.
    //
    sRect.i16XMin = 0;
    sRect.i16YMin = 0;
    sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
    sRect.i16YMax = GrContextDpyHeightGet(&sContext) - 1;
    GrRectFill(&sContext, &sRect);

    //
    // Indicate that the calibration data is being displayed.
    //
    GrContextForegroundSet(&sContext, ClrWhite);
    GrStringDraw(&sContext, "Calibration data:", -1, 16, 32, 0);

    //
    // Compute and display the M0 calibration value.
    //
    usprintf(pcBuffer, "M0 = %d",
             (((ppi32Points[0][0] - ppi32Points[2][0]) *
               (ppi32Points[1][3] - ppi32Points[2][3])) -
              ((ppi32Points[1][0] - ppi32Points[2][0]) *
               (ppi32Points[0][3] - ppi32Points[2][3]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 72, 0);

    //
    // Compute and display the M1 calibration value.
    //
    usprintf(pcBuffer, "M1 = %d",
             (((ppi32Points[0][2] - ppi32Points[2][2]) *
               (ppi32Points[1][0] - ppi32Points[2][0])) -
              ((ppi32Points[0][0] - ppi32Points[2][0]) *
               (ppi32Points[1][2] - ppi32Points[2][2]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 92, 0);

    //
    // Compute and display the M2 calibration value.
    //
    usprintf(pcBuffer, "M2 = %d",
             ((((ppi32Points[2][2] * ppi32Points[1][0]) -
                (ppi32Points[1][2] * ppi32Points[2][0])) * ppi32Points[0][3]) +
              (((ppi32Points[0][2] * ppi32Points[2][0]) -
                (ppi32Points[2][2] * ppi32Points[0][0])) * ppi32Points[1][3]) +
              (((ppi32Points[1][2] * ppi32Points[0][0]) -
                (ppi32Points[0][2] * ppi32Points[1][0])) * ppi32Points[2][3])));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 112, 0);

    //
    // Compute and display the M3 calibration value.
    //
    usprintf(pcBuffer, "M3 = %d",
             (((ppi32Points[0][1] - ppi32Points[2][1]) *
               (ppi32Points[1][3] - ppi32Points[2][3])) -
              ((ppi32Points[1][1] - ppi32Points[2][1]) *
               (ppi32Points[0][3] - ppi32Points[2][3]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 132, 0);

    //
    // Compute and display the M4 calibration value.
    //
    usprintf(pcBuffer, "M4 = %d",
             (((ppi32Points[0][2] - ppi32Points[2][2]) *
               (ppi32Points[1][1] - ppi32Points[2][1])) -
              ((ppi32Points[0][1] - ppi32Points[2][1]) *
               (ppi32Points[1][2] - ppi32Points[2][2]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 152, 0);

    //
    // Compute and display the M5 calibration value.
    //
    usprintf(pcBuffer, "M5 = %d",
             ((((ppi32Points[2][2] * ppi32Points[1][1]) -
                (ppi32Points[1][2] * ppi32Points[2][1])) * ppi32Points[0][3]) +
              (((ppi32Points[0][2] * ppi32Points[2][1]) -
                (ppi32Points[2][2] * ppi32Points[0][1])) * ppi32Points[1][3]) +
              (((ppi32Points[1][2] * ppi32Points[0][1]) -
                (ppi32Points[0][2] * ppi32Points[1][1])) * ppi32Points[2][3])));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 172, 0);

    //
    // Compute and display the M6 calibration value.
    //
    usprintf(pcBuffer, "M6 = %d",
             (((ppi32Points[0][2] - ppi32Points[2][2]) *
               (ppi32Points[1][3] - ppi32Points[2][3])) -
              ((ppi32Points[1][2] - ppi32Points[2][2]) *
               (ppi32Points[0][3] - ppi32Points[2][3]))));
    GrStringDraw(&sContext, pcBuffer, -1, 16, 192, 0);

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

    //
    // The calibration is complete.  Sit around and wait for a reset.
    //
    while(1)
    {
    }
}
Пример #24
0
//*****************************************************************************
//
// This function initializes the ADC hardware in preparation for data
// acquisition.
//
//*****************************************************************************
void
AcquireInit(void)
{
    unsigned long ulChan;

    //
    // Enable the ADC peripherals and the associated GPIO port
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);

    ROM_SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS);

    ROM_GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6 |GPIO_PIN_7 | GPIO_PIN_3);
    ROM_GPIOPinTypeADC(GPIO_PORTP_BASE, GPIO_PIN_0);

//    ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);
    //ROM_ADCR

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    HWREG(GPIO_PORTB_BASE + GPIO_O_AMSEL) |= GPIO_PIN_6;
    ADCSequenceDisable(ADC0_BASE,SEQUENCER);

    ROM_ADCSequenceConfigure(ADC0_BASE, SEQUENCER, ADC_TRIGGER_TIMER, 0);

    for(ulChan = 0; ulChan < 2; ulChan++)
    {
        unsigned long ulChCtl;


        if (ulChan ==1)
        {

            ROM_ADCSequenceStepConfigure(ADC0_BASE, SEQUENCER, ulChan, ADC_CTL_CH1|ADC_CTL_IE | ADC_CTL_END);
        }
        else if(ulChan==0)
        {
        	ulChCtl = ADC_CTL_CH0;
        	ROM_ADCSequenceStepConfigure(ADC0_BASE, SEQUENCER, ulChan, ADC_CTL_CH0);
        }


    }

    ADCHardwareOversampleConfigure(ADC0_BASE, 1);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    //SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

    ROM_TimerConfigure(TIMER0_BASE,TIMER_CFG_32_BIT_PER );

    //100 micro
    unsigned long freq=SAMPLING_FREQUENCY;
    unsigned long period=(2*ROM_SysCtlClockGet()/(freq));

    ROM_TimerLoadSet(TIMER0_BASE, TIMER_A,period);
    ROM_TimerControlTrigger(TIMER0_BASE, TIMER_A, true);

    //ROM_TimerConfigure(TIMER1_BASE, TIMER_CFG_PERIODIC);
    //ROM_TimerLoadSet(TIMER1_BASE, TIMER_A, ROM_SysCtlClockGet() /2);




    CFAL96x64x16Init();
    GrContextInit(&sDisplayContext, &g_sCFAL96x64x16);
    sRect1.sXMin = 0;
    sRect1.sYMin = 0;
    sRect1.sXMax = GrContextDpyWidthGet(&sDisplayContext) - 1;
    sRect1.sYMax = 23;

    sRect2.sXMin = 0;
    sRect2.sYMin = 23;
    sRect2.sXMax = GrContextDpyWidthGet(&sDisplayContext) - 1;
    sRect2.sYMax = GrContextDpyHeightGet(&sDisplayContext) - 1;


	snprintf(text,sizeof(text),"STart");


    GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    GrRectFill(&sDisplayContext, &sRect1);
    GrContextForegroundSet(&sDisplayContext, ClrWhite);
    //GrRectDraw(&sDisplayContext, &sRect1);
    GrContextFontSet(&sDisplayContext, g_pFontCm12);
    GrStringDrawCentered(&sDisplayContext,text, -1,
                         GrContextDpyWidthGet(&sDisplayContext) / 2, 10, 0);

    //GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    //GrRectFill(&sDisplayContext, &sRect1);
    //GrContextForegroundSet(&sDisplayContext, ClrWhite);
    //GrRectDraw(&sDisplayContext, &sRect1);

    /*GrContextForegroundSet(&sDisplayContext, ClrDarkBlue);
    GrRectFill(&sDisplayContext, &sRect2);
    GrContextForegroundSet(&sDisplayContext, ClrWhite);
    GrRectDraw(&sDisplayContext, &sRect2);
*/
    compute_filter();
    maxi1=0;
    maxi2=0;
    max1=0;
    max2=0;
    res=0;
    res1=0;
    g_ulADCCount=0;
    buffer_index=0;
    ulLastADCCount=0;

}
Пример #25
0
//*****************************************************************************
//
// 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) {
    }
}
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    tRectangle sRect;

    //
    // Set the clocking to run directly from the crystal.
    //
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
                   SYSCTL_XTAL_8MHZ);

    //
    // Enable the peripherals used by this example.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

    //
    // Configure the relevant pins such that UART0 owns them.
    //
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

    //
    // Open UART0 for debug output.
    //
    UARTStdioInit(0);

    //
    // Enable the USB mux GPIO.
    //
    SysCtlPeripheralEnable(USB_MUX_GPIO_PERIPH);

    //
    // The LM3S3748 board uses a USB mux that must be switched to use the
    // host connector and not the device connector.
    //
    GPIOPinTypeGPIOOutput(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN);
    GPIOPinWrite(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN, USB_MUX_SEL_HOST);

    //
    // Configure the power pins for host controller.
    //
    GPIOPinTypeUSBDigital(GPIO_PORTH_BASE, GPIO_PIN_3 | GPIO_PIN_4);

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

    //
    // Put the application name in the middle of the banner.
    //
    GrContextFontSet(&g_sContext, g_pFontFixed6x8);
    GrStringDrawCentered(&g_sContext, "usb_host_keyboard", -1,
                         GrContextDpyWidthGet(&g_sContext) / 2, 7, 0);

    //
    // Calculate the number of characters that will fit on a line.
    // Make sure to leave a small border for the text box.
    //
    g_ulCharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 4) /
                        GrFontMaxWidthGet(g_pFontFixed6x8);

    //
    // Calculate the number of lines per usable text screen.  This requires
    // taking off space for the top and bottom banners and adding a small bit
    // for a border.
    //
    g_ulLinesPerScreen = (GrContextDpyHeightGet(&g_sContext) -
                          (2*(DISPLAY_BANNER_HEIGHT + 1)))/
                          GrFontHeightGet(g_pFontFixed6x8);

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

    //
    // Open and instance of the keyboard class driver.
    //
    UARTprintf("Host Keyboard Application\n");

    //
    // Open an instance of the keyboard driver.  The keyboard does not need
    // to be present at this time, this just save a place for it and allows
    // the applications to be notified when a keyboard is present.
    //
    g_ulKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pucBuffer,
                                            KEYBOARD_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);

    //
    // Initialize the host controller stack.
    //
    USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE);

    //
    // Call the main loop for the Host controller driver.
    //
    USBHCDMain();

    //
    // Initial update of the screen.
    //
    UpdateStatus();

    //
    // The main loop for the application.
    //
    while(1)
    {
        switch(g_eUSBState)
        {
            //
            // This state is entered when they keyboard is first detected.
            //
            case STATE_KEYBOARD_INIT:
            {
                //
                // Initialized the newly connected keyboard.
                //
                USBHKeyboardInit(g_ulKeyboardInstance);

                //
                // Proceed to the keyboard connected state.
                //
                g_eUSBState = STATE_KEYBOARD_CONNECTED;

                USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers);

                //
                // Update the screen now that the keyboard has been
                // initialized.
                //
                UpdateStatus();

                break;
            }
            case STATE_KEYBOARD_UPDATE:
            {
                //
                // If the application detected a change that required an
                // update to be sent to the keyboard to change the modifier
                // state then call it and return to the connected state.
                //
                g_eUSBState = STATE_KEYBOARD_CONNECTED;

                USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers);

                break;
            }
            case STATE_KEYBOARD_CONNECTED:
            {
                //
                // Nothing is currently done in the main loop when the keyboard
                // is connected.
                //
                break;
            }
            case STATE_UNKNOWN_DEVICE:
            {
                //
                // Nothing to do as the device is unknown.
                //
                break;
            }
            case STATE_NO_DEVICE:
            {
                //
                // Nothing is currently done in the main loop when the keyboard
                // is not connected.
                //
                break;
            }
            default:
            {
                break;
            }
        }

        //
        // Periodic call the main loop for the Host controller driver.
        //
        USBHCDMain();
    }
}
//*****************************************************************************
//
// This function prints the character out the UART and into the text area of
// the screen.
//
// \param ucChar is the character to print out.
//
// This function handles all of the detail of printing a character to both the
// UART and to the text area of the screen on the evaluation board.  The text
// area of the screen will be cleared any time the text goes beyond the end
// of the text area.
//
// \return None.
//
//*****************************************************************************
void
PrintChar(const char ucChar)
{
    tRectangle sRect;

    //
    // If both the line and column have gone to zero then clear the screen.
    //
    if((g_ulLine == 0) && (g_ulColumn == 0))
    {
        //
        // Form the rectangle that makes up the text box.
        //
        sRect.sXMin = 0;
        sRect.sYMin = DISPLAY_BANNER_HEIGHT + DISPLAY_TEXT_BORDER;
        sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - DISPLAY_TEXT_BORDER;
        sRect.sYMax = GrContextDpyHeightGet(&g_sContext) -
                      DISPLAY_BANNER_HEIGHT - DISPLAY_TEXT_BORDER;

        //
        // Change the foreground color to black and draw black rectangle to
        // clear the screen.
        //
        GrContextForegroundSet(&g_sContext, DISPLAY_TEXT_BG);
        GrRectFill(&g_sContext, &sRect);

        //
        // Reset the foreground color to the text color.
        //
        GrContextForegroundSet(&g_sContext, DISPLAY_TEXT_FG);
    }

    //
    // Send the character to the UART.
    //
    UARTprintf("%c", ucChar);

    //
    // Allow new lines to cause the column to go back to zero.
    //
    if(ucChar != '\n')
    {
        //
        // Print the character to the screen.
        //
        GrStringDraw(&g_sContext, &ucChar, 1,
                     GrFontMaxWidthGet(g_pFontFixed6x8) * g_ulColumn,
                     DISPLAY_BANNER_HEIGHT + DISPLAY_TEXT_BORDER +
                     (g_ulLine * GrFontHeightGet(g_pFontFixed6x8)), 0);
    }
    else
    {
        //
        // This will allow the code below to properly handle the new line.
        //
        g_ulColumn = g_ulCharsPerLine;
    }

    //
    // Update the text row and column that the next character will use.
    //
    if(g_ulColumn < g_ulCharsPerLine)
    {
        //
        // No line wrap yet so move one column over.
        //
        g_ulColumn++;
    }
    else
    {
        //
        // Line wrapped so go back to the first column and update the line.
        //
        g_ulColumn = 0;
        g_ulLine++;

        //
        // The line has gone past the end so go back to the first line.
        //
        if(g_ulLine >= g_ulLinesPerScreen)
        {
            g_ulLine = 0;
        }
    }
}
Пример #28
0
//*****************************************************************************
//
// This example demonstrates the use of both watchdog timers.
//
//*****************************************************************************
int
main(void)
{
    uint32_t ui32SysClock;

    //
    // Run from the PLL at 120 MHz.
    //
    ui32SysClock = 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, "watchdog");

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

    //
    // Reconfigure PF1 as a GPIO output so that it can be directly driven
    // (instead of being an Ethernet LED).
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);

    //
    // Show the state and offer some instructions to the user.
    //
    GrContextFontSet(&g_sContext, g_psFontCmss20);
    GrStringDrawCentered(&g_sContext, "Watchdog 0:", -1, 80, 80, 0);
    GrStringDrawCentered(&g_sContext, "Watchdog 1:", -1, 240, 80, 0);
    GrContextFontSet(&g_sContext, g_psFontCmss14);
    GrStringDrawCentered(&g_sContext,
                         "Tap the left screen to starve the watchdog 0",
                         -1, GrContextDpyWidthGet(&g_sContext) / 2 ,
                         (GrContextDpyHeightGet(&g_sContext) / 2) + 40, 1);
    GrStringDrawCentered(&g_sContext,
                         "Tap the right screen to starve the watchdog 1",
                         -1, GrContextDpyWidthGet(&g_sContext) / 2 ,
                         (GrContextDpyHeightGet(&g_sContext) / 2) + 60, 1);

    //
    // Enable the peripherals used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG1);

    //
    // Enable the watchdog interrupt.
    //
    ROM_IntEnable(INT_WATCHDOG);

    //
    // Set the period of the watchdog timer.
    //
    ROM_WatchdogReloadSet(WATCHDOG0_BASE, ui32SysClock);
    ROM_WatchdogReloadSet(WATCHDOG1_BASE, 16000000);

    //
    // Enable reset generation from the watchdog timer.
    //
    ROM_WatchdogResetEnable(WATCHDOG0_BASE);
    ROM_WatchdogResetEnable(WATCHDOG1_BASE);

    //
    // Enable the watchdog timer.
    //
    ROM_WatchdogEnable(WATCHDOG0_BASE);
    ROM_WatchdogEnable(WATCHDOG1_BASE);

    //
    // Loop forever while the LED winks as watchdog interrupts are handled.
    //
    while(1)
    {
    }
}
Пример #29
0
//*****************************************************************************
//
// The main application loop.
//
//*****************************************************************************
int
main(void)
{
    int32_t i32Status, i32Idx;
    uint32_t ui32SysClock, ui32PLLRate;
#ifdef USE_ULPI
    uint32_t ui32Setting;
#endif

    ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
                                           SYSCTL_OSC_MAIN | SYSCTL_USE_PLL |
                                           SYSCTL_CFG_VCO_480), 120000000);

    //
    // Set the part pin out appropriately for this device.
    //
    PinoutSet();

#ifdef USE_ULPI
    //
    // Switch the USB ULPI Pins over.
    //
    USBULPIPinoutSet();

    //
    // Enable USB ULPI with high speed support.
    //
    ui32Setting = USBLIB_FEATURE_ULPI_HS;
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting);

    //
    // Setting the PLL frequency to zero tells the USB library to use the
    // external USB clock.
    //
    ui32PLLRate = 0;
#else
    //
    // Save the PLL rate used by this application.
    //
    ui32PLLRate = 480000000;
#endif

    //
    // Initialize the hub port status.
    //
    for(i32Idx = 0; i32Idx < NUM_HUB_STATUS; i32Idx++)
    {
        g_psHubStatus[i32Idx].bConnected = false;
    }

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

    //
    // Enable Interrupts
    //
    ROM_IntMasterEnable();

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

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

    //
    // Open the Keyboard interface.
    //
    KeyboardOpen();
    MSCOpen(ui32SysClock);

    //
    // Open a hub instance and provide it with the memory required to hold
    // configuration descriptors for each attached device.
    //
    USBHHubOpen(HubCallback);

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

    //
    // Tell the USB library the CPU clock and the PLL frequency.
    //
    USBOTGFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock);
    USBOTGFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate);

    //
    // Initialize the USB controller for Host mode.
    //
    USBHCDInit(0, g_pui8HCDPool, sizeof(g_pui8HCDPool));

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

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

    //
    // Draw the application frame.
    //
    FrameDraw(&g_sContext, "usb-host-hub");

    //
    // Calculate the number of characters that will fit on a line.
    // Make sure to leave a small border for the text box.
    //
    g_ui32CharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 16) /
                         GrFontMaxWidthGet(g_psFontFixed6x8);

    //
    // Calculate the number of lines per usable text screen.  This requires
    // taking off space for the top and bottom banners and adding a small bit
    // for a border.
    //
    g_ui32LinesPerScreen = (GrContextDpyHeightGet(&g_sContext) -
                           (2*(DISPLAY_BANNER_HEIGHT + 1)))/
                           GrFontHeightGet(g_psFontFixed6x8);

    //
    // Initial update of the screen.
    //
    UpdateStatus(0);
    UpdateStatus(1);
    UpdateStatus(2);
    UpdateStatus(3);

    g_ui32CmdIdx = 0;
    g_ui32CurrentLine = 0;

    //
    // Initialize the file system.
    //
    FileInit();

    //
    // The main loop for the application.
    //
    while(1)
    {
        //
        // Print a prompt to the console.  Show the CWD.
        //
        WriteString("> ");

        //
        // Is there a command waiting to be processed?
        //
        while((g_ui32Flags & FLAG_CMD_READY) == 0)
        {
            //
            // Call the YSB library to let non-interrupt code run.
            //
            USBHCDMain();

            //
            // Call the keyboard and mass storage main routines.
            //
            KeyboardMain();
            MSCMain();
        }

        //
        // Pass the line from the user to the command processor.
        // It will be parsed and valid commands executed.
        //
        i32Status = CmdLineProcess(g_pcCmdBuf);

        //
        // Handle the case of bad command.
        //
        if(i32Status == CMDLINE_BAD_CMD)
        {
            WriteString("Bad command!\n");
        }
        //
        // Handle the case of too many arguments.
        //
        else if(i32Status == CMDLINE_TOO_MANY_ARGS)
        {
            WriteString("Too many arguments for command processor!\n");
        }
        //
        // Otherwise the command was executed.  Print the error
        // code if one was returned.
        //
        else if(i32Status != 0)
        {
            WriteString("Command returned error code\n");
            WriteString((char *)StringFromFresult((FRESULT)i32Status));
            WriteString("\n");
        }

        //
        // Reset the command flag and the command index.
        //
        g_ui32Flags &= ~FLAG_CMD_READY;
        g_ui32CmdIdx = 0;
    }
}
Пример #30
0
void main(void)
{
    // Stop WDT
    WDTCTL = WDTPW + WDTHOLD;

    // Initialize the boards
    boardInit();
    clockInit();
    timerInit();
    flashInit();

    __bis_SR_register(GIE);

    // Set up the LCD
    LCDInit();
    GrContextInit(&g_sContext, &g_sharp96x96LCD);
    GrContextForegroundSet(&g_sContext, ClrBlack);
    GrContextBackgroundSet(&g_sContext, ClrWhite);
    GrContextFontSet(&g_sContext, &g_sFontFixed6x8);
    GrClearDisplay(&g_sContext);
    GrFlush(&g_sContext);

    // Intro Screen
    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_long();
    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_long();
    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_long();
    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);
    GrFlush(&g_sContext);
    Delay_long();
    GrClearDisplay(&g_sContext);

    // Combining Primitive screen
    GrStringDrawCentered(&g_sContext, 
                         "Combining", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         15, 
                         TRANSPARENT_TEXT);
    GrStringDrawCentered(&g_sContext, 
                         "Primitives to", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         35, 
                         TRANSPARENT_TEXT);
    GrStringDrawCentered(&g_sContext, 
                         "create menus", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         51, 
                         TRANSPARENT_TEXT);
    GrStringDrawCentered(&g_sContext, 
                         "and animations", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         75, 
                         TRANSPARENT_TEXT);
    GrFlush(&g_sContext);
    Delay_long();
    GrClearDisplay(&g_sContext);

    // Draw a Menu screen
    GrStringDrawCentered(&g_sContext, 
                         "Create a Menu", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         5, 
                         TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleOption1);
    GrStringDraw(&g_sContext,"Option #1", 10,15,15,TRANSPARENT_TEXT);
    GrRectFill(&g_sContext, &myRectangleOption2);
    GrStringDraw(&g_sContext,"Option #2", 10,15,25,TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleOption3);
    GrStringDraw(&g_sContext,"Option #3", 10,15,35,TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleOption4);
    GrStringDraw(&g_sContext,"Option #4", 10,15,45,TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleOption5);
    GrStringDraw(&g_sContext,"Option #5", 10,15,55,TRANSPARENT_TEXT);
    GrFlush(&g_sContext);
    Delay_long();
    GrClearDisplay(&g_sContext);

    // Show progress bar screen
    // The following animation consist on displaying a progress bar and 
    // updating the progress bar in increments of 25%.
    GrStringDrawCentered(&g_sContext, 
                         "Show progress", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         5, 
                         TRANSPARENT_TEXT);
    GrRectDraw(&g_sContext, &myRectangleFrame);
    GrStringDrawCentered(&g_sContext,
                         "Processing...", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         75, 
                         TRANSPARENT_TEXT);
    GrFlush(&g_sContext);
    Delay_short();

    // Update display with 25 %. Initial value of "myRectangleProgress" are set 
    // to update bar with a 25 % increment.
    GrRectFill(&g_sContext, &myRectangleProgress);
    GrFlush(&g_sContext);
    Delay_short();

    // Set myRectangleProgress values to update progress bar with 50 %
    myRectangleProgress.sXMin = 30;
    myRectangleProgress.sYMin = 40;
    myRectangleProgress.sXMax = 50;
    myRectangleProgress.sYMax = 60;

    GrRectFill(&g_sContext, &myRectangleProgress);
    GrFlush(&g_sContext);
    Delay_short();

    // Set myRectangleProgress values to update progress bar with 75 %
    myRectangleProgress.sXMin = 50;
    myRectangleProgress.sYMin = 40;
    myRectangleProgress.sXMax = 70;
    myRectangleProgress.sYMax = 60;

    GrRectFill(&g_sContext, &myRectangleProgress);
    GrFlush(&g_sContext);
    Delay_short();

    // Set myRectangleProgress values to update progress bar with 100 %
    myRectangleProgress.sXMin = 70;
    myRectangleProgress.sYMin = 40;
    myRectangleProgress.sXMax = 90;
    myRectangleProgress.sYMax = 60;
    GrRectFill(&g_sContext, &myRectangleProgress);

    GrStringDrawCentered(&g_sContext,
                         "DONE!", 
                         AUTO_STRING_LENGTH, 
                         48, 
                         85, 
                         TRANSPARENT_TEXT);
    GrFlush(&g_sContext);
    Delay_long();



    while(1);

}