diff options
Diffstat (limited to 'LUFA/Drivers/USB/Core')
27 files changed, 301 insertions, 449 deletions
diff --git a/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h b/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h index 9899251ee..b5dc7e439 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h +++ b/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.h @@ -132,8 +132,8 @@ * \note This macro should only be used if the device has indicated to the host that it * supports the Remote Wakeup feature in the device descriptors, and should only be * issued if the host is currently allowing remote wakeup events from the device (i.e., - * the \ref USB_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP compile - * time option is used, this macro is unavailable. + * the \ref USB_Device_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP + * compile time option is used, this macro is unavailable. * \n\n * * \note The USB clock must be running for this function to operate. If the stack is initialized with diff --git a/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c b/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c index 2ec49a5d5..6d4df036b 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c +++ b/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c @@ -36,7 +36,7 @@ #include "../Endpoint.h" #if !defined(FIXED_CONTROL_ENDPOINT_SIZE) -uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE; +uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE; #endif bool Endpoint_ConfigureEndpoint_Prv(const uint8_t Number, diff --git a/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.h b/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.h index 7868ac36a..8611dd638 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.h +++ b/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.h @@ -846,9 +846,9 @@ * changed in value. */ #if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__)) - extern uint8_t USB_ControlEndpointSize; + extern uint8_t USB_Device_ControlEndpointSize; #else - #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE + #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE #endif /* Function Prototypes: */ diff --git a/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c b/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c index 5f475a1cc..55cd8f991 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c +++ b/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.c @@ -137,7 +137,7 @@ void USB_Host_ProcessNextHostState(void) break; } - USB_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)]; + USB_Host_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)]; USB_Host_ResetDevice(); @@ -146,7 +146,7 @@ void USB_Host_ProcessNextHostState(void) case HOST_STATE_Default_PostReset: Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL, PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP, - USB_ControlPipeSize, PIPE_BANK_SINGLE); + USB_Host_ControlPipeSize, PIPE_BANK_SINGLE); if (!(Pipe_IsConfigured())) { @@ -175,8 +175,9 @@ void USB_Host_ProcessNextHostState(void) case HOST_STATE_Default_PostAddressSet: USB_Host_SetDeviceAddress(USB_HOST_DEVICEADDRESS); - EVENT_USB_Host_DeviceEnumerationComplete(); USB_HostState = HOST_STATE_Addressed; + + EVENT_USB_Host_DeviceEnumerationComplete(); break; } @@ -253,6 +254,8 @@ static void USB_Host_ResetDevice(void) USB_Host_ResetBus(); while (!(USB_Host_IsBusResetComplete())); USB_Host_ResumeBus(); + + USB_Host_ConfigurationNumber = 0; bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI); @@ -285,88 +288,5 @@ static void USB_Host_ResetDevice(void) USB_INT_Enable(USB_INT_DDISCI); } -uint8_t USB_Host_SetDeviceConfiguration(const 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); -} - -uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr) -{ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE), - .bRequest = REQ_GetDescriptor, - .wValue = (DTYPE_Device << 8), - .wIndex = 0, - .wLength = sizeof(USB_Descriptor_Device_t), - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - - return USB_Host_SendControlRequest(DeviceDescriptorPtr); -} - -uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, - void* const Buffer, - const uint8_t BufferLength) -{ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE), - .bRequest = REQ_GetDescriptor, - .wValue = (DTYPE_String << 8) | Index, - .wIndex = 0, - .wLength = BufferLength, - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - - return USB_Host_SendControlRequest(Buffer); -} - -uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointNum) -{ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT), - .bRequest = REQ_ClearFeature, - .wValue = FEATURE_SEL_EndpointHalt, - .wIndex = EndpointNum, - .wLength = 0, - }; - - Pipe_SelectPipe(PIPE_CONTROLPIPE); - - return USB_Host_SendControlRequest(NULL); -} - -uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceIndex, - const uint8_t AltSetting) -{ - USB_ControlRequest = (USB_Request_Header_t) - { - .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE), - .bRequest = REQ_SetInterface, - .wValue = AltSetting, - .wIndex = InterfaceIndex, - .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 6854128d3..1b34801d4 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.h +++ b/LUFA/Drivers/USB/Core/AVR8/Host_AVR8.h @@ -207,6 +207,9 @@ /** Suspends the USB bus, preventing any communications from occurring between the host and attached * device until the bus has been resumed. This stops the transmission of the 1MS Start Of Frame * messages to the device. + * + * \note While the USB bus is suspended, all USB interrupt sources are also disabled; this means that + * some events (such as device disconnections) will not fire until the bus is resumed. */ static inline void USB_Host_SuspendBus(void) ATTR_ALWAYS_INLINE; static inline void USB_Host_SuspendBus(void) @@ -276,73 +279,6 @@ return ((UHCON & (1 << RESUME)) ? false : true); } - /* Function Prototypes: */ - /** Convenience function. This routine sends a SET CONFIGURATION 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[in] 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(const uint8_t ConfigNumber); - - /** Convenience function. This routine sends a GET DESCRIPTOR standard request to the attached - * device, requesting the device descriptor. This can be used to easily retrieve information - * about the device such as its VID, PID and power requirements. - * - * \note After this routine returns, the control pipe will be selected. - * - * \param[out] DeviceDescriptorPtr Pointer to the destination device descriptor structure where - * the read data is to be stored. - * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. - */ - uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr); - - /** Convenience function. This routine sends a GET DESCRIPTOR standard request to the attached - * device, requesting the string descriptor of the specified index. This can be used to easily - * retrieve string descriptors from the device by index, after the index is obtained from the - * Device or Configuration descriptors. - * - * \note After this routine returns, the control pipe will be selected. - * - * \param[in] Index Index of the string index to retrieve. - * \param[out] Buffer Pointer to the destination buffer where the retrieved string descriptor is - * to be stored. - * \param[in] BufferLength Maximum size of the string descriptor which can be stored into the buffer. - * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. - */ - uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, - void* const Buffer, - const uint8_t BufferLength); - - /** Clears a stall condition on the given pipe, via a CLEAR FEATURE standard request to the attached device. - * - * \note After this routine returns, the control pipe will be selected. - * - * \param[in] EndpointIndex Index of the endpoint to clear, including the endpoint's direction. - * - * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. - */ - uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointIndex); - - /** Selects a given alternative setting for the specified 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 InterfaceIndex, - const uint8_t AltSetting); - /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Macros: */ diff --git a/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c b/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c index e93b256c6..5d7c8ac1b 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c +++ b/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c @@ -35,7 +35,7 @@ #include "../Pipe.h" -uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; +uint8_t USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, diff --git a/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.h b/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.h index 1939d3906..efe0ef1ba 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.h +++ b/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.h @@ -804,7 +804,7 @@ * \note This variable should be treated as read-only in the user application, and never manually * changed in value. */ - extern uint8_t USB_ControlPipeSize; + extern uint8_t USB_Host_ControlPipeSize; /* Function Prototypes: */ /** Configures the specified pipe number with the given pipe type, token, target endpoint number in the diff --git a/LUFA/Drivers/USB/Core/AVR8/Template/Template_Endpoint_Control_W.c b/LUFA/Drivers/USB/Core/AVR8/Template/Template_Endpoint_Control_W.c index 1d6361fb8..5d4fc42f2 100644 --- a/LUFA/Drivers/USB/Core/AVR8/Template/Template_Endpoint_Control_W.c +++ b/LUFA/Drivers/USB/Core/AVR8/Template/Template_Endpoint_Control_W.c @@ -58,7 +58,7 @@ uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer, { uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint(); - while (Length && (BytesInEndpoint < USB_ControlEndpointSize)) + while (Length && (BytesInEndpoint < USB_Device_ControlEndpointSize)) { TEMPLATE_TRANSFER_BYTE(DataStream); TEMPLATE_BUFFER_MOVE(DataStream, 1); @@ -66,7 +66,7 @@ uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer, BytesInEndpoint++; } - LastPacketFull = (BytesInEndpoint == USB_ControlEndpointSize); + LastPacketFull = (BytesInEndpoint == USB_Device_ControlEndpointSize); Endpoint_ClearIN(); } } diff --git a/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c b/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c index 4802463f0..571ab6c8a 100644 --- a/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c +++ b/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c @@ -178,15 +178,15 @@ void USB_ResetInterface(void) #if defined(USB_CAN_BE_DEVICE) static void USB_Init_Device(void) { - USB_DeviceState = DEVICE_STATE_Unattached; - USB_ConfigurationNumber = 0; + USB_DeviceState = DEVICE_STATE_Unattached; + USB_Device_ConfigurationNumber = 0; #if !defined(NO_DEVICE_REMOTE_WAKEUP) - USB_RemoteWakeupEnabled = false; + USB_Device_RemoteWakeupEnabled = false; #endif #if !defined(NO_DEVICE_SELF_POWER) - USB_CurrentlySelfPowered = false; + USB_Device_CurrentlySelfPowered = false; #endif #if !defined(FIXED_CONTROL_ENDPOINT_SIZE) @@ -199,21 +199,21 @@ static void USB_Init_Device(void) if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr, &DescriptorAddressSpace) != NO_DESCRIPTOR) { if (DescriptorAddressSpace == MEMSPACE_FLASH) - USB_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size); else if (DescriptorAddressSpace == MEMSPACE_EEPROM) - USB_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size); else - USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size; + USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size; } #else if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR) { #if defined(USE_RAM_DESCRIPTORS) - USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size; + USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size; #elif defined(USE_EEPROM_DESCRIPTORS) - USB_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + USB_Device_ControlEndpointSize = eeprom_read_byte(&DeviceDescriptorPtr->Endpoint0Size); #else - USB_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size); + USB_Device_ControlEndpointSize = pgm_read_byte(&DeviceDescriptorPtr->Endpoint0Size); #endif } #endif @@ -229,7 +229,7 @@ static void USB_Init_Device(void) #endif Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, - ENDPOINT_DIR_OUT, USB_ControlEndpointSize, + ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize, ENDPOINT_BANK_SINGLE); USB_INT_Clear(USB_INT_SUSPI); @@ -243,8 +243,9 @@ static void USB_Init_Device(void) #if defined(USB_CAN_BE_HOST) static void USB_Init_Host(void) { - USB_HostState = HOST_STATE_Unattached; - USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; + USB_HostState = HOST_STATE_Unattached; + USB_Host_ConfigurationNumber = 0; + USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE; USB_Host_HostMode_On(); @@ -254,7 +255,7 @@ static void USB_Init_Host(void) USB_INT_Enable(USB_INT_SRPI); USB_INT_Enable(USB_INT_BCERRI); - + USB_Attach(); } #endif diff --git a/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c b/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c index 4939ec2ed..328017ef3 100644 --- a/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c +++ b/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c @@ -144,7 +144,7 @@ ISR(USB_GEN_vect, ISR_BLOCK) USB_INT_Disable(USB_INT_WAKEUPI); USB_INT_Enable(USB_INT_SUSPI); - if (USB_ConfigurationNumber) + if (USB_Device_ConfigurationNumber) USB_DeviceState = DEVICE_STATE_Configured; else USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered; @@ -160,15 +160,15 @@ ISR(USB_GEN_vect, ISR_BLOCK) { USB_INT_Clear(USB_INT_EORSTI); - USB_DeviceState = DEVICE_STATE_Default; - USB_ConfigurationNumber = 0; + USB_DeviceState = DEVICE_STATE_Default; + USB_Device_ConfigurationNumber = 0; USB_INT_Clear(USB_INT_SUSPI); USB_INT_Disable(USB_INT_SUSPI); USB_INT_Enable(USB_INT_WAKEUPI); Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL, - ENDPOINT_DIR_OUT, USB_ControlEndpointSize, + ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize, ENDPOINT_BANK_SINGLE); #if defined(INTERRUPT_CONTROL_ENDPOINT) diff --git a/LUFA/Drivers/USB/Core/DeviceStandardReq.c b/LUFA/Drivers/USB/Core/DeviceStandardReq.c index f9c64b6f8..c3a111e35 100644 --- a/LUFA/Drivers/USB/Core/DeviceStandardReq.c +++ b/LUFA/Drivers/USB/Core/DeviceStandardReq.c @@ -36,14 +36,14 @@ #define __INCLUDE_FROM_DEVICESTDREQ_C #include "DeviceStandardReq.h" -uint8_t USB_ConfigurationNumber; +uint8_t USB_Device_ConfigurationNumber; #if !defined(NO_DEVICE_SELF_POWER) -bool USB_CurrentlySelfPowered; +bool USB_Device_CurrentlySelfPowered; #endif #if !defined(NO_DEVICE_REMOTE_WAKEUP) -bool USB_RemoteWakeupEnabled; +bool USB_Device_RemoteWakeupEnabled; #endif void USB_Device_ProcessControlRequest(void) @@ -184,11 +184,11 @@ static void USB_Device_SetConfiguration(void) Endpoint_ClearSETUP(); - USB_ConfigurationNumber = (uint8_t)USB_ControlRequest.wValue; + USB_Device_ConfigurationNumber = (uint8_t)USB_ControlRequest.wValue; Endpoint_ClearStatusStage(); - if (USB_ConfigurationNumber) + if (USB_Device_ConfigurationNumber) USB_DeviceState = DEVICE_STATE_Configured; else USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered; @@ -200,7 +200,7 @@ static void USB_Device_GetConfiguration(void) { Endpoint_ClearSETUP(); - Endpoint_Write_8(USB_ConfigurationNumber); + Endpoint_Write_8(USB_Device_ConfigurationNumber); Endpoint_ClearIN(); Endpoint_ClearStatusStage(); @@ -285,12 +285,12 @@ static void USB_Device_GetStatus(void) #if !defined(NO_DEVICE_SELF_POWER) || !defined(NO_DEVICE_REMOTE_WAKEUP) case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE): #if !defined(NO_DEVICE_SELF_POWER) - if (USB_CurrentlySelfPowered) + if (USB_Device_CurrentlySelfPowered) CurrentStatus |= FEATURE_SELFPOWERED_ENABLED; #endif #if !defined(NO_DEVICE_REMOTE_WAKEUP) - if (USB_RemoteWakeupEnabled) + if (USB_Device_RemoteWakeupEnabled) CurrentStatus |= FEATURE_REMOTE_WAKEUP_ENABLED; #endif break; @@ -324,7 +324,7 @@ static void USB_Device_ClearSetFeature(void) #if !defined(NO_DEVICE_REMOTE_WAKEUP) case REQREC_DEVICE: if ((uint8_t)USB_ControlRequest.wValue == FEATURE_SEL_DeviceRemoteWakeup) - USB_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature); + USB_Device_RemoteWakeupEnabled = (USB_ControlRequest.bRequest == REQ_SetFeature); else return; diff --git a/LUFA/Drivers/USB/Core/DeviceStandardReq.h b/LUFA/Drivers/USB/Core/DeviceStandardReq.h index 24b3e60da..f47d8f644 100644 --- a/LUFA/Drivers/USB/Core/DeviceStandardReq.h +++ b/LUFA/Drivers/USB/Core/DeviceStandardReq.h @@ -91,7 +91,7 @@ * * \ingroup Group_Device */ - extern uint8_t USB_ConfigurationNumber; + extern uint8_t USB_Device_ConfigurationNumber; #if !defined(NO_DEVICE_REMOTE_WAKEUP) /** Indicates if the host is currently allowing the device to issue remote wakeup events. If this @@ -108,7 +108,7 @@ * * \ingroup Group_Device */ - extern bool USB_RemoteWakeupEnabled; + extern bool USB_Device_RemoteWakeupEnabled; #endif #if !defined(NO_DEVICE_SELF_POWER) @@ -118,7 +118,7 @@ * * \ingroup Group_Device */ - extern bool USB_CurrentlySelfPowered; + extern bool USB_Device_CurrentlySelfPowered; #endif /* Private Interface - For use in library only: */ diff --git a/LUFA/Drivers/USB/Core/Events.h b/LUFA/Drivers/USB/Core/Events.h index 2ea14bf10..8afd3b53c 100644 --- a/LUFA/Drivers/USB/Core/Events.h +++ b/LUFA/Drivers/USB/Core/Events.h @@ -249,7 +249,7 @@ * This event is time-critical; exceeding OS-specific delays within this event handler (typically of around * one second) will prevent the device from enumerating correctly. * - * This event fires after the value of \ref USB_ConfigurationNumber has been changed. + * This event fires after the value of \ref USB_Device_ConfigurationNumber has been changed. * * \note This event does not exist if the \c USB_HOST_ONLY token is supplied to the compiler (see * \ref Group_USBManagement documentation). diff --git a/LUFA/Drivers/USB/Core/Host.h b/LUFA/Drivers/USB/Core/Host.h index 53a6b9a6c..6bd7fab20 100644 --- a/LUFA/Drivers/USB/Core/Host.h +++ b/LUFA/Drivers/USB/Core/Host.h @@ -65,8 +65,7 @@ /* Public Interface - May be used in end-application: */
/* 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.
+ /** Enum for the various states of the USB Host state machine.
*
* For information on each possible USB host state, refer to the USB 2.0 specification.
* Several of the USB host states are broken up further into multiple smaller sub-states,
@@ -76,94 +75,49 @@ */
enum USB_Host_States_t
{
- HOST_STATE_WaitForDeviceRemoval = 0, /**< Internally implemented by the library. This state can be
- * used by the library to wait until the attached device is
- * removed by the user - useful for when an error occurs or
- * further communication with the device is not needed. This
- * allows for other code to run while the state machine is
- * effectively disabled.
+ HOST_STATE_WaitForDevice = 0, /**< This state indicates that the stack is waiting for an interval
+ * to elapse before continuing with the next step of the device
+ * enumeration process.
*/
- HOST_STATE_WaitForDevice = 1, /**< Internally implemented by the library. This state indicates
- * that the stack is waiting for an interval to elapse before
- * continuing with the next step of the device enumeration
- * process.
- *
- * \note Do not manually change to this state in the user code.
- */
- HOST_STATE_Unattached = 2, /**< Internally implemented by the library. This state indicates
- * that the host state machine is waiting for a device to be
- * attached so that it can start the enumeration process.
- *
- * \note Do not manually change to this state in the user code.
+ HOST_STATE_Unattached = 1, /**< This state indicates that the host state machine is waiting for
+ * a device to be attached so that it can start the enumeration process.
*/
- HOST_STATE_Powered = 3, /**< Internally implemented by the library. This state indicates
- * that a device has been attached, and the library's internals
- * are being configured to begin the enumeration process.
- *
- * \note Do not manually change to this state in the user code.
+ HOST_STATE_Powered = 2, /**< This state indicates that a device has been attached, and the
+ * library's internals are being configured to begin the enumeration
+ * process.
*/
- HOST_STATE_Powered_WaitForDeviceSettle = 4, /**< Internally implemented by the library. This state indicates
- * that the stack is waiting for the initial settling period to
- * elapse before beginning the enumeration process.
- *
- * \note Do not manually change to this state in the user code.
+ HOST_STATE_Powered_WaitForDeviceSettle = 3, /**< This state indicates that the stack is waiting for the initial
+ * settling period to elapse before beginning the enumeration process.
*/
- HOST_STATE_Powered_WaitForConnect = 5, /**< Internally implemented by the library. This state indicates
- * that the stack is waiting for a connection event from the USB
- * controller to indicate a valid USB device has been attached to
- * the bus and is ready to be enumerated.
- *
- * \note Do not manually change to this state in the user code.
+ HOST_STATE_Powered_WaitForConnect = 4, /**< This state indicates that the stack is waiting for a connection event
+ * from the USB controller to indicate a valid USB device has been attached
+ * to the bus and is ready to be enumerated.
*/
- HOST_STATE_Powered_DoReset = 6, /**< Internally implemented by the library. This state indicates
- * that a valid USB device has been attached, and that it is
- * will now be reset to ensure it is ready for enumeration.
- *
- * \note Do not manually change to this state in the user code.
+ HOST_STATE_Powered_DoReset = 5, /**< This state indicates that a valid USB device has been attached, and that
+ * it will now be reset to ensure it is ready for enumeration.
*/
- HOST_STATE_Powered_ConfigPipe = 7, /**< Internally implemented by the library. This state indicates
- * that the attached device is currently powered and reset, and
- * that the control pipe is now being configured by the stack.
- *
- * \note Do not manually change to this state in the user code.
+ HOST_STATE_Powered_ConfigPipe = 6, /**< This state indicates that the attached device is currently powered and
+ * reset, and that the control pipe is now being configured by the stack.
*/
- HOST_STATE_Default = 8, /**< Internally implemented by the library. This state indicates
- * that the stack is currently retrieving the control endpoint's
- * size from the device, so that the control pipe can be altered
+ HOST_STATE_Default = 7, /**< This state indicates that the stack is currently retrieving the control
+ * endpoint's size from the device, so that the control pipe can be altered
* to match.
- *
- * \note Do not manually change to this state in the user code.
- */
- HOST_STATE_Default_PostReset = 9, /**< Internally implemented by the library. This state indicates that
- * the control pipe is being reconfigured to match the retrieved
- * control endpoint size from the device, and the device's USB bus
- * address is being set.
- *
- * \note Do not manually change to this state in the user code.
*/
- HOST_STATE_Default_PostAddressSet = 10, /**< Internally implemented by the library. This state indicates that
- * the device's address has now been set, and the stack is has now
- * completed the device enumeration process. This state causes the
- * stack to change the current USB device address to that set for
- * the connected device, before progressing to the user-implemented
- * \ref HOST_STATE_Addressed state for further communications.
- *
- * \note Do not manually change to this state in the user code.
+ HOST_STATE_Default_PostReset = 8, /**< This state indicates that the control pipe is being reconfigured to match
+ * the retrieved control endpoint size from the device, and the device's USB
+ * bus address is being set.
*/
- HOST_STATE_Addressed = 11, /**< May be implemented by the user project. This state should
- * set the device configuration before progressing to the
- * \ref HOST_STATE_Configured state. Other processing (such as the
- * retrieval and processing of the device descriptor) should also
- * be placed in this state.
+ HOST_STATE_Default_PostAddressSet = 9, /**< This state indicates that the device's address has now been set, and the
+ * stack is has now completed the device enumeration process. This state causes
+ * the stack to change the current USB device address to that set for the
+ * connected device, before progressing to the \ref HOST_STATE_Addressed state
+ * ready for use in the user application.
*/
- HOST_STATE_Configured = 12, /**< May be implemented by the user project. This state should implement the
- * actual work performed on the attached device and changed to the
- * \ref HOST_STATE_Suspended or \ref HOST_STATE_WaitForDeviceRemoval states as needed.
+ HOST_STATE_Addressed = 10, /**< Indicates that the device has been enumerated and addressed, and is now waiting
+ * for the user application to configure the device ready for use.
*/
- HOST_STATE_Suspended = 15, /**< May be implemented by the user project. This state should be maintained
- * while the bus is suspended, and changed to either the \ref HOST_STATE_Configured
- * (after resuming the bus with the USB_Host_ResumeBus() macro) or the
- * \ref HOST_STATE_WaitForDeviceRemoval states as needed.
+ HOST_STATE_Configured = 11, /**< Indicates that the device has been configured into a valid device configuration,
+ * ready for general use by the user application.
*/
};
diff --git a/LUFA/Drivers/USB/Core/HostStandardReq.c b/LUFA/Drivers/USB/Core/HostStandardReq.c index 412ac8968..a9451ff16 100644 --- a/LUFA/Drivers/USB/Core/HostStandardReq.c +++ b/LUFA/Drivers/USB/Core/HostStandardReq.c @@ -36,6 +36,8 @@ #define __INCLUDE_FROM_HOSTSTDREQ_C #include "HostStandardReq.h" +uint8_t USB_Host_ConfigurationNumber; + uint8_t USB_Host_SendControlRequest(void* const BufferPtr) { uint8_t* DataStream = (uint8_t*)BufferPtr; @@ -119,7 +121,7 @@ uint8_t USB_Host_SendControlRequest(void* const BufferPtr) if ((ReturnStatus = USB_Host_WaitForIOS(USB_HOST_WAITFOR_OutReady)) != HOST_SENDCONTROL_Successful) goto End_Of_Control_Send; - while (DataLen && (Pipe_BytesInPipe() < USB_ControlPipeSize)) + while (DataLen && (Pipe_BytesInPipe() < USB_Host_ControlPipeSize)) { Pipe_Write_8(*(DataStream++)); DataLen--; @@ -178,5 +180,96 @@ static uint8_t USB_Host_WaitForIOS(const uint8_t WaitType) return HOST_SENDCONTROL_Successful; } +uint8_t USB_Host_SetDeviceConfiguration(const uint8_t ConfigNumber) +{ + uint8_t ErrorCode; + + 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); + + if ((ErrorCode = USB_Host_SendControlRequest(NULL)) == HOST_SENDCONTROL_Successful) + { + USB_Host_ConfigurationNumber = ConfigNumber; + USB_HostState = (ConfigNumber) ? HOST_STATE_Configured : HOST_STATE_Addressed; + } + + return ErrorCode; +} + +uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE), + .bRequest = REQ_GetDescriptor, + .wValue = (DTYPE_Device << 8), + .wIndex = 0, + .wLength = sizeof(USB_Descriptor_Device_t), + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(DeviceDescriptorPtr); +} + +uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, + void* const Buffer, + const uint8_t BufferLength) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE), + .bRequest = REQ_GetDescriptor, + .wValue = (DTYPE_String << 8) | Index, + .wIndex = 0, + .wLength = BufferLength, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(Buffer); +} + +uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointNum) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT), + .bRequest = REQ_ClearFeature, + .wValue = FEATURE_SEL_EndpointHalt, + .wIndex = EndpointNum, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(NULL); +} + +uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceIndex, + const uint8_t AltSetting) +{ + USB_ControlRequest = (USB_Request_Header_t) + { + .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE), + .bRequest = REQ_SetInterface, + .wValue = AltSetting, + .wIndex = InterfaceIndex, + .wLength = 0, + }; + + Pipe_SelectPipe(PIPE_CONTROLPIPE); + + return USB_Host_SendControlRequest(NULL); +} + #endif diff --git a/LUFA/Drivers/USB/Core/HostStandardReq.h b/LUFA/Drivers/USB/Core/HostStandardReq.h index 46822221c..b74aa3a3e 100644 --- a/LUFA/Drivers/USB/Core/HostStandardReq.h +++ b/LUFA/Drivers/USB/Core/HostStandardReq.h @@ -77,6 +77,19 @@ HOST_SENDCONTROL_SoftwareTimeOut = 4, /**< The request or data transfer timed out. */ }; + /* Global Variables: */ + /** Indicates the currently set configuration number of the attached device. This indicates the currently + * selected configuration value if one has been set sucessfully, or 0 if no configuration has been selected. + * + * To set a device configuration, call the \ref USB_Host_SetDeviceConfiguration() function. + * + * \note This variable should be treated as read-only in the user application, and never manually + * changed in value. + * + * \ingroup Group_Host + */ + extern uint8_t USB_Host_ConfigurationNumber; + /* Function Prototypes: */ /** Sends the request stored in the \ref USB_ControlRequest global structure to the attached device, * and transfers the data stored in the buffer to the device, or from the device to the buffer @@ -91,6 +104,85 @@ */ uint8_t USB_Host_SendControlRequest(void* const BufferPtr); + /** Convenience function. This routine sends a SET CONFIGURATION 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. + * + * This routine will automatically update the \ref USB_HostState and \ref USB_Host_ConfigurationNumber + * state variables according to the given function parameters and the result of the request. + * + * \note After this routine returns, the control pipe will be selected. + * + * \ingroup Group_PipeControlReq + * + * \param[in] 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(const uint8_t ConfigNumber); + + /** Convenience function. This routine sends a GET DESCRIPTOR standard request to the attached + * device, requesting the device descriptor. This can be used to easily retrieve information + * about the device such as its VID, PID and power requirements. + * + * \note After this routine returns, the control pipe will be selected. + * + * \ingroup Group_PipeControlReq + * + * \param[out] DeviceDescriptorPtr Pointer to the destination device descriptor structure where + * the read data is to be stored. + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. + */ + uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr); + + /** Convenience function. This routine sends a GET DESCRIPTOR standard request to the attached + * device, requesting the string descriptor of the specified index. This can be used to easily + * retrieve string descriptors from the device by index, after the index is obtained from the + * Device or Configuration descriptors. + * + * \note After this routine returns, the control pipe will be selected. + * + * \ingroup Group_PipeControlReq + * + * \param[in] Index Index of the string index to retrieve. + * \param[out] Buffer Pointer to the destination buffer where the retrieved string descriptor is + * to be stored. + * \param[in] BufferLength Maximum size of the string descriptor which can be stored into the buffer. + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. + */ + uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index, + void* const Buffer, + const uint8_t BufferLength); + + /** Clears a stall condition on the given pipe, via a CLEAR FEATURE standard request to the attached device. + * + * \note After this routine returns, the control pipe will be selected. + * + * \ingroup Group_PipeControlReq + * + * \param[in] EndpointIndex Index of the endpoint to clear, including the endpoint's direction. + * + * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result. + */ + uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointIndex); + + /** Selects a given alternative setting for the specified interface, via a SET INTERFACE standard request to + * the attached device. + * + * \note After this routine returns, the control pipe will be selected. + * + * \ingroup Group_PipeControlReq + * + * \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 InterfaceIndex, + const uint8_t AltSetting); + /* Private Interface - For use in library only: */ #if !defined(__DOXYGEN__) /* Enums: */ diff --git a/LUFA/Drivers/USB/Core/UC3/Device_UC3.h b/LUFA/Drivers/USB/Core/UC3/Device_UC3.h index f5a89221f..5ed86612b 100644 --- a/LUFA/Drivers/USB/Core/UC3/Device_UC3.h +++ b/LUFA/Drivers/USB/Core/UC3/Device_UC3.h @@ -122,8 +122,8 @@ * \note This macro should only be used if the device has indicated to the host that it
* supports the Remote Wakeup feature in the device descriptors, and should only be
* issued if the host is currently allowing remote wakeup events from the device (i.e.,
- * the \ref USB_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP compile
- * time option is used, this macro is unavailable.
+ * the \ref USB_Device_RemoteWakeupEnabled flag is set). When the \c NO_DEVICE_REMOTE_WAKEUP
+ * compile time option is used, this macro is unavailable.
* \n\n
*
* \note The USB clock must be running for this function to operate. If the stack is initialized with
diff --git a/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c index 9c7d6b62d..3337c7d5c 100644 --- a/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.c @@ -36,7 +36,7 @@ #include "../Endpoint.h"
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
-uint8_t USB_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
+uint8_t USB_Device_ControlEndpointSize = ENDPOINT_CONTROLEP_DEFAULT_SIZE;
#endif
volatile uint32_t USB_SelectedEndpoint = ENDPOINT_CONTROLEP;
diff --git a/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.h b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.h index 98067e635..2ed7b5d80 100644 --- a/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.h +++ b/LUFA/Drivers/USB/Core/UC3/Endpoint_UC3.h @@ -830,9 +830,9 @@ * changed in value.
*/
#if (!defined(FIXED_CONTROL_ENDPOINT_SIZE) || defined(__DOXYGEN__))
- extern uint8_t USB_ControlEndpointSize;
+ extern uint8_t USB_Device_ControlEndpointSize;
#else
- #define USB_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
+ #define USB_Device_ControlEndpointSize FIXED_CONTROL_ENDPOINT_SIZE
#endif
/* Function Prototypes: */
diff --git a/LUFA/Drivers/USB/Core/UC3/Host_UC3.c b/LUFA/Drivers/USB/Core/UC3/Host_UC3.c index 1dd2b578b..a56ef4819 100644 --- a/LUFA/Drivers/USB/Core/UC3/Host_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/Host_UC3.c @@ -137,7 +137,7 @@ void USB_Host_ProcessNextHostState(void) break;
}
- USB_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)];
+ USB_Host_ControlPipeSize = DataBuffer[offsetof(USB_Descriptor_Device_t, Endpoint0Size)];
USB_Host_ResetDevice();
@@ -146,7 +146,7 @@ void USB_Host_ProcessNextHostState(void) case HOST_STATE_Default_PostReset:
Pipe_ConfigurePipe(PIPE_CONTROLPIPE, EP_TYPE_CONTROL,
PIPE_TOKEN_SETUP, ENDPOINT_CONTROLEP,
- USB_ControlPipeSize, PIPE_BANK_SINGLE);
+ USB_Host_ControlPipeSize, PIPE_BANK_SINGLE);
if (!(Pipe_IsConfigured()))
{
@@ -175,8 +175,9 @@ void USB_Host_ProcessNextHostState(void) case HOST_STATE_Default_PostAddressSet:
USB_Host_SetDeviceAddress(USB_HOST_DEVICEADDRESS);
- EVENT_USB_Host_DeviceEnumerationComplete();
USB_HostState = HOST_STATE_Addressed;
+
+ EVENT_USB_Host_DeviceEnumerationComplete();
break;
}
@@ -253,6 +254,8 @@ static void USB_Host_ResetDevice(void) USB_Host_ResetBus();
while (!(USB_Host_IsBusResetComplete()));
USB_Host_ResumeBus();
+
+ USB_Host_ConfigurationNumber = 0;
bool HSOFIEnabled = USB_INT_IsEnabled(USB_INT_HSOFI);
@@ -285,88 +288,5 @@ static void USB_Host_ResetDevice(void) USB_INT_Enable(USB_INT_DDISCI);
}
-uint8_t USB_Host_SetDeviceConfiguration(const 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);
-}
-
-uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr)
-{
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
- .bRequest = REQ_GetDescriptor,
- .wValue = (DTYPE_Device << 8),
- .wIndex = 0,
- .wLength = sizeof(USB_Descriptor_Device_t),
- };
-
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
- return USB_Host_SendControlRequest(DeviceDescriptorPtr);
-}
-
-uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index,
- void* const Buffer,
- const uint8_t BufferLength)
-{
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),
- .bRequest = REQ_GetDescriptor,
- .wValue = (DTYPE_String << 8) | Index,
- .wIndex = 0,
- .wLength = BufferLength,
- };
-
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
- return USB_Host_SendControlRequest(Buffer);
-}
-
-uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointNum)
-{
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),
- .bRequest = REQ_ClearFeature,
- .wValue = FEATURE_SEL_EndpointHalt,
- .wIndex = EndpointNum,
- .wLength = 0,
- };
-
- Pipe_SelectPipe(PIPE_CONTROLPIPE);
-
- return USB_Host_SendControlRequest(NULL);
-}
-
-uint8_t USB_Host_SetInterfaceAltSetting(const uint8_t InterfaceIndex,
- const uint8_t AltSetting)
-{
- USB_ControlRequest = (USB_Request_Header_t)
- {
- .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE),
- .bRequest = REQ_SetInterface,
- .wValue = AltSetting,
- .wIndex = InterfaceIndex,
- .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 7fd46a313..4bcba566b 100644 --- a/LUFA/Drivers/USB/Core/UC3/Host_UC3.h +++ b/LUFA/Drivers/USB/Core/UC3/Host_UC3.h @@ -208,6 +208,9 @@ /** Suspends the USB bus, preventing any communications from occurring between the host and attached
* device until the bus has been resumed. This stops the transmission of the 1MS Start Of Frame
* messages to the device.
+ *
+ * \note While the USB bus is suspended, all USB interrupt sources are also disabled; this means that
+ * some events (such as device disconnections) will not fire until the bus is resumed.
*/
static inline void USB_Host_SuspendBus(void) ATTR_ALWAYS_INLINE;
static inline void USB_Host_SuspendBus(void)
@@ -277,73 +280,6 @@ return AVR32_USBB.UHCON.resume;
}
- /* Function Prototypes: */
- /** Convenience function. This routine sends a SET CONFIGURATION 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[in] 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(const uint8_t ConfigNumber);
-
- /** Convenience function. This routine sends a GET DESCRIPTOR standard request to the attached
- * device, requesting the device descriptor. This can be used to easily retrieve information
- * about the device such as its VID, PID and power requirements.
- *
- * \note After this routine returns, the control pipe will be selected.
- *
- * \param[out] DeviceDescriptorPtr Pointer to the destination device descriptor structure where
- * the read data is to be stored.
- *
- * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
- */
- uint8_t USB_Host_GetDeviceDescriptor(void* const DeviceDescriptorPtr);
-
- /** Convenience function. This routine sends a GET DESCRIPTOR standard request to the attached
- * device, requesting the string descriptor of the specified index. This can be used to easily
- * retrieve string descriptors from the device by index, after the index is obtained from the
- * Device or Configuration descriptors.
- *
- * \note After this routine returns, the control pipe will be selected.
- *
- * \param[in] Index Index of the string index to retrieve.
- * \param[out] Buffer Pointer to the destination buffer where the retrieved string descriptor is
- * to be stored.
- * \param[in] BufferLength Maximum size of the string descriptor which can be stored into the buffer.
- *
- * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
- */
- uint8_t USB_Host_GetDeviceStringDescriptor(const uint8_t Index,
- void* const Buffer,
- const uint8_t BufferLength);
-
- /** Clears a stall condition on the given pipe, via a CLEAR FEATURE standard request to the attached device.
- *
- * \note After this routine returns, the control pipe will be selected.
- *
- * \param[in] EndpointIndex Index of the endpoint to clear, including the endpoint's direction.
- *
- * \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.
- */
- uint8_t USB_Host_ClearPipeStall(const uint8_t EndpointIndex);
-
- /** Selects a given alternative setting for the specified 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 InterfaceIndex,
- const uint8_t AltSetting);
-
/* Private Interface - For use in library only: */
#if !defined(__DOXYGEN__)
/* Macros: */
diff --git a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c index 4e67f9691..83d3fd6ad 100644 --- a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.c @@ -35,7 +35,7 @@ #include "../Pipe.h"
-uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
+uint8_t USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
volatile uint32_t USB_SelectedPipe = PIPE_CONTROLPIPE;
volatile uint8_t* USB_PipeFIFOPos[PIPE_TOTAL_PIPES];
diff --git a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.h b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.h index 2444a2c63..c9f9eaac2 100644 --- a/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.h +++ b/LUFA/Drivers/USB/Core/UC3/Pipe_UC3.h @@ -804,7 +804,7 @@ * \note This variable should be treated as read-only in the user application, and never manually
* changed in value.
*/
- extern uint8_t USB_ControlPipeSize;
+ extern uint8_t USB_Host_ControlPipeSize;
/* Function Prototypes: */
/** Configures the specified pipe number with the given pipe type, token, target endpoint number in the
diff --git a/LUFA/Drivers/USB/Core/UC3/Template/Template_Endpoint_Control_W.c b/LUFA/Drivers/USB/Core/UC3/Template/Template_Endpoint_Control_W.c index 1d6361fb8..5d4fc42f2 100644 --- a/LUFA/Drivers/USB/Core/UC3/Template/Template_Endpoint_Control_W.c +++ b/LUFA/Drivers/USB/Core/UC3/Template/Template_Endpoint_Control_W.c @@ -58,7 +58,7 @@ uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer, { uint16_t BytesInEndpoint = Endpoint_BytesInEndpoint(); - while (Length && (BytesInEndpoint < USB_ControlEndpointSize)) + while (Length && (BytesInEndpoint < USB_Device_ControlEndpointSize)) { TEMPLATE_TRANSFER_BYTE(DataStream); TEMPLATE_BUFFER_MOVE(DataStream, 1); @@ -66,7 +66,7 @@ uint8_t TEMPLATE_FUNC_NAME (const void* const Buffer, BytesInEndpoint++; } - LastPacketFull = (BytesInEndpoint == USB_ControlEndpointSize); + LastPacketFull = (BytesInEndpoint == USB_Device_ControlEndpointSize); Endpoint_ClearIN(); } } diff --git a/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c b/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c index 0b0d04d63..7cfa28ede 100644 --- a/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/USBController_UC3.c @@ -147,22 +147,22 @@ void USB_ResetInterface(void) #if defined(USB_CAN_BE_DEVICE)
static void USB_Init_Device(void)
{
- USB_DeviceState = DEVICE_STATE_Unattached;
- USB_ConfigurationNumber = 0;
+ USB_DeviceState = DEVICE_STATE_Unattached;
+ USB_Device_ConfigurationNumber = 0;
#if !defined(NO_DEVICE_REMOTE_WAKEUP)
- USB_RemoteWakeupEnabled = false;
+ USB_Device_RemoteWakeupEnabled = false;
#endif
#if !defined(NO_DEVICE_SELF_POWER)
- USB_CurrentlySelfPowered = false;
+ USB_Device_CurrentlySelfPowered = false;
#endif
#if !defined(FIXED_CONTROL_ENDPOINT_SIZE)
USB_Descriptor_Device_t* DeviceDescriptorPtr;
if (CALLBACK_USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DeviceDescriptorPtr) != NO_DESCRIPTOR)
- USB_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
+ USB_Device_ControlEndpointSize = DeviceDescriptorPtr->Endpoint0Size;
#endif
if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
@@ -173,7 +173,7 @@ static void USB_Init_Device(void) USB_INT_Enable(USB_INT_VBUSTI);
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
- ENDPOINT_DIR_OUT, USB_ControlEndpointSize,
+ ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
ENDPOINT_BANK_SINGLE);
USB_INT_Clear(USB_INT_SUSPI);
@@ -187,8 +187,9 @@ static void USB_Init_Device(void) #if defined(USB_CAN_BE_HOST)
static void USB_Init_Host(void)
{
- USB_HostState = HOST_STATE_Unattached;
- USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
+ USB_HostState = HOST_STATE_Unattached;
+ USB_Host_ConfigurationNumber = 0;
+ USB_Host_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;
USB_Host_HostMode_On();
diff --git a/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c b/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c index 5191ee67f..7a9c14885 100644 --- a/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c +++ b/LUFA/Drivers/USB/Core/UC3/USBInterrupt_UC3.c @@ -97,7 +97,7 @@ ISR(USB_GEN_vect) USB_INT_Disable(USB_INT_WAKEUPI);
USB_INT_Enable(USB_INT_SUSPI);
- if (USB_ConfigurationNumber)
+ if (USB_Device_ConfigurationNumber)
USB_DeviceState = DEVICE_STATE_Configured;
else
USB_DeviceState = (USB_Device_IsAddressSet()) ? DEVICE_STATE_Configured : DEVICE_STATE_Powered;
@@ -109,8 +109,8 @@ ISR(USB_GEN_vect) {
USB_INT_Clear(USB_INT_EORSTI);
- USB_DeviceState = DEVICE_STATE_Default;
- USB_ConfigurationNumber = 0;
+ USB_DeviceState = DEVICE_STATE_Default;
+ USB_Device_ConfigurationNumber = 0;
USB_INT_Clear(USB_INT_SUSPI);
USB_INT_Disable(USB_INT_SUSPI);
@@ -118,7 +118,7 @@ ISR(USB_GEN_vect) USB_Device_SetDeviceAddress(0);
Endpoint_ConfigureEndpoint(ENDPOINT_CONTROLEP, EP_TYPE_CONTROL,
- ENDPOINT_DIR_OUT, USB_ControlEndpointSize,
+ ENDPOINT_DIR_OUT, USB_Device_ControlEndpointSize,
ENDPOINT_BANK_SINGLE);
EVENT_USB_Device_Reset();
diff --git a/LUFA/Drivers/USB/Core/USBTask.h b/LUFA/Drivers/USB/Core/USBTask.h index 30231bf16..586ce6ed2 100644 --- a/LUFA/Drivers/USB/Core/USBTask.h +++ b/LUFA/Drivers/USB/Core/USBTask.h @@ -93,9 +93,8 @@ /** Indicates the current host state machine state. When in host mode, this indicates the state * via one of the values of the \ref USB_Host_States_t enum values. * - * This value may be altered by the user application to implement the \ref HOST_STATE_Addressed, - * \ref HOST_STATE_Configured and \ref HOST_STATE_Suspended states which are not implemented by - * the library internally. + * This value should not be altered by the user application as it is handled automatically by the + * library. * * To reduce program size and speed up checks of this global on the AVR8 architecture, it can be * placed into one of the AVR's \c GPIOR hardware registers instead of RAM by defining the |