//***************************************************************************** // // This example demonstrates how to configure MPU regions for different levels // of memory protection. The following memory map is set up: // // 0000.0000 - 0000.1C00 - rgn 0: executable read-only, flash // 0000.1C00 - 0000.2000 - rgn 0: no access, flash (disabled sub-region 7) // 2000.0000 - 2000.8000 - rgn 1: read-write, RAM // 2000.8000 - 2000.A000 - rgn 2: read-only, RAM (disabled sub-rgn 4 of rgn 1) // 2000.A000 - 2000.FFFF - rgn 1: read-write, RAM // 4000.0000 - 4001.0000 - rgn 3: read-write, peripherals // 4001.0000 - 4002.0000 - rgn 3: no access (disabled sub-region 1) // 4002.0000 - 4006.0000 - rgn 3: read-write, peripherals // 4006.0000 - 4008.0000 - rgn 3: no access (disabled sub-region 6, 7) // E000.E000 - E000.F000 - rgn 4: read-write, NVIC // // The example code will attempt to perform the following operations and check // the faulting behavior: // // - write to flash (should fault) // - read from the disabled area of flash (should fault) // - read from the read-only area of RAM (should not fault) // - write to the read-only section of RAM (should fault) // //***************************************************************************** int main(void) { tRectangle sRect; unsigned int bFail = 0; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the display driver. // Formike128x128x16Init(); // // Turn on the backlight. // Formike128x128x16BacklightOn(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sFormike128x128x16); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = 14; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, &g_sFontFixed6x8); GrStringDrawCentered(&g_sContext, "mpu_fault", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Configure an executable, read-only MPU region for flash. It is a 16 KB // region with the last 2 KB disabled to result in a 14 KB executable // region. This region is needed so that the program can execute from // flash. // MPURegionSet(0, FLASH_BASE, MPU_RGN_SIZE_16K | MPU_RGN_PERM_EXEC | MPU_RGN_PERM_PRV_RO_USR_RO | MPU_SUB_RGN_DISABLE_7 | MPU_RGN_ENABLE); // // Configure a read-write MPU region for RAM. It is a 64 KB region. There // is a 8 KB sub-region in the middle that is disabled in order to open up // a hole in which different permissions can be applied. // MPURegionSet(1, SRAM_BASE, MPU_RGN_SIZE_64K | MPU_RGN_PERM_NOEXEC | MPU_RGN_PERM_PRV_RW_USR_RW | MPU_SUB_RGN_DISABLE_4 | MPU_RGN_ENABLE); // // Configure a read-only MPU region for the 8 KB of RAM that is disabled in // the previous region. This region is used for demonstrating read-only // permissions. // MPURegionSet(2, SRAM_BASE + 0x8000, MPU_RGN_SIZE_2K | MPU_RGN_PERM_NOEXEC | MPU_RGN_PERM_PRV_RO_USR_RO | MPU_RGN_ENABLE); // // Configure a read-write MPU region for peripherals. The region is 512 KB // total size, with several sub-regions disabled to prevent access to areas // where there are no peripherals. This region is needed because the // program needs access to some peripherals. // MPURegionSet(3, 0x40000000, MPU_RGN_SIZE_512K | MPU_RGN_PERM_NOEXEC | MPU_RGN_PERM_PRV_RW_USR_RW | MPU_SUB_RGN_DISABLE_1 | MPU_SUB_RGN_DISABLE_6 | MPU_SUB_RGN_DISABLE_7 | MPU_RGN_ENABLE); // // Configure a read-write MPU region for access to the NVIC. The region is // 4 KB in size. This region is needed because NVIC registers are needed // in order to control the MPU. // MPURegionSet(4, NVIC_BASE, MPU_RGN_SIZE_4K | MPU_RGN_PERM_NOEXEC | MPU_RGN_PERM_PRV_RW_USR_RW | MPU_RGN_ENABLE); // // Need to clear the NVIC fault status register to make sure there is no // status hanging around from a previous program. // g_ulFaultStatus = HWREG(NVIC_FAULT_STAT); HWREG(NVIC_FAULT_STAT) = g_ulFaultStatus; // // Enable the MPU fault. // ROM_IntEnable(FAULT_MPU); // // Enable the MPU. This will begin to enforce the memory protection // regions. The MPU is configured so that when in the hard fault or NMI // exceptions, a default map will be used. Neither of these should occur // in this example program. // MPUEnable(MPU_CONFIG_HARDFLT_NMI); // // Attempt to write to the flash. This should cause a protection fault due // to the fact that this region is read-only. // GrStringDraw(&g_sContext, "Check flash write", -1, 0, 24, 0); g_ulMPUFaultCount = 0; HWREG(0x100) = 0x12345678; // // Verify that the fault occurred, at the expected address. // if((g_ulMPUFaultCount == 1) && (g_ulFaultStatus == 0x82) && (g_ulMMAR == 0x100)) { GrStringDraw(&g_sContext, " OK", -1, 108, 24, 0); } else { bFail = 1; GrStringDraw(&g_sContext, "NOK", -1, 108, 24, 0); } // // The MPU was disabled when the previous fault occurred, so it needs to be // re-enabled. // MPUEnable(MPU_CONFIG_HARDFLT_NMI); // // Attempt to read from the disabled section of flash, the upper 2 KB of // the 16 KB region. // GrStringDraw(&g_sContext, "Check flash read", -1, 0, 32, 0); g_ulMPUFaultCount = 0; g_ulValue = HWREG(0x3820); // // Verify that the fault occurred, at the expected address. // if((g_ulMPUFaultCount == 1) && (g_ulFaultStatus == 0x82) && (g_ulMMAR == 0x3820)) { GrStringDraw(&g_sContext, " OK", -1, 108, 32, 0); } else { bFail = 1; GrStringDraw(&g_sContext, "NOK", -1, 108, 32, 0); } // // The MPU was disabled when the previous fault occurred, so it needs to be // re-enabled. // MPUEnable(MPU_CONFIG_HARDFLT_NMI); // // Attempt to read from the read-only area of RAM, the middle 8 KB of the // 64 KB region. // GrStringDraw(&g_sContext, "Check RAM read", -1, 0, 40, 0); g_ulMPUFaultCount = 0; g_ulValue = HWREG(0x20008440); // // Verify that the RAM read did not cause a fault. // if(g_ulMPUFaultCount == 0) { GrStringDraw(&g_sContext, " OK", -1, 108, 40, 0); } else { bFail = 1; GrStringDraw(&g_sContext, "NOK", -1, 108, 40, 0); } // // The MPU should not have been disabled since the last access was not // supposed to cause a fault. But if it did cause a fault, then the MPU // will be disabled, so re-enable it here anyway, just in case. // MPUEnable(MPU_CONFIG_HARDFLT_NMI); // // Attempt to write to the read-only area of RAM, the middle 8 KB of the // 64 KB region. // GrStringDraw(&g_sContext, "Check RAM write", -1, 0, 48, 0); g_ulMPUFaultCount = 0; HWREG(0x20008460) = 0xabcdef00; // // Verify that the RAM write caused a fault. // if((g_ulMPUFaultCount == 1) && (g_ulFaultStatus == 0x82) && (g_ulMMAR == 0x20008460)) { GrStringDraw(&g_sContext, " OK", -1, 108, 48, 0); } else { bFail = 1; GrStringDraw(&g_sContext, "NOK", -1, 108, 48, 0); } // // Display the results of the example program. // if(bFail) { GrStringDrawCentered(&g_sContext, "Failure!", -1, GrContextDpyWidthGet(&g_sContext) / 2, 96, 0); } else { GrStringDrawCentered(&g_sContext, "Success!", -1, GrContextDpyWidthGet(&g_sContext) / 2, 96, 0); } // // Disable the MPU, so there are no lingering side effects if another // program is run. // MPUDisable(); // // Loop forever. // while(1) { } }
//***************************************************************************** // // main routine. // //***************************************************************************** int main(void) { tLPMFeature sLPMFeature; // // Run from the PLL at 120 MHz. // g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Configure the UART. // UARTStdioConfig(0, 115200, g_ui32SysClock); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(g_ui32SysClock); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&g_sContext, "usb-otg-mouse"); // // Configure USB for OTG operation. // USBOTGInit(g_ui32SysClock, ModeCallback); sLPMFeature.ui32HIRD = 500; sLPMFeature.ui32Features = USBLIB_FEATURE_LPM_EN | USBLIB_FEATURE_LPM_RMT_WAKE; USBHCDFeatureSet(0, USBLIB_FEATURE_LPM, &sLPMFeature); // // Initialize the host stack. // HostInit(); // // Initialize the device stack. // DeviceInit(); // // Initialize the USB controller for dual mode operation with a 2ms polling // rate. // USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE); // // Set the new state so that the screen updates on the first // pass. // g_ui32NewState = 1; // // Loop forever. // while(1) { // // Tell the OTG library code how much time has passed in milliseconds // since the last call. // USBOTGMain(GetTickms()); // // Handle deferred state change. // if(g_ui32NewState) { g_ui32NewState =0; // // Update the status area of the screen. // ClearMainWindow(); // // Update the status bar with the new mode. // switch(g_iCurrentMode) { case eUSBModeHost: { UpdateStatus("Host Mode", 0, true); break; } case eUSBModeDevice: { UpdateStatus("Device Mode", 0, true); break; } case eUSBModeNone: { UpdateStatus("Idle Mode\n", 0, true); break; } default: { break; } } } if(g_iCurrentMode == eUSBModeDevice) { DeviceMain(); } else if(g_iCurrentMode == eUSBModeHost) { HostMain(); } } }
//***************************************************************************** // // This is the main application entry function. // //***************************************************************************** int main(void) { unsigned long ulTxCount; unsigned long ulRxCount; tRectangle sRect; char pcBuffer[16]; unsigned long ulFullness; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run from the PLL at 50MHz // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure the required pins for USB operation. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN); ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Erratum workaround for silicon revision A1. VBUS must have pull-down. // if(CLASS_IS_BLIZZARD && REVISION_IS_A1) { HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1; } // // Not configured initially. // g_bUSBConfigured = false; // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sCFAL96x64x16); // // 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 = 9; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_pFontFixed6x8); GrStringDrawCentered(&g_sContext, "usb-dev-serial", -1, GrContextDpyWidthGet(&g_sContext) / 2, 4, 0); // // Show the various static text elements on the color STN display. // GrStringDraw(&g_sContext, "Tx #",-1, 0, 12, false); GrStringDraw(&g_sContext, "Tx buf", -1, 0, 22, false); GrStringDraw(&g_sContext, "Rx #", -1, 0, 32, false); GrStringDraw(&g_sContext, "Rx buf", -1, 0, 42, false); DrawBufferMeter(&g_sContext, 40, 22); DrawBufferMeter(&g_sContext, 40, 42); // // Enable the UART that we will be redirecting. // ROM_SysCtlPeripheralEnable(USB_UART_PERIPH); // // Enable and configure the UART RX and TX pins // ROM_SysCtlPeripheralEnable(TX_GPIO_PERIPH); ROM_SysCtlPeripheralEnable(RX_GPIO_PERIPH); ROM_GPIOPinTypeUART(TX_GPIO_BASE, TX_GPIO_PIN); ROM_GPIOPinTypeUART(RX_GPIO_BASE, RX_GPIO_PIN); // // TODO: Add code to configure handshake GPIOs if required. // // // Set the default UART configuration. // ROM_UARTConfigSetExpClk(USB_UART_BASE, ROM_SysCtlClockGet(), DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG); ROM_UARTFIFOLevelSet(USB_UART_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); // // Configure and enable UART interrupts. // ROM_UARTIntClear(USB_UART_BASE, ROM_UARTIntStatus(USB_UART_BASE, false)); ROM_UARTIntEnable(USB_UART_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX)); // // Enable the system tick. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Tell the user what we are up to. // DisplayStatus(&g_sContext, " Configuring... "); // // Initialize the transmit and receive buffers. // USBBufferInit((tUSBBuffer *)&g_sTxBuffer); USBBufferInit((tUSBBuffer *)&g_sRxBuffer); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass our device information to the USB library and place the device // on the bus. // USBDCDCInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Wait for initial configuration to complete. // DisplayStatus(&g_sContext, "Waiting for host"); // // Clear our local byte counters. // ulRxCount = 0; ulTxCount = 0; // // Enable interrupts now that the application is ready to start. // ROM_IntEnable(USB_UART_INT); // // Main application loop. // while(1) { // // Have we been asked to update the status display? // if(g_ulFlags & COMMAND_STATUS_UPDATE) { // // Clear the command flag // ROM_IntMasterDisable(); g_ulFlags &= ~COMMAND_STATUS_UPDATE; ROM_IntMasterEnable(); DisplayStatus(&g_sContext, g_pcStatus); } // // Has there been any transmit traffic since we last checked? // if(ulTxCount != g_ulUARTTxCount) { // // Take a snapshot of the latest transmit count. // ulTxCount = g_ulUARTTxCount; // // Update the display of bytes transmitted by the UART. // usnprintf(pcBuffer, 16, "%d ", ulTxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 40, 12, true); // // Update the RX buffer fullness. Remember that the buffers are // named relative to the USB whereas the status display is from // the UART's perspective. The USB's receive buffer is the UART's // transmit buffer. // ulFullness = ((USBBufferDataAvailable(&g_sRxBuffer) * 100) / UART_BUFFER_SIZE); UpdateBufferMeter(&g_sContext, ulFullness, 40, 22); } // // Has there been any receive traffic since we last checked? // if(ulRxCount != g_ulUARTRxCount) { // // Take a snapshot of the latest receive count. // ulRxCount = g_ulUARTRxCount; // // Update the display of bytes received by the UART. // usnprintf(pcBuffer, 16, "%d ", ulRxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 40, 32, true); // // Update the TX buffer fullness. Remember that the buffers are // named relative to the USB whereas the status display is from // the UART's perspective. The USB's transmit buffer is the UART's // receive buffer. // ulFullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) / UART_BUFFER_SIZE); UpdateBufferMeter(&g_sContext, ulFullness, 40, 42); } } }
//***************************************************************************** // // 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 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 connecter. // GPIOPinTypeGPIOOutput(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN); GPIOPinWrite(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN, USB_MUX_SEL_DEVICE); #ifdef DEBUG // // Configure the relevant pins such that UART0 owns them. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Open UART0 for debug output. // UARTStdioInit(0); #endif // // Initialize the pushbuttons. // ButtonsInit(); ButtonsSetAutoRepeat((LEFT_BUTTON | RIGHT_BUTTON | UP_BUTTON | DOWN_BUTTON), 0, 2); // // Set the system tick to fire 100 times per second. // SysTickPeriodSet(SysCtlClockGet() / SYSTICKS_PER_SECOND); SysTickIntEnable(); SysTickEnable(); // // Initialize the display driver. // Formike128x128x16Init(); // // Turn on the backlight. // Formike128x128x16BacklightOn(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sFormike128x128x16); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = 14; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_pFontFixed6x8); GrStringDrawCentered(&g_sContext, "boot_demo_usb", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Initialize each of the device instances that will form our composite // USB device. // g_sCompDevice.psDevices[0].pvInstance = USBDHIDMouseCompositeInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); g_sCompDevice.psDevices[1].pvInstance = USBDDFUCompositeInit(0, (tUSBDDFUDevice *)&g_sDFUDevice); // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_BUFFER_SIZE, g_pcDescriptorBuffer); // // Drop into the main loop. // while(!g_bUpdateSignalled) { // // Fill all but the top 15 rows of the screen with black to erase the // previous status. // sRect.sXMin = 0; sRect.sYMin = 15; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = GrContextDpyHeightGet(&g_sContext) - 1; GrContextForegroundSet(&g_sContext, ClrBlack); GrRectFill(&g_sContext, &sRect); // // Tell the user what we are doing. // GrContextForegroundSet(&g_sContext, ClrWhite); GrStringDrawCentered(&g_sContext, "Waiting for host...", -1, GrContextDpyWidthGet(&g_sContext) / 2, 24, true); // // Wait for USB configuration to complete. // while(!g_bConnected) { } // // Update the status. // GrStringDrawCentered(&g_sContext, " Host connected... ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 24, true); // // Now keep processing the mouse as long as the host is connected. // while(g_bConnected && !g_bUpdateSignalled) { // // If it is time to check the button state then do so. // if(g_ulCommands & BUTTON_TICK_EVENT) { g_ulCommands &= ~BUTTON_TICK_EVENT; ButtonHandler(); } } // // If we drop out of the previous loop, the host has disconnected so // go back and wait for a new connection. // } // // If we drop out of the main loop, the host has signalled that it wants us // to switch into DFU mode in preparation for a firmware upgrade. First, // let the user know what's going on. // GrStringDrawCentered(&g_sContext, "Entering DFU mode...", -1, GrContextDpyWidthGet(&g_sContext) / 2, 24, true); // // Call the USB DFU device class to tidy things up and transfer control to // the boot loader for us. Note that this function never returns. // USBDDFUUpdateBegin(); }
//***************************************************************************** // // The program main function. It performs initialization, then runs // a command processing loop to read commands from the console. // //***************************************************************************** int main(void) { uint32_t ui32DriveTimeout; uint32_t ui32SysClock; tContext sContext; // // 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(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "usb-host-msc"); // // Configure SysTick for a 100Hz interrupt. // ROM_SysTickPeriodSet(ui32SysClock / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Enable the uDMA controller and set up the control table base. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_sDMAControlTable); // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground); // // Set some initial strings. // ListBoxTextAdd(&g_sDirList, "Waiting for device..."); // // Issue the initial paint request to the widgets then immediately call // the widget manager to process the paint message. This ensures that the // display is drawn as quickly as possible and saves the delay we would // otherwise experience if we processed the paint message after mounting // and reading the SD card. // WidgetPaint(WIDGET_ROOT); WidgetMessageQueueProcess(); // // Initially wait for device connection. // g_eState = STATE_NO_DEVICE; // // Initialize the USB stack for host mode. // USBStackModeSet(0, eUSBModeHost, 0); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers); // // Open an instance of the mass storage class driver. // g_psMSCInstance = USBHMSCDriveOpen(0, MSCCallback); // // Initialize the drive timeout. // ui32DriveTimeout = USBMSC_DRIVE_RETRY; // // 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 host operation. // USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE); // // Initialize the file system. // FileInit(); // // Enter an (almost) infinite loop for reading and processing commands from // the user. // while(1) { // // Call the USB stack to keep it running. // USBHCDMain(); // // Process any messages in the widget message queue. This keeps the // display UI running. // WidgetMessageQueueProcess(); switch(g_eState) { case STATE_DEVICE_ENUM: { // // Take it easy on the Mass storage device if it is slow to // start up after connecting. // if(USBHMSCDriveReady(g_psMSCInstance) != 0) { // // Wait about 500ms before attempting to check if the // device is ready again. // ROM_SysCtlDelay(ui32SysClock / (3 * 2)); // // Decrement the retry count. // ui32DriveTimeout--; // // If the timeout is hit then go to the // STATE_TIMEOUT_DEVICE state. // if(ui32DriveTimeout == 0) { g_eState = STATE_TIMEOUT_DEVICE; } break; } // // Getting here means the device is ready. // Reset the CWD to the root directory. // g_cCwdBuf[0] = '/'; g_cCwdBuf[1] = 0; // // Set the initial directory level to the root // g_ui32Level = 0; // // Fill the list box with the files and directories found. // if(!PopulateFileListBox(true)) { // // If there were no errors reported, we are ready for // MSC operation. // g_eState = STATE_DEVICE_READY; } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // If there is no device then just wait for one. // case STATE_NO_DEVICE: { if(g_ui32Flags == FLAGS_DEVICE_PRESENT) { // // Empty the list box on the display. // ListBoxClear(&g_sDirList); ListBoxTextAdd(&g_sDirList, "Waiting for device..."); WidgetPaint((tWidget *)&g_sDirList); // // Clear the Device Present flag. // g_ui32Flags &= ~FLAGS_DEVICE_PRESENT; } break; } // // An unknown device was connected. // case STATE_UNKNOWN_DEVICE: { // // If this is a new device then change the status. // if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0) { // // Clear the screen and indicate that an unknown device // is present. // ListBoxClear(&g_sDirList); ListBoxTextAdd(&g_sDirList, "Unknown device."); WidgetPaint((tWidget *)&g_sDirList); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // The connected mass storage device is not reporting ready. // case STATE_TIMEOUT_DEVICE: { // // If this is the first time in this state then print a // message. // if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0) { // // Clear the screen and indicate that an unknown device // is present. // ListBoxClear(&g_sDirList); ListBoxTextAdd(&g_sDirList, "Device Timeout."); WidgetPaint((tWidget *)&g_sDirList); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // Something has caused a power fault. // case STATE_POWER_FAULT: { break; } default: { break; } } } }
//***************************************************************************** // //! Draws the contents of a listbox. //! //! \param pWidget is a pointer to the listbox widget to be drawn. //! //! This function draws the contents of a listbox on the display. This is //! called in response to a \b #WIDGET_MSG_PAINT message. //! //! \return None. // //***************************************************************************** static void ListBoxPaint(tWidget *pWidget) { tListBoxWidget *pListBox; tContext sCtx; tRectangle sWidgetRect, sLineRect; short sHeight; long lWidth; unsigned short usCount, usString; // // Check the arguments. // ASSERT(pWidget); // // Convert the generic widget pointer into a listbox widget pointer. // pListBox = (tListBoxWidget *)pWidget; // // Initialize a drawing context. // GrContextInit(&sCtx, pWidget->pDisplay); GrContextFontSet(&sCtx, pListBox->pFont); // // Initialize the clipping region based on the extents of this listbox. // sWidgetRect = pWidget->sPosition; GrContextClipRegionSet(&sCtx, &sWidgetRect); // // See if the listbox outline style is selected. // if(pListBox->ulStyle & LISTBOX_STYLE_OUTLINE) { // // Outline the listbox with the outline color. // GrContextForegroundSet(&sCtx, pListBox->ulOutlineColor); GrRectDraw(&sCtx, &(pWidget->sPosition)); // // Shrink the widget region by one pixel on each side and draw another // rectangle, this time in the background color. This ensures that the // text will not interfere with the colored border. // sWidgetRect.sXMin++; sWidgetRect.sYMin++; sWidgetRect.sXMax--; sWidgetRect.sYMax--; GrContextForegroundSet(&sCtx, pListBox->ulBackgroundColor); GrRectDraw(&sCtx, &sWidgetRect); // // Reduce the size of the rectangle by another pixel to get the final // area into which we will put the text. // sWidgetRect.sXMin++; sWidgetRect.sYMin++; sWidgetRect.sXMax--; sWidgetRect.sYMax--; GrContextClipRegionSet(&sCtx, &sWidgetRect); } // // Start drawing at the top of the widget. // sLineRect = sWidgetRect; usCount = 0; usString = pListBox->usStartEntry; sHeight = GrFontHeightGet(pListBox->pFont); // // Keep drawing until we reach the bottom of the listbox or run out of // strings to draw. // while((sLineRect.sYMin < sWidgetRect.sYMax) && (usCount < pListBox->usPopulated)) { // // Calculate the rectangle that will enclose this line of text. // sLineRect.sYMax = sLineRect.sYMin + sHeight - 1; // // Set foreground and background colors appropriately. // GrContextBackgroundSet(&sCtx, ((usString == pListBox->sSelected) ? pListBox->ulSelectedBackgroundColor : pListBox->ulBackgroundColor)); GrContextForegroundSet(&sCtx, ((usString == pListBox->sSelected) ? pListBox->ulSelectedTextColor : pListBox->ulTextColor)); // // Draw the text. // GrStringDraw(&sCtx, pListBox->ppcText[usString], -1, sLineRect.sXMin, sLineRect.sYMin, 1); // // Determine the width of the string we just rendered. // lWidth = GrStringWidthGet(&sCtx, pListBox->ppcText[usString], -1); // // Do we need to clear the area to the right of the string? // if(lWidth < (sLineRect.sXMax - sLineRect.sXMin + 1)) { // // Yes - we need to fill the right side of this string with // background color. // GrContextForegroundSet(&sCtx, ((usString == pListBox->sSelected) ? pListBox->ulSelectedBackgroundColor : pListBox->ulBackgroundColor)); sLineRect.sXMin += lWidth; GrRectFill(&sCtx, &sLineRect); sLineRect.sXMin = sWidgetRect.sXMin; } // // Move on to the next string. // usCount++; usString++; if(usString == pListBox->usMaxEntries) { usString = 0; } sLineRect.sYMin += sHeight; } // // Fill the remainder of the listbox area with the background color. // if(sLineRect.sYMin < sWidgetRect.sYMax) { // // Determine the rectangle to be filled. // sLineRect.sYMax = sWidgetRect.sYMax; // // Fill the rectangle with the background color. // GrContextForegroundSet(&sCtx, pListBox->ulBackgroundColor); GrRectFill(&sCtx, &sLineRect); } }
//***************************************************************************** // // Print "Hello World!" to the display. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the display driver. // Formike128x128x16Init(); // // Turn on the backlight. // Formike128x128x16BacklightOn(); // // Initialize the graphics context. // GrContextInit(&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(&sContext) - 1; sRect.sYMax = 14; 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_pFontFixed6x8); GrStringDrawCentered(&sContext, "hello", -1, GrContextDpyWidthGet(&sContext) / 2, 7, 0); // // Say hello using the Computer Modern 20 point font. // GrContextFontSet(&sContext, g_pFontCm20); GrStringDrawCentered(&sContext, "Hello World!", -1, GrContextDpyWidthGet(&sContext) / 2, ((GrContextDpyHeightGet(&sContext) - 16) / 2) + 16, 0); // // Flush any cached drawing operations. // GrFlush(&sContext); // // Loop forever. // while(1) { } }
void main(void) { // Stop WDT WDT_A_hold(WDT_A_BASE); // Basic GPIO initialization Board_init(); Clock_init(); // Set up LCD Dogs102x64_UC1701Init(); GrContextInit(&g_sContext, &g_sDogs102x64_UC1701); GrContextForegroundSet(&g_sContext, ClrBlack); GrContextBackgroundSet(&g_sContext, ClrWhite); GrContextFontSet(&g_sContext, &g_sFontFixed6x8); GrClearDisplay(&g_sContext); int toggle=0; while(1){ //GrClearDisplay(&g_sContext); print_string(0,0,"===Team Members==="); print_string(0,8,"Anson Bastos"); print_string(0,16,"Dhiraj Patil"); print_string(0,24,"Abhinendra Singh"); print_string(0,32,"Melroy Tellis"); print_string(0,40,"Abhishek Suryawanshi"); toggle=(toggle>4)?(0):(toggle); switch(toggle){ case 0: highlight_and_print_string(0,8,"Anson Bastos"); Delay(); toggle++; break; case 1: highlight_and_print_string(0,16,"Dhiraj Patil"); Delay(); toggle++; break; case 2: highlight_and_print_string(0,24,"Abhinendra Singh"); Delay(); toggle++; break; case 3: highlight_and_print_string(0,32,"Melroy Tellis"); Delay(); toggle++; break; case 4: highlight_and_print_string(0,40,"Abhishek Suryawanshi"); Delay(); toggle++; break; } } }
//***************************************************************************** // // Initialize and operate the data logger. // //***************************************************************************** int main(void) { tContext sDisplayContext, sBufferContext; uint32_t ui32HibIntStatus, ui32SysClock, ui32LastTickCount; bool bSkipSplash; uint8_t ui8ButtonState, ui8ButtonChanged; uint_fast8_t ui8X, ui8Y; // // 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. // MAP_FPULazyStackingEnable(); // // Set the clocking to run at 50 MHz. // MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); ui32SysClock = MAP_SysCtlClockGet(); // // Initialize locals. // bSkipSplash = false; ui32LastTickCount = 0; // // Check Board Revision, report if software / hardware are incompatible // CheckBoardRevision(); // // Initialize the data acquisition module. This initializes the ADC // hardware. // AcquireInit(); // Enable interrupts to the processor. // ROM_IntMasterEnable(); // // Enable access to the hibernate peripheral. If the hibernate peripheral // was already running then this will have no effect. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); // // Check to see if the hiberate module is already active and if so then // read the saved configuration state. If both are okay, then proceed // to check and see if we are logging data using sleep mode. // if(HibernateIsActive() && !GetSavedState(&g_sConfigState)) { // // Read the status of the hibernate module. // ui32HibIntStatus = HibernateIntStatus(1); // // If this is a pin wake, that means the user pressed the select // button and we should terminate the sleep logging. In this case // we will fall out of this conditional section, and go through the // normal startup below, but skipping the splash screen so the user // gets immediate response. // if(ui32HibIntStatus & HIBERNATE_INT_PIN_WAKE) { // // Clear the interrupt flag so it is not seen again until another // wake. // HibernateIntClear(HIBERNATE_INT_PIN_WAKE); bSkipSplash = true; } // // Otherwise if we are waking from hibernate and it was not a pin // wake, then it must be from RTC match. Check to see if we are // sleep logging and if so then go through an abbreviated startup // in order to collect the data and go back to sleep. // else if(g_sConfigState.ui32SleepLogging && (ui32HibIntStatus & HIBERNATE_INT_RTC_MATCH_0)) { // // Start logger and pass the configuration. The logger should // configure itself to take one sample. // AcquireStart(&g_sConfigState); g_iLoggerState = eSTATE_LOGGING; // // Enter a forever loop to run the acquisition. This will run // until a new sample has been taken and stored. // while(!AcquireRun()) { } // // Getting here means that a data acquisition was performed and we // can now go back to sleep. Save the configuration and then // activate the hibernate. // SetSavedState(&g_sConfigState); // // Set wake condition on pin-wake or RTC match. Then put the // processor in hibernation. // HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); HibernateRequest(); // // Hibernating takes a finite amount of time to occur, so wait // here forever until hibernate activates and the processor // power is removed. // for(;;) { } } // // Otherwise, this was not a pin wake, and we were not sleep logging, // so just fall out of this conditional and go through the normal // startup below. // } else { // // In this case, either the hibernate module was not already active, or // the saved configuration was not valid. Initialize the configuration // to the default state and then go through the normal startup below. // GetDefaultState(&g_sConfigState); } // // Enable the Hibernate module to run. // HibernateEnableExpClk(SysCtlClockGet()); // // The hibernate peripheral trim register must be set per silicon // erratum 2.1 // HibernateRTCTrimSet(0x7FFF); // // Start the RTC running. If it was already running then this will have // no effect. // HibernateRTCEnable(); // // In case we were sleep logging and are now finished (due to user // pressing select button), then disable sleep logging so it doesnt // try to start up again. // g_sConfigState.ui32SleepLogging = 0; SetSavedState(&g_sConfigState); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the buttons driver. // ButtonsInit(); // // Pass the restored state to the menu system. // MenuSetState(&g_sConfigState); // // Enable the USB peripheral // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Configure the required pins for USB operation. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); MAP_GPIOPinConfigure(GPIO_PG4_USB0EPEN); MAP_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); MAP_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); MAP_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Erratum workaround for silicon revision A1. VBUS must have pull-down. // if(CLASS_IS_BLIZZARD && REVISION_IS_A1) { HWREG(GPIO_PORTB_BASE + GPIO_O_PDR) |= GPIO_PIN_1; } // // Initialize the USB stack mode and pass in a mode callback. // USBStackModeSet(0, eUSBModeOTG, ModeCallback); // // Initialize the stack to be used with USB stick. // USBStickInit(); // // Initialize the stack to be used as a serial device. // USBSerialInit(); // // Initialize the USB controller for dual mode operation with a 2ms polling // rate. // USBOTGModeInit(0, 2000, g_pui8HCDPool, HCD_MEMORY_SIZE); // // Initialize the menus module. This module will control the user // interface menuing system. // MenuInit(WidgetActivated); // // Configure SysTick to periodically interrupt. // g_ui32TickCount = 0; MAP_SysTickPeriodSet(ui32SysClock / CLOCK_RATE); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Initialize the display context and another context that is used // as an offscreen drawing buffer for display animation effect // GrContextInit(&sDisplayContext, &g_sCFAL96x64x16); GrContextInit(&sBufferContext, &g_sOffscreenDisplayA); // // Show the splash screen if we are not skipping it. The only reason to // skip it is if the application was in sleep-logging mode and the user // just waked it up with the select button. // if(!bSkipSplash) { const uint8_t *pui8SplashLogo = g_pui8Image_TI_Black; // // Draw the TI logo on the display. Use an animation effect where the // logo will "slide" onto the screen. Allow select button to break // out of animation. // for(ui8X = 0; ui8X < 96; ui8X++) { if(ButtonsPoll(0, 0) & SELECT_BUTTON) { break; } GrImageDraw(&sDisplayContext, pui8SplashLogo, 95 - ui8X, 0); } // // Leave the logo on the screen for a long duration. Monitor the // buttons so that if the user presses the select button, the logo // display is terminated and the application starts immediately. // while(g_ui32TickCount < 400) { if(ButtonsPoll(0, 0) & SELECT_BUTTON) { break; } } // // Extended splash sequence // if(ButtonsPoll(0, 0) & UP_BUTTON) { for(ui8X = 0; ui8X < 96; ui8X += 4) { GrImageDraw(&sDisplayContext, g_ppui8Image_Splash[(ui8X / 4) & 3], (int32_t)ui8X - 96L, 0); GrImageDraw(&sDisplayContext, pui8SplashLogo, ui8X, 0); MAP_SysCtlDelay(ui32SysClock / 12); } MAP_SysCtlDelay(ui32SysClock / 3); pui8SplashLogo = g_ppui8Image_Splash[4]; GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, 0); MAP_SysCtlDelay(ui32SysClock / 12); } // // Draw the initial menu into the offscreen buffer. // SlideMenuDraw(&g_sMenuWidget, &sBufferContext, 0); // // Now, draw both the TI logo splash screen (from above) and the initial // menu on the screen at the same time, moving the coordinates so that // the logo "slides" off the display and the menu "slides" onto the // display. // for(ui8Y = 0; ui8Y < 64; ui8Y++) { GrImageDraw(&sDisplayContext, pui8SplashLogo, 0, -ui8Y); GrImageDraw(&sDisplayContext, g_pui8OffscreenBufA, 0, 63 - ui8Y); } } // // Add the menu widget to the widget tree and send an initial paint // request. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sMenuWidget); WidgetPaint(WIDGET_ROOT); // // Set the focus handle to the menu widget. Any button events will be // sent to this widget // g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget; // // Forever loop to run the application // while(1) { // // Each time the timer tick occurs, process any button events. // if(g_ui32TickCount != ui32LastTickCount) { // // Remember last tick count // ui32LastTickCount = g_ui32TickCount; // // Read the debounced state of the buttons. // ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0); // // Pass any button presses through to the widget message // processing mechanism. The widget that has the button event // focus (probably the menu widget) will catch these button events. // if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_SELECT); } if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_UP); } if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN); } if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); } if(BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT); } } // // Tell the OTG library code how much time has passed in milliseconds // since the last call. // USBOTGMain(GetTickms()); // // Call functions as needed to keep the host or device mode running. // if(g_iCurrentUSBMode == eUSBModeDevice) { USBSerialRun(); } else if(g_iCurrentUSBMode == eUSBModeHost) { USBStickRun(); } // // If in the logging state, then call the logger run function. This // keeps the data acquisition running. // if((g_iLoggerState == eSTATE_LOGGING) || (g_iLoggerState == eSTATE_VIEWING)) { if(AcquireRun() && g_sConfigState.ui32SleepLogging) { // // If sleep logging is enabled, then at this point we have // stored the first data item, now save the state and start // hibernation. Wait for the power to be cut. // SetSavedState(&g_sConfigState); HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); HibernateRequest(); for(;;) { } } // // If viewing instead of logging then request a repaint to keep // the viewing window updated. // if(g_iLoggerState == eSTATE_VIEWING) { WidgetPaint(WIDGET_ROOT); } } // // If in the saving state, then save data from flash storage to // USB stick. // if(g_iLoggerState == eSTATE_SAVING) { // // Save data from flash to USB // FlashStoreSave(); // // Return to idle state // g_iLoggerState = eSTATE_IDLE; } // // If in the erasing state, then erase the data stored in flash. // if(g_iLoggerState == eSTATE_ERASING) { // // Save data from flash to USB // FlashStoreErase(); // // Return to idle state // g_iLoggerState = eSTATE_IDLE; } // // If in the flash reporting state, then show the report of the amount // of used and free flash memory. // if(g_iLoggerState == eSTATE_FREEFLASH) { // // Report free flash space // FlashStoreReport(); // // Return to idle state // g_iLoggerState = eSTATE_IDLE; } // // If we are exiting the clock setting widget, that means that control // needs to be given back to the menu system. // if(g_iLoggerState == eSTATE_CLOCKEXIT) { // // Give the button event focus back to the menu system // g_ui32KeyFocusWidgetHandle = (uint32_t)&g_sMenuWidget; // // Send a button event to the menu widget that means the left // key was pressed. This signals the menu widget to deactivate // the current child widget (which was the clock setting wigdet). // This will cause the menu widget to slide the clock set widget // off the screen and resume control of the display. // SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); g_iLoggerState = eSTATE_IDLE; } // // Process any new messages that are in the widget queue. This keeps // the user interface running. // WidgetMessageQueueProcess(); } }
//***************************************************************************** // // This example encrypts a block of payload using AES128 in CCM mode. It // does the encryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32CipherText[16], pui32Tag[4], ui32Errors, ui32Idx; uint32_t ui32PayloadLength, ui32TagLength; uint32_t ui32NonceLength, ui32AuthDataLength; uint32_t *pui32Nonce, *pui32AuthData, ui32SysClock; uint32_t *pui32Key, *pui32Payload, *pui32ExpCipherText; uint8_t ui8Vector; uint8_t *pui8ExpTag, *pui8Tag; tContext sContext; // // 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(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "aes128-ccm-encrypt"); // // Show some instructions on the display // GrContextFontSet(&sContext, g_psFontCm20); GrStringDrawCentered(&sContext, "Connect a terminal to", -1, GrContextDpyWidthGet(&sContext) / 2, 60, false); GrStringDrawCentered(&sContext, "UART0 (115200,N,8,1)", -1, GrContextDpyWidthGet(&sContext) / 2, 80, false); GrStringDrawCentered(&sContext, "for more information.", -1, GrContextDpyWidthGet(&sContext) / 2, 100, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } pui8Tag = (uint8_t *)pui32Tag; // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Configure the system clock to run off the internal 16MHz oscillator. // ROM_SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_OSC, 16000000); // // Enable AES interrupts. // ROM_IntEnable(INT_AES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting AES128 CCM encryption demo.\n"); GrStringDrawCentered(&sContext, "Starting demo...", -1, GrContextDpyWidthGet(&sContext) / 2, 140, false); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and AES modules. // if(!AESInit()) { UARTprintf("Initialization of the AES module failed.\n"); ui32Errors |= 0x00000001; } // // Loop through all the given vectors. // for(ui8Vector = 0; (ui8Vector < (sizeof(g_psAESCCMTestVectors) / sizeof(g_psAESCCMTestVectors[0]))) && (ui32Errors == 0); ui8Vector++) { UARTprintf("Starting vector #%d\n", ui8Vector); // // Get the current vector's data members. // pui32Key = g_psAESCCMTestVectors[ui8Vector].pui32Key; pui32Payload = g_psAESCCMTestVectors[ui8Vector].pui32Payload; ui32PayloadLength = g_psAESCCMTestVectors[ui8Vector].ui32PayloadLength; pui32AuthData = g_psAESCCMTestVectors[ui8Vector].pui32AuthData; ui32AuthDataLength = g_psAESCCMTestVectors[ui8Vector].ui32AuthDataLength; pui32ExpCipherText = g_psAESCCMTestVectors[ui8Vector].pui32CipherText; pui8ExpTag = (uint8_t *)g_psAESCCMTestVectors[ui8Vector].pui32Tag; ui32TagLength = g_psAESCCMTestVectors[ui8Vector].ui32TagLength; pui32Nonce = g_psAESCCMTestVectors[ui8Vector].pui32Nonce; ui32NonceLength = g_psAESCCMTestVectors[ui8Vector].ui32NonceLength; // // Perform the encryption without uDMA. // UARTprintf("Performing encryption without uDMA.\n"); AES128CCMEncrypt(pui32Key, pui32Payload, pui32CipherText, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32CipherText[ui32Idx] != pui32ExpCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < ui32TagLength; ui32Idx++) { if(pui8Tag[ui32Idx] != pui8ExpTag[ui32Idx]) { UARTprintf("Tag mismatch on byte %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui8ExpTag[ui32Idx], pui8Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Perform the encryption with uDMA. // UARTprintf("Performing encryption with uDMA.\n"); AES128CCMEncrypt(pui32Key, pui32Payload, pui32CipherText, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32CipherText[ui32Idx] != pui32ExpCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < ui32TagLength; ui32Idx++) { if(pui8Tag[ui32Idx] != pui8ExpTag[ui32Idx]) { UARTprintf("Tag mismatch on byte %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui8ExpTag[ui32Idx], pui8Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); GrStringDrawCentered(&sContext, "Demo failed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } else { UARTprintf("Demo completed successfully.\n"); GrStringDrawCentered(&sContext, "Demo passed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } while(1) { } }
//***************************************************************************** // //! Draws a rectangular push button. //! //! \param psWidget is a pointer to the push button widget to be drawn. //! //! This function draws a rectangular push button on the display. This is //! called in response to a \b #WIDGET_MSG_PAINT message. //! //! \return None. // //***************************************************************************** static void RectangularButtonPaint(tWidget *psWidget) { const uint8_t *pui8Image; tPushButtonWidget *pPush; tContext sCtx; int32_t i32X, i32Y; // // Check the arguments. // ASSERT(psWidget); // // Convert the generic widget pointer into a push button widget pointer. // pPush = (tPushButtonWidget *)psWidget; // // Initialize a drawing context. // GrContextInit(&sCtx, psWidget->psDisplay); // // Initialize the clipping region based on the extents of this rectangular // push button. // GrContextClipRegionSet(&sCtx, &(psWidget->sPosition)); // // See if the push button fill style is selected. // if(pPush->ui32Style & PB_STYLE_FILL) { // // Fill the push button with the fill color. // GrContextForegroundSet(&sCtx, ((pPush->ui32Style & PB_STYLE_PRESSED) ? pPush->ui32PressFillColor : pPush->ui32FillColor)); GrRectFill(&sCtx, &(psWidget->sPosition)); } // // See if the push button outline style is selected. // if(pPush->ui32Style & PB_STYLE_OUTLINE) { // // Outline the push button with the outline color. // GrContextForegroundSet(&sCtx, pPush->ui32OutlineColor); GrRectDraw(&sCtx, &(psWidget->sPosition)); } // // See if the push button text or image style is selected. // if(pPush->ui32Style & (PB_STYLE_TEXT | PB_STYLE_IMG)) { // // Compute the center of the push button. // i32X = (psWidget->sPosition.i16XMin + ((psWidget->sPosition.i16XMax - psWidget->sPosition.i16XMin + 1) / 2)); i32Y = (psWidget->sPosition.i16YMin + ((psWidget->sPosition.i16YMax - psWidget->sPosition.i16YMin + 1) / 2)); // // If the push button outline style is selected then shrink the // clipping region by one pixel on each side so that the outline is not // overwritten by the text or image. // if(pPush->ui32Style & PB_STYLE_OUTLINE) { sCtx.sClipRegion.i16XMin++; sCtx.sClipRegion.i16YMin++; sCtx.sClipRegion.i16XMax--; sCtx.sClipRegion.i16YMax--; } // // See if the push button image style is selected. // if(pPush->ui32Style & PB_STYLE_IMG) { // // Set the foreground and background colors to use for 1 BPP // images. // GrContextForegroundSet(&sCtx, pPush->ui32TextColor); GrContextBackgroundSet(&sCtx, ((pPush->ui32Style & PB_STYLE_PRESSED) ? pPush->ui32PressFillColor : pPush->ui32FillColor)); // // Get the image to be drawn. // pui8Image = (((pPush->ui32Style & PB_STYLE_PRESSED) && pPush->pui8PressImage) ? pPush->pui8PressImage : pPush->pui8Image); // // Draw the image centered in the push button. // GrImageDraw(&sCtx, pui8Image, i32X - (GrImageWidthGet(pui8Image) / 2), i32Y - (GrImageHeightGet(pui8Image) / 2)); } // // See if the push button text style is selected. // if(pPush->ui32Style & PB_STYLE_TEXT) { // // Draw the text centered in the middle of the push button. // GrContextFontSet(&sCtx, pPush->psFont); GrContextForegroundSet(&sCtx, pPush->ui32TextColor); GrContextBackgroundSet(&sCtx, ((pPush->ui32Style & PB_STYLE_PRESSED) ? pPush->ui32PressFillColor : pPush->ui32FillColor)); GrStringDrawCentered(&sCtx, pPush->pcText, -1, i32X, i32Y, pPush->ui32Style & PB_STYLE_TEXT_OPAQUE); } } }
//***************************************************************************** // // Initialize SafeRTOS and start the initial set of tasks. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // Set the clocking to run at 80 MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Initialize the device pinout appropriately for this board. // PinoutSet(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 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_pFontCm20); GrStringDrawCentered(&sContext, "safertos-demo", -1, GrContextDpyWidthGet(&sContext) / 2, 10, 0); // // Set the location and size of the system stack. // g_sSafeRTOSPortInit.pulSystemStackLocation = (unsigned portLONG *)(*(unsigned long *)0); g_sSafeRTOSPortInit.ulSystemStackSizeBytes = 128 * 4; // // Set the location of the vector table. // g_sSafeRTOSPortInit.pulVectorTableBase = (unsigned portLONG *)HWREG(NVIC_VTABLE); // // Initialize the SafeRTOS kernel. // vTaskInitializeScheduler((signed portCHAR *)g_pulIdleTaskStack, sizeof(g_pulIdleTaskStack), 0, &g_sSafeRTOSPortInit); // // Create the display task. // if(DisplayTaskInit() != 0) { GrContextForegroundSet(&sContext, ClrRed); GrStringDrawCentered(&sContext, "Failed to create display task!", -1, GrContextDpyWidthGet(&sContext) / 2, (((GrContextDpyHeightGet(&sContext) - 24) / 2) + 24), 0); while(1) { } } // // Create the spider task. // if(SpiderTaskInit() != 0) { GrContextForegroundSet(&sContext, ClrRed); GrStringDrawCentered(&sContext, "Failed to create spider task!", -1, GrContextDpyWidthGet(&sContext) / 2, (((GrContextDpyHeightGet(&sContext) - 24) / 2) + 24), 0); while(1) { } } // // Create the LED task. // if(LEDTaskInit() != 0) { GrContextForegroundSet(&sContext, ClrRed); GrStringDrawCentered(&sContext, "Failed to create LED task!", -1, GrContextDpyWidthGet(&sContext) / 2, (((GrContextDpyHeightGet(&sContext) - 24) / 2) + 24), 0); while(1) { } } // // Create the lwIP tasks. // if(lwIPTaskInit() != 0) { GrContextForegroundSet(&sContext, ClrRed); GrStringDrawCentered(&sContext, "Failed to create lwIP tasks!", -1, GrContextDpyWidthGet(&sContext) / 2, (((GrContextDpyHeightGet(&sContext) - 24) / 2) + 24), 0); while(1) { } } // // Start the scheduler. This should not return. // xTaskStartScheduler(pdTRUE); // // In case the scheduler returns for some reason, print an error and loop // forever. // GrContextForegroundSet(&sContext, ClrRed); GrStringDrawCentered(&sContext, "Failed to start scheduler!", -1, GrContextDpyWidthGet(&sContext) / 2, (((GrContextDpyHeightGet(&sContext) - 24) / 2) + 24), 0); while(1) { } }
//***************************************************************************** // // Performs calibration of the touch screen. // //***************************************************************************** int main(void) { long lIdx, lX1, lY1, lX2, lY2, lCount; long pplPoints[3][4]; char pcBuffer[32]; tRectangle sRect; // // Enable the PLL and clock the part at 50 MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the device pinout appropriately for this board. // PinoutSet(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKitronix320x240x16_SSD2119); // // 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) - 1; sRect.sYMax = 23; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_pFontCm20); GrStringDrawCentered(&g_sContext, "calibrate", -1, GrContextDpyWidthGet(&g_sContext) / 2, 11, 0); // // Print the instructions across the middle of the screen in white with a // 20 point small-caps font. // GrContextForegroundSet(&g_sContext, ClrWhite); GrContextFontSet(&g_sContext, g_pFontCmsc20); GrStringDraw(&g_sContext, "Touch the box", -1, 0, (GrContextDpyHeightGet(&g_sContext) / 2) - 10, 0); // // Set the points used for calibration based on the size of the screen. // pplPoints[0][0] = GrContextDpyWidthGet(&g_sContext) / 10; pplPoints[0][1] = (GrContextDpyHeightGet(&g_sContext) * 2)/ 10; pplPoints[1][0] = GrContextDpyWidthGet(&g_sContext) / 2; pplPoints[1][1] = (GrContextDpyHeightGet(&g_sContext) * 9) / 10; pplPoints[2][0] = (GrContextDpyWidthGet(&g_sContext) * 9) / 10; pplPoints[2][1] = GrContextDpyHeightGet(&g_sContext) / 2; // // Initialize the touch screen driver. // TouchScreenInit(); // // Loop through the calibration points. // for(lIdx = 0; lIdx < 3; lIdx++) { // // Fill a white box around the calibration point. // GrContextForegroundSet(&g_sContext, ClrWhite); sRect.sXMin = pplPoints[lIdx][0] - 5; sRect.sYMin = pplPoints[lIdx][1] - 5; sRect.sXMax = pplPoints[lIdx][0] + 5; sRect.sYMax = pplPoints[lIdx][1] + 5; GrRectFill(&g_sContext, &sRect); // // Flush any cached drawing operations. // GrFlush(&g_sContext); // // Initialize the raw sample accumulators and the sample count. // lX1 = 0; lY1 = 0; lCount = -5; // // Loop forever. This loop is explicitly broken out of when the pen is // lifted. // while(1) { // // Grab the current raw touch screen position. // lX2 = g_sTouchX; lY2 = g_sTouchY; // // See if the pen is up or down. // if((lX2 < g_sTouchMin) || (lY2 < g_sTouchMin)) { // // The pen is up, so see if any samples have been accumulated. // if(lCount > 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. // lX1 = 0; lY1 = 0; lCount = -5; // // Grab the next sample. // continue; } // // Increment the count of samples. // lCount++; // // If the sample count is greater than zero, add this sample to the // accumulators. // if(lCount > 0) { lX1 += lX2; lY1 += lY2; } } // // Save the averaged raw ADC reading for this calibration point. // pplPoints[lIdx][2] = lX1 / lCount; pplPoints[lIdx][3] = lY1 / lCount; // // Erase the box around this calibration point. // GrContextForegroundSet(&g_sContext, ClrBlack); GrRectFill(&g_sContext, &sRect); } // // Clear the screen. // sRect.sXMin = 0; sRect.sYMin = 24; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = GrContextDpyHeightGet(&g_sContext) - 1; GrRectFill(&g_sContext, &sRect); // // Indicate that the calibration data is being displayed. // GrContextForegroundSet(&g_sContext, ClrWhite); GrStringDraw(&g_sContext, "Calibration data:", -1, 0, 40, 0); // // Compute and display the M0 calibration value. // usprintf(pcBuffer, "M0 = %d", (((pplPoints[0][0] - pplPoints[2][0]) * (pplPoints[1][3] - pplPoints[2][3])) - ((pplPoints[1][0] - pplPoints[2][0]) * (pplPoints[0][3] - pplPoints[2][3])))); GrStringDraw(&g_sContext, pcBuffer, -1, 0, 80, 0); // // Compute and display the M1 calibration value. // usprintf(pcBuffer, "M1 = %d", (((pplPoints[0][2] - pplPoints[2][2]) * (pplPoints[1][0] - pplPoints[2][0])) - ((pplPoints[0][0] - pplPoints[2][0]) * (pplPoints[1][2] - pplPoints[2][2])))); GrStringDraw(&g_sContext, pcBuffer, -1, 0, 100, 0); // // Compute and display the M2 calibration value. // usprintf(pcBuffer, "M2 = %d", ((((pplPoints[2][2] * pplPoints[1][0]) - (pplPoints[1][2] * pplPoints[2][0])) * pplPoints[0][3]) + (((pplPoints[0][2] * pplPoints[2][0]) - (pplPoints[2][2] * pplPoints[0][0])) * pplPoints[1][3]) + (((pplPoints[1][2] * pplPoints[0][0]) - (pplPoints[0][2] * pplPoints[1][0])) * pplPoints[2][3]))); GrStringDraw(&g_sContext, pcBuffer, -1, 0, 120, 0); // // Compute and display the M3 calibration value. // usprintf(pcBuffer, "M3 = %d", (((pplPoints[0][1] - pplPoints[2][1]) * (pplPoints[1][3] - pplPoints[2][3])) - ((pplPoints[1][1] - pplPoints[2][1]) * (pplPoints[0][3] - pplPoints[2][3])))); GrStringDraw(&g_sContext, pcBuffer, -1, 0, 140, 0); // // Compute and display the M4 calibration value. // usprintf(pcBuffer, "M4 = %d", (((pplPoints[0][2] - pplPoints[2][2]) * (pplPoints[1][1] - pplPoints[2][1])) - ((pplPoints[0][1] - pplPoints[2][1]) * (pplPoints[1][2] - pplPoints[2][2])))); GrStringDraw(&g_sContext, pcBuffer, -1, 0, 160, 0); // // Compute and display the M5 calibration value. // usprintf(pcBuffer, "M5 = %d", ((((pplPoints[2][2] * pplPoints[1][1]) - (pplPoints[1][2] * pplPoints[2][1])) * pplPoints[0][3]) + (((pplPoints[0][2] * pplPoints[2][1]) - (pplPoints[2][2] * pplPoints[0][1])) * pplPoints[1][3]) + (((pplPoints[1][2] * pplPoints[0][1]) - (pplPoints[0][2] * pplPoints[1][1])) * pplPoints[2][3]))); GrStringDraw(&g_sContext, pcBuffer, -1, 0, 180, 0); // // Compute and display the M6 calibration value. // usprintf(pcBuffer, "M6 = %d", (((pplPoints[0][2] - pplPoints[2][2]) * (pplPoints[1][3] - pplPoints[2][3])) - ((pplPoints[1][2] - pplPoints[2][2]) * (pplPoints[0][3] - pplPoints[2][3])))); GrStringDraw(&g_sContext, pcBuffer, -1, 0, 200, 0); // // Flush any cached drawing operations. // GrFlush(&g_sContext); // // The calibration is complete. Sit around and wait for a reset. // while(1) { } }
//***************************************************************************** // // A simple demonstration of the features of the Stellaris Graphics Library. // //***************************************************************************** int main(void) { tContext sContext; tRectangle sRect; // // If running on Rev A2 silicon, turn the LDO voltage up to 2.75V. This is // a workaround to allow the PLL to operate reliably. // if(REVISION_IS_A2) { SysCtlLDOSet(SYSCTL_LDO_2_75V); } // // Set the clocking to run from the PLL. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Turn on the backlight. // Kitronix320x240x16_SSD2119BacklightOn(255); // // Set graphics library text rendering defaults. // GrLibInit(&GRLIB_INIT_STRUCT); // // Set the string table and the default language. // GrStringTableSet(STRING_TABLE); // // Set the default language. // ChangeLanguage(GrLangEnUS); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKitronix320x240x16_SSD2119); // // Fill the top 26 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&sContext) - 1; sRect.sYMax = 25; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&sContext, ClrWhite); GrRectDraw(&sContext, &sRect); // // Load the static strings from the string table. These strings are // independent of the language in use but we store them in the string // table nonetheless since (a) we may be using codepage remapping in // which case it would be difficult to hardcode them into the app source // anyway (ASCII or ISO8859-1 text would not render properly with the // remapped custom font) and (b) even if we're not using codepage remapping, // we may have generated a custom font from the string table output and // we want to make sure that all glyphs required by the application are // present in that font. If we hardcode some text in the application // source and don't put it in the string table, we run the risk of having // characters missing in the font. // GrStringGet(STR_ENGLISH, g_pcEnglish, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_DEUTSCH, g_pcDeutsch, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ESPANOL, g_pcEspanol, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_ITALIANO, g_pcItaliano, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_CHINESE, g_pcChinese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_KOREAN, g_pcKorean, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_JAPANESE, g_pcJapanese, MAX_LANGUAGE_NAME_LEN); GrStringGet(STR_PLUS, g_pcPlus, 2); GrStringGet(STR_MINUS, g_pcMinus, 2); // // Put the application name in the middle of the banner. // GrStringGet(STR_APPNAME, g_pcBuffer, SCOMP_MAX_STRLEN); GrContextFontSet(&sContext, FONT_20PT); GrStringDrawCentered(&sContext, g_pcBuffer, -1, GrContextDpyWidthGet(&sContext) / 2, 10, 0); // // Initialize the sound driver. // SoundInit(); // // Initialize the touch screen driver and have it route its messages to the // widget tree. // TouchScreenInit(); TouchScreenCallbackSet(WidgetPointerMessage); // // Add the title block and the previous and next buttons to the widget // tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sPrevious); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sTitle); WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sNext); // // Add the first panel to the widget tree. // g_ulPanel = 0; WidgetAdd(WIDGET_ROOT, (tWidget *)g_psPanels); // // Set the string for the title. // CanvasTextSet(&g_sTitle, g_pcTitle); // // Initialize the pointer to the button text. // PushButtonTextSet(&g_sFirmwareUpdateBtn, g_pcUpdateButton); // // Issue the initial paint request to the widgets. // WidgetPaint(WIDGET_ROOT); // // Loop forever unless we receive a signal that a firmware update has been // requested. // while(!g_bFirmwareUpdate) { // // Process any messages in the widget message queue. // WidgetMessageQueueProcess(); } // // If we drop out, a firmware update request has been made. We call // WidgetMessageQueueProcess once more to ensure that any final messages // are processed then jump into the bootloader. // WidgetMessageQueueProcess(); // // Wait a while for the last keyboard click sound to finish. This is about // 500mS since the delay loop is 3 cycles long. // SysCtlDelay(SysCtlClockGet() / 6); // // Pass control to the bootloader. // JumpToBootLoader(); // // The boot loader should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { uint8_t ui8ButtonsChanged, ui8Buttons; uint32_t ui32SysClock; // // Set the clocking to run from the PLL at 120MHz // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Configure the buttons driver. // ButtonsInit(ALL_BUTTONS); // // 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-dev-gamepad"); // // Default status is disconnected. // DisplayStatus(&g_sContext, "Disconnected"); // // Not configured initially. // g_iGamepadState = eStateNotConfigured; // // Initialize the USB stack for device mode. // USBStackModeSet(0, eUSBModeDevice, 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. // g_sReport.ui8Buttons = 0; g_sReport.i8XPos = 0; g_sReport.i8YPos = 0; // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); // // Set the touch screen event handler. // TouchScreenCallbackSet(TSHandler); // // 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) { // // See if the buttons updated. // ButtonsPoll(&ui8ButtonsChanged, &ui8Buttons); g_sReport.ui8Buttons = 0; // // Set button 1 if up button pressed. // if(ui8Buttons & UP_BUTTON) { g_sReport.ui8Buttons |= 0x01; } // // Set button 2 if down button pressed. // if(ui8Buttons & DOWN_BUTTON) { g_sReport.ui8Buttons |= 0x02; } // // Set button 3 if select button pressed. // if(ui8Buttons & SELECT_BUTTON) { g_sReport.ui8Buttons |= 0x04; } if(ui8ButtonsChanged) { g_bUpdate = true; } // // Send the report if there was an update. // if(g_bUpdate) { g_bUpdate = false; USBDHIDGamepadSendReport(&g_sGamepadDevice, &g_sReport, sizeof(g_sReport)); // // Now sending data but protect this from an interrupt since // it can change in interrupt context as well. // IntMasterDisable(); g_iGamepadState = eStateSending; IntMasterEnable(); } } } }
int_t main(void) { error_t error; MacAddr macAddr; Ipv4Addr ipv4Addr; Ipv6Addr ipv6Addr; NetInterface *interface; OsTask *task; //Initialize kernel osInitKernel(); //Configure debug UART debugInit(115200); //Start-up message TRACE_INFO("\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n"); TRACE_INFO("**********************************\r\n"); TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n"); TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__); TRACE_INFO("Target: TM4C129X\r\n"); TRACE_INFO("\r\n"); //Configure I/Os PinoutSet(); //Initialize LCD display Kentec320x240x16_SSD2119Init(SystemCoreClock); //Initialize drawing context GrContextInit(&grContext, &g_sKentec320x240x16_SSD2119); GrContextForegroundSet(&grContext, ClrWhite); //GrContextFontSet(&grContext, g_psFontCmss18b); GrContextFontSet(&grContext, g_psFontFixed6x8); //Welcome message lcdSetCursor(0, 0); printf("FTP Client Demo"); //TCP/IP stack initialization error = tcpIpStackInit(); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n"); } //Configure the first Ethernet interface interface = &netInterface[0]; //Set interface name tcpIpStackSetInterfaceName(interface, "eth0"); //Set host name tcpIpStackSetHostname(interface, "FTPClientDemo"); //Select the relevant network adapter tcpIpStackSetDriver(interface, &tm4c129xEthDriver); //Set host MAC address macStringToAddr(APP_MAC_ADDR, &macAddr); tcpIpStackSetMacAddr(interface, &macAddr); //Initialize network interface error = tcpIpStackConfigInterface(interface); //Any error to report? if(error) { //Debug message TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name); } #if (IPV4_SUPPORT == ENABLED) #if (APP_USE_DHCP == ENABLED) //Get default settings dhcpClientGetDefaultSettings(&dhcpClientSettings); //Set the network interface to be configured by DHCP dhcpClientSettings.interface = interface; //Disable rapid commit option dhcpClientSettings.rapidCommit = FALSE; //DHCP client initialization error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings); //Failed to initialize DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to initialize DHCP client!\r\n"); } //Start DHCP client error = dhcpClientStart(&dhcpClientContext); //Failed to start DHCP client? if(error) { //Debug message TRACE_ERROR("Failed to start DHCP client!\r\n"); } #else //Set IPv4 host address ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr); ipv4SetHostAddr(interface, ipv4Addr); //Set subnet mask ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr); ipv4SetSubnetMask(interface, ipv4Addr); //Set default gateway ipv4StringToAddr(APP_IPV4_DEFAULT_GATEWAY, &ipv4Addr); ipv4SetDefaultGateway(interface, ipv4Addr); //Set primary and secondary DNS servers ipv4StringToAddr(APP_IPV4_PRIMARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 0, ipv4Addr); ipv4StringToAddr(APP_IPV4_SECONDARY_DNS, &ipv4Addr); ipv4SetDnsServer(interface, 1, ipv4Addr); #endif #endif #if (IPV6_SUPPORT == ENABLED) #if (APP_USE_SLAAC == ENABLED) //Get default settings slaacGetDefaultSettings(&slaacSettings); //Set the network interface to be configured slaacSettings.interface = interface; //SLAAC initialization error = slaacInit(&slaacContext, &slaacSettings); //Failed to initialize SLAAC? if(error) { //Debug message TRACE_ERROR("Failed to initialize SLAAC!\r\n"); } //Start IPv6 address autoconfiguration process error = slaacStart(&slaacContext); //Failed to start SLAAC process? if(error) { //Debug message TRACE_ERROR("Failed to start SLAAC!\r\n"); } #else //Set link-local address ipv6StringToAddr(APP_IPV6_LINK_LOCAL_ADDR, &ipv6Addr); ipv6SetLinkLocalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set IPv6 prefix ipv6StringToAddr(APP_IPV6_PREFIX, &ipv6Addr); ipv6SetPrefix(interface, &ipv6Addr, APP_IPV6_PREFIX_LENGTH); //Set global address ipv6StringToAddr(APP_IPV6_GLOBAL_ADDR, &ipv6Addr); ipv6SetGlobalAddr(interface, &ipv6Addr, IPV6_ADDR_STATE_VALID); //Set router ipv6StringToAddr(APP_IPV6_ROUTER, &ipv6Addr); ipv6SetRouter(interface, &ipv6Addr); //Set primary and secondary DNS servers ipv6StringToAddr(APP_IPV6_PRIMARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 0, &ipv6Addr); ipv6StringToAddr(APP_IPV6_SECONDARY_DNS, &ipv6Addr); ipv6SetDnsServer(interface, 1, &ipv6Addr); #endif #endif //Create user task task = osCreateTask("User Task", userTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Create a task to blink the LED task = osCreateTask("Blink", blinkTask, NULL, 500, 1); //Failed to create the task? if(task == OS_INVALID_HANDLE) { //Debug message TRACE_ERROR("Failed to create task!\r\n"); } //Start the execution of tasks osStartKernel(); //This function should never return return 0; }
//***************************************************************************** // // Demonstrate the use of the USB stick update example. // //***************************************************************************** int main(void) { uint32_t ui32Count; uint32_t ui32SysClock; tContext i16Context; tRectangle i16Rect; // // 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(&i16Context, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&i16Context, "usb-stick-demo"); // // Fill the top 24 rows of the screen with blue to create the banner. // i16Rect.i16XMin = 0; i16Rect.i16YMin = 0; i16Rect.i16XMax = GrContextDpyWidthGet(&i16Context) - 1; i16Rect.i16YMax = 23; GrContextForegroundSet(&i16Context, ClrDarkBlue); GrRectFill(&i16Context, &i16Rect); // // Put a white box around the banner. // GrContextForegroundSet(&i16Context, ClrWhite); GrRectDraw(&i16Context, &i16Rect); // // Put the application name in the middle of the banner. // GrContextFontSet(&i16Context, g_psFontCm20); GrStringDrawCentered(&i16Context, "usb-stick-demo", -1, GrContextDpyWidthGet(&i16Context) / 2, 10, 0); // // Indicate what is happening. // GrContextFontSet(&i16Context, g_psFontCm24); GrStringDrawCentered(&i16Context, "Press the SEL button to", -1, GrContextDpyWidthGet(&i16Context) / 2, 60, 0); GrStringDrawCentered(&i16Context, "start the USB stick updater", -1, GrContextDpyWidthGet(&i16Context) / 2, 84, 0); // // Flush any cached drawing operations. // GrFlush(&i16Context); // // Wait for the pullup to take effect or the next loop will exist too soon. // ROM_SysCtlDelay(1000); // // Wait until the select button has been pressed for ~40ms (in order to // debounce the press). // ui32Count = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTP_BASE, GPIO_PIN_1) == 0) { // // Increment the count since the button is pressed. // ui32Count++; // // If the count has reached 4, then the button has been debounced // as being pressed. // if(ui32Count == 4) { break; } } else { // // Reset the count since the button is not pressed. // ui32Count = 0; } // // Delay for approximately 10ms. // ROM_SysCtlDelay(120000000 / (3 * 100)); } // // Wait until the select button has been released for ~40ms (in order to // debounce the release). // ui32Count = 0; while(1) { // // See if the button is pressed. // if(ROM_GPIOPinRead(GPIO_PORTP_BASE, GPIO_PIN_1) != 0) { // // Increment the count since the button is released. // ui32Count++; // // If the count has reached 4, then the button has been debounced // as being released. // if(ui32Count == 4) { break; } } else { // // Reset the count since the button is pressed. // ui32Count = 0; } // // Delay for approximately 10ms. // ROM_SysCtlDelay(120000000 / (3 * 100)); } // // Indicate that the updater is being called. // GrStringDrawCentered(&i16Context, "The USB stick updater is now", -1, GrContextDpyWidthGet(&i16Context) / 2, 140, 0); GrStringDrawCentered(&i16Context, "waiting for a USB stick", -1, GrContextDpyWidthGet(&i16Context) / 2, 164, 0); // // Flush any cached drawing operations. // GrFlush(&i16Context); // // Call the updater so that it will search for an update on a memory stick. // (*((void (*)(void))(*(uint32_t *)0x2c)))(); // // The updater should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
//***************************************************************************** // // Capture one sequence of DEVCTL register values during a session request. // //***************************************************************************** int main(void) { tRectangle sRect; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the pinout appropriately for this board. // PinoutSet(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKitronix320x240x16_SSD2119); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = 14; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_pFontFixed6x8); GrStringDrawCentered(&g_sContext, "OTG Example", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); #ifdef DEBUG // // Configure the relevant pins such that UART0 owns them. // ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Open the UART for I/O // UARTStdioInit(0); #endif // // Determine the number of SysCtlDelay loops required to delay 1mS. // g_ulClockMS = ROM_SysCtlClockGet() / (3 * 1000); // // Configure the required pins for USB operation. // ROM_GPIOPinTypeUSBDigital(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_GPIOPinTypeUSBDigital(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Initialize the USB stack mode and pass in a mode callback. // USBStackModeSet(0, USB_MODE_OTG, ModeCallback); // // Initialize the host stack. // HostInit(); // // Initialize the device stack. // DeviceInit(); // // Initialize the USB controller for dual mode operation with a 2ms polling // rate. // USBOTGModeInit(0, 2000, g_pHCDPool, HCD_MEMORY_SIZE); // // Set the new state so that the screen updates on the first // pass. // g_ulNewState = 1; // // Loop forever. // while(1) { // // Tell the OTG library code how much time has passed in milliseconds // since the last call. // USBOTGMain(GetTickms()); // // Handle deferred state change. // if(g_ulNewState) { g_ulNewState =0; // // Update the status area of the screen. // ClearMainWindow(); // // Update the status bar with the new mode. // switch(g_eCurrentUSBMode) { case USB_MODE_HOST: { UpdateStatus("Host Mode", 0, true); break; } case USB_MODE_DEVICE: { UpdateStatus("Device Mode", 0, true); break; } case USB_MODE_NONE: { UpdateStatus("Idle Mode", 0, true); break; } default: { break; } } } if(g_eCurrentUSBMode == USB_MODE_DEVICE) { DeviceMain(); } else if(g_eCurrentUSBMode == USB_MODE_HOST) { HostMain(); } } }
void main(void) { tRectangle myRectangle1 = { 5, 10, 60, 50}; tRectangle myRectangle2 = { 30, 20, 100, 60}; tRectangle myRectangle3 = { 0, 0, 101, 63}; // Stop WDT WDT_A_hold(WDT_A_BASE); // Basic GPIO initialization Board_init(); Clock_init(); // Set up LCD Dogs102x64_UC1701Init(); GrContextInit(&g_sContext, &g_sDogs102x64_UC1701); GrContextForegroundSet(&g_sContext, ClrBlack); GrContextBackgroundSet(&g_sContext, ClrWhite); GrContextFontSet(&g_sContext, &g_sFontFixed6x8); GrClearDisplay(&g_sContext); // Intro Screen GrStringDrawCentered(&g_sContext, "How to use MSP430", AUTO_STRING_LENGTH, 51, 16, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "Graphics Library", AUTO_STRING_LENGTH, 51, 32, TRANSPARENT_TEXT); GrStringDrawCentered(&g_sContext, "Primitives", AUTO_STRING_LENGTH, 51, 48, TRANSPARENT_TEXT); Delay(); GrClearDisplay(&g_sContext); // Draw pixels and lines on the display GrStringDraw(&g_sContext, "Draw Pixels", AUTO_STRING_LENGTH, 20, 0, TRANSPARENT_TEXT); GrStringDraw(&g_sContext, "& Lines", AUTO_STRING_LENGTH, 30, 10, TRANSPARENT_TEXT); GrPixelDraw(&g_sContext, 10, 10); GrPixelDraw(&g_sContext, 10, 12); GrPixelDraw(&g_sContext, 12, 12); GrPixelDraw(&g_sContext, 12, 10); GrLineDraw(&g_sContext, 15, 15, 60, 60); GrLineDraw(&g_sContext, 10, 50, 90, 10); GrLineDraw(&g_sContext, 0, GrContextDpyHeightGet(&g_sContext) - 1, GrContextDpyWidthGet(&g_sContext) - 1, GrContextDpyHeightGet(&g_sContext) - 1); Delay(); GrClearDisplay(&g_sContext); // Draw circles on the display GrStringDrawCentered(&g_sContext, "Draw Circles", AUTO_STRING_LENGTH, 51, 5, TRANSPARENT_TEXT); GrCircleDraw(&g_sContext, 30, 50, 10); GrCircleFill(&g_sContext, 65, 37, 23); Delay(); GrClearDisplay(&g_sContext); // Draw rectangles on the display GrStringDrawCentered(&g_sContext, "Draw Rectangles", AUTO_STRING_LENGTH, 51, 5, TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangle1); GrRectFill(&g_sContext, &myRectangle2); // Text won't be visible on screen due to transparency GrStringDrawCentered(&g_sContext, "Normal Text", AUTO_STRING_LENGTH, 65, 30, TRANSPARENT_TEXT); // Text draws foreground and background for opacity GrStringDrawCentered(&g_sContext, "Opaque Text", AUTO_STRING_LENGTH, 65, 40, OPAQUE_TEXT); GrContextForegroundSet(&g_sContext, ClrWhite); GrContextBackgroundSet(&g_sContext, ClrBlack); // Text draws with inverted color to become visible GrStringDrawCentered(&g_sContext, "Invert Text", AUTO_STRING_LENGTH, 65, 50, TRANSPARENT_TEXT); Delay(); GrClearDisplay(&g_sContext); // Invert the foreground and background colors GrContextForegroundSet(&g_sContext, ClrBlack); GrContextBackgroundSet(&g_sContext, ClrWhite); GrRectFill(&g_sContext, &myRectangle3); GrContextForegroundSet(&g_sContext, ClrWhite); GrContextBackgroundSet(&g_sContext, ClrBlack); GrStringDrawCentered(&g_sContext, "Invert Colors", AUTO_STRING_LENGTH, 51, 5, TRANSPARENT_TEXT); GrRectDraw(&g_sContext, &myRectangle1); GrRectFill(&g_sContext, &myRectangle2); // Text won't be visible on screen due to transparency GrStringDrawCentered(&g_sContext, "Normal Text", AUTO_STRING_LENGTH, 65, 30, TRANSPARENT_TEXT); // Text draws foreground and background for opacity GrStringDrawCentered(&g_sContext, "Opaque Text", AUTO_STRING_LENGTH, 65, 40, OPAQUE_TEXT); GrContextForegroundSet(&g_sContext, ClrBlack); GrContextBackgroundSet(&g_sContext, ClrWhite); // Text draws with inverted color to become visible GrStringDrawCentered(&g_sContext, "Invert Text", AUTO_STRING_LENGTH, 65, 50, TRANSPARENT_TEXT); Delay(); GrContextForegroundSet(&g_sContext, ClrBlack); GrContextBackgroundSet(&g_sContext, ClrWhite); GrClearDisplay(&g_sContext); // Draw Images on the display GrImageDraw(&g_sContext, &LPRocket_96x37_1BPP_UNCOMP, 3, 13); Delay(); GrClearDisplay(&g_sContext); GrImageDraw(&g_sContext, &TI_Logo_69x64_1BPP_UNCOMP, 16, 0); while(1) { } }
//***************************************************************************** // //! Draws a container widget. //! //! \param psWidget is a pointer to the container widget to be drawn. //! //! This function draws a container widget on the display. This is called in //! response to a \b #WIDGET_MSG_PAINT message. //! //! \return None. // //***************************************************************************** static void ContainerPaint(tWidget *psWidget) { tContainerWidget *pContainer; int32_t i32X1, i32X2, i32Y; tContext sCtx; // // Check the arguments. // ASSERT(psWidget); // // Convert the generic widget pointer into a container widget pointer. // pContainer = (tContainerWidget *)psWidget; // // Initialize a drawing context. // GrContextInit(&sCtx, psWidget->psDisplay); // // Initialize the clipping region based on the extents of this container. // GrContextClipRegionSet(&sCtx, &(psWidget->sPosition)); // // See if the container fill style is selected. // if(pContainer->ui32Style & CTR_STYLE_FILL) { // // Fill the container with the fill color. // GrContextForegroundSet(&sCtx, pContainer->ui32FillColor); GrRectFill(&sCtx, &(psWidget->sPosition)); } // // See if the container text style is selected. // if(pContainer->ui32Style & CTR_STYLE_TEXT) { // // Set the font and colors used to draw the container text. // GrContextFontSet(&sCtx, pContainer->psFont); GrContextForegroundSet(&sCtx, pContainer->ui32TextColor); GrContextBackgroundSet(&sCtx, pContainer->ui32FillColor); // // Get the width of the container text. // i32X2 = GrStringWidthGet(&sCtx, pContainer->pcText, -1); // // Determine the position of the text. The position depends on the // the width of the string and if centering is enabled. // if(pContainer->ui32Style & CTR_STYLE_TEXT_CENTER) { i32X1 = (psWidget->sPosition.i16XMin + ((psWidget->sPosition.i16XMax - psWidget->sPosition.i16XMin + 1 - i32X2 - 8) / 2)); } else { i32X1 = psWidget->sPosition.i16XMin + 4; } // // Draw the container text. // GrStringDraw(&sCtx, pContainer->pcText, -1, i32X1 + 4, psWidget->sPosition.i16YMin, pContainer->ui32Style & CTR_STYLE_TEXT_OPAQUE); // // See if the container outline style is selected. // if(pContainer->ui32Style & CTR_STYLE_OUTLINE) { // // Get the position of the right side of the string. // i32X2 = i32X1 + i32X2 + 8; // // Get the position of the vertical center of the text. // i32Y = (psWidget->sPosition.i16YMin + (GrFontBaselineGet(pContainer->psFont) / 2)); // // Set the color to draw the outline. // GrContextForegroundSet(&sCtx, pContainer->ui32OutlineColor); // // Draw the outline around the container widget, leaving a gap // where the text reside across the top of the widget. // GrLineDraw(&sCtx, i32X1, i32Y, psWidget->sPosition.i16XMin, i32Y); GrLineDraw(&sCtx, psWidget->sPosition.i16XMin, i32Y, psWidget->sPosition.i16XMin, psWidget->sPosition.i16YMax); GrLineDraw(&sCtx, psWidget->sPosition.i16XMin, psWidget->sPosition.i16YMax, psWidget->sPosition.i16XMax, psWidget->sPosition.i16YMax); GrLineDraw(&sCtx, psWidget->sPosition.i16XMax, psWidget->sPosition.i16YMax, psWidget->sPosition.i16XMax, i32Y); GrLineDraw(&sCtx, psWidget->sPosition.i16XMax, i32Y, i32X2, i32Y); } } // // Otherwise, see if the container outline style is selected. // else if(pContainer->ui32Style & CTR_STYLE_OUTLINE) { // // Outline the container with the outline color. // GrContextForegroundSet(&sCtx, pContainer->ui32OutlineColor); GrRectDraw(&sCtx, &(psWidget->sPosition)); } }
//***************************************************************************** // //! Draws an image button. //! //! \param psWidget is a pointer to the image button widget to be drawn. //! //! This function draws a rectangular image button on the display. This is //! called in response to a \b #WIDGET_MSG_PAINT message. //! //! \return None. // //***************************************************************************** static void ImageButtonPaint(tWidget *psWidget) { const uint8_t *pui8Image; tImageButtonWidget *psPush; tContext sCtx; int32_t i32X, i32Y; // // Check the arguments. // ASSERT(psWidget); // // Convert the generic widget pointer into a image button widget pointer. // psPush = (tImageButtonWidget *)psWidget; // // Initialize a drawing context. // GrContextInit(&sCtx, psWidget->psDisplay); // // Initialize the clipping region based on the extents of this rectangular // image button. // GrContextClipRegionSet(&sCtx, &(psWidget->sPosition)); // // Compute the center of the image button. // i32X = (psWidget->sPosition.i16XMin + ((psWidget->sPosition.i16XMax - psWidget->sPosition.i16XMin + 1) / 2)); i32Y = (psWidget->sPosition.i16YMin + ((psWidget->sPosition.i16YMax - psWidget->sPosition.i16YMin + 1) / 2)); // // Do we need to fill the widget background with a color? // if(psPush->ui32Style & IB_STYLE_FILL) { // // Yes. Set the appropriate color depending upon whether or not // the widget is currently pressed. // GrContextForegroundSet(&sCtx, ((psPush->ui32Style & IB_STYLE_PRESSED) ? psPush->ui32PressedColor : psPush->ui32BackgroundColor)); GrRectFill(&sCtx, &(psWidget->sPosition)); } // // Set the foreground and background colors to use for 1 BPP // images and text // GrContextForegroundSet(&sCtx, psPush->ui32ForegroundColor); GrContextBackgroundSet(&sCtx, ((psPush->ui32Style & IB_STYLE_PRESSED) ? psPush->ui32PressedColor : psPush->ui32BackgroundColor)); // // Do we need to draw the background image? // if(!(psPush->ui32Style & IB_STYLE_IMAGE_OFF)) { // // Get the background image to be drawn. // pui8Image = ((psPush->ui32Style & IB_STYLE_PRESSED) ? psPush->pui8PressImage : psPush->pui8Image); // // Draw the image centered in the image button. // GrImageDraw(&sCtx, pui8Image, i32X - (GrImageWidthGet(pui8Image) / 2), i32Y - (GrImageHeightGet(pui8Image) / 2)); } // // Adjust the drawing position if the button is pressed. // i32X += ((psPush->ui32Style & IB_STYLE_PRESSED) ? psPush->i16XOffset : 0); i32Y += ((psPush->ui32Style & IB_STYLE_PRESSED) ? psPush->i16YOffset : 0); // // If there is a keycap image and it is not disabled, center this on the // top of the button, applying any offset defined if the button is // currently pressed. // if(psPush->pui8KeycapImage && !(psPush->ui32Style & IB_STYLE_KEYCAP_OFF)) { // // Draw the keycap image. // GrImageDraw(&sCtx, psPush->pui8KeycapImage, i32X - (GrImageWidthGet(psPush->pui8KeycapImage) / 2), i32Y - (GrImageHeightGet(psPush->pui8KeycapImage) / 2)); } // // See if the button text style is selected. // if(psPush->ui32Style & IB_STYLE_TEXT) { // // Draw the text centered in the middle of the button with offset // applied if the button is currently pressed. // GrContextFontSet(&sCtx, psPush->psFont); GrStringDrawCentered(&sCtx, psPush->pcText, -1, i32X, i32Y, 0); } }
/***************************************************************************** * * This is the main loop that runs the application. * *****************************************************************************/ int main(void) { tRectangle sRect; MMUConfigAndEnable(); /* Enable USB module clock */ USB0ModuleClkConfig(); /* Enable DM timer 3 module clock */ DMTimer3ModuleClkConfig(); /* Enbale touch screen module colock */ TSCADCModuleClkConfig(); /* Enable touch screen ADC pinmux */ TSCADCPinMuxSetUp(); /* configures arm interrupt controller to generate raster interrupt */ USBInterruptEnable(); /* LCD Back light setup */ LCDBackLightEnable(); /* UPD Pin setup */ UPDNPinControl(); /* Delay timer setup */ DelayTimerSetup(); /* Configures raster to display image */ SetUpLCD(); /* Register touch scren interrupt */ TouchIntRegister(); IntSystemEnable(SYS_INT_TINT3); IntPrioritySet(SYS_INT_TINT3, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_ADC_TSC_GENINT); IntPrioritySet(SYS_INT_ADC_TSC_GENINT, 0, AINTC_HOSTINT_ROUTE_IRQ); /* Configures raster to display image and Copy palette info into buffer */ LCDInit(); GrOffScreen24BPPInit(&g_s35_480x272x24Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT); /* Initialize a drawing context. */ GrContextInit(&g_sContext, &g_s35_480x272x24Display); /* enable End of frame interrupt */ RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS); /* enable raster */ RasterEnable(SOC_LCDC_0_REGS); /* 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) - 1; sRect.sYMax = (MAX_ROW_NUM - 1); GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); /* Put a white box around the banner. */ GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); /* Put the application name in the middle of the banner. */ GrContextFontSet(&g_sContext, &g_sFontCm20); GrStringDrawCentered(&g_sContext, "usb-dev-composite", -1, GrContextDpyWidthGet(&g_sContext) / 2, 10, 0); sRect.sXMin = 0; sRect.sYMin = (MAX_ROW_NUM + 1); sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = GrContextDpyHeightGet(&g_sContext) - BUTTON_HEIGHT - 2; GrContextForegroundSet(&g_sContext, ClrBlack); GrRectFill(&g_sContext, &sRect); /* Put a white box around the banner. */ GrContextForegroundSet(&g_sContext, ClrRed); GrRectDraw(&g_sContext, &sRect); /* Draw the buttons in their initial (unpressed)state. */ UpdateDisplay(g_ucButtons, true); /* Show the various static text elements on the color STN display. */ GrContextFontSet(&g_sContext, TEXT_FONT); GrStringDraw(&g_sContext, "Tx bytes:", -1, CDC_STR_X_POSITION, CDC_STR_Y_POSITION, false); GrStringDraw(&g_sContext, "Tx buffer:", -1, CDC_STR_X_POSITION, (CDC_STR_Y_POSITION + CDC_STR_Y_DIFF), false); GrStringDraw(&g_sContext, "Rx bytes:", -1, CDC_STR_X_POSITION, (CDC_STR_Y_POSITION + (CDC_STR_Y_DIFF * 3)), false); GrStringDraw(&g_sContext, "Rx buffer:", -1, CDC_STR_X_POSITION, (CDC_STR_Y_POSITION + (CDC_STR_Y_DIFF * 4)), false); DrawBufferMeter(&g_sContext, BUFFER_METER_X_POS, BUFFER_METER_Y_POS); DrawBufferMeter(&g_sContext, BUFFER_METER_X_POS, (BUFFER_METER_Y_POS + CDC_BUF_METER_Y_DIFF)); /* Tell the user what we are up to. */ DisplayStatus(&g_sContext, " Waiting for host... "); /* Initialize touch screen */ TouchInit(); /* Touch screen Interrupt enbale */ TouchIntEnable(); /* Touch Screen Enable */ TouchEnable(); /* Pass the USB library our device information, initialize the USB controller and connect the device to the bus. */ g_psCompDevices[0].pvInstance = USBDHIDMouseCompositeInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); /* Pass the device information to the USB library and place the device on the bus. */ USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); /* Initialize the mouse and serial devices. */ SerialInit(); /* Drop into the main loop. */ while(1) { /* Allow the main serial routine to run. */ SerialMain(); /* Allow the main mouse routine to run. */ MouseMain(); } }
//***************************************************************************** // // Run the hibernate example. Use a loop to put the microcontroller into // hibernate mode, and to wake up based on time. Also allow the user to cause // it to hibernate and/or wake up based on button presses. // //***************************************************************************** int main(void) { uint32_t ui32Idx; uint32_t ui32Status = 0; uint32_t ui32HibernateCount = 0; tContext sContext; tRectangle sRect; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Initialize the UART. // ConfigureUART(); // // Initialize the OLED display // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sCFAL96x64x16); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 9; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&sContext, ClrWhite); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_psFontFixed6x8); GrStringDrawCentered(&sContext, "hibernate", -1, GrContextDpyWidthGet(&sContext) / 2, 4, 0); // // Initialize the buttons driver // ButtonsInit(); // // Set up systick to generate interrupts at 100 Hz. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Enable the Hibernation module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); // // Print wake cause message on display. // GrStringDrawCentered(&sContext, "Wake due to:", -1, GrContextDpyWidthGet(&sContext) / 2, Row(2) + 4, true); // // Check to see if Hibernation module is already active, which could mean // that the processor is waking from a hibernation. // if(HibernateIsActive()) { // // Read the status bits to see what caused the wake. // ui32Status = HibernateIntStatus(0); HibernateIntClear(ui32Status); // // Wake was due to the push button. // if(ui32Status & HIBERNATE_INT_PIN_WAKE) { GrStringDrawCentered(&sContext, "BUTTON", -1, GrContextDpyWidthGet(&sContext) / 2, Row(3) + 4, true); } // // Wake was due to RTC match // else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0) { GrStringDrawCentered(&sContext, "TIMEOUT", -1, GrContextDpyWidthGet(&sContext) / 2, Row(3) + 4, true); } // // Wake is due to neither button nor RTC, so it must have been a hard // reset. // else { GrStringDrawCentered(&sContext, "RESET", -1, GrContextDpyWidthGet(&sContext) / 2, Row(3) + 4, true); } // // If the wake is due to button or RTC, then read the first location // from the battery backed memory, as the hibernation count. // if(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0)) { HibernateDataGet(&ui32HibernateCount, 1); } } // // Enable the Hibernation module. This should always be called, even if // the module was already enabled, because this function also initializes // some timing parameters. // HibernateEnableExpClk(ROM_SysCtlClockGet()); // // If the wake was not due to button or RTC match, then it was a reset. // if(!(ui32Status & (HIBERNATE_INT_PIN_WAKE | HIBERNATE_INT_RTC_MATCH_0))) { // // Configure the module clock source. // HibernateClockConfig(HIBERNATE_OSC_LOWDRIVE); // // Finish the wake cause message. // GrStringDrawCentered(&sContext, "RESET", -1, GrContextDpyWidthGet(&sContext) / 2, Row(3) + 4, true); // // Wait a couple of seconds in case we need to break in with the // debugger. // SysTickWait(3 * 100); // // Allow time for the crystal to power up. This line is separated from // the above to make it clear this is still needed, even if the above // delay is removed. // SysTickWait(15); } // // Print the count of times that hibernate has occurred. // usnprintf(g_pcBuf, sizeof(g_pcBuf), "Hib count=%4u", ui32HibernateCount); GrStringDrawCentered(&sContext, g_pcBuf, -1, GrContextDpyWidthGet(&sContext) / 2, Row(1) + 4, true); // // Print messages on the screen about hibernation. // GrStringDrawCentered(&sContext, "Select to Hib", -1, GrContextDpyWidthGet(&sContext) / 2, Row(4) + 4, true); GrStringDrawCentered(&sContext, "Wake in 5 s,", -1, GrContextDpyWidthGet(&sContext) / 2, Row(5) + 4, true); GrStringDrawCentered(&sContext, "or press Select", -1, GrContextDpyWidthGet(&sContext) / 2, Row(6) + 4, true); GrStringDrawCentered(&sContext, "for immed. wake.", -1, GrContextDpyWidthGet(&sContext) / 2, Row(7) + 4, true); // // Clear the button pressed flag, in case it was held down at the // beginning. // bSelectPressed = 0; // // Wait for user to press the button. // while(!bSelectPressed) { // // Wait a bit before looping again. // SysTickWait(10); } // // Tell user to release the button. // GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, Row(4) + 4, true); GrStringDrawCentered(&sContext, " Release the ", -1, GrContextDpyWidthGet(&sContext) / 2, Row(5) + 4, true); GrStringDrawCentered(&sContext, " button. ", -1, GrContextDpyWidthGet(&sContext) / 2, Row(6) + 4, true); GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, Row(7) + 4, true); // // Wait for user to release the button. // while(bSelectPressed) { } // // If hibernation count is very large, it may be that there was already // a value in the hibernate memory, so reset the count. // ui32HibernateCount = (ui32HibernateCount > 10000) ? 0 : ui32HibernateCount; // // Increment the hibernation count, and store it in the battery backed // memory. // ui32HibernateCount++; HibernateDataSet(&ui32HibernateCount, 1); // // Clear and enable the RTC and set the match registers to 5 seconds in the // future. Set both to same, though they could be set differently, the // first to match will cause a wake. // HibernateRTCSet(0); HibernateRTCEnable(); HibernateRTCMatchSet(0, 5); // // Set wake condition on pin or RTC match. Board will wake when 5 seconds // elapses, or when the button is pressed. // HibernateWakeSet(HIBERNATE_WAKE_PIN | HIBERNATE_WAKE_RTC); // // Request hibernation. // HibernateRequest(); // // Give it time to activate, it should never get past this wait. // SysTickWait(100); // // Should not have got here, something is wrong. Print an error message to // the user. // sRect.i16XMin = 0; sRect.i16XMax = 95; sRect.i16YMin = 0; sRect.i16YMax = 63; GrContextForegroundSet(&sContext, ClrBlack); GrRectFill(&sContext, &sRect); GrContextForegroundSet(&sContext, ClrWhite); ui32Idx = 0; while(g_pcErrorText[ui32Idx]) { GrStringDraw(&sContext, g_pcErrorText[ui32Idx], -1, Col(0), Row(ui32Idx), true); ui32Idx++; } // // Wait for the user to press the button, then restart the app. // bSelectPressed = 0; while(!bSelectPressed) { } // // Reset the processor. // ROM_SysCtlReset(); // // Finished. // while(1) { } }
//***************************************************************************** // // This example decrypts blocks of plaintext using AES128 in CBC mode. It // does the decryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32PlainText[16], ui32Errors, ui32Idx, ui32SysClock; tContext sContext; // // Run from the PLL at 120 MHz. // ui32SysClock = 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, "aes128-cbc-decrypt"); // // Show some instructions on the display // GrContextFontSet(&sContext, g_psFontCm20); GrContextForegroundSet(&sContext, ClrWhite); GrStringDrawCentered(&sContext, "Connect a terminal to", -1, GrContextDpyWidthGet(&sContext) / 2, 60, false); GrStringDrawCentered(&sContext, "UART0 (115200,N,8,1)", -1, GrContextDpyWidthGet(&sContext) / 2, 80, false); GrStringDrawCentered(&sContext, "for more information.", -1, GrContextDpyWidthGet(&sContext) / 2, 100, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32PlainText[ui32Idx] = 0; } // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Enable AES interrupts. // ROM_IntEnable(INT_AES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting AES128 CBC decryption demo.\n"); GrStringDrawCentered(&sContext, "Starting demo...", -1, GrContextDpyWidthGet(&sContext) / 2, 140, false); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and AES modules. // if(!AESInit()) { UARTprintf("Initialization of the AES module failed.\n"); ui32Errors |= 0x00000001; } // // Perform the decryption without uDMA. // UARTprintf("Performing decryption without uDMA.\n"); AES128CBCDecrypt(g_pui32AES128CipherText, pui32PlainText, g_pui32AES128Key, g_pui32AES128IV, 64, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32PlainText[ui32Idx] != g_pui32AES128PlainText[ui32Idx]) { UARTprintf("Plaintext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32AES128PlainText[ui32Idx], pui32PlainText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } // // Clear the array containing the plaintext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32PlainText[ui32Idx] = 0; } // // Perform the decryption with uDMA. // UARTprintf("Performing decryption with uDMA.\n"); AES128CBCDecrypt(g_pui32AES128CipherText, pui32PlainText, g_pui32AES128Key, g_pui32AES128IV, 64, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32PlainText[ui32Idx] != g_pui32AES128PlainText[ui32Idx]) { UARTprintf("Plaintext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32AES128PlainText[ui32Idx], pui32PlainText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); GrStringDrawCentered(&sContext, "Demo failed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } else { UARTprintf("Demo completed successfully.\n"); GrStringDrawCentered(&sContext, "Demo passed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } while(1) { } }
//***************************************************************************** // // This is the main application entry function. // //***************************************************************************** int main(void) { unsigned long ulTxCount; unsigned long ulRxCount; tRectangle sRect; char pcBuffer[16]; // // Set the clocking to run from the PLL at 50MHz // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); #ifdef DEBUG // // Configure the relevant pins such that UART0 owns them. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Open UART0 for debug output. // UARTStdioInit(0); #endif // // Not configured initially. // g_bUSBConfigured = false; // // Initialize the display driver. // Formike128x128x16Init(); // // Turn on the backlight. // Formike128x128x16BacklightOn(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sFormike128x128x16); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = 14; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_pFontFixed6x8); GrStringDrawCentered(&g_sContext, "usb_dev_bulk", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Show the various static text elements on the color STN display. // GrContextFontSet(&g_sContext, TEXT_FONT); GrStringDraw(&g_sContext, "Tx bytes:", -1, 8, 70, false); GrStringDraw(&g_sContext, "Rx bytes:", -1, 8, 90, false); // // Configure the USB mux on the board to put us in device mode. We pull // the relevant pin high to do this. // ROM_SysCtlPeripheralEnable(USB_MUX_GPIO_PERIPH); ROM_GPIOPinTypeGPIOOutput(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN); ROM_GPIOPinWrite(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN, USB_MUX_SEL_DEVICE); // // Enable the system tick. // ROM_SysTickPeriodSet(SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Show the application name on the display and UART output. // DEBUG_PRINT("\nStellaris USB bulk device example\n"); DEBUG_PRINT("---------------------------------\n\n"); // // Tell the user what we are up to. // DisplayStatus(&g_sContext, "Configuring USB..."); // // Initialize the transmit and receive buffers. // USBBufferInit((tUSBBuffer *)&g_sTxBuffer); USBBufferInit((tUSBBuffer *)&g_sRxBuffer); // // Pass our device information to the USB library and place the device // on the bus. // USBDBulkInit(0, (tUSBDBulkDevice *)&g_sBulkDevice); // // Wait for initial configuration to complete. // DisplayStatus(&g_sContext, "Waiting for host..."); // // Clear our local byte counters. // ulRxCount = 0; ulTxCount = 0; // // Main application loop. // while(1) { // // Have we been asked to update the status display? // if(g_ulFlags & COMMAND_STATUS_UPDATE) { // // Clear the command flag // g_ulFlags &= ~COMMAND_STATUS_UPDATE; DisplayStatus(&g_sContext, g_pcStatus); } // // Has there been any transmit traffic since we last checked? // if(ulTxCount != g_ulTxCount) { // // Take a snapshot of the latest transmit count. // ulTxCount = g_ulTxCount; // // Update the display of bytes transmitted by the UART. // usnprintf(pcBuffer, 16, "%d", ulTxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 70, 70, true); } // // Has there been any receive traffic since we last checked? // if(ulRxCount != g_ulRxCount) { // // Take a snapshot of the latest receive count. // ulRxCount = g_ulRxCount; // // Update the display of bytes received by the UART. // usnprintf(pcBuffer, 16, "%d", ulRxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 70, 90, true); } } }
int main(void) { tRectangle sRect; unsigned int i = 0; unsigned char *src = (unsigned char *) palette_32b; unsigned char *dest = (unsigned char *) (g_pucBuffer+4); MMUConfigAndEnable(); // //Enable USB module clock // USB0ModuleClkConfig(); // //Enable DM timer 3 module clock // DMTimer3ModuleClkConfig(); // //Enbale touch screen module colock // TSCADCModuleClkConfig(); // //Enable touch screen ADC pinmux // TSCADCPinMuxSetUp(); // //Enbale USB interrupts // USBInterruptEnable(); // //Switch ON LCD back light // LCDBackLightEnable(); // //UDP Pin control // UPDNPinControl(); // //Delay timer setup // DelayTimerSetup(); // //Configures raster to display image // SetUpLCD(); // //Register touch scren interrupt // TouchIntRegister(); IntSystemEnable(SYS_INT_TINT3); IntPrioritySet(SYS_INT_TINT3, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_ADC_TSC_GENINT); IntPrioritySet(SYS_INT_ADC_TSC_GENINT, 0, AINTC_HOSTINT_ROUTE_IRQ); RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int)(g_pucBuffer+PALETTE_OFFSET), (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET, FRAME_BUFFER_0); RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int)(g_pucBuffer+PALETTE_OFFSET), (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET, FRAME_BUFFER_1); src = (unsigned char *) palette_32b; dest = (unsigned char *) (g_pucBuffer+PALETTE_OFFSET); // Copy palette info into buffer for( i = PALETTE_OFFSET; i < (PALETTE_SIZE+PALETTE_OFFSET); i++) { *dest++ = *src++; } GrOffScreen24BPPInit(&g_s35_480x272x24Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT); // Initialize a drawing context. GrContextInit(&g_sContext, &g_s35_480x272x24Display); /* enable End of frame interrupt */ RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS); /* enable raster */ RasterEnable(SOC_LCDC_0_REGS); // // 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) - 1; sRect.sYMax = 23; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, &g_sFontCm20); GrStringDrawCentered(&g_sContext, "usb-dev-mouse", -1, GrContextDpyWidthGet(&g_sContext) / 2, 10, 0); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 25; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = GrContextDpyHeightGet(&g_sContext) - BUTTON_HEIGHT - 2; GrContextForegroundSet(&g_sContext, ClrDarkGray); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrRed); GrRectDraw(&g_sContext, &sRect); // // Draw the buttons in their initial (unpressed)state. // UpdateDisplay(g_ucButtons, true); // //Initialize touch screen // TouchInit(); // //Touch screen Interrupt enbale // TouchIntEnable(); // //Touch Screen Enable // TouchEnable(); // // Initialize the mouse // USBDHIDMouseInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); // // Drop into the main loop. // while(1) { // // Wait for USB configuration to complete. // while(!bConnected) { } // //Wait till someone touches the screen // while(!g_iTouch) { g_iTouch = TouchDetect(); } // //Loop here as long as someone moving the finger/stylus on the touch screen // do { // //If so, read the x and Y vlaue and give it to touch handler // TouchCoOrdGet(&g_lScreenX, &g_lScreenY); // //Call touch handler // TouchHandler(); }while(TouchDetect()); // //Touch is released // g_released = 1; // //Reset the button status // g_ucButtons = 0; // //Call the touch handler to update the release status // TouchHandler(); // //Reset the touch flag // g_iTouch = 0; } }
//***************************************************************************** // //! Draws a key on the keyboard. //! //! \param psWidget is a pointer to the keyboard widget to be drawn. //! \param psKey is a pointer to the key to draw. //! //! This function draws a single key on the display. This is called whenever //! a key on the keyboard needs to be updated. //! //! \return None. // //***************************************************************************** static void ButtonPaintText(tWidget *psWidget, const tKeyText *psKey) { tKeyboardWidget *psKeyboard; tContext sCtx; int32_t i32X, i32Y; uint32_t ui32Range, ui32Size; tRectangle sRect; char pcKeyCap[4]; // // Check the arguments. // ASSERT(psWidget); // // Convert the generic widget pointer into a keyboard widget pointer. // psKeyboard = (tKeyboardWidget *)psWidget; // // Initialize a drawing context. // GrContextInit(&sCtx, psWidget->psDisplay); // // Initialize the clipping region based on the extents of this keyboard. // GrContextClipRegionSet(&sCtx, &(psWidget->sPosition)); // // Calculate a keys bounding box. // ui32Range = psWidget->sPosition.i16XMax - psWidget->sPosition.i16XMin + 1; sRect.i16XMin = psWidget->sPosition.i16XMin + 1; sRect.i16XMin += (ui32Range * (uint32_t)psKey->ui16XPos) / 10000; sRect.i16XMax = sRect.i16XMin - 3 + ((ui32Range * (uint32_t)psKey->ui16Width) / 10000); ui32Range = psWidget->sPosition.i16YMax - psWidget->sPosition.i16YMin + 1; sRect.i16YMin = psWidget->sPosition.i16YMin + 1; sRect.i16YMin += (ui32Range * (uint32_t)psKey->ui16YPos) / 10000; sRect.i16YMax = sRect.i16YMin - 3 + ((ui32Range * (uint32_t)psKey->ui16Height) / 10000); // // See if the keyboard fill style is selected. // if(psKeyboard->ui32Style & KEYBOARD_STYLE_FILL) { // // Fill the key with the fill color. // GrContextForegroundSet(&sCtx, ((psKeyboard->ui32Flags & FLAG_KEY_PRESSED) ? psKeyboard->ui32PressFillColor : psKeyboard->ui32FillColor)); GrRectFill(&sCtx, &sRect); } // // See if the keyboard outline style is selected. // if(psKeyboard->ui32Style & KEYBOARD_STYLE_OUTLINE) { // // Outline the key with the outline color. // GrContextForegroundSet(&sCtx, psKeyboard->ui32OutlineColor); GrRectDraw(&sCtx, &sRect); } // // Compute the center of the key. // i32X = (sRect.i16XMin + ((sRect.i16XMax - sRect.i16XMin + 1) / 2)); i32Y = (sRect.i16YMin + ((sRect.i16YMax - sRect.i16YMin + 1) / 2)); // // If the keyboard outline style is selected then shrink the // clipping region by one pixel on each side so that the outline is not // overwritten by the text or image. // if(psKeyboard->ui32Style & KEYBOARD_STYLE_OUTLINE) { sCtx.sClipRegion.i16XMin++; sCtx.sClipRegion.i16YMin++; sCtx.sClipRegion.i16XMax--; sCtx.sClipRegion.i16YMax--; } // // Draw the text centered in the middle of the key. // GrContextFontSet(&sCtx, psKeyboard->psFont); GrContextForegroundSet(&sCtx, psKeyboard->ui32TextColor); GrContextBackgroundSet(&sCtx, ((psKeyboard->ui32Flags & FLAG_KEY_PRESSED) ? psKeyboard->ui32PressFillColor : psKeyboard->ui32FillColor)); ui32Size = 0; if(psKey->ui32Code == UNICODE_BACKSPACE) { pcKeyCap[0] = 'B'; pcKeyCap[1] = 'S'; ui32Size = 2; } else if(psKey->ui32Code == UNICODE_RETURN) { pcKeyCap[0] = 'E'; pcKeyCap[1] = 'n'; pcKeyCap[2] = 't'; ui32Size = 3; } else if(psKey->ui32Code == UNICODE_CUSTOM_SHIFT) { pcKeyCap[0] = 'C'; pcKeyCap[1] = 'a'; pcKeyCap[2] = 'p'; ui32Size = 3; } else if(psKey->ui32Code == UNICODE_CUSTOM_MODE_TOG) { pcKeyCap[0] = '1'; pcKeyCap[1] = '2'; pcKeyCap[2] = '3'; ui32Size = 3; } else { ui32Size = 1; pcKeyCap[0] = (char)psKey->ui32Code; } GrStringDrawCentered(&sCtx, (const char *)pcKeyCap, ui32Size, i32X, i32Y, psKeyboard->ui32Style & KEYBOARD_STYLE_TEXT_OPAQUE); }
//***************************************************************************** // //! Draws a circular push button. //! //! \param pWidget is a pointer to the push button widget to be drawn. //! //! This function draws a circular push button on the display. This is called //! in response to a \b #WIDGET_MSG_PAINT message. //! //! \return None. // //***************************************************************************** static void CircularButtonPaint(tWidget *pWidget) { const unsigned char *pucImage; tPushButtonWidget *pPush; tContext sCtx; long lX, lY, lR; // // Check the arguments. // ASSERT(pWidget); // // Convert the generic widget pointer into a push button widget pointer. // pPush = (tPushButtonWidget *)pWidget; // // Initialize a drawing context. // GrContextInit(&sCtx, pWidget->pDisplay); // // Initialize the clipping region based on the extents of this circular // push button. // GrContextClipRegionSet(&sCtx, &(pWidget->sPosition)); // // Get the radius of the circular push button, along with the X and Y // coordinates for its center. // lR = (pWidget->sPosition.sXMax - pWidget->sPosition.sXMin + 1) / 2; lX = pWidget->sPosition.sXMin + lR; lY = pWidget->sPosition.sYMin + lR; // // See if the push button fill style is selected. // if(pPush->ulStyle & PB_STYLE_FILL) { // // Fill the push button with the fill color. // GrContextForegroundSet(&sCtx, ((pPush->ulStyle & PB_STYLE_PRESSED) ? pPush->ulPressFillColor : pPush->ulFillColor)); GrCircleFill(&sCtx, lX, lY, lR); } // // See if the push button outline style is selected. // if(pPush->ulStyle & PB_STYLE_OUTLINE) { // // Outline the push button with the outline color. // GrContextForegroundSet(&sCtx, pPush->ulOutlineColor); GrCircleDraw(&sCtx, lX, lY, lR); } // // See if the push button text or image style is selected. // if(pPush->ulStyle & (PB_STYLE_TEXT | PB_STYLE_IMG)) { // // If the push button outline style is selected then shrink the // clipping region by one pixel on each side so that the outline is not // overwritten by the text or image. // if(pPush->ulStyle & PB_STYLE_OUTLINE) { sCtx.sClipRegion.sXMin++; sCtx.sClipRegion.sYMin++; sCtx.sClipRegion.sXMax--; sCtx.sClipRegion.sYMax--; } // // See if the push button image style is selected. // if(pPush->ulStyle & PB_STYLE_IMG) { // // Set the foreground and background colors to use for 1 BPP // images. // GrContextForegroundSet(&sCtx, pPush->ulTextColor); GrContextBackgroundSet(&sCtx, ((pPush->ulStyle & PB_STYLE_PRESSED) ? pPush->ulPressFillColor : pPush->ulFillColor)); // // Get the image to be drawn. // pucImage = (((pPush->ulStyle & PB_STYLE_PRESSED) && pPush->pucPressImage) ? pPush->pucPressImage : pPush->pucImage); // // Draw the image centered in the push button. // GrImageDraw(&sCtx, pucImage, lX - (GrImageWidthGet(pucImage) / 2), lY - (GrImageHeightGet(pucImage) / 2)); } // // See if the push button text style is selected. // if(pPush->ulStyle & PB_STYLE_TEXT) { // // Draw the text centered in the middle of the push button. // GrContextFontSet(&sCtx, pPush->pFont); GrContextForegroundSet(&sCtx, pPush->ulTextColor); GrContextBackgroundSet(&sCtx, ((pPush->ulStyle & PB_STYLE_PRESSED) ? pPush->ulPressFillColor : pPush->ulFillColor)); GrStringDrawCentered(&sCtx, pPush->pcText, -1, lX, lY, pPush->ulStyle & PB_STYLE_TEXT_OPAQUE); } } }
//***************************************************************************** // // This is the main application entry function. // //***************************************************************************** int main(void) { uint32_t ui32TxCount, ui32RxCount, ui32Fullness, ui32SysClock, ui32PLLRate; tRectangle sRect; char pcBuffer[16]; #ifdef USE_ULPI uint32_t ui32Setting; #endif // // Set the system clock to run at 120MHz from the PLL. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // 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 // // Enable the system tick. // ROM_SysTickPeriodSet(ui32SysClock / TICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Not configured initially. // g_ui32Flags = 0; // // 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-dev-serial"); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.i16YMax = 23; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Show the various static text elements on the color STN display. // GrContextFontSet(&g_sContext, TEXT_FONT); GrStringDraw(&g_sContext, "Tx bytes:", -1, 8, 80, false); GrStringDraw(&g_sContext, "Tx buffer:", -1, 8, 105, false); GrStringDraw(&g_sContext, "Rx bytes:", -1, 8, 160, false); GrStringDraw(&g_sContext, "Rx buffer:", -1, 8, 185, false); DrawBufferMeter(&g_sContext, 150, 105); DrawBufferMeter(&g_sContext, 150, 185); // // Enable the UART that we will be redirecting. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Change the UART clock to the 16 MHz PIOSC. // UARTClockSourceSet(UART0_BASE, UART_CLOCK_PIOSC); // // Set the default UART configuration. // ROM_UARTConfigSetExpClk(UART0_BASE, UART_CLOCK, DEFAULT_BIT_RATE, DEFAULT_UART_CONFIG); ROM_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8); // // Configure and enable UART interrupts. // ROM_UARTIntClear(UART0_BASE, ROM_UARTIntStatus(UART0_BASE, false)); ROM_UARTIntEnable(UART0_BASE, (UART_INT_OE | UART_INT_BE | UART_INT_PE | UART_INT_FE | UART_INT_RT | UART_INT_TX | UART_INT_RX)); // // Tell the user what we are up to. // DisplayStatus(&g_sContext, " Configuring USB... "); // // Initialize the transmit and receive buffers. // USBBufferInit(&g_sTxBuffer); USBBufferInit(&g_sRxBuffer); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, eUSBModeDevice, 0); // // Tell the USB library the CPU clock and the PLL frequency. This is a // new requirement for TM4C129 devices. // USBDCDFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock); USBDCDFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate); // // Pass our device information to the USB library and place the device // on the bus. // USBDCDCInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Wait for initial configuration to complete. // DisplayStatus(&g_sContext, " Waiting for host... "); // // Clear our local byte counters. // ui32RxCount = 0; ui32TxCount = 0; g_ui32UARTTxCount = 0; g_ui32UARTRxCount = 0; #ifdef DEBUG g_ui32UARTRxErrors = 0; #endif // // Enable interrupts now that the application is ready to start. // ROM_IntEnable(INT_UART0); // // Main application loop. // while(1) { // // Have we been asked to update the status display? // if(HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE)) { // // Clear the command flag // HWREGBITW(&g_ui32Flags, FLAG_STATUS_UPDATE) = 0; DisplayStatus(&g_sContext, g_pcStatus); } // // Has there been any transmit traffic since we last checked? // if(ui32TxCount != g_ui32UARTTxCount) { // // Take a snapshot of the latest transmit count. // ui32TxCount = g_ui32UARTTxCount; // // Update the display of bytes transmitted by the UART. // usnprintf(pcBuffer, 16, "%d ", ui32TxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 150, 80, true); // // Update the RX buffer fullness. Remember that the buffers are // named relative to the USB whereas the status display is from // the UART's perspective. The USB's receive buffer is the UART's // transmit buffer. // ui32Fullness = ((USBBufferDataAvailable(&g_sRxBuffer) * 100) / UART_BUFFER_SIZE); UpdateBufferMeter(&g_sContext, ui32Fullness, 150, 105); } // // Has there been any receive traffic since we last checked? // if(ui32RxCount != g_ui32UARTRxCount) { // // Take a snapshot of the latest receive count. // ui32RxCount = g_ui32UARTRxCount; // // Update the display of bytes received by the UART. // usnprintf(pcBuffer, 16, "%d ", ui32RxCount); GrStringDraw(&g_sContext, pcBuffer, -1, 150, 160, true); // // Update the TX buffer fullness. Remember that the buffers are // named relative to the USB whereas the status display is from // the UART's perspective. The USB's transmit buffer is the UART's // receive buffer. // ui32Fullness = ((USBBufferDataAvailable(&g_sTxBuffer) * 100) / UART_BUFFER_SIZE); UpdateBufferMeter(&g_sContext, ui32Fullness, 150, 185); } } }
//***************************************************************************** // // A simple application demonstrating use of the boot loader, // //***************************************************************************** int main(void) { tRectangle sRect; tContext sContext; uint32_t ui32SysClock; // // 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_XTAL_16MHZ | SYSCTL_OSC_MAIN); ui32SysClock = ROM_SysCtlClockGet(); // // Initialize the peripherals that each of the boot loader flavors // supports. Since this example is intended for use with any of the // boot loaders and we don't know which is actually in use, we cover all // bases and initialize for serial, Ethernet and USB use here. // SetupForUART(); SetupForUSB(); // // Initialize the buttons driver. // ButtonsInit(); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sCFAL96x64x16); // // Fill the top part of the screen with blue to create the banner. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = 9; GrContextForegroundSet(&sContext, ClrDarkBlue); GrRectFill(&sContext, &sRect); // // Change foreground for white text. // GrContextForegroundSet(&sContext, ClrWhite); // // Put the application name in the middle of the banner. // GrContextFontSet(&sContext, g_psFontFixed6x8); GrStringDrawCentered(&sContext, "boot-demo2", -1, GrContextDpyWidthGet(&sContext) / 2, 4, 0); GrStringDrawCentered(&sContext, "Press select", -1, GrContextDpyWidthGet(&sContext) / 2, 20, false); GrStringDrawCentered(&sContext, "button to", -1, GrContextDpyWidthGet(&sContext) / 2, 30, false); GrStringDrawCentered(&sContext, "update.", -1, GrContextDpyWidthGet(&sContext) / 2, 40, false); // // Wait for select button to be pressed. // while ((ButtonsPoll(0, 0) & SELECT_BUTTON) == 0) { ROM_SysCtlDelay(ui32SysClock / 1000); } GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, 20, true); GrStringDrawCentered(&sContext, " Updating... ", -1, GrContextDpyWidthGet(&sContext) / 2, 30, true); GrStringDrawCentered(&sContext, " ", -1, GrContextDpyWidthGet(&sContext) / 2, 40, true); // // Transfer control to the boot loader. // JumpToBootLoader(); // // The previous function never returns but we need to stick in a return // code here to keep the compiler from generating a warning. // return(0); }