//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { tRectangle sRect; // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Enable the peripherals used by this example. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Configure the relevant pins such that UART0 owns them. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Open UART0 for debug output. // UARTStdioInit(0); // // Enable the USB mux GPIO. // SysCtlPeripheralEnable(USB_MUX_GPIO_PERIPH); // // The LM3S3748 board uses a USB mux that must be switched to use the // host connector and not the device connector. // GPIOPinTypeGPIOOutput(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN); GPIOPinWrite(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN, USB_MUX_SEL_HOST); // // Configure the power pins for host controller. // GPIOPinTypeUSBDigital(GPIO_PORTH_BASE, GPIO_PIN_3 | GPIO_PIN_4); // // Initialize the display driver. // Formike128x128x16Init(); // // Turn on the backlight. // Formike128x128x16BacklightOn(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sFormike128x128x16); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = DISPLAY_BANNER_HEIGHT; GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_pFontFixed6x8); GrStringDrawCentered(&g_sContext, "usb_host_keyboard", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Calculate the number of characters that will fit on a line. // Make sure to leave a small border for the text box. // g_ulCharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 4) / GrFontMaxWidthGet(g_pFontFixed6x8); // // Calculate the number of lines per usable text screen. This requires // taking off space for the top and bottom banners and adding a small bit // for a border. // g_ulLinesPerScreen = (GrContextDpyHeightGet(&g_sContext) - (2*(DISPLAY_BANNER_HEIGHT + 1)))/ GrFontHeightGet(g_pFontFixed6x8); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ulNumHostClassDrivers); // // Open and instance of the keyboard class driver. // UARTprintf("Host Keyboard Application\n"); // // Open an instance of the keyboard driver. The keyboard does not need // to be present at this time, this just save a place for it and allows // the applications to be notified when a keyboard is present. // g_ulKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pucBuffer, KEYBOARD_MEMORY_SIZE); // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH); // // Initialize the host controller stack. // USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE); // // Call the main loop for the Host controller driver. // USBHCDMain(); // // Initial update of the screen. // UpdateStatus(); // // The main loop for the application. // while(1) { switch(g_eUSBState) { // // This state is entered when they keyboard is first detected. // case STATE_KEYBOARD_INIT: { // // Initialized the newly connected keyboard. // USBHKeyboardInit(g_ulKeyboardInstance); // // Proceed to the keyboard connected state. // g_eUSBState = STATE_KEYBOARD_CONNECTED; USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers); // // Update the screen now that the keyboard has been // initialized. // UpdateStatus(); break; } case STATE_KEYBOARD_UPDATE: { // // If the application detected a change that required an // update to be sent to the keyboard to change the modifier // state then call it and return to the connected state. // g_eUSBState = STATE_KEYBOARD_CONNECTED; USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers); break; } case STATE_KEYBOARD_CONNECTED: { // // Nothing is currently done in the main loop when the keyboard // is connected. // break; } case STATE_UNKNOWN_DEVICE: { // // Nothing to do as the device is unknown. // break; } case STATE_NO_DEVICE: { // // Nothing is currently done in the main loop when the keyboard // is not connected. // break; } default: { break; } } // // Periodic call the main loop for the Host controller driver. // USBHCDMain(); } }
//***************************************************************************** // // This 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); } } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { FRESULT FileResult; tRectangle sRect; // // Initially wait for device connection. // g_eState = STATE_NO_DEVICE; // // Set the clocking to run directly from the crystal. // SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Enable Clocking to the USB controller. // SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Enable the peripherals used by this example. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOH); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Set the USB pins to be controlled by the USB controller. // GPIOPinTypeUSBDigital(GPIO_PORTH_BASE, GPIO_PIN_3 | GPIO_PIN_4); // // The LM3S3748 board uses a USB mux that must be switched to use the // host connecter 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_HOST); // // Turn on USB Phy clock. // SysCtlUSBPLLEnable(); // // Set the system tick to fire 100 times per second. // SysTickPeriodSet(SysCtlClockGet()/100); SysTickIntEnable(); SysTickEnable(); // // Enable the uDMA controller and set up the control table base. // SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); uDMAEnable(); uDMAControlBaseSet(g_sDMAControlTable); // // 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 = SPLASH_HEIGHT - 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_sFontFixed6x8); GrStringDrawCentered(&g_sContext, "usb_host_msc", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Set the color to white and select the 20 point font. // GrContextForegroundSet(&g_sContext, FILE_COLOR); GrStringDraw(&g_sContext, "No Device", 100, 0, TOP_HEIGHT, 1); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ulNumHostClassDrivers); // // Open an instance of the mass storage class driver. // g_ulMSCInstance = USBHMSCDriveOpen(0, MSCCallback); // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USB_HOST_PWREN_HIGH); // // Initialize the host controller. // USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE); // // Initialize the pushbuttons. // ButtonsInit(); // // Set the auto repeat rates for the up and down buttons. // ButtonsSetAutoRepeat(UP_BUTTON, 50, 15); ButtonsSetAutoRepeat(DOWN_BUTTON, 50, 15); // // Current directory is "/" // g_DirData.szPWD[0] = '/'; g_DirData.szPWD[1] = 0; // // Initialize the file system. // FileInit(); while(1) { USBHCDMain(); switch(g_eState) { case STATE_DEVICE_ENUM: { // // Reset the root directory. // g_DirData.szPWD[0] = '/'; g_DirData.szPWD[1] = 0; // // Open the root directory. // FileResult = f_opendir(&g_DirData.DirState, g_DirData.szPWD); // // Wait for the root directory to open successfully. The MSC // device can enumerate before being read to be accessed, so // there may be some delay before it is ready. // if(FileResult == FR_OK) { // // Reset the directory state. // g_DirData.ulIndex = 0; g_DirData.ulSelectIndex = 0; g_DirData.ulValidValues = 0; g_eState = STATE_DEVICE_READY; // // Ignore buttons pressed before being ready. // g_ulButtons = 0; // // Update the screen if the root dir opened successfully. // DirUpdate(); UpdateWindow(); } else if(FileResult != FR_NOT_READY) { // some kind of error } // // Set the Device Present flag. // g_ulFlags = FLAGS_DEVICE_PRESENT; break; } // // This is the running state where buttons are checked and the // screen is updated. // case STATE_DEVICE_READY: { // // Down button pressed and released. // if(g_ulButtons & BUTTON_DOWN_CLICK) { // // Update the screen and directory state. // MoveDown(); // // Clear the button pressed event. // g_ulButtons &= ~BUTTON_DOWN_CLICK; } // // Up button pressed and released. // if(g_ulButtons & BUTTON_UP_CLICK) { // // Update the screen and directory state. // MoveUp(); // // Clear the button pressed event. // g_ulButtons &= ~BUTTON_UP_CLICK; } // // Select button pressed and released. // if(g_ulButtons & BUTTON_SELECT_CLICK) { // // If this was a directory go into it. // SelectDir(); // // Clear the button pressed event. // g_ulButtons &= ~BUTTON_SELECT_CLICK; } break; } // // If there is no device then just wait for one. // case STATE_NO_DEVICE: { if(g_ulFlags == FLAGS_DEVICE_PRESENT) { // // Clear the screen and indicate that there is no longer // a device present. // ClearTextBox(); GrStringDraw(&g_sContext, "No Device", 100, 0, TOP_HEIGHT, 1); // // Clear the Device Present flag. // g_ulFlags &= ~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_ulFlags & FLAGS_DEVICE_PRESENT) == 0) { // // Clear the screen and indicate that an unknown device is // present. // ClearTextBox(); GrStringDraw(&g_sContext, "Unknown Device", 100, 0, TOP_HEIGHT, 1); } // // Set the Device Present flag. // g_ulFlags = FLAGS_DEVICE_PRESENT; break; } // // Something has caused a power fault. // case STATE_POWER_FAULT: { break; } default: { break; } } } }
//***************************************************************************** // // A simple demonstration of the features of the Stellaris Graphics Library. // //***************************************************************************** int main(void) { unsigned long ulIdx; tRectangle sRect; // // Set the clocking to run from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | 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, "grlib_demo", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Draw a vertical sweep of lines from red to green. // for(ulIdx = 0; ulIdx <= 10; ulIdx++) { GrContextForegroundSet(&g_sContext, (((((10 - ulIdx) * 255) / 10) << ClrRedShift) | (((ulIdx * 255) / 10) << ClrGreenShift))); GrLineDraw(&g_sContext, 62, 70, 2, 70 - (5 * ulIdx)); } // // Draw a horizontal sweep of lines from green to blue. // for(ulIdx = 1; ulIdx <= 10; ulIdx++) { GrContextForegroundSet(&g_sContext, (((((10 - ulIdx) * 255) / 10) << ClrGreenShift) | (((ulIdx * 255) / 10) << ClrBlueShift))); GrLineDraw(&g_sContext, 62, 70, 2 + (ulIdx * 6), 20); } // // Draw a filled circle with an overlapping circle. // GrContextForegroundSet(&g_sContext, ClrBrown); GrCircleFill(&g_sContext, 88, 37, 17); GrContextForegroundSet(&g_sContext, ClrSkyBlue); GrCircleDraw(&g_sContext, 104, 45, 17); // // Draw a filled rectangle with an overlapping rectangle. // GrContextForegroundSet(&g_sContext, ClrSlateGray); sRect.sXMin = 4; sRect.sYMin = 84; sRect.sXMax = 42; sRect.sYMax = 104; GrRectFill(&g_sContext, &sRect); GrContextForegroundSet(&g_sContext, ClrSlateBlue); sRect.sXMin += 12; sRect.sYMin += 15; sRect.sXMax += 12; sRect.sYMax += 15; GrRectDraw(&g_sContext, &sRect); // // Draw a piece of text in fonts of increasing size. // GrContextForegroundSet(&g_sContext, ClrSilver); GrStringDraw(&g_sContext, "Strings", -1, 75, 114, 0); // // Draw an image. // GrImageDraw(&g_sContext, g_pucLogo, 80, 77); // // Flush any cached drawing operations. // GrFlush(&g_sContext); // // Loop forever. // while(1) { } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { tRectangle sRect; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Enable the USB mux GPIO. // ROM_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. // ROM_GPIOPinTypeGPIOOutput(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN); ROM_GPIOPinWrite(USB_MUX_GPIO_BASE, USB_MUX_GPIO_PIN, USB_MUX_SEL_DEVICE); // // Configure SysTick for a 100Hz interrupt. The FatFs driver wants a 10 ms // tick. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); uDMAControlBaseSet(&sDMAControlTable[0]); uDMAEnable(); // // Initialize the display driver. // Formike128x128x16Init(); // // Turn on the backlight. // Formike128x128x16BacklightOn(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sFormike128x128x16); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = DISPLAY_BANNER_HEIGHT; GrContextForegroundSet(&g_sContext, 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_msc", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; // // Initialize the state to idle. // g_eMSCState = MSC_DEV_IDLE; // // Draw the status bar and set it to idle. // UpdateStatus("Idle", 1); // // Pass our device information to the USB library and place the device // on the bus. // USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); // // Drop into the main loop. // while(1) { switch(g_eMSCState) { case MSC_DEV_READ: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { UpdateStatus("Reading", 0); g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { UpdateStatus("Idle ", 0); g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_WRITE: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { UpdateStatus("Writing", 0); g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { UpdateStatus("Idle ", 0); g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_IDLE: default: { break; } } } }
//***************************************************************************** // // This example demonstrates how to setup the PWM block to generate signals. // //***************************************************************************** int main(void) { tRectangle sRect; unsigned long ulPeriod; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); ROM_SysCtlPWMClockSet(SYSCTL_PWMDIV_1); // // 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, "pwmgen", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Tell the user what is happening. // GrStringDrawCentered(&g_sContext, "Generating PWM on", -1, GrContextDpyWidthGet(&g_sContext) / 2, 56, 0); GrStringDrawCentered(&g_sContext, "pins PWM0 and PWM1", -1, GrContextDpyWidthGet(&g_sContext) / 2, 68, 0); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_PWM0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // // Set GPIO F0 and F1 as PWM pins. They are used to output the PWM0 and // PWM1 signals. // ROM_GPIOPinTypePWM(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1); ROM_GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_0 | GPIO_PIN_1, GPIO_STRENGTH_8MA, GPIO_PIN_TYPE_STD); // // Compute the PWM period based on the system clock. // ulPeriod = ROM_SysCtlClockGet() / 8000; // // Set the PWM period to 440 (A) Hz. // ROM_PWMGenConfigure(PWM0_BASE, PWM_GEN_0, PWM_GEN_MODE_UP_DOWN | PWM_GEN_MODE_NO_SYNC); ROM_PWMGenPeriodSet(PWM0_BASE, PWM_GEN_0, ulPeriod); // // Set PWM0 to a duty cycle of 50% and PWM1 to a duty cycle of 80%. // ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_0, ((ulPeriod * 8) / 10)); ROM_PWMPulseWidthSet(PWM0_BASE, PWM_OUT_1, ((ulPeriod * 2) / 10)); // // Enable the PWM0 and PWM1 output signals. // ROM_PWMOutputState(PWM0_BASE, PWM_OUT_0_BIT | PWM_OUT_1_BIT, true); // // Enable the PWM generator. // ROM_PWMGenEnable(PWM0_BASE, PWM_GEN_0); // // Loop forever while the PWM signals are generated. // while(1) { } }
//***************************************************************************** // // This example demonstrates how to send a string of data to the UART. // //***************************************************************************** int main(void) { tRectangle sRect; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // Initialize the display driver. // Formike128x128x16Init(); // // Turn on the backlight. // Formike128x128x16BacklightOn(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sFormike128x128x16); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = 14; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, &g_sFontFixed6x8); GrStringDrawCentered(&g_sContext, "uart_echo", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Initialize the CSTN display and write status. // GrStringDraw(&g_sContext, "Port: Uart 0", -1, 12, 24, 0); GrStringDraw(&g_sContext, "Baud: 115,200 bps", -1, 12, 32, 0); GrStringDraw(&g_sContext, "Data: 8 Bit", -1, 12, 40, 0); GrStringDraw(&g_sContext, "Parity: None", -1, 12, 48, 0); GrStringDraw(&g_sContext, "Stop: 1 Bit", -1, 12, 56, 0); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Enable processor interrupts. // IntMasterEnable(); // // Set GPIO A0 and A1 as UART pins. // ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Enable the UART interrupt. // ROM_IntEnable(INT_UART0); ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT); // // Prompt for text to be entered. // UARTSend((unsigned char *)"Ingrese un Texto: ", 18); // // Loop forever echoing data through the UART. // while(1) { } }
//***************************************************************************** // // Demonstrate the use of the boot loader. // //***************************************************************************** int main(void) { tRectangle sRect; // // Set the clocking to run directly from the crystal. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); // // If running on Rev A0 silicon, write the FMPRE[2-3]/FMPPE[2-3] registers // to zero. This is a workaround to allow the mass erase in the ROM-based // boot loader to succeed if a locked device recovery has been performed. // if(REVISION_IS_A0) { HWREG(FLASH_FMPPE2) = 0; HWREG(FLASH_FMPPE3) = 0; HWREG(FLASH_FMPRE2) = 0; HWREG(FLASH_FMPRE3) = 0; } // // Enable the UART and GPIO modules. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); // // Make the UART pins be peripheral controlled. // ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure the UART for 115,200, 8-N-1 operation. // ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); // // Initialize the display driver. // Formike128x128x16Init(); // // Turn on the backlight. // Formike128x128x16BacklightOn(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sFormike128x128x16); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = 14; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, &g_sFontFixed6x8); GrStringDrawCentered(&g_sContext, "boot_demo1", -1, GrContextDpyWidthGet(&g_sContext) / 2, 7, 0); // // Indicate what is happening. // GrStringDrawCentered(&g_sContext, "The boot loader is", -1, GrContextDpyWidthGet(&g_sContext) / 2, 24, 0); GrStringDrawCentered(&g_sContext, "now running and", -1, GrContextDpyWidthGet(&g_sContext) / 2, 32, 0); GrStringDrawCentered(&g_sContext, "awaiting an update", -1, GrContextDpyWidthGet(&g_sContext) / 2, 40, 0); GrStringDrawCentered(&g_sContext, "over UART0 at", -1, GrContextDpyWidthGet(&g_sContext) / 2, 48, 0); GrStringDrawCentered(&g_sContext, "115200, 8-N-1.", -1, GrContextDpyWidthGet(&g_sContext) / 2, 56, 0); // // Call the boot loader so that it will listen for an update on the UART. // ROM_UpdateUART(); // // The boot loader should take control, so this should never be reached. // Just in case, loop forever. // while(1) { } }
//***************************************************************************** // // 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(); }
//***************************************************************************** // // 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) { } }
//***************************************************************************** // // 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) { } }