Added new USB_Host_ClearPipeStall() convenience function to clear a stall condition...
authorDean Camera <dean@fourwalledcubicle.com>
Thu, 18 Jun 2009 07:53:51 +0000 (07:53 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Thu, 18 Jun 2009 07:53:51 +0000 (07:53 +0000)
Added new USB_Host_GetDeviceDescriptor() convenience function to retrieve the attached device's Device descriptor.

Make Pipe_ConfigurePipe() mask the given endpoint number against PIPE_EPNUM_MASK to ensure the endpoint IN direction bit is cleared to prevent endpoint type corruption.

Fix documentation mentioning Pipe_GetCurrentToken() function when real name is Pipe_GetPipeToken().

15 files changed:
Bootloaders/CDC/makefile
Bootloaders/DFU/makefile
Bootloaders/TeensyHID/makefile
Demos/Host/ClassDriver/MassStorageHost/Lib/MassStoreCommands.c
Demos/Host/ClassDriver/MassStorageHost/Lib/MassStoreCommands.h
Demos/Host/Incomplete/BluetoothHost/BluetoothHost.c
Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.c
Demos/Host/LowLevel/MassStorageHost/Lib/MassStoreCommands.h
LUFA/Drivers/USB/HighLevel/USBTask.h
LUFA/Drivers/USB/LowLevel/Host.c
LUFA/Drivers/USB/LowLevel/Host.h
LUFA/Drivers/USB/LowLevel/Pipe.c
LUFA/Drivers/USB/LowLevel/Pipe.h
LUFA/ManPages/ChangeLog.txt
LUFA/ManPages/FutureChanges.txt

index cf7030d..8425e9b 100644 (file)
@@ -206,10 +206,6 @@ CFLAGS += -ffunction-sections
 CFLAGS += -fpack-struct\r
 CFLAGS += -fshort-enums\r
 CFLAGS += -fno-inline-small-functions\r
-CFLAGS += -fno-reorder-blocks\r
-CFLAGS += -fno-reorder-blocks-and-partition\r
-CFLAGS += -fno-reorder-functions\r
-CFLAGS += -fno-toplevel-reorder\r
 CFLAGS += -Wall\r
 CFLAGS += -Wstrict-prototypes\r
 CFLAGS += -Wundef\r
index f9f8f65..871a92d 100644 (file)
@@ -207,10 +207,6 @@ CFLAGS += -fdata-sections
 CFLAGS += -fpack-struct\r
 CFLAGS += -fshort-enums\r
 CFLAGS += -fno-inline-small-functions\r
-CFLAGS += -fno-reorder-blocks\r
-CFLAGS += -fno-reorder-blocks-and-partition\r
-CFLAGS += -fno-reorder-functions\r
-CFLAGS += -fno-toplevel-reorder\r
 CFLAGS += -Wall\r
 CFLAGS += -Wstrict-prototypes\r
 CFLAGS += -Wundef\r
index 91d3ada..fb3f1eb 100644 (file)
@@ -206,10 +206,6 @@ CFLAGS += -ffunction-sections
 CFLAGS += -fpack-struct\r
 CFLAGS += -fshort-enums\r
 CFLAGS += -fno-inline-small-functions\r
-CFLAGS += -fno-reorder-blocks\r
-CFLAGS += -fno-reorder-blocks-and-partition\r
-CFLAGS += -fno-reorder-functions\r
-CFLAGS += -fno-toplevel-reorder\r
 CFLAGS += -Wall\r
 CFLAGS += -Wstrict-prototypes\r
 CFLAGS += -Wundef\r
index afeace0..7597473 100644 (file)
@@ -134,7 +134,7 @@ static uint8_t MassStore_WaitForDataReceived(void)
                if (Pipe_IsStalled())\r
                {\r
                        /* Clear the stall condition on the OUT pipe */\r
-                       MassStore_ClearPipeStall(MASS_STORE_DATA_OUT_PIPE);\r
+                       USB_Host_ClearPipeStall(MASS_STORE_DATA_OUT_PIPE);\r
 \r
                        return PIPE_RWSTREAM_PipeStalled;\r
                }\r
@@ -147,7 +147,7 @@ static uint8_t MassStore_WaitForDataReceived(void)
                if (Pipe_IsStalled())\r
                {\r
                        /* Clear the stall condition on the IN pipe */\r
-                       MassStore_ClearPipeStall(MASS_STORE_DATA_IN_PIPE);\r
+                       USB_Host_ClearPipeStall(MASS_STORE_DATA_IN_PIPE);\r
 \r
                        return PIPE_RWSTREAM_PipeStalled;\r
                }\r
index e939f1c..78700de 100644 (file)
                        static uint8_t MassStore_GetReturnedStatus(void);\r
                #endif\r
                \r
-               uint8_t MassStore_ClearPipeStall(const uint8_t EndpointNum);\r
                uint8_t MassStore_MassStorageReset(void);\r
                uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex);\r
                uint8_t MassStore_RequestSense(const uint8_t LUNIndex, const SCSI_Request_Sense_Response_t* const SensePtr)\r
