X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/ac70ddd0a1c412bb54def48e53caaebd0b5c9c61..23f3c3deee8bd153d59f2ac4e659c71ee75915f7:/Demos/Host/LowLevel/CDCHost/CDCHost.c diff --git a/Demos/Host/LowLevel/CDCHost/CDCHost.c b/Demos/Host/LowLevel/CDCHost/CDCHost.c index 9a5e81ae4..b3e067418 100644 --- a/Demos/Host/LowLevel/CDCHost/CDCHost.c +++ b/Demos/Host/LowLevel/CDCHost/CDCHost.c @@ -132,36 +132,6 @@ void CDC_Host_Task(void) switch (USB_HostState) { case HOST_STATE_Addressed: - /* Standard request to set the device configuration to configuration 1 */ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE), - .bRequest = REQ_SetConfiguration, - .wValue = 1, - .wIndex = 0, - .wLength = 0, - }; - - /* Select the control pipe for the request transfer */ - Pipe_SelectPipe(PIPE_CONTROLPIPE); - - /* Send the request, display error and wait for device detach if request fails */ - if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful) - { - puts_P(PSTR("Control Error (Set Configuration).\r\n")); - printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode); - - /* Indicate error via status LEDs */ - LEDs_SetAllLEDs(LEDMASK_USB_ERROR); - - /* Wait until USB device disconnected */ - while (USB_IsConnected); - break; - } - - USB_HostState = HOST_STATE_Configured; - break; - case HOST_STATE_Configured: puts_P(PSTR("Getting Config Data.\r\n")); /* Get and process the configuration descriptor data */ @@ -181,7 +151,24 @@ void CDC_Host_Task(void) while (USB_IsConnected); break; } + + /* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */ + if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful) + { + puts_P(PSTR("Control Error (Set Configuration).\r\n")); + printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode); + + /* Indicate error via status LEDs */ + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + /* Wait until USB device disconnected */ + while (USB_IsConnected); + break; + } + + USB_HostState = HOST_STATE_Configured; + break; + case HOST_STATE_Configured: puts_P(PSTR("CDC Device Enumerated.\r\n")); USB_HostState = HOST_STATE_Ready; @@ -189,10 +176,14 @@ void CDC_Host_Task(void) case HOST_STATE_Ready: /* Select and the data IN pipe */ Pipe_SelectPipe(CDC_DATAPIPE_IN); + Pipe_Unfreeze(); /* Check to see if a packet has been received */ if (Pipe_IsINReceived()) { + /* Re-freeze IN pipe after the packet has been received */ + Pipe_Freeze(); + /* Check if data is in the pipe */ if (Pipe_IsReadWriteAllowed()) { @@ -212,6 +203,9 @@ void CDC_Host_Task(void) Pipe_ClearIN(); } + /* Re-freeze IN pipe after use */ + Pipe_Freeze(); + /* Select and unfreeze the notification pipe */ Pipe_SelectPipe(CDC_NOTIFICATIONPIPE); Pipe_Unfreeze();