void composite_device_init() { tUSBDMSCDevice *psDevice; // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // g_psCompDevices[0].pvInstance = USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); backUpCompDevices[0].pvInstance = g_psCompDevices[0].pvInstance; // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); psDevice = g_psCompDevices[0].pvInstance; store = psDevice->psPrivateData->pvMedia; //make a copy of the media to restore later }
//**************************************************************************** // // This is the main loop that runs the application. // //**************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // g_psCompDevices[0].pvInstance = USBDHIDMouseCompositeInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); // // Initialize the mouse and serial devices. // MouseInit(); SerialInit(); // // Drop into the main loop. // while(1) { // // Allow the main mouse routine to run. // MouseMain(); // // Allow the main serial routine to run. // SerialMain(); } }
/* Initialise the USB bulk device */ void usb_init() { /* Zero status variables */ USBConfigured = 0; USBDataAvail = 0; /* USB module clock enable */ USB0ModuleClkConfig(); /* Registering the Interrupt Service Routine (ISR) */ IntRegister(SYS_INT_USB0, USB0DeviceIntHandler); /* Setting the priority for the system interrupt in AINTC - set it high to allow USB to be prempted */ IntPrioritySet(SYS_INT_USB0, 127, AINTC_HOSTINT_ROUTE_IRQ); /* Enabling the system interrupt in AINTC */ IntSystemEnable(SYS_INT_USB0); /* Enable the delay timer */ DelayTimerSetup(); /* Initialize the transmit and receive buffers */ USBBufferInit((tUSBBuffer *)&g_sTxBulkBuffer); USBBufferInit((tUSBBuffer *)&g_sRxBulkBuffer); USBBufferInit((tUSBBuffer *)&g_sTxCDCBuffer); USBBufferInit((tUSBBuffer *)&g_sRxCDCBuffer); /* Register the two instances */ g_psCompDevices[0].pvInstance = USBDBulkCompositeInit(0, (tUSBDBulkDevice *)&g_sBulkDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); /* Register our device and place it on the bus */ USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { // // Turn on stacking of FPU registers if FPU is used in the ISR. // FPULazyStackingEnable(); // // Set the clocking to run from the PLL at 40MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Enable the Debug UART. // ConfigureUART(); // // Print the welcome message to the terminal. // UARTprintf("\033[2JAir Mouse Application\n"); // // Configure desired interrupt priorities. This makes certain that the DCM // is fed data at a consistent rate. Lower numbers equal higher priority. // ROM_IntPrioritySet(INT_I2C3, 0x00); ROM_IntPrioritySet(INT_GPIOB, 0x10); ROM_IntPrioritySet(FAULT_SYSTICK, 0x20); ROM_IntPrioritySet(INT_UART1, 0x60); ROM_IntPrioritySet(INT_UART0, 0x70); ROM_IntPrioritySet(INT_WTIMER5B, 0x80); // // Configure the USB D+ and D- pins. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_5 | GPIO_PIN_4); // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // USBDHIDMouseCompositeInit(0, &g_sMouseDevice, &g_psCompDevices[0]); USBDHIDKeyboardCompositeInit(0, &g_sKeyboardDevice, &g_psCompDevices[1]); // // Set the USB stack mode to Force Device mode. // USBStackModeSet(0, eUSBModeForceDevice, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pui8DescriptorData); // // User Interface Init // ButtonsInit(); RGBInit(0); RGBEnable(); // // Initialize the motion sub system. // MotionInit(); // // Initialize the Radio Systems. // LPRFInit(); // // Drop into the main loop. // while(1) { // // Check for and handle timer tick events. // if(HWREGBITW(&g_ui32Events, USB_TICK_EVENT) == 1) { // // Clear the Tick event flag. Set in SysTick interrupt handler. // HWREGBITW(&g_ui32Events, USB_TICK_EVENT) = 0; // // Each tick period handle wired mouse and keyboard. // if(HWREGBITW(&g_ui32USBFlags, FLAG_CONNECTED) == 1) { MouseMoveHandler(); KeyboardMain(); } } // // Check for LPRF tick events. LPRF Ticks are slower since UART to // RNP is much slower data connection than the USB. // if(HWREGBITW(&g_ui32Events, LPRF_TICK_EVENT) == 1) { // // Clear the event flag. // HWREGBITW(&g_ui32Events, LPRF_TICK_EVENT) = 0; // // Perform the LPRF Main task handling // LPRFMain(); } // // Check for and handle motion events. // if((HWREGBITW(&g_ui32Events, MOTION_EVENT) == 1) || (HWREGBITW(&g_ui32Events, MOTION_ERROR_EVENT) == 1)) { // // Clear the motion event flag. Set in the Motion I2C interrupt // handler when an I2C transaction to get sensor data is complete. // HWREGBITW(&g_ui32Events, MOTION_EVENT) = 0; // // Process the motion data that has been captured // MotionMain(); } } }
/***************************************************************************** * * This is the main loop that runs the application. * *****************************************************************************/ int main(void) { tRectangle sRect; MMUConfigAndEnable(); /* Enable USB module clock */ USB0ModuleClkConfig(); /* configures arm interrupt controller to generate raster interrupt */ USBInterruptEnable(); /* LCD Back light setup */ LCDBackLightEnable(); /* UPD Pin setup */ UPDNPinControl(); /* Delay timer setup */ DelayTimerSetup(); /* Configures raster to display image */ SetUpLCD(); /* Configures raster to display image and Copy palette info into buffer */ LCDInit(); 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 24 rows of the screen with blue to create the banner. */ sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = (MAX_ROW_NUM - 1); GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); /* Put a white box around the banner. */ GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); /* Put the application name in the middle of the banner. */ GrContextFontSet(&g_sContext, &g_sFontCm20); GrStringDrawCentered(&g_sContext, "usb-dev-composite", -1, GrContextDpyWidthGet(&g_sContext) / 2, 10, 0); /* Show the various static text elements on the color STN display. */ GrContextFontSet(&g_sContext, TEXT_FONT); GrContextForegroundSet(&g_sContext, ClrViolet); GrStringDraw(&g_sContext, "CDC Serial 1 :-", -1, CDC1_STR_X_POSITION, CDC1_STR_Y_POSITION, false); GrStringDraw(&g_sContext, "CDC Serial 2 :-", -1, CDC2_STR_X_POSITION, CDC1_STR_Y_POSITION, false); GrContextForegroundSet(&g_sContext, ClrWhite); GrStringDraw(&g_sContext, "Tx bytes:", -1, CDC1_STR_X_POSITION, (CDC1_STR_Y_POSITION + CDC_STR_Y_DIFF), false); GrStringDraw(&g_sContext, "Tx buffer:", -1, CDC1_STR_X_POSITION, (CDC1_STR_Y_POSITION + (CDC_STR_Y_DIFF * 2)), false); GrStringDraw(&g_sContext, "Rx bytes:", -1, CDC1_STR_X_POSITION, (CDC1_STR_Y_POSITION + (CDC_STR_Y_DIFF * 4)), false); GrStringDraw(&g_sContext, "Rx buffer:", -1, CDC1_STR_X_POSITION, (CDC1_STR_Y_POSITION + (CDC_STR_Y_DIFF * 5)), false); DrawBufferMeter(&g_sContext, CDC1_BUF_METER_X_POS, CDC1_BUF_METER_Y_POS); DrawBufferMeter(&g_sContext, CDC1_BUF_METER_X_POS, (CDC1_BUF_METER_Y_POS + CDC_BUF_METER_Y_DIFF)); GrStringDraw(&g_sContext, "Tx bytes:", -1, CDC2_STR_X_POSITION, (CDC2_STR_Y_POSITION + CDC_STR_Y_DIFF), false); GrStringDraw(&g_sContext, "Tx buffer:", -1, CDC2_STR_X_POSITION, (CDC2_STR_Y_POSITION + (CDC_STR_Y_DIFF * 2)), false); GrStringDraw(&g_sContext, "Rx bytes:", -1, CDC2_STR_X_POSITION, (CDC2_STR_Y_POSITION + (CDC_STR_Y_DIFF * 4)), false); GrStringDraw(&g_sContext, "Rx buffer:", -1, CDC2_STR_X_POSITION, (CDC2_STR_Y_POSITION + (CDC_STR_Y_DIFF * 5)), false); DrawBufferMeter(&g_sContext, CDC2_BUF_METER_X_POS, CDC2_BUF_METER_Y_POS); DrawBufferMeter(&g_sContext, CDC2_BUF_METER_X_POS, (CDC2_BUF_METER_Y_POS + CDC_BUF_METER_Y_DIFF)); DisplayStatus(&g_sContext, " Waiting for host... "); /* Pass the USB library our device information, initialize the USB controller and connect the device to the bus. */ g_psCompDevices[0].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice1); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice2); /* Pass the device information to the USB library and place the device on the bus. */ USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); /* Initialize the serial devices. */ SerialInit(); /* Drop into the main loop. */ while(1) { /* Allow the main serial routine to run. */ SerialMain(); } }
//***************************************************************************** // // 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_16MHZ); // // Set the device pinout appropriately for this board. // PinoutSet(); #ifdef DEBUG // // Open UART0 for debug output. // UARTStdioInit(0); #endif // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the display driver. // Kitronix320x240x16_SSD2119Init(); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKitronix320x240x16_SSD2119); // // Fill the top 24 rows of the screen with blue to create the banner. // sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = 23; GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); // // Put a white box around the banner. // GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); // // Put the application name in the middle of the banner. // GrContextFontSet(&g_sContext, g_pFontCm20); GrStringDrawCentered(&g_sContext, "boot-demo-usb", -1, GrContextDpyWidthGet(&g_sContext) / 2, 10, 0); // // Draw the buttons in their initial (unpressed)state. // UpdateDisplay(g_ucButtons, true); // // 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); // // Initialize the touch screen driver. // TouchScreenInit(); // // Set the touch screen event handler. // TouchScreenCallbackSet(MouseTouchHandler); // // Drop into the main loop. // while(!g_bUpdateSignalled) { // // Tell the user what we are doing. // GrContextFontSet(&g_sContext, g_pFontCmss22b); GrContextForegroundSet(&g_sContext, ClrWhite); GrStringDrawCentered(&g_sContext, " Waiting for host... ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 40, true); // // Wait for USB configuration to complete. // while(!g_bConnected) { } // // Update the status. // GrStringDrawCentered(&g_sContext, " Host connected... ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 40, true); // // Now keep processing the mouse as long as the host is connected and // we've not been told to prepare for a firmware upgrade. // while(g_bConnected && !g_bUpdateSignalled) { // // If it is time to check the touchscreen state then do so. // if(g_ulCommands & TOUCH_TICK_EVENT) { g_ulCommands &= ~TOUCH_TICK_EVENT; TouchHandler(); } } // // If we drop out of the previous loop, either the host has // disconnected or a firmware upgrade has been signalled. // } // // Tell the user what's going on. // GrContextFontSet(&g_sContext, g_pFontCmss22b); GrStringDrawCentered(&g_sContext, " Switching to DFU mode ", -1, GrContextDpyWidthGet(&g_sContext) / 2, 40, true); // // If we get here, a firmware upgrade has been signalled so we need to get // back into the boot loader to allow this to happen. Call the USB DFU // device class to do this for us. Note that this function never returns. // USBDDFUUpdateBegin(); }
//**************************************************************************** // // This is the main loop that runs the application. // //**************************************************************************** int main(void) { // // Set the clocking to run from the PLL at 50MHz. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Configure and enable uDMA // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); SysCtlDelay(10); ROM_uDMAControlBaseSet(&sDMAControlTable[0]); ROM_uDMAEnable(); // // Initialize the idle timeout and reset all flags. // g_ulIdleTimeout = 0; g_ulFlags = 0; g_eMSCState = MSC_DEV_DISCONNECTED; // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // g_psCompDevices[0].pvInstance = USBDMSCInit(0, (tUSBDMSCDevice *)&g_sMSCDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, USB_MODE_DEVICE, 0); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); SerialInit(); disk_initialize(0); // // Drop into the main loop. // while(1) { // // Allow the main serial routine to run. // SerialMain(); switch(g_eMSCState) { case MSC_DEV_READ: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_WRITE: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } // // If there is no activity then return to the idle state. // if(g_ulIdleTimeout == 0) { g_eMSCState = MSC_DEV_IDLE; } break; } case MSC_DEV_DISCONNECTED: { // // Update the screen if necessary. // if(g_ulFlags & FLAG_UPDATE_STATUS) { g_ulFlags &= ~FLAG_UPDATE_STATUS; } break; } case MSC_DEV_IDLE: { break; } default: { break; } } } }
//***************************************************************************** // // This is the main loop that runs the application. // //***************************************************************************** int main(void) { uint32_t ui32SysClock; // // Run from the PLL at 120 MHz. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); // // Set the touch screen event handler. // TouchScreenCallbackSet(UITouchCallback); // // Set the system tick to fire 100 times per second. // ROM_SysTickPeriodSet(ui32SysClock / SYSTICKS_PER_SECOND); ROM_SysTickIntEnable(); ROM_SysTickEnable(); // // Initialize the USB stack for device mode. // USBStackModeSet(0, eUSBModeDevice, 0); // // Initialize the USB keyboard interface. // USBKeyboardInit(); // // Initialize the USB mouse interface. // USBMouseInit(); // // Call the composite device initialization for both the mouse and // keyboard. // USBDHIDMouseCompositeInit(0, &g_sMouseDevice, &g_psCompDevices[0]); USBDHIDKeyboardCompositeInit(0, &g_sKeyboardDevice, &g_psCompDevices[1]); // // Pass the device information to the USB library and place the device // on the bus. // USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pui8DescriptorData); // // Initialize the user interface. // UIInit(); while(1) { // // Run the main loop for the user interface. // UIMain(); } }
int main(void) { int i; uint8_t data[64]; // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. ROM_FPULazyStackingEnable(); // Set the clocking to run from the PLL at 50MHz. ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); // Enable the GPIO peripheral used for USB, and configure the USB // pins. ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); ROM_GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1 + GPIO_PIN_2 + GPIO_PIN_3); ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1 + GPIO_PIN_2 + GPIO_PIN_3, 0); // Init diagnostic diagnostic_clear_eventhistory(); // Init UART ConfigureUART(); // Print welcome message UARTprintf("Configuring USB\n"); //------------------------------------------------------ // // Set the USB stack mode to Device mode with VBUS monitoring. // USBStackModeSet(0, eUSBModeForceDevice, 0); // // // Pass our device information to the USB library and place the device // // on the bus. // USBDHIDInit(0, &hiddatapipe_device); //------------------------------------------------------ USBStackModeSet(0, eUSBModeForceDevice, 0); USBDHIDCompositeInit(0, &hiddatapipe_device, &(composite_device.psDevices[0])); USBDDFUCompositeInit(0, &dfu_device, &(composite_device.psDevices[1])); // // Pass the USB library our device information, initialize the USB // controller and connect the device to the bus. // USBDCompositeInit(0, &composite_device, DESCRIPTOR_BUFFER_SIZE, composite_descriptorbuffer); // Block until connected while (!usbstate.connected) ; // Configure SysTick ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 1000); // 1 ms ROM_SysTickEnable(); ROM_SysTickIntEnable(); // enable first IN report by clearing USB tx complete usbstate.txcomplete = 1; while(1) { // uncomment this if event history log is needed // if (events.print_history == true) // diagnostic_print_eventhistory(); // usbstate.txcomplete flag was set to 1 by txhandler after usbdhidreportwrite had succeeded if (usbstate.txcomplete && usbstate.txdataupdated) { // clear usbstate.txcomplete flag to indicate that usbdhidreportwrite is busy usbstate.txcomplete = 0; usbstate.txdataupdated = 0; // put data (1 byte in this case) into the usb pipeline and the host will poll&read it // the polling rate is defined in the interrupt IN endpoint descriptor data[0] = txdata.buffer[0]; // temp buffer to avoid update change of txdata.buffer between the next 2 calls USBDHIDReportWrite(&hiddatapipe_device, data, 1, 0); UARTprintf("Sending irq IN to host: %d\n", data[0]); } if (usbstate.hostsentreport) { // clear hostsentreport flag usbstate.hostsentreport = 0; for (i = 0; i < HID_REPORTOUT_SIZE; i++) { UARTprintf("Received OUT report from host: %02x\n", rxdata.buffer[i]); rxdata.buffer[i] = 0; } } } }
//***************************************************************************** // // 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(); }
/***************************************************************************** * * This is the main loop that runs the application. * *****************************************************************************/ int main(void) { tRectangle sRect; MMUConfigAndEnable(); /* Enable USB module clock */ USB0ModuleClkConfig(); /* Enable DM timer 3 module clock */ DMTimer3ModuleClkConfig(); /* Enbale touch screen module colock */ TSCADCModuleClkConfig(); /* Enable touch screen ADC pinmux */ TSCADCPinMuxSetUp(); /* configures arm interrupt controller to generate raster interrupt */ USBInterruptEnable(); /* LCD Back light setup */ LCDBackLightEnable(); /* UPD Pin setup */ UPDNPinControl(); /* Delay timer setup */ DelayTimerSetup(); /* Configures raster to display image */ SetUpLCD(); /* Register touch scren interrupt */ TouchIntRegister(); IntSystemEnable(SYS_INT_TINT3); IntPrioritySet(SYS_INT_TINT3, 0, AINTC_HOSTINT_ROUTE_IRQ); IntSystemEnable(SYS_INT_ADC_TSC_GENINT); IntPrioritySet(SYS_INT_ADC_TSC_GENINT, 0, AINTC_HOSTINT_ROUTE_IRQ); /* Configures raster to display image and Copy palette info into buffer */ LCDInit(); GrOffScreen24BPPInit(&g_s35_480x272x24Display, g_pucBuffer, LCD_WIDTH, LCD_HEIGHT); /* Initialize a drawing context. */ GrContextInit(&g_sContext, &g_s35_480x272x24Display); /* enable End of frame interrupt */ RasterEndOfFrameIntEnable(SOC_LCDC_0_REGS); /* enable raster */ RasterEnable(SOC_LCDC_0_REGS); /* Fill the top 24 rows of the screen with blue to create the banner. */ sRect.sXMin = 0; sRect.sYMin = 0; sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = (MAX_ROW_NUM - 1); GrContextForegroundSet(&g_sContext, ClrDarkBlue); GrRectFill(&g_sContext, &sRect); /* Put a white box around the banner. */ GrContextForegroundSet(&g_sContext, ClrWhite); GrRectDraw(&g_sContext, &sRect); /* Put the application name in the middle of the banner. */ GrContextFontSet(&g_sContext, &g_sFontCm20); GrStringDrawCentered(&g_sContext, "usb-dev-composite", -1, GrContextDpyWidthGet(&g_sContext) / 2, 10, 0); sRect.sXMin = 0; sRect.sYMin = (MAX_ROW_NUM + 1); sRect.sXMax = GrContextDpyWidthGet(&g_sContext) - 1; sRect.sYMax = GrContextDpyHeightGet(&g_sContext) - BUTTON_HEIGHT - 2; GrContextForegroundSet(&g_sContext, ClrBlack); GrRectFill(&g_sContext, &sRect); /* Put a white box around the banner. */ GrContextForegroundSet(&g_sContext, ClrRed); GrRectDraw(&g_sContext, &sRect); /* Draw the buttons in their initial (unpressed)state. */ UpdateDisplay(g_ucButtons, true); /* Show the various static text elements on the color STN display. */ GrContextFontSet(&g_sContext, TEXT_FONT); GrStringDraw(&g_sContext, "Tx bytes:", -1, CDC_STR_X_POSITION, CDC_STR_Y_POSITION, false); GrStringDraw(&g_sContext, "Tx buffer:", -1, CDC_STR_X_POSITION, (CDC_STR_Y_POSITION + CDC_STR_Y_DIFF), false); GrStringDraw(&g_sContext, "Rx bytes:", -1, CDC_STR_X_POSITION, (CDC_STR_Y_POSITION + (CDC_STR_Y_DIFF * 3)), false); GrStringDraw(&g_sContext, "Rx buffer:", -1, CDC_STR_X_POSITION, (CDC_STR_Y_POSITION + (CDC_STR_Y_DIFF * 4)), false); DrawBufferMeter(&g_sContext, BUFFER_METER_X_POS, BUFFER_METER_Y_POS); DrawBufferMeter(&g_sContext, BUFFER_METER_X_POS, (BUFFER_METER_Y_POS + CDC_BUF_METER_Y_DIFF)); /* Tell the user what we are up to. */ DisplayStatus(&g_sContext, " Waiting for host... "); /* Initialize touch screen */ TouchInit(); /* Touch screen Interrupt enbale */ TouchIntEnable(); /* Touch Screen Enable */ TouchEnable(); /* Pass the USB library our device information, initialize the USB controller and connect the device to the bus. */ g_psCompDevices[0].pvInstance = USBDHIDMouseCompositeInit(0, (tUSBDHIDMouseDevice *)&g_sMouseDevice); g_psCompDevices[1].pvInstance = USBDCDCCompositeInit(0, (tUSBDCDCDevice *)&g_sCDCDevice); /* Pass the device information to the USB library and place the device on the bus. */ USBDCompositeInit(0, &g_sCompDevice, DESCRIPTOR_DATA_SIZE, g_pucDescriptorData); /* Initialize the mouse and serial devices. */ SerialInit(); /* Drop into the main loop. */ while(1) { /* Allow the main serial routine to run. */ SerialMain(); /* Allow the main mouse routine to run. */ MouseMain(); } }