//***************************************************************************** // // Calls the USB host stack tick function. // // This function is called periodically to allow the USB host stack to // process any outstanding items. // // \return None. // //***************************************************************************** void ScopeUSBHostTick(void) { tBoolean bRetcode; // // Call the stack to allow it to perform any processing needing done. // USBHCDMain(); // // See if we need to do anything here. // if(g_eState == STATE_DEVICE_ENUM) { // // The device is available. Try to open its root directory just // to make sure it is accessible. // bRetcode = FileIsDrivePresent(1); if(bRetcode) { // // The USB drive is accessible so dump a message and set the state // to indicate that the device is ready for use. // UARTprintf("Opened root directory - USB drive present.\n"); RendererSetAlert("USB drive\ndetected.", 200); g_eState = STATE_DEVICE_READY; } } }
//***************************************************************************** // // This function must be called periodically from the main loop of the // application to handle connection and disconnection of the USB keyboard. // //***************************************************************************** void USBKeyboardProcess(void) { // // Periodically call the main loop for the Host controller driver. // USBHCDMain(); 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; break; } default: { break; } } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** void HostMain(void) { switch(iUSBState) { // // This state is entered when the mouse is first detected. // case eStateMouseInit: { // // Initialize the newly connected mouse. // USBHMouseInit(g_psMouseInstance); // // Proceed to the mouse connected state. // iUSBState = eStateMouseConnected; // // Update the status on the screen. // UpdateStatus(0, 0, true); // // Update the cursor on the screen. // UpdateCursor(GrContextDpyWidthGet(&g_sContext) / 2, GrContextDpyHeightGet(&g_sContext)/ 2); break; } case eStateMouseConnected: { // // Nothing is currently done in the main loop when the mouse // is connected. // break; } case eStateNoDevice: { // // The mouse is not connected so nothing needs to be done here. // break; } default: { break; } } // // Periodically call the main loop for the Host controller driver. // USBHCDMain(); }
//***************************************************************************** // // This is the main routine for performing an update from a mass storage // device. // // This function forms the main loop of the USB stick updater. It polls for // a USB mass storage device to be connected, Once a device is connected // it will attempt to read a firmware image from the device and load it into // flash. // // \return None. // //***************************************************************************** void UpdaterUSB(void) { // // Loop forever, running the USB host driver. // while(1) { USBHCDMain(); // // Check for a state change from the USB driver. // switch(g_eState) { // // This state means that a mass storage device has been // plugged in and enumerated. // case STATE_DEVICE_ENUM: { // // Attempt to read the application image from the storage // device and load it into flash memory. // if(ReadAppAndProgram()) { // // There was some error reading or programming the app, // so reset the state to no device which will cause a // wait for a new device to be plugged in. // g_eState = STATE_NO_DEVICE; } else { // // User app load and programming was successful, so reboot // the micro. Perform a software reset request. This // will cause the microcontroller to reset; no further // code will be executed. // HWREG(NVIC_APINT) = NVIC_APINT_VECTKEY | NVIC_APINT_SYSRESETREQ; // // The microcontroller should have reset, so this should // never be reached. Just in case, loop forever. // while(1) { } } break; } // // This state means that there is no device present, so just // do nothing until something is plugged in. // case STATE_NO_DEVICE: { break; } } } }
/* * ======== USBMSCHFatFsTiva_serviceUSBHost ======== * Task to periodically service the USB Stack * * USBHCDMain handles the USB Stack's statemachine. For example it handles the * enumeration process when a device connects. * Future USB library improvement goal is to remove this polling requirement.. */ static void USBMSCHFatFsTiva_serviceUSBHost(UArg arg0, UArg arg1) { unsigned int key; USBMSCHFatFsTiva_Object *object = USBMSCHFatFs_config->object; while (true) { key = GateMutex_enter(GateMutex_handle(&(object->gateUSBLibAccess))); USBHCDMain(); GateMutex_leave(GateMutex_handle(&(object->gateUSBLibAccess)), key); /* Future enhancement to remove the Task_sleep */ Task_sleep(10); } }
void _usb_mouse_host_init(unsigned int instance) { MouseXPosition = 0; MouseYPosition = 0; if(instance == 0) { //g_eMouseState0 = STATE_MOUSE_NO_DEVICE; //g_eMouseUIState0 = STATE_MOUSE_NO_DEVICE; // // Enable Clocking to the USB controller. // USB0ModuleClkConfig(); } else { //g_eMouseState1 = STATE_MOUSE_NO_DEVICE; //g_eMouseUIState1 = STATE_MOUSE_NO_DEVICE; } // //Setup the AINT Controller // USBInterruptEnable(instance); // // Register the host class drivers. // USBHCDRegisterDrivers(USB_INSTANCE_Host_Mouse, g_ppHostClassDrivers, g_ulNumHostClassDrivers); // // Open an instance of the mouse driver. The mouse does not need // to be present at this time, this just saves a place for it and allows // the applications to be notified when a mouse is present. // g_ulMouseInstance = USBHMouseOpen(USB_INSTANCE_Host_Mouse, MouseCallback, g_pucMouseBuffer, MOUSE_MEMORY_SIZE); // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(USB_INSTANCE_Host_Mouse, USBHCD_VBUS_AUTO_HIGH); // // Initialize the host controller stack. // USBHCDInit(USB_INSTANCE_Host_Mouse, g_pHCDPool, MOUSE_MEMORY_SIZE); // // Call the main loop for the Host controller driver. // USBHCDMain(USB_INSTANCE_Host_Mouse, g_ulMouseInstance); }
//***************************************************************************** // // Calls the USB host stack tick function. // // This function is called periodically to allow the USB host stack to // process any outstanding items. // // \return None. // //***************************************************************************** void ScopeUSBHostTick(void) { tBoolean bRetcode; // // Call the stack to allow it to perform any processing needing done. // USBHCDMain(); // // See if we need to do anything here. // if(g_eState == STATE_DEVICE_ENUM) { // // Take it easy on the Mass storage device if it is slow to // start up after connecting. // if(USBHMSCDriveReady(g_ulMSCInstance) != 0) { // // Wait about 500ms before attempting to check if the // device is ready again. // SysCtlDelay(SysCtlClockGet()/(3*2)); } else { // // The device is available. Try to open its root directory just // to make sure it is accessible. // bRetcode = FileIsDrivePresent(1); if(bRetcode) { // // The USB drive is accessible so dump a message and set the state // to indicate that the device is ready for use. // UARTprintf("Opened root directory - USB drive present.\n"); RendererSetAlert("USB drive\ndetected.", 200); g_eState = STATE_DEVICE_READY; } } } }
void usbMscProcess() { USBHCDMain(USB_INSTANCE_FOR_USBDISK, g_ulMSCInstance); switch (g_usbMscState) { case USBMSC_NO_DEVICE: break; case USBMSC_DEVICE_ENUM: if (USBHMSCDriveReady(g_ulMSCInstance) == 0) { f_mount(FatFS_Drive_Index, &g_sFatFs); g_usbMscState = USBMSC_DEVICE_READY; } break; case USBMSC_DEVICE_READY: break; default: break; } }
//***************************************************************************** // // Initializes the USB stack for mass storage. // //***************************************************************************** void USBStickInit(void) { // // Enable the uDMA controller and set up the control table base. // The uDMA controller is used by the USB library. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); MAP_uDMAEnable(); MAP_uDMAControlBaseSet(g_psDMAControlTable); // // Initially wait for device connection. // g_iState = eSTATE_NO_DEVICE; // // 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 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); // // Run initial pass through USB host stack. // USBHCDMain(); // // Initialize the file system. // FileInit(); }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { tRectangle sRect; unsigned int i; unsigned char *src, *dest; // //configures arm interrupt controller to generate raster interrupt // SetupIntc(); // //Configures raster to display image // SetUpLCD(); /* configuring the base ceiling */ RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int)(g_pucBuffer+PALETTE_OFFSET), (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET, 0); RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int)(g_pucBuffer+PALETTE_OFFSET), (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET, 1); // Copy palette info into buffer src = (unsigned char *) palette_32b; dest = (unsigned char *) (g_pucBuffer+PALETTE_OFFSET); for( i = 4; i < (PALETTE_SIZE+4); i++) { *dest++ = *src++; } GrOffScreen16BPPInit(&g_sSHARP480x272x16Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT); GrContextInit(&g_sContext, &g_sSHARP480x272x16Display); /* enable End of frame interrupt */ RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS); /* enable raster */ RasterEnable(SOC_LCDC_0_REGS); ConfigRasterDisplayEnable(); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = DISPLAY_BANNER_HEIGHT; // // Set the banner background. // GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, &g_sFontCm20); GrStringDrawCentered(&g_sContext, "usb host keyboard", -1, GrContextDpyWidthGet(&g_sContext) / 2, 10, 0); // //Setup the interrupt controller // #ifdef _TMS320C6X SetupDSPINTCInt(); ConfigureDSPINTCIntUSB(); #else SetupAINTCInt(); ConfigureAINTCIntUSB(); #endif DelayTimerSetup(); // // Calculate the number of characters that will fit on a line. // Make sure to leave a small border for the text box. // g_ulCharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 4) / GrFontMaxWidthGet(&g_sFontCm20); // // Calculate the number of lines per usable text screen. This requires // taking off space for the top and bottom banners and adding a small bit // for a border. // g_ulLinesPerScreen = (GrContextDpyHeightGet(&g_sContext) - (2*(DISPLAY_BANNER_HEIGHT + 1)))/ GrFontHeightGet(&g_sFontCm20); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ulNumHostClassDrivers); // Open an instance of the keyboard driver. The keyboard does not need // to be present at this time, this just save a place for it and allows // the applications to be notified when a keyboard is present. // g_ulKeyboardInstance = USBHKeyboardOpen(KeyboardCallback, g_pucBuffer, KEYBOARD_MEMORY_SIZE); // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH); // // Initialize the host controller stack. // USBHCDInit(0, g_pHCDPool, HCD_MEMORY_SIZE); // // Call the main loop for the Host controller driver. // USBHCDMain(); // // Initial update of the screen. // UpdateStatus(); // // The main loop for the application. // while(1) { switch(g_eUSBState) { // // This state is entered when they keyboard is first detected. // case STATE_KEYBOARD_INIT: { // // Initialized the newly connected keyboard. // USBHKeyboardInit(g_ulKeyboardInstance); // // Proceed to the keyboard connected state. // g_eUSBState = STATE_KEYBOARD_CONNECTED; // // Update the screen now that the keyboard has been // initialized. // UpdateStatus(); break; } case STATE_KEYBOARD_UPDATE: { // // If the application detected a change that required an // update to be sent to the keyboard to change the modifier // state then call it and return to the connected state. // g_eUSBState = STATE_KEYBOARD_CONNECTED; USBHKeyboardModifierSet(g_ulKeyboardInstance, g_ulModifiers); break; } case STATE_KEYBOARD_CONNECTED: { // // Nothing is currently done in the main loop when the keyboard // is connected. // break; } case STATE_UNKNOWN_DEVICE: { // // Nothing to do as the device is unknown. // break; } case STATE_NO_DEVICE: { // // Nothing is currently done in the main loop when the keyboard // is not connected. // break; } default: { break; } } // // Periodic call the main loop for the Host controller driver. // USBHCDMain(); } }
void _usb_mouse_host_idle(unsigned int instance, tControlCommandData *control_comand) { MouseState = 0; switch(eMouseState) { // // This state is entered when the mouse is first detected. // case STATE_MOUSE_INIT: { // // Initialize the newly connected mouse. // USBHMouseInit(g_ulMouseInstance); // // Proceed to the mouse connected state. // eMouseState = STATE_MOUSE_CONNECTED; MouseState = 1; // // Update the status on the screen. // //UpdateStatus(); break; } case STATE_MOUSE_CONNECTED: { // // Nothing is currently done in the main loop when the mouse // is connected. // MouseState = 2; break; } case STATE_MOUSE_NO_DEVICE: { // // The mouse is not connected so nothing needs to be done here. // MouseState = 3; break; } default: { break; } } USBHCDMain(USB_INSTANCE_Host_Mouse, g_ulMouseInstance); control_comand->X = MouseXPosition; control_comand->Y = MouseYPosition; if(MouseClkDrLastState == Cursor_NoAction && (g_ulButtons & 0x1)) { MouseClkDrLastState = Cursor_Down; control_comand->Cursor = Cursor_Down; } else if((MouseClkDrLastState == Cursor_Down || MouseClkDrLastState == Cursor_Move) && (g_ulButtons & 0x1)) { MouseClkDrLastState = Cursor_Move; control_comand->Cursor = Cursor_Move; } else if((MouseClkDrLastState == Cursor_Down || MouseClkDrLastState == Cursor_Move) && (~g_ulButtons & 0x1)) { MouseClkDrLastState = Cursor_Up; control_comand->Cursor = Cursor_Up; } else if(MouseClkDrLastState == Cursor_Up && (~g_ulButtons & 0x1)) { MouseClkDrLastState = Cursor_NoAction; control_comand->Cursor = Cursor_NoAction; } if(MousePositionChange) { control_comand->WindowRefresh |= true; MousePositionChange = false; } }
//***************************************************************************** // // The main application loop. // //***************************************************************************** int main(void) { int32_t i32Status, i32Idx; uint32_t ui32SysClock, ui32PLLRate; #ifdef USE_ULPI uint32_t ui32Setting; #endif ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Set the part pin out appropriately for this device. // PinoutSet(); #ifdef USE_ULPI // // Switch the USB ULPI Pins over. // USBULPIPinoutSet(); // // Enable USB ULPI with high speed support. // ui32Setting = USBLIB_FEATURE_ULPI_HS; USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting); // // Setting the PLL frequency to zero tells the USB library to use the // external USB clock. // ui32PLLRate = 0; #else // // Save the PLL rate used by this application. // ui32PLLRate = 480000000; #endif // // Initialize the hub port status. // for(i32Idx = 0; i32Idx < NUM_HUB_STATUS; i32Idx++) { g_psHubStatus[i32Idx].bConnected = false; } // // Enable Clocking to the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Enable Interrupts // ROM_IntMasterEnable(); // // Initialize the USB stack mode and pass in a mode callback. // USBStackModeSet(0, eUSBModeHost, 0); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers); // // Open the Keyboard interface. // KeyboardOpen(); MSCOpen(ui32SysClock); // // Open a hub instance and provide it with the memory required to hold // configuration descriptors for each attached device. // USBHHubOpen(HubCallback); // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER); // // Tell the USB library the CPU clock and the PLL frequency. // USBOTGFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock); USBOTGFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate); // // Initialize the USB controller for Host mode. // USBHCDInit(0, g_pui8HCDPool, sizeof(g_pui8HCDPool)); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&g_sContext, "usb-host-hub"); // // Calculate the number of characters that will fit on a line. // Make sure to leave a small border for the text box. // g_ui32CharsPerLine = (GrContextDpyWidthGet(&g_sContext) - 16) / GrFontMaxWidthGet(g_psFontFixed6x8); // // Calculate the number of lines per usable text screen. This requires // taking off space for the top and bottom banners and adding a small bit // for a border. // g_ui32LinesPerScreen = (GrContextDpyHeightGet(&g_sContext) - (2*(DISPLAY_BANNER_HEIGHT + 1)))/ GrFontHeightGet(g_psFontFixed6x8); // // Initial update of the screen. // UpdateStatus(0); UpdateStatus(1); UpdateStatus(2); UpdateStatus(3); g_ui32CmdIdx = 0; g_ui32CurrentLine = 0; // // Initialize the file system. // FileInit(); // // The main loop for the application. // while(1) { // // Print a prompt to the console. Show the CWD. // WriteString("> "); // // Is there a command waiting to be processed? // while((g_ui32Flags & FLAG_CMD_READY) == 0) { // // Call the YSB library to let non-interrupt code run. // USBHCDMain(); // // Call the keyboard and mass storage main routines. // KeyboardMain(); MSCMain(); } // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32Status = CmdLineProcess(g_pcCmdBuf); // // Handle the case of bad command. // if(i32Status == CMDLINE_BAD_CMD) { WriteString("Bad command!\n"); } // // Handle the case of too many arguments. // else if(i32Status == CMDLINE_TOO_MANY_ARGS) { WriteString("Too many arguments for command processor!\n"); } // // Otherwise the command was executed. Print the error // code if one was returned. // else if(i32Status != 0) { WriteString("Command returned error code\n"); WriteString((char *)StringFromFresult((FRESULT)i32Status)); WriteString("\n"); } // // Reset the command flag and the command index. // g_ui32Flags &= ~FLAG_CMD_READY; g_ui32CmdIdx = 0; } }
//***************************************************************************** // // The program main function. It performs initialization, then runs a loop to // process USB activities and operate the user interface. // //***************************************************************************** int main(void) { uint32_t ui32DriveTimeout; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the system clock to run at 50MHz from the PLL. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Configure the required pins for USB operation. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); ROM_GPIOPinConfigure(GPIO_PG4_USB0EPEN); ROM_GPIOPinTypeUSBDigital(GPIO_PORTG_BASE, GPIO_PIN_4); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTL_BASE, GPIO_PIN_6 | GPIO_PIN_7); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Configure SysTick for a 100Hz interrupt. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); ROM_SysTickIntEnable(); // // Enable the uDMA controller and set up the control table base. // The uDMA controller is used by the USB library. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Enable Interrupts // ROM_IntMasterEnable(); // // Initialize the display driver. // CFAL96x64x16Init(); // // Initialize the buttons driver. // ButtonsInit(); // // Initialize two offscreen displays and assign the palette. These // buffers are used by the slide menu widget to allow animation effects. // GrOffScreen4BPPInit(&g_sOffscreenDisplayA, g_pui8OffscreenBufA, 96, 64); GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayA, g_pui32Palette, 0, NUM_PALETTE_ENTRIES); GrOffScreen4BPPInit(&g_sOffscreenDisplayB, g_pui8OffscreenBufB, 96, 64); GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplayB, g_pui32Palette, 0, NUM_PALETTE_ENTRIES); // // Show an initial status screen // g_pcStatusLines[0] = "Waiting"; g_pcStatusLines[1] = "for device"; ShowStatusScreen(g_pcStatusLines, 2); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sFileMenuWidget); // // 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_pui8HCDPool, HCD_MEMORY_SIZE); // // Initialize the file system. // FileInit(); // // Enter an infinite loop to run the user interface and process USB // events. // while(1) { uint32_t ui32LastTickCount = 0; // // Call the USB stack to keep it running. // USBHCDMain(); // // Process any messages in the widget message queue. This keeps the // display UI running. // WidgetMessageQueueProcess(); // // Take action based on the application state. // switch(g_eState) { // // A device has enumerated. // case STATE_DEVICE_ENUM: { // // Check to see if the device is ready. If not then stay // in this state and we will check it again on the next pass. // if(USBHMSCDriveReady(g_psMSCInstance) != 0) { // // Wait about 500ms before attempting to check if the // device is ready again. // ROM_SysCtlDelay(ROM_SysCtlClockGet()/(3)); // // 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_pcCwdBuf[0] = '/'; g_pcCwdBuf[1] = 0; // // Set the initial directory level to the root // g_ui32Level = 0; // // We need to reset the indexes of the root menu to 0, so that // it will start at the top of the file list, and reset the // slide menu widget to start with the root menu. // g_psFileMenus[g_ui32Level].ui32CenterIndex = 0; g_psFileMenus[g_ui32Level].ui32FocusIndex = 0; SlideMenuMenuSet(&g_sFileMenuWidget, &g_psFileMenus[g_ui32Level]); // // Initiate a directory change to the root. This will // populate a menu structure representing the root directory. // if(ProcessDirChange("/", g_ui32Level)) { // // 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; // // Request a repaint so the file menu will be shown // WidgetPaint(WIDGET_ROOT); } break; } // // If there is no device then just wait for one. // case STATE_NO_DEVICE: { if(g_ui32Flags == FLAGS_DEVICE_PRESENT) { // // Show waiting message on screen // g_pcStatusLines[0] = "Waiting"; g_pcStatusLines[1] = "for device"; ShowStatusScreen(g_pcStatusLines, 2); // // 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. // g_pcStatusLines[0] = "Unknown"; g_pcStatusLines[1] = "device"; ShowStatusScreen(g_pcStatusLines, 2); } // // 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. // g_pcStatusLines[0] = "Device"; g_pcStatusLines[1] = "Timeout"; ShowStatusScreen(g_pcStatusLines, 2); } // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // The device is ready and in use. // case STATE_DEVICE_READY: { // // Process occurrence of timer tick. Check for user input // once each tick. // if(g_ui32SysTickCount != ui32LastTickCount) { uint8_t ui8ButtonState; uint8_t ui8ButtonChanged; ui32LastTickCount = g_ui32SysTickCount; // // Get the current debounced state of the buttons. // ui8ButtonState = ButtonsPoll(&ui8ButtonChanged, 0); // // If select button or right button is pressed, then we // are trying to descend into another directory // if(BUTTON_PRESSED(SELECT_BUTTON, ui8ButtonState, ui8ButtonChanged) || BUTTON_PRESSED(RIGHT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { uint32_t ui32NewLevel; uint32_t ui32ItemIdx; char *pcItemName; // // Get a pointer to the current menu for this CWD. // tSlideMenu *psMenu = &g_psFileMenus[g_ui32Level]; // // Get the highlighted index in the current file list. // This is the currently highlighted file or dir // on the display. Then get the name of the file at // this index. // ui32ItemIdx = SlideMenuFocusItemGet(psMenu); pcItemName = psMenu->psSlideMenuItems[ui32ItemIdx].pcText; // // Make sure we are not yet past the maximum tree // depth. // if(g_ui32Level < MAX_SUBDIR_DEPTH) { // // Potential new level is one greater than the // current level. // ui32NewLevel = g_ui32Level + 1; // // Process the directory change to the new // directory. This function will populate a menu // structure with the files and subdirs in the new // directory. // if(ProcessDirChange(pcItemName, ui32NewLevel)) { // // If the change was successful, then update // the level. // g_ui32Level = ui32NewLevel; // // Now that all the prep is done, send the // KEY_RIGHT message to the widget and it will // "slide" from the previous file list to the // new file list of the CWD. // SendWidgetKeyMessage(WIDGET_MSG_KEY_RIGHT); } } } // // If the UP button is pressed, just pass it to the widget // which will handle scrolling the list of files. // if(BUTTON_PRESSED(UP_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_UP); } // // If the DOWN button is pressed, just pass it to the widget // which will handle scrolling the list of files. // if(BUTTON_PRESSED(DOWN_BUTTON, ui8ButtonState, ui8ButtonChanged)) { SendWidgetKeyMessage(WIDGET_MSG_KEY_DOWN); } // // If the LEFT button is pressed, then we are attempting // to go up a level in the file system. // if(BUTTON_PRESSED(LEFT_BUTTON, ui8ButtonState, ui8ButtonChanged)) { uint32_t ui32NewLevel; // // Make sure we are not already at the top of the // directory tree (at root). // if(g_ui32Level) { // // Potential new level is one less than the // current level. // ui32NewLevel = g_ui32Level - 1; // // Process the directory change to the new // directory. This function will populate a menu // structure with the files and subdirs in the new // directory. // if(ProcessDirChange("..", ui32NewLevel)) { // // If the change was successful, then update // the level. // g_ui32Level = ui32NewLevel; // // Now that all the prep is done, send the // KEY_LEFT message to the widget and it will // "slide" from the previous file list to the // new file list of the CWD. // SendWidgetKeyMessage(WIDGET_MSG_KEY_LEFT); } } } } break; } // // Something has caused a power fault. // case STATE_POWER_FAULT: { // // Clear the screen and show a power fault indication. // g_pcStatusLines[0] = "Power"; g_pcStatusLines[1] = "fault"; ShowStatusScreen(g_pcStatusLines, 2); break; } default: { break; } } } }
//***************************************************************************** // // The main application loop. // //***************************************************************************** int main(void) { uint32_t ui32SysClock, ui32PLLRate; #ifdef USE_ULPI uint32_t ui32Setting; #endif // // Set the application to run at 120 MHz with a PLL frequency of 480 MHz. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Set the part pin out appropriately for this device. // PinoutSet(); #ifdef USE_ULPI // // Switch the USB ULPI Pins over. // USBULPIPinoutSet(); // // Enable USB ULPI with high speed support. // ui32Setting = USBLIB_FEATURE_ULPI_HS; USBOTGFeatureSet(0, USBLIB_FEATURE_USBULPI, &ui32Setting); // // Setting the PLL frequency to zero tells the USB library to use the // external USB clock. // ui32PLLRate = 0; #else // // Save the PLL rate used by this application. // ui32PLLRate = 480000000; #endif // // Initialize the connection status. // g_sStatus.bConnected = false; // // Initially there are no modifiers set. // g_sStatus.ui32Modifiers = 0; // // Enable Clocking to the USB controller. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_USB0); // // Enable Interrupts // ROM_IntMasterEnable(); // // Initialize the USB stack mode and pass in a mode callback. // USBStackModeSet(0, eUSBModeHost, 0); // // Register the host class drivers. // USBHCDRegisterDrivers(0, g_ppHostClassDrivers, g_ui32NumHostClassDrivers); // // Open 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_psKeyboard = USBHKeyboardOpen(KeyboardCallback, 0, 0); // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(0, USBHCD_VBUS_AUTO_HIGH | USBHCD_VBUS_FILTER); // // Tell the USB library the CPU clock and the PLL frequency. This is a // new requirement for TM4C129 devices. // USBHCDFeatureSet(0, USBLIB_FEATURE_CPUCLK, &ui32SysClock); USBHCDFeatureSet(0, USBLIB_FEATURE_USBPLL, &ui32PLLRate); // // Initialize the USB controller for Host mode. // USBHCDInit(0, g_pui8HCDPool, sizeof(g_pui8HCDPool)); // // Initialize the GUI elements. // UIInit(ui32SysClock); // // The main loop for the application. // while(1) { // // Call the USB library to let non-interrupt code run. // USBHCDMain(); // // Call the keyboard and mass storage main routines. // KeyboardMain(); } }
//***************************************************************************** // // 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; } } } }
//***************************************************************************** // // This is called by the application main loop to perform regular processing. // It keeps the USB host stack running and tracks the state of the attached // device. // //***************************************************************************** void USBStickRun(void) { // // Call the USB stack to keep it running. // USBHCDMain(); // // Take action based on the application state. // switch(g_iState) { // // A device has enumerated. // case eSTATE_DEVICE_ENUM: { // // Check to see if the device is ready. If not then stay // in this state and we will check it again on the next pass. // if(USBHMSCDriveReady(g_psMSCInstance) != 0) { // // Wait about 500ms before attempting to check if the // device is ready again. // MAP_SysCtlDelay(MAP_SysCtlClockGet()/3); break; } // // If there were no errors reported, we are ready for // MSC operation. // g_iState = eSTATE_DEVICE_READY; // // Set the Device Present flag. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // If there is no device then just wait for one. // case eSTATE_NO_DEVICE: { if(g_ui32Flags == FLAGS_DEVICE_PRESENT) { // // Clear the Device Present flag. // g_ui32Flags &= ~(FLAGS_DEVICE_PRESENT | FLAGS_FILE_OPENED); } break; } // // An unknown device was connected. // case eSTATE_UNKNOWN_DEVICE: { // // If this is a new device then change the status. // if((g_ui32Flags & FLAGS_DEVICE_PRESENT) == 0) { // // Unknown device is present // } // // Set the Device Present flag even though the unknown device // is not useful to us. // g_ui32Flags = FLAGS_DEVICE_PRESENT; break; } // // The device is ready and in use. // case eSTATE_DEVICE_READY: { break; } // // Something has caused a power fault. // case eSTATE_POWER_FAULT: { break; } // // Unexpected USB state. Set back to default. // default: { g_iState = eSTATE_NO_DEVICE; g_ui32Flags &= ~(FLAGS_DEVICE_PRESENT | FLAGS_FILE_OPENED); break; } } }
//***************************************************************************** // // 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 loop that runs the application. // //***************************************************************************** int main(void) { tRectangle sRect; unsigned int i; unsigned char *src, *dest; MMUConfigAndEnable(); // //configures arm interrupt controller to generate raster interrupt // USBInterruptEnable(USB_INSTANCE); // //LCD back light setup // LCDBackLightEnable(); // //UPD Pin setup // UPDNPinControl(); // //Delay timer setup // DelayTimerSetup(); // //Configures raster to display image // SetUpLCD(); /* configuring the base ceiling */ RasterDMAFBConfig(SOC_LCDC_0_REGS, (unsigned int)(g_pucBuffer+PALETTE_OFFSET), (unsigned int)(g_pucBuffer+PALETTE_OFFSET) + sizeof(g_pucBuffer) - 2 - PALETTE_OFFSET, 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_800x480x24Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT); // Initialize a drawing context. GrContextInit(&g_sContext, &g_s35_800x480x24Display); /* enable End of frame interrupt */ RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS); /* enable raster */ RasterEnable(SOC_LCDC_0_REGS); // // Fill the top 15 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = DISPLAY_BANNER_HEIGHT; // // Set the banner background. // GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_BG); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, DISPLAY_BANNER_FG); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, &g_sFontCm20); GrStringDrawCentered(&g_sContext, "usb_host_mouse", -1, GrContextDpyWidthGet(&g_sContext) / 2, 10, 0); // // Register the host class drivers. // USBHCDRegisterDrivers(USB_INSTANCE, g_ppHostClassDrivers, g_ulNumHostClassDrivers); // // Initialized the cursor. // g_ulButtons = 0; g_sCursor.sXMin = GrContextDpyWidthGet(&g_sContext) / 2; g_sCursor.sXMax = g_sCursor.sXMin + DISPLAY_MOUSE_SIZE; g_sCursor.sYMin = GrContextDpyHeightGet(&g_sContext) / 2; g_sCursor.sYMax = g_sCursor.sYMin + DISPLAY_MOUSE_SIZE; // // Update the status on the screen. // UpdateStatus(); // // Update the cursor once to display it. // UpdateCursor(0, 0); // // Open an instance of the mouse driver. The mouse does not need // to be present at this time, this just saves a place for it and allows // the applications to be notified when a mouse is present. // g_ulMouseInstance = USBHMouseOpen(USB_INSTANCE, MouseCallback, g_pucMouseBuffer, MOUSE_MEMORY_SIZE); // // Initialize the power configuration. This sets the power enable signal // to be active high and does not enable the power fault. // USBHCDPowerConfigInit(USB_INSTANCE, USBHCD_VBUS_AUTO_HIGH); // // Initialize the host controller stack. // USBHCDInit(USB_INSTANCE, g_pHCDPool, HCD_MEMORY_SIZE); // // Call the main loop for the Host controller driver. // USBHCDMain(USB_INSTANCE, g_ulMouseInstance); // // The main loop for the application. // while(1) { switch(eUSBState) { // // This state is entered when the mouse is first detected. // case STATE_MOUSE_INIT: { // // Initialize the newly connected mouse. // USBHMouseInit(g_ulMouseInstance); // // Proceed to the mouse connected state. // eUSBState = STATE_MOUSE_CONNECTED; // // Update the status on the screen. // UpdateStatus(); break; } case STATE_MOUSE_CONNECTED: { // // Nothing is currently done in the main loop when the mouse // is connected. // break; } case STATE_NO_DEVICE: { // // The mouse is not connected so nothing needs to be done here. // break; } default: { break; } } // // Periodically call the main loop for the Host controller driver. // USBHCDMain(USB_INSTANCE, g_ulMouseInstance); } }
//***************************************************************************** // //! This function is the main routine for the OTG Controller Driver. //! //! \param ui32MsTicks is the number of milliseconds that have passed since the //! last time this function was called. //! //! This function is the main routine for the USB controller when using the //! library in OTG mode. This routine must be called periodically by the main //! application outside of a callback context. The \e ui32MsTicks value is //! used for basic timing needed by the USB library when operating in OTG mode. //! This allows for a simple cooperative system to access the the OTG //! controller driver interface without the need for an RTOS. All time //! critical operations are handled in interrupt context but all longer //! operations are run from the this function to allow them to block and wait //! for completion without holding off other interrupts. //! //! \return None. // //***************************************************************************** void USBOTGMain(uint32_t ui32MsTicks) { tEventInfo sEvent; if(ui32MsTicks > g_ui32WaitTicks) { g_ui32WaitTicks = 0; } else { g_ui32WaitTicks -= ui32MsTicks; } switch(g_eOTGModeState) { case eUSBOTGModeIdle: { g_eOTGModeState = eUSBOTGModeWaitID; // // Initiate a session request and check the ID pin. // USBOTGSessionRequest(USB0_BASE, true); break; } case eUSBOTGModeWait: case eUSBOTGModeWaitID: { // // If reached the timeout and polling is enabled then look again. // if((g_ui32WaitTicks == 0) && (g_ui32PollRate != 0)) { // // Remove the session request. // USBOTGSessionRequest(USB0_BASE, false); // // Return to idle mode. // USBOTGSetMode(eUSBModeNone); // // Check if the controller is automatically applying power or // not. // if(USBHCDPowerAutomatic(0) == 0) { // // Call the registered event driver to allow it to disable // power. // sEvent.ui32Event = USB_EVENT_POWER_DISABLE; sEvent.ui32Instance = 0; InternalUSBHCDSendEvent(0, &sEvent, USBHCD_EVFLAG_PWRDIS); } // // Go back to the idle state. // g_eOTGModeState = eUSBOTGModeIdle; } break; } case eUSBOTGModeAHost: { // // Call the host main routine when acting as a host. // USBHCDMain(); break; } case eUSBOTGModeBWaitCon: case eUSBOTGModeBDevice: default: { break; } } }
//***************************************************************************** // // 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; } } } }