diff --git a/Demos/Host/LowLevel/CDCHost/CDCHost.c b/Demos/Host/LowLevel/CDCHost/CDCHost.c index 9a5e81ae44..e00332f9fc 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; diff --git a/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c b/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c index ac764fad04..5bb89af473 100644 --- a/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c +++ b/Demos/Host/LowLevel/GenericHIDHost/GenericHIDHost.c @@ -233,36 +233,6 @@ void HID_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 status */ - 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 */ @@ -282,7 +252,24 @@ void HID_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 status */ + 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("HID Device Enumerated.\r\n")); USB_HostState = HOST_STATE_Ready; diff --git a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c index 64bcf0906a..734ef2a572 100644 --- a/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c +++ b/Demos/Host/LowLevel/KeyboardHost/KeyboardHost.c @@ -197,36 +197,6 @@ void Keyboard_HID_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 status */ - 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 */ @@ -247,6 +217,23 @@ void Keyboard_HID_Task(void) 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 status */ + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + /* Wait until USB device disconnected */ + while (USB_IsConnected); + break; + } + + USB_HostState = HOST_STATE_Configured; + break; + case HOST_STATE_Configured: /* HID class request to set the keyboard protocol to the Boot Protocol */ USB_ControlRequest = (USB_Request_Header_t) { diff --git a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c index 620f158e01..54e400ded7 100644 --- a/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c +++ b/Demos/Host/LowLevel/KeyboardHostWithParser/KeyboardHostWithParser.c @@ -132,36 +132,6 @@ void Keyboard_HID_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,25 @@ void Keyboard_HID_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("Processing HID Report.\r\n")); /* Get and process the device's first HID report descriptor */ diff --git a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c index 354a75fc72..905077e815 100644 --- a/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c +++ b/Demos/Host/LowLevel/MassStorageHost/MassStorageHost.c @@ -138,36 +138,6 @@ void MassStorage_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 */ @@ -188,6 +158,23 @@ void MassStorage_Task(void) 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("Mass Storage Disk Enumerated.\r\n")); USB_HostState = HOST_STATE_Ready; diff --git a/Demos/Host/LowLevel/MouseHost/MouseHost.c b/Demos/Host/LowLevel/MouseHost/MouseHost.c index 9b4db30860..2a2e1b9948 100644 --- a/Demos/Host/LowLevel/MouseHost/MouseHost.c +++ b/Demos/Host/LowLevel/MouseHost/MouseHost.c @@ -193,36 +193,6 @@ void Mouse_HID_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 status */ - 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 */ @@ -242,7 +212,24 @@ void Mouse_HID_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 status */ + LEDs_SetAllLEDs(LEDMASK_USB_ERROR); + + /* Wait until USB device disconnected */ + while (USB_IsConnected); + break; + } + + USB_HostState = HOST_STATE_Configured; + break; + case HOST_STATE_Configured: /* HID class request to set the mouse protocol to the Boot Protocol */ USB_ControlRequest = (USB_Request_Header_t) { diff --git a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c index 3ef5503b3c..5f0d35866f 100644 --- a/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c +++ b/Demos/Host/LowLevel/MouseHostWithParser/MouseHostWithParser.c @@ -132,37 +132,7 @@ void Mouse_HID_Task(void) /* Switch to determine what user-application handled host state the host state machine is in */ 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: + case HOST_STATE_Addressed: puts_P(PSTR("Getting Config Data.\r\n")); /* Get and process the configuration descriptor data */ @@ -183,6 +153,23 @@ void Mouse_HID_Task(void) 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("Processing HID Report.\r\n")); /* Get and process the device's first HID report descriptor */ diff --git a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c index 318e257314..a337ab0455 100644 --- a/Demos/Host/LowLevel/StillImageHost/StillImageHost.c +++ b/Demos/Host/LowLevel/StillImageHost/StillImageHost.c @@ -133,35 +133,6 @@ void StillImage_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 (USB_Host_SendControlRequest(NULL) != HOST_SENDCONTROL_Successful) - { - puts_P(PSTR("Control error.\r\n")); - - /* 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 */ @@ -182,6 +153,22 @@ void StillImage_Task(void) 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.\r\n")); + + /* 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("Still Image Device Enumerated.\r\n")); USB_HostState = HOST_STATE_Ready; diff --git a/LUFA.pnproj b/LUFA.pnproj index 1a94c56de3..7da83d90cd 100644 --- a/LUFA.pnproj +++ b/LUFA.pnproj @@ -1 +1 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/LUFA/Drivers/USB/LowLevel/Host.c b/LUFA/Drivers/USB/LowLevel/Host.c index 5f3eeb8e87..c059b43acf 100644 --- a/LUFA/Drivers/USB/LowLevel/Host.c +++ b/LUFA/Drivers/USB/LowLevel/Host.c @@ -285,4 +285,21 @@ static void USB_Host_ResetDevice(void) USB_INT_Enable(USB_INT_DDISCI); } + +uint8_t USB_Host_SetDeviceConfiguration(uint8_t ConfigNumber) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE), + .bRequest = REQ_SetConfiguration, + .wValue = ConfigNumber, + .wIndex = 0, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(NULL); +} + #endif diff --git a/LUFA/Drivers/USB/LowLevel/Host.h b/LUFA/Drivers/USB/LowLevel/Host.h index 911b41bd99..7130c7579c 100644 --- a/LUFA/Drivers/USB/LowLevel/Host.h +++ b/LUFA/Drivers/USB/LowLevel/Host.h @@ -173,6 +173,19 @@ #define USB_Host_IsResumeFromWakeupRequestSent() ((UHCON & (1 << RESUME)) ? false : true) #endif + /* Function Prototypes: */ + /** Convenience function. This routine sends a SetConfiguration standard request to the attached + * device, with the given configuration index. This can be used to easily set the device + * configuration without creating and sending the request manually. + * + * \note After this routine returns, the control pipe will be selected. + * + * \param ConfigNumber Configuration index to send to the device + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. + */ + uint8_t USB_Host_SetDeviceConfiguration(uint8_t ConfigNumber); + /* Enums: */ /** Enum for the various states of the USB Host state machine. Only some states are * implemented in the LUFA library - other states are left to the user to implement. diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt index 1047d4933e..2bedb1d636 100644 --- a/LUFA/ManPages/ChangeLog.txt +++ b/LUFA/ManPages/ChangeLog.txt @@ -18,6 +18,8 @@ * to only unfreeze and check one data pipe at a time) * - Internal per-device preprocessing conditions changed to per-device series rather than per controller group for finer-grain * internal control + * - Added new USB_Host_SetDeviceConfiguration() convenience function for easy configuration selection of devices while in USB + * host mode * * * \section Sec_ChangeLog090605 Version 090605