index b7d49f6..1aaa814 100644 (file)
@@ -144,22 +144,12 @@ void Bluetooth_Management_Task(void)
                        }\r
 \r
                        puts_P(PSTR("Bluetooth Dongle Detected.\r\n"));\r
-\r
-                       /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_ControlRequest = (USB_Request_Header_t)\r
-                               {\r
-                                       bmRequestType: (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
-                                       bRequest:      REQ_SetConfiguration,\r
-                                       wValue:        1,\r
-                                       wIndex:        0,\r
-                                       wLength:       0,\r
-                               };\r
                                \r
                        /* Select the control pipe for the request transfer */\r
                        Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
 \r
-                       /* Send the request, display error and wait for device detatch if request fails */\r
-                       if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
+                       /* Set the device configuration to the first configuration (rarely do devices use multiple configurations) */\r
+                       if ((ErrorCode = USB_Host_SetDeviceConfiguration(1)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                                puts_P(PSTR("Control Error (Set Configuration).\r\n"));\r
                                printf_P(PSTR(" -- Error Code: %d\r\n"), ErrorCode);\r
index afeace0..c524b53 100644 (file)
@@ -134,7 +134,7 @@ static uint8_t MassStore_WaitForDataReceived(void)
                if (Pipe_IsStalled())\r
                {\r
                        /* Clear the stall condition on the OUT pipe */\r
-                       MassStore_ClearPipeStall(MASS_STORE_DATA_OUT_PIPE);\r
+                       USB_Host_ClearPipeStall(MASS_STORE_DATA_OUT_PIPE);\r
 \r
                        return PIPE_RWSTREAM_PipeStalled;\r
                }\r
@@ -147,7 +147,7 @@ static uint8_t MassStore_WaitForDataReceived(void)
                if (Pipe_IsStalled())\r
                {\r
                        /* Clear the stall condition on the IN pipe */\r
-                       MassStore_ClearPipeStall(MASS_STORE_DATA_IN_PIPE);\r
+                       USB_Host_ClearPipeStall(MASS_STORE_DATA_IN_PIPE);\r
 \r
                        return PIPE_RWSTREAM_PipeStalled;\r
                }\r
@@ -243,29 +243,6 @@ static uint8_t MassStore_GetReturnedStatus(void)
        return PIPE_RWSTREAM_NoError;\r
 }\r
 \r
-/** Clears the stall condition in the attached device on the nominated endpoint number.\r
- *\r
- *  \param EndpointNum  Endpoint number in the attached device whose stall condition is to be cleared\r
- *\r
- *  \return A value from the USB_Host_SendControlErrorCodes_t enum\r
- */\r
-uint8_t MassStore_ClearPipeStall(const uint8_t EndpointNum)\r
-{\r
-       USB_ControlRequest = (USB_Request_Header_t)\r
-               {\r
-                       .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),\r
-                       .bRequest      = REQ_ClearFeature,\r
-                       .wValue        = FEATURE_ENDPOINT_HALT,\r
-                       .wIndex        = EndpointNum,\r
-                       .wLength       = 0,\r
-               };\r
-       \r
-       /* Select the control pipe for the request transfer */\r
-       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
-\r
-       return USB_Host_SendControlRequest(NULL);\r
-}\r
-\r
 /** Issues a Mass Storage class specific request to reset the attached device's Mass Storage interface,\r
  *  readying the device for the next CBW.\r
  *\r
index e939f1c..78700de 100644 (file)
                        static uint8_t MassStore_GetReturnedStatus(void);\r
                #endif\r
                \r
-               uint8_t MassStore_ClearPipeStall(const uint8_t EndpointNum);\r
                uint8_t MassStore_MassStorageReset(void);\r
                uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex);\r
                uint8_t MassStore_RequestSense(const uint8_t LUNIndex, const SCSI_Request_Sense_Response_t* const SensePtr)\r
index e4c8a02..2a9bf19 100644 (file)
                         *\r
                         *  \note This global is only present if the user application can be a USB host.\r
                         *\r
+                        *  \see \ref USB_Host_States_t for a list of possible host states\r
+                        *\r
                         *  \ingroup Group_Host\r
                         */\r
                        extern volatile uint8_t USB_HostState;\r
index c059b43..421719b 100644 (file)
@@ -302,4 +302,39 @@ uint8_t USB_Host_SetDeviceConfiguration(uint8_t ConfigNumber)
        return USB_Host_SendControlRequest(NULL);\r
 }\r
 \r
+uint8_t USB_Host_GetDeviceDescriptor(USB_Descriptor_Device_t* DeviceDescriptorPtr)\r
+{\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
+               {\r
+                       bmRequestType: (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),\r
+                       bRequest:      REQ_GetDescriptor,\r
+                       wValue:        (DTYPE_Device << 8),\r
+                       wIndex:        0,\r
+                       wLength:       sizeof(USB_Descriptor_Device_t),\r
+               };\r
+\r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+       \r
+       return USB_Host_SendControlRequest(DeviceDescriptorPtr);\r
+}\r
+\r
+uint8_t USB_Host_ClearPipeStall(uint8_t EndpointNum)\r
+{\r
+       if (Pipe_GetPipeToken() == PIPE_TOKEN_IN)\r
+         EndpointNum |= (1 << 7);\r
+\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
+               {\r
+                       .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),\r
+                       .bRequest      = REQ_ClearFeature,\r
+                       .wValue        = FEATURE_ENDPOINT_HALT,\r
+                       .wIndex        = EndpointNum,\r
+                       .wLength       = 0,\r
+               };\r
+\r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+       \r
+       return USB_Host_SendControlRequest(NULL);\r
+}\r
+\r
 #endif\r
