diff --git a/Demos/Host/LowLevel/PrinterHost/PrinterHost.c b/Demos/Host/LowLevel/PrinterHost/PrinterHost.c index 045ecd9fbc11b95f0dbcfd8c023d07f29d4ee70d..6265eeeb93a7e0a1f4d1f53c45b462e8ab8a3121 100644 --- a/Demos/Host/LowLevel/PrinterHost/PrinterHost.c +++ b/Demos/Host/LowLevel/PrinterHost/PrinterHost.c @@ -177,16 +177,7 @@ void USB_Printer_Host(void) * request to switch to the interface alternate setting with the Bidirectional protocol */ if (PrinterAltSetting) { - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE), - .bRequest = REQ_SetInterface, - .wValue = PrinterAltSetting, - .wIndex = PrinterInterfaceNumber, - .wLength = 0, - }; - - if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful) + if ((ErrorCode = USB_Host_SetInterfaceAltSetting(PrinterInterfaceNumber, PrinterAltSetting)) != HOST_SENDCONTROL_Successful) { printf_P(PSTR(ESC_FG_RED "Control Error (Set Interface).\r\n" " -- Error Code: %d\r\n" ESC_FG_WHITE), ErrorCode); diff --git a/LUFA/Drivers/USB/Class/Host/Printer.c b/LUFA/Drivers/USB/Class/Host/Printer.c index 278df2e3fd13083f4e05bebdd70e4021d5f12368..290393ac5ffa17cb1a6534f57610363446a578d9 100644 --- a/LUFA/Drivers/USB/Class/Host/Printer.c +++ b/LUFA/Drivers/USB/Class/Host/Printer.c @@ -181,19 +181,11 @@ uint8_t PRNT_Host_SetBidirectionalMode(USB_ClassInfo_PRNT_Host_t* const PRNTInte { uint8_t ErrorCode; - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE), - .bRequest = REQ_SetInterface, - .wValue = PRNTInterfaceInfo->State.AlternateSetting, - .wIndex = PRNTInterfaceInfo->State.InterfaceNumber, - .wLength = 0, - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - - if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful) - return ErrorCode; + if ((ErrorCode = USB_Host_SetInterfaceAltSetting(PRNTInterfaceInfo->State.InterfaceNumber, + PRNTInterfaceInfo->State.AlternateSetting)) != HOST_SENDCONTROL_Successful) + { + return ErrorCode; + } } return HOST_SENDCONTROL_Successful; diff --git a/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c b/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c index 6c45265d7edd4bebc77ec5420a79ab554e3b0251..d18e023c72b07c6bdd744497bbcb7f0c1969b4f7 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c +++ b/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c @@ -351,5 +351,22 @@ uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointNum) return USB_Host_SendControlRequest(NULL); } +uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceNum, + const uint8_t AltSetting) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE), + .bRequest = REQ_SetInterface, + .wValue = AltSetting, + .wIndex = InterfaceNum, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(NULL); +} + #endif diff --git a/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.h b/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.h index 836c83b678c4d2b46c1338dc58fcec2097fc6e98..58d980442997db3f4122dccbad457c6707f55352 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.h +++ b/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.h @@ -330,6 +330,19 @@ */ uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointIndex); + /** Selects a given alternative setting for the specfied interface, via a SET INTERFACE standard request to + * the attached device. + * + * \note After this routine returns, the control pipe will be selected. + * + * \param[in] InterfaceIndex Index of the interface whose alternative setting is to be altered. + * \param[in] AltSetting Index of the interface's alternative setting which is to be selected. + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. + */ + uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceNum, + const uint8_t AltSetting); + /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ diff --git a/LUFA/Drivers/USB/Core/UC3/Host_UC3.c b/LUFA/Drivers/USB/Core/UC3/Host_UC3.c index 88a7df5c4f2c8de820e99712b3fd02ace8d4ad21..02cb1e68eafeed2d5ca4f846351812981933cf77 100644 --- a/LUFA/Drivers/USB/Core/UC3/Host_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/Host_UC3.c @@ -351,5 +351,22 @@ uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointNum) return USB_Host_SendControlRequest(NULL); } +uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceNum, + const uint8_t AltSetting) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE), + .bRequest = REQ_SetInterface, + .wValue = AltSetting, + .wIndex = InterfaceNum, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(NULL); +} + #endif diff --git a/LUFA/Drivers/USB/Core/UC3/Host_UC3.h b/LUFA/Drivers/USB/Core/UC3/Host_UC3.h index 6040eb32b8978ea273992fc31a38442d8e4e54c2..c5dfe76fd1f1193f175f24fe6610c53e208b77e2 100644 --- a/LUFA/Drivers/USB/Core/UC3/Host_UC3.h +++ b/LUFA/Drivers/USB/Core/UC3/Host_UC3.h @@ -331,6 +331,19 @@ */ uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointIndex); + /** Selects a given alternative setting for the specfied interface, via a SET INTERFACE standard request to + * the attached device. + * + * \note After this routine returns, the control pipe will be selected. + * + * \param[in] InterfaceIndex Index of the interface whose alternative setting is to be altered. + * \param[in] AltSetting Index of the interface's alternative setting which is to be selected. + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. + */ + uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceNum, + const uint8_t AltSetting); + /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ diff --git a/LUFA/ManPages/ChangeLog.txt b/LUFA/ManPages/ChangeLog.txt index 1ba3d37b9a46fb9c998832fb1c603c43da257672..f619983ec1cf40a639951a8da47054c121db292b 100644 --- a/LUFA/ManPages/ChangeLog.txt +++ b/LUFA/ManPages/ChangeLog.txt @@ -11,7 +11,7 @@ * - Core: * - Added USE_LUFA_CONFIG_HEADER compile time option to include a LUFAConfig.h header in the user director for LUFA configuration * tokens as an alternative to tokens defined in the project makefile - * - Added new RNDIS Device Classs Driver packet send and receive functions + * - Added new USB_Host_SetInterfaceAltSetting() convenience function for the selection of an interface's alternative setting * - Library Applications: * - Added new MediaControl project * - Added new incomplete AndroidAccessoryHost Host LowLevel demo @@ -50,6 +50,7 @@ * - Internal restructuring for eventual multiple architecture ports * - Added AVR32 UC3 architecture port (currently incomplete/experimental) * - Added new architecture independant functions to enable, disable, save and restore the Global Interrupt Enable flags + * - Added new RNDIS Device Classs Driver packet send and receive functions * - Library Applications: * - Added ability to write protect Mass Storage disk write operations from the host OS * - Added new MIDIToneGenerator project