示例#1
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "CDC Host Demo running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);
	GlobalInterruptEnable();

	for (;;)
	{
		CDCHost_Task();

		CDC_Host_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}
示例#2
0
/** Main program entry point. This routine configures the hardware required by the application, then
		keeps calling the CDC application task for bulk data, CDC Host task for processing interrupt endpoints
		and the core USB host task.
 */
int main(void)
{
	uint8_t i;
	
	SetupHardware();
	
	serialInfCount = 0;

	DEBUGOUT("Serial Host Demo running.\r\n");

	for (;; ) {
		SerialHost_Task();

		for (i = 0; i < serialInfCount; i++) {
			CDC_Host_USBTask(&Serial_Interface[i]);
		}
		USB_USBTask(Serial_Interface[0].Config.PortNumber, USB_MODE_Host);
	}
}
示例#3
0
/** Main program entry point. This routine configures the hardware required by the application, then
 *  enters a loop to run the application tasks in sequence.
 */
int main(void)
{
	SetupHardware();

	puts_P(PSTR(ESC_FG_CYAN "CDC Host Demo running.\r\n" ESC_FG_WHITE));

	LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);

	for (;;)
	{
		switch (USB_HostState)
		{
			case HOST_STATE_Addressed:
				LEDs_SetAllLEDs(LEDMASK_USB_ENUMERATING);
			
				uint16_t ConfigDescriptorSize;
				uint8_t  ConfigDescriptorData[512];

				if (USB_Host_GetDeviceConfigDescriptor(1, &ConfigDescriptorSize, ConfigDescriptorData,
				                                       sizeof(ConfigDescriptorData)) != HOST_GETCONFIG_Successful)
				{
					printf("Error Retrieving Configuration Descriptor.\r\n");
					LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
					USB_HostState = HOST_STATE_WaitForDeviceRemoval;
					break;
				}

				if (CDC_Host_ConfigurePipes(&VirtualSerial_CDC_Interface,
				                            ConfigDescriptorSize, ConfigDescriptorData) != CDC_ENUMERROR_NoError)
				{
					printf("Attached Device Not a Valid CDC Class Device.\r\n");
					LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
					USB_HostState = HOST_STATE_WaitForDeviceRemoval;
					break;
				}
				
				if (USB_Host_SetDeviceConfiguration(1) != HOST_SENDCONTROL_Successful)
				{
					printf("Error Setting Device Configuration.\r\n");
					LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
					USB_HostState = HOST_STATE_WaitForDeviceRemoval;
					break;
				}
				
				printf("CDC Device Enumerated.\r\n");
				LEDs_SetAllLEDs(LEDMASK_USB_READY);
				USB_HostState = HOST_STATE_Configured;
				break;
			case HOST_STATE_Configured:
				if (CDC_Host_BytesReceived(&VirtualSerial_CDC_Interface))
				{
					/* Echo received bytes from the attached device through the USART */
					while (CDC_Host_BytesReceived(&VirtualSerial_CDC_Interface))
					  putchar(CDC_Host_ReceiveByte(&VirtualSerial_CDC_Interface));
					  
					CDC_Host_Flush(&VirtualSerial_CDC_Interface);  
				}
			
				break;
		}
	
		CDC_Host_USBTask(&VirtualSerial_CDC_Interface);
		USB_USBTask();
	}
}