index 7130c75..2a40a1d 100644 (file)
@@ -47,6 +47,8 @@
 \r
                #include "../../../Common/Common.h"\r
                #include "../HighLevel/USBInterrupt.h"\r
+               #include "../HighLevel/StdDescriptors.h"\r
+               #include "Pipe.h"\r
 \r
        /* Enable C linkage for C++ Compilers: */\r
                #if defined(__cplusplus)\r
                         *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.\r
                         */\r
                        uint8_t USB_Host_SetDeviceConfiguration(uint8_t ConfigNumber);\r
+                       \r
+                       /** Convenience function. This routine sends a GetDescriptor standard request to the attached\r
+                        *  device, requesting the device descriptor. This can be used to easily retrieve information\r
+                        *  about the device such as its VID, PID and power requirements.\r
+                        *\r
+                        *  \note After this routine returns, the control pipe will be selected.\r
+                        *\r
+                        *  \param DeviceDescriptorPtr  Pointer to the destination device descriptor structure where\r
+                        *                              the read data is to be stored\r
+                        *\r
+                        *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.\r
+                        */\r
+                       uint8_t USB_Host_GetDeviceDescriptor(USB_Descriptor_Device_t* DeviceDescriptorPtr);\r
+                       \r
+                       /** Clears a stall condition on the given pipe, via a ClearFeature request to the attached device.\r
+                        *\r
+                        *  \note After this routine returns, the control pipe will be selected.\r
+                        *\r
+                        *  \param EndpointIndex  Index of the endpoint to clear\r
+                        *\r
+                        *  \return A value from the \ref USB_Host_SendControlErrorCodes_t enum to indicate the result.\r
+                        */                     \r
+                       uint8_t USB_Host_ClearPipeStall(uint8_t EndpointIndex);\r
 \r
                /* Enums: */\r
                        /** Enum for the various states of the USB Host state machine. Only some states are\r
index 3c493fe..189aaa6 100644 (file)
@@ -45,7 +45,7 @@ bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t
 \r
        UPCFG1X = 0;\r
        \r
-       UPCFG0X = ((Type << EPTYPE0) | Token | (EndpointNumber << PEPNUM0));\r
+       UPCFG0X = ((Type << EPTYPE0) | Token | ((EndpointNumber & PIPE_EPNUM_MASK) << PEPNUM0));\r
        UPCFG1X = ((1 << ALLOC) | Banks | Pipe_BytesToEPSizeMask(Size));\r
 \r
        return Pipe_IsConfigured();\r
index 62cbe65..82d9b69 100644 (file)
                                 *\r
                                 *  \return The current pipe token, as a PIPE_TOKEN_* mask\r
                                 */\r
-                               static inline uint8_t Pipe_GetCurrentToken(void);\r
+                               static inline uint8_t Pipe_GetPipeToken(void);\r
                                \r
                                /** Sets the token for the currently selected pipe to one of the tokens specified by the PIPE_TOKEN_*\r
                                 *  masks. This can be used on CONTROL type pipes, to allow for bidirectional transfer of data during\r
index b3d533d..3ef3a6e 100644 (file)
   *    internal control\r
   *  - Added new USB_Host_SetDeviceConfiguration() convenience function for easy configuration selection of devices while in USB\r
   *    host mode\r
+  *  - Added new USB_Host_ClearPipeStall() convenience function to clear a stall condition on an attached device's endpoint\r
+  *  - Added new USB_Host_GetDeviceDescriptor() convenience function to retrieve the attached device's Device descriptor\r
   *  - Added USB Missle Launcher project, submitted by Dave Fletcher\r
   *  - Pipe_GetErrorFlags() now returns additional error flags for overflow and underflow errors\r
+  *  - Make Pipe_ConfigurePipe() mask the given endpoint number against PIPE_EPNUM_MASK to ensure the endpoint IN direction bit is\r
+  *    cleared to prevent endpoint type corruption\r
+  *  - Fix documentation mentioning Pipe_GetCurrentToken() function when real name is Pipe_GetPipeToken()\r
   *\r
   *\r
   *  \section Sec_ChangeLog090605 Version 090605\r
index e8ae785..2a714f7 100644 (file)
@@ -21,4 +21,7 @@
   *  - Port LUFA to the Atmel ARM7 series microcontrollers\r
   *  - Remake AVRStudio project files\r
   *  - Master LUFA include file\r
+  *  - Debug mode for pipe/endpoint calls\r
+  *  - Device descriptor get routines\r
+  *  - Add ClearPipeStall host function\r
   */\r