Пример #1
0
int main (void)
{
        SysCtlClockSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

        // Konfiguracja GPIO
        //
        // Enable the GPIO port that is used for the on-board LED.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
        GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);


        // Konfiguracja USB

        // Enable the GPIO peripheral used for USB, and configure the USB
        // pins.
        //
        SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
        SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD);
        GPIOPinTypeUSBAnalog(GPIO_PORTD_AHB_BASE, GPIO_PIN_4 | GPIO_PIN_5);

        //
        // Set the USB stack mode to Device mode.
        //
        USBStackModeSet(0, eUSBModeForceDevice, 0);


        void *pvDevice = USBDHIDKeyboardInit(0, &g_sKeyboardDevice);
        GPIOPinWrite (GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

        if (!pvDevice) {
                while (1);
        }

        GPIOPinWrite (GPIO_PORTF_BASE, GPIO_PIN_3, GPIO_PIN_3);

        uint32_t ui32Loop;

        while (1) {
                USBDHIDKeyboardKeyStateChange (pvDevice, 0, 0x04, true);

                // DELAY
                for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++)
                {
                }
        }
}
Пример #2
0
void stellaris_gpio_early_init(void)
{
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOG);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOH);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
}
Пример #3
0
//*****************************************************************************
//
// Initialize the ADC inputs used by the game pad device.  This example uses
// the ADC pins on Port E pins 1, 2, and 3(AIN0-2).
//
//*****************************************************************************
void
ADCInit(void)
{
    int32_t ui32Chan;

    //
    // Enable the GPIOs and the ADC used by this example.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOE);

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);

    //
    // Select the external reference for greatest accuracy.
    //
    ROM_ADCReferenceSet(ADC0_BASE, ADC_REF_EXT_3V);

    //
    // Configure the pins which are used as analog inputs.
    //
    ROM_GPIOPinTypeADC(GPIO_PORTE_AHB_BASE, GPIO_PIN_3 | GPIO_PIN_2 |
                       GPIO_PIN_1);

    //
    // Configure the sequencer for 3 steps.
    //
    for(ui32Chan = 0; ui32Chan < 2; ui32Chan++)
    {
        //
        // Configure the sequence step
        //
        ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, ui32Chan, ui32Chan);
    }

    ROM_ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2 | ADC_CTL_IE |
                                 ADC_CTL_END);
    //
    // Enable the sequence but do not start it yet.
    //
    ROM_ADCSequenceEnable(ADC0_BASE, 0);
}
Пример #4
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    uint8_t ui8ButtonsChanged, ui8Buttons;
    bool bUpdate;

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

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Enable the GPIO pin for the Blue LED (PF2).
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);

    //
    // Open UART0 and show the application name on the UART.
    //
    ConfigureUART();

    UARTprintf("\033[2JTiva C Series USB gamepad device example\n");
    UARTprintf("---------------------------------\n\n");

    //
    // Not configured initially.
    //
    g_iGamepadState = eStateNotConfigured;

    //
    // Enable the GPIO peripheral used for USB, and configure the USB
    // pins.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_AHB_BASE, GPIO_PIN_4 | GPIO_PIN_5);

    //
    // Configure the GPIOS for the buttons.
    //
    ButtonsInit();

    //
    // Initialize the ADC channels.
    //
    ADCInit();

    //
    // Tell the user what we are up to.
    //
    UARTprintf("Configuring USB\n");

    //
    // Set the USB stack mode to Device mode.
    //
    USBStackModeSet(0, eUSBModeForceDevice, 0);

    //
    // Pass the device information to the USB library and place the device
    // on the bus.
    //
    USBDHIDGamepadInit(0, &g_sGamepadDevice);

    //
    // Zero out the initial report.
    //
    sReport.ui8Buttons = 0;
    sReport.i8XPos = 0;
    sReport.i8YPos = 0;
    sReport.i8ZPos = 0;

    //
    // Tell the user what we are doing and provide some basic instructions.
    //
    UARTprintf("\nWaiting For Host...\n");

    //
    // Trigger an initial ADC sequence.
    //
    ADCProcessorTrigger(ADC0_BASE, 0);

    //
    // The main loop starts here.  We begin by waiting for a host connection
    // then drop into the main gamepad handling section.  If the host
    // disconnects, we return to the top and wait for a new connection.
    //
    while(1)
    {
        //
        // Wait here until USB device is connected to a host.
        //
        if(g_iGamepadState == eStateIdle)
        {
            //
            // No update by default.
            //
            bUpdate = false;

            //
            // See if the buttons updated.
            //
            ButtonsPoll(&ui8ButtonsChanged, &ui8Buttons);

            sReport.ui8Buttons = 0;

            //
            // Set button 1 if left pressed.
            //
            if(ui8Buttons & LEFT_BUTTON)
            {
                sReport.ui8Buttons |= 0x01;
            }

            //
            // Set button 2 if right pressed.
            //
            if(ui8Buttons & RIGHT_BUTTON)
            {
                sReport.ui8Buttons |= 0x02;
            }

            if(ui8ButtonsChanged)
            {
                bUpdate = true;
            }

            //
            // See if the ADC updated.
            //
            if(ADCIntStatus(ADC0_BASE, 0, false) != 0)
            {
                //
                // Clear the ADC interrupt.
                //
                ADCIntClear(ADC0_BASE, 0);

                //
                // Read the data and trigger a new sample request.
                //
                ADCSequenceDataGet(ADC0_BASE, 0, &g_pui32ADCData[0]);
                ADCProcessorTrigger(ADC0_BASE, 0);

                //
                // Update the report.
                //
                sReport.i8XPos = Convert8Bit(g_pui32ADCData[0]);
                sReport.i8YPos = Convert8Bit(g_pui32ADCData[1]);
                sReport.i8ZPos = Convert8Bit(g_pui32ADCData[2]);
                bUpdate = true;
            }

            //
            // Send the report if there was an update.
            //
            if(bUpdate)
            {
                USBDHIDGamepadSendReport(&g_sGamepadDevice, &sReport,
                                         sizeof(sReport));

                //
                // Now sending data but protect this from an interrupt since
                // it can change in interrupt context as well.
                //
                IntMasterDisable();
                g_iGamepadState = eStateSending;
                IntMasterEnable();

                //
                // Limit the blink rate of the LED.
                //
                if(g_ui32Updates++ == 40)
                {
                    //
                    // Turn on the blue LED.
                    //
                    ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);

                    //
                    // Reset the update count.
                    //
                    g_ui32Updates = 0;
                }
            }
        }
    }
}
//*****************************************************************************
//
// Main cap-touch example.
//
//*****************************************************************************
int
main(void)
{
    uint8_t ui8CenterButtonTouched;
    uint32_t ui32WheelTouchCounter;
    uint8_t ui8ConvertedWheelPosition;
    uint8_t ui8GestureDetected;
    uint8_t ui8Loop;

    //
    // 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 PLL at 80 MHz.
    //
    ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |
                       SYSCTL_OSC_MAIN);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    //
    // Initialize a few GPIO outputs for the LEDs
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_4);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTE_BASE, GPIO_PIN_5);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_4);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_6);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_7);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE, GPIO_PIN_5);

    //
    // Turn on the Center LED
    //
    ROM_GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_5, GPIO_PIN_5);

    //
    // Initialize the UART.
    //
    ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
    ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
    ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
    UARTStdioConfig(0, 9600, ROM_SysCtlClockGet());

    //
    // Configure the pins needed for capacitive touch sensing.  The capsense
    // driver assumes that these pins are already configured, and that they
    // will be accessed through the AHB bus
    //
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOA);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_2);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_3);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_4);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_6);
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTA_AHB_BASE, GPIO_PIN_7);

    //
    // Start up Systick to measure time.  This is also required by the capsense
    // drivers.
    //
    ROM_SysTickPeriodSet(0x00FFFFFF);
    ROM_SysTickEnable();

    //
    // Set the baseline capacitance measurements for our wheel and center
    // button.
    //
    TI_CAPT_Init_Baseline(&g_sSensorWheel);
    TI_CAPT_Update_Baseline(&g_sSensorWheel, 10);
    TI_CAPT_Init_Baseline(&g_sMiddleButton);
    TI_CAPT_Update_Baseline(&g_sMiddleButton, 10);

    //
    // Send the "sleep" code.  The TIVA C-series version of this app doesn't
    // actually sleep, but the MSP430-based GUI it interacts with expects to
    // see this code on startup, so we will provide it here.
    //
    UARTprintf("\0xDE\0xAD");

    //
    // Send the "awake" code.
    //
    UARTprintf("\0xBE\0xEF");

    //
    // Perform an LED startup sequence.
    //
    for(ui8Loop = 0; ui8Loop < 16; ui8Loop++)
    {
        LEDOutput(ui8Loop);
        DelayMs(10);
    }

    LEDOutput(0);


    //
    // Assume that the center button starts off "untouched", the wheel has no
    // position, and no gestures are in progress.
    //
    ui8CenterButtonTouched = 0;
    ui8ConvertedWheelPosition = INVALID_CONVERTED_POSITION;
    ui8GestureDetected = 0;

    //
    // This "wheel counter" gets incremented when a button on the wheel is held
    // down.  Every time it hits the value of WHEEL_TOUCH_DELAY, the device
    // sends a signal to the GUI reporting another button press.  We want this
    // delay normally, but we'll set the counter to just below the threshold
    // for now, so we'll avoid any percieved lag between the initial button
    // press and the first position report to the GUI.
    //
    ui32WheelTouchCounter = WHEEL_TOUCH_DELAY - 1;

    //
    // Begin the main capsense loop.
    //
    while(1)
    {
        //
        // Start by taking a fresh measurement from the wheel.  If it remains
        // set to ILLEGAL_SLIDER_WHEEL_POSITION, we will know it has not been
        // touched at all.  Otherwise we will have an updated position.
        //
        g_ui32WheelPosition = ILLEGAL_SLIDER_WHEEL_POSITION;
        g_ui32WheelPosition = TI_CAPT_Wheel(&g_sSensorWheel);

        //
        // If we registered a touch somewhere on the wheel, we will need to
        // figure out how to report that touch back to the GUI on the PC.
        //
        if(g_ui32WheelPosition != ILLEGAL_SLIDER_WHEEL_POSITION)
        {
            //
            // First, make sure we're not reporting center button touches while
            // the wheel is active.
            //
            ui8CenterButtonTouched = 0;

            //
            // We need to do a quick formatting change on the wheel position.
            // The "zero" postion as reported by the driver is about 40 degrees
            // off from "up" on the physical wheel.  We'll do that correction
            // here.
            //
            if(g_ui32WheelPosition < 8)
            {
                g_ui32WheelPosition += 64 - 8;
            }
            else
            {
                g_ui32WheelPosition -= 8;
            }

            //
            // We also need to reduce the effective number of positions on the
            // wheel.  The driver reports a wheel position from zero to
            // sixty-three, but the GUI only recognizes positions from zero to
            // sixteen.  Dividing our position by four accomplishes the
            // necessary conversion.
            //
            g_ui32WheelPosition = g_ui32WheelPosition >> 2;

            //
            // Now that we have a properly formatted wheel position, we will
            // use the GetGesture function to determine whether the user has
            // been sliding their finger around the wheel.  If so, this function
            // will return the magnitude and direction of the slide (Check the
            // function description for an example of how this is formated).
            // Otherwise, we will get back a zero.
            //
            ui8ConvertedWheelPosition = GetGesture(g_ui32WheelPosition);

            //
            // If the magnitude of our slide was one wheel position (of
            // sixteen) or less, don't register it.  This prevents excessive
            // reporting of toggles between two adjacent wheel positions.
            //
            if((ui8GestureDetected == 0) &&
               ((ui8ConvertedWheelPosition <= 1) ||
                (ui8ConvertedWheelPosition == 0x11) ||
                (ui8ConvertedWheelPosition == 0x10)))
            {
                //
                // If we obtained a valid wheel position last time we ran this
                // loop, keep our wheel position set to that instead of
                // updating it.  This prevents a mismatch between our recorded
                // absolute position and our recorded swipe magnitude.
                //
                if(g_ui32PreviousWheelPosition !=
                   ILLEGAL_SLIDER_WHEEL_POSITION)
                {
                    g_ui32WheelPosition = g_ui32PreviousWheelPosition;
                }

                //
                // Set the swipe magnitude to zero.
                //
                ui8ConvertedWheelPosition = 0;
            }

            //
            // We've made all of the position adjustments we're going to make,
            // so turn on LEDs to indicate that we've detected a finger on the
            // wheel.
            //
            LEDOutput(g_ui32WheelPosition);

            //
            // If the (adjusted) magnitude of the swipe we detected earlier is
            // valid and non-zero, we should alert the GUI that a gesture is
            // occurring.
            //
            if((ui8ConvertedWheelPosition != 0) &&
               (ui8ConvertedWheelPosition != 16) &&
               (ui8ConvertedWheelPosition != INVALID_CONVERTED_POSITION))
            {
                //
                // If this is a new gesture, we will need to send the gesture
                // start code.
                //
                if(ui8GestureDetected == 0)
                {
                    //
                    // Remember that we've started a gesture.
                    //
                    ui8GestureDetected = 1;

                    //
                    // Transmit gesture start status update & position via UART
                    // to PC.
                    //
                    ROM_UARTCharPut(UART0_BASE, GESTURE_START);
                    ROM_UARTCharPut(UART0_BASE, (g_ui32PreviousWheelPosition +
                                                 GESTURE_POSITION_OFFSET));
                }

                //
                // Transmit gesture & position via UART to PC
                //
                ROM_UARTCharPut(UART0_BASE, ui8ConvertedWheelPosition);
                ROM_UARTCharPut(UART0_BASE, (g_ui32WheelPosition +
                                             GESTURE_POSITION_OFFSET));
            }
            else
            {
                //
                // If we get here, the wheel has been touched, but there hasn't
                // been any sliding recently.  If there hasn't been any sliding
                // AT ALL, then this is a "press" event, and we need to start
                // sending press-style updates to the PC
                //
                if(ui8GestureDetected == 0)
                {
                    //
                    // Increment our wheel counter.
                    //
                    ui32WheelTouchCounter = ui32WheelTouchCounter + 1;

                    //
                    // If the user's finger is still in the same place...
                    //
                    if(ui32WheelTouchCounter >= WHEEL_TOUCH_DELAY)
                    {
                        //
                        // Transmit wheel position (twice) via UART to PC.
                        //
                        ui32WheelTouchCounter = 0;
                        ROM_UARTCharPut(UART0_BASE, (g_ui32WheelPosition +
                                                     WHEEL_POSITION_OFFSET));
                        ROM_UARTCharPut(UART0_BASE, (g_ui32WheelPosition +
                                                     WHEEL_POSITION_OFFSET));
                    }
                }
                else
                {
                    //
                    // We've received a slide input somewhat recently, but not
                    // during this loop instance.  This most likely means that
                    // the user started a gesture, but is currently just
                    // holding their finger in one spot.  This isn't really a
                    // "press" event, so there isn't anything to report.  We
                    // should, however, make sure the touch counter is primed
                    // for future press events.
                    //
                    ui32WheelTouchCounter = WHEEL_TOUCH_DELAY - 1;
                }
            }

            //
            // Regardless of all pressing, sliding, reporting, and LED events
            // that may have occurred, we need to record our measured
            // (adjusted) wheel position for reference for the next pass
            // through the loop.
            //
            g_ui32PreviousWheelPosition = g_ui32WheelPosition;
        }
        else
        {
            //
            // If we get here, there were no touches recorded on the slider
            // wheel.  We should check our middle button to see if it has been
            // pressed, and clean up our recorded state to prepare for future
            // possible wheel-touch events.
            //
            if(TI_CAPT_Button(&g_sMiddleButton))
Пример #6
0
//*****************************************************************************
//
// This is the main loop that runs the application.
//
//*****************************************************************************
int
main(void)
{
    uint_fast32_t ui32LastTickCount;
    bool bLastSuspend;


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

    //
    // Enable the GPIO port that is used for the on-board LED.
    //
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);

    //
    // Enable the GPIO pin for the Blue LED (PF2).
    //
    ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 | GPIO_PIN_2 | GPIO_PIN_3);

    //
    // Enable the UART.
    //
    ConfigureUART();
    UARTprintf("Keyboard device application\n");

    // Configure USB0DM & USB0DP (PD4 & PD5)
    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    SysCtlGPIOAHBEnable(SYSCTL_PERIPH_GPIOD);
    ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_AHB_BASE, GPIO_PIN_4 | GPIO_PIN_5);

    //Configure USB0ID & USB0VBUS (PB0 & PB1)
//    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
//    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_TM4C123 && REVISION_IS_A1)
    {
        HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1;
    }


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

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

    //
    // Initialize the USB stack for device mode.
    //
    //USBStackModeSet(0, eUSBModeDevice, 0);
    USBStackModeSet(0, eUSBModeForceDevice, 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.
        //
        UARTprintf("Waiting for host...\n");

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

        //
        // Update the status.
        //
        UARTprintf("Host connected...\n");

        //
        // 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;
                UARTprintf(bLastSuspend ? "Bus suspended...\n" :"Host connected...\n");
            }

            //
            // See if the button was just pressed.
            //
            ui8Buttons = ButtonsPoll(&ui8ButtonsChanged, 0);
            if(BUTTON_PRESSED(LEFT_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)
            {

            }
        }

        //
        // Dropping out of the previous loop indicates that the host has
        // disconnected so go back and wait for reconnection.
        //

        if(g_bConnected == false)
                {
                    UARTprintf("Host disconnected...\n");
                }

    }
}