The USB_Host_SendControlRequest() function no longer automatically selects the Contro...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 14 Apr 2009 08:35:47 +0000 (08:35 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 14 Apr 2009 08:35:47 +0000 (08:35 +0000)
The USB Host management task now saves and restores the currently selected pipe before and after the task completes.

18 files changed:
Demos/Host/CDCHost/CDCHost.c
Demos/Host/GenericHIDHost/GenericHIDHost.c
Demos/Host/KeyboardHost/KeyboardHost.c
Demos/Host/KeyboardHostWithParser/HIDReport.c
Demos/Host/KeyboardHostWithParser/KeyboardHostWithParser.c
Demos/Host/MassStorageHost/MassStorageHost.c
Demos/Host/MassStorageHost/MassStoreCommands.c
Demos/Host/MouseHost/MouseHost.c
Demos/Host/MouseHostWithParser/HIDReport.c
Demos/Host/MouseHostWithParser/MouseHostWithParser.c
Demos/Host/StillImageHost/StillImageCommands.c
Demos/Host/StillImageHost/StillImageHost.c
LUFA/ChangeLog.txt
LUFA/Drivers/USB/Class/ConfigDescriptor.c
LUFA/Drivers/USB/HighLevel/USBTask.c
LUFA/Drivers/USB/LowLevel/HostChapter9.c
LUFA/Drivers/USB/LowLevel/HostChapter9.h
LUFA/MigrationInformation.txt

index a51f597..9ecf060 100644 (file)
@@ -196,6 +196,9 @@ TASK(USB_CDC_Host)
                                        wLength:       0,\r
                                };\r
 \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 detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
index 605fc6f..4d2fefb 100644 (file)
@@ -262,6 +262,9 @@ void WriteNextReport(uint8_t* ReportOUTData, uint16_t ReportLength)
                                wLength:       ReportLength,\r
                        };\r
 \r
                                wLength:       ReportLength,\r
                        };\r
 \r
+               /* Select the control pipe for the request transfer */\r
+               Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
                /* Send the request to the device */\r
                USB_Host_SendControlRequest(ReportOUTData);\r
        }\r
                /* Send the request to the device */\r
                USB_Host_SendControlRequest(ReportOUTData);\r
        }\r
@@ -288,6 +291,9 @@ TASK(USB_HID_Host)
                                        wLength:       0,\r
                                };\r
 \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 detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
index f73e568..947f232 100644 (file)
@@ -263,6 +263,9 @@ TASK(USB_Keyboard_Host)
                                        wLength:       0,\r
                                };\r
 \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 detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
@@ -310,6 +313,9 @@ TASK(USB_Keyboard_Host)
                                        wLength:       0,\r
                                };\r
 \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 detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
index 89bd1c8..d177a88 100644 (file)
@@ -56,6 +56,9 @@ uint8_t GetHIDReportData(void)
                        wLength:       HIDReportSize,\r
                };\r
 \r
                        wLength:       HIDReportSize,\r
                };\r
 \r
+       /* Select the control pipe for the request transfer */\r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
        /* Send control request to retrieve the HID report from the attached device */\r
        if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)\r
          return ParseControlError;\r
        /* Send control request to retrieve the HID report from the attached device */\r
        if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)\r
          return ParseControlError;\r
index eefd2fa..d19929d 100644 (file)
@@ -199,6 +199,9 @@ TASK(USB_Keyboard_Host)
                                        wLength:       0,\r
                                };\r
 \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 detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
index a7b550c..ec5bc61 100644 (file)
@@ -170,6 +170,9 @@ TASK(USB_MassStore_Host)
                                        wLength:       0,\r
                                };\r
                                \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 detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
index 0d88acb..bf736e7 100644 (file)
@@ -256,6 +256,9 @@ uint8_t MassStore_ClearPipeStall(const uint8_t EndpointNum)
                        wLength:       0,\r
                };\r
        \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
        return USB_Host_SendControlRequest(NULL);\r
 }\r
 \r
@@ -275,6 +278,9 @@ uint8_t MassStore_MassStorageReset(void)
                        wLength:       0,\r
                };\r
        \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
        return USB_Host_SendControlRequest(NULL);\r
 }\r
 \r
@@ -298,6 +304,9 @@ uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex)
                        wLength:       1,\r
                };\r
                \r
                        wLength:       1,\r
                };\r
                \r
+       /* Select the control pipe for the request transfer */\r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
        if ((ErrorCode = USB_Host_SendControlRequest(MaxLUNIndex)) == HOST_SENDCONTROL_SetupStalled)\r
        {\r
                /* Clear the pipe stall */\r
        if ((ErrorCode = USB_Host_SendControlRequest(MaxLUNIndex)) == HOST_SENDCONTROL_SetupStalled)\r
        {\r
                /* Clear the pipe stall */\r
index 29cbd87..ff25428 100644 (file)
@@ -259,6 +259,9 @@ TASK(USB_Mouse_Host)
                                        wLength:       0,\r
                                };\r
 \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 detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
@@ -306,6 +309,9 @@ TASK(USB_Mouse_Host)
                                        wLength:       0,\r
                                };\r
 \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 detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
index 55f250d..3d06bb1 100644 (file)
@@ -56,6 +56,9 @@ uint8_t GetHIDReportData(void)
                        wLength:       HIDReportSize,\r
                };\r
 \r
                        wLength:       HIDReportSize,\r
                };\r
 \r
+       /* Select the control pipe for the request transfer */\r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
        /* Send control request to retrieve the HID report from the attached device */\r
        if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)\r
          return ParseControlError;\r
        /* Send control request to retrieve the HID report from the attached device */\r
        if (USB_Host_SendControlRequest(HIDReportData) != HOST_SENDCONTROL_Successful)\r
          return ParseControlError;\r
index 79cecdf..6aeca4b 100644 (file)
@@ -200,6 +200,9 @@ TASK(USB_Mouse_Host)
                                        wLength:       0,\r
                                };\r
 \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 detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if ((ErrorCode = USB_Host_SendControlRequest(NULL)) != HOST_SENDCONTROL_Successful)\r
                        {\r
index be6f748..43e57e1 100644 (file)
@@ -272,5 +272,8 @@ uint8_t SImage_ClearPipeStall(const uint8_t PipeEndpointNum)
                        wLength:       0,\r
                };\r
        \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
        return USB_Host_SendControlRequest(NULL);\r
 }\r
index 787629c..1694322 100644 (file)
@@ -165,6 +165,9 @@ TASK(USB_SImage_Host)
                                        wLength:       0,\r
                                };\r
 \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 detach if request fails */\r
                        if (USB_Host_SendControlRequest(NULL) != HOST_SENDCONTROL_Successful)\r
                        {\r
                        /* Send the request, display error and wait for device detach if request fails */\r
                        if (USB_Host_SendControlRequest(NULL) != HOST_SENDCONTROL_Successful)\r
                        {\r
index 78f1ec7..80436f6 100644 (file)
@@ -31,6 +31,9 @@
   *  - Fixed WriteNextReport code in the GenericHIDHost demo using incorrect parameter types and not selecting the correct endpoint\r
   *  - Adjusted sample CTC timer calculations in the AudioOutput and AudioInput demos to account for situations where the division results\r
   *    in a value with no remainder, requiring one to be subtracted from the result (thanks to Robin Theunis)\r
   *  - Fixed WriteNextReport code in the GenericHIDHost demo using incorrect parameter types and not selecting the correct endpoint\r
   *  - Adjusted sample CTC timer calculations in the AudioOutput and AudioInput demos to account for situations where the division results\r
   *    in a value with no remainder, requiring one to be subtracted from the result (thanks to Robin Theunis)\r
+  *  - The USB_Host_SendControlRequest() function no longer automatically selects the Control pipe (pipe 0), so that other control type\r
+  *    pipes can be used with the function\r
+  *  - The USB Host management task now saves and restores the currently selected pipe before and after the task completes\r
   *\r
   *  \section Sec_ChangeLog090401 Version 090401\r
   *\r
   *\r
   *  \section Sec_ChangeLog090401 Version 090401\r
   *\r
index d791069..f22426b 100644 (file)
@@ -43,6 +43,8 @@ uint8_t USB_Host_GetDeviceConfigDescriptor(uint16_t* const ConfigSizePtr, void*
                        wLength:       sizeof(USB_Descriptor_Configuration_Header_t),\r
                };\r
        \r
                        wLength:       sizeof(USB_Descriptor_Configuration_Header_t),\r
                };\r
        \r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
        if (BufferPtr == NULL)\r
        {\r
                uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)];\r
        if (BufferPtr == NULL)\r
        {\r
                uint8_t ConfigHeader[sizeof(USB_Descriptor_Configuration_Header_t)];\r
index 395f2d2..e62ac68 100644 (file)
@@ -86,6 +86,10 @@ static void USB_HostTask(void)
        static uint16_t WaitMSRemaining;\r
        static uint8_t  PostWaitState;\r
 \r
        static uint16_t WaitMSRemaining;\r
        static uint8_t  PostWaitState;\r
 \r
+       uint8_t PrevPipe = Pipe_GetCurrentPipe();\r
+\r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+\r
        switch (USB_HostState)\r
        {\r
                case HOST_STATE_WaitForDevice:\r
        switch (USB_HostState)\r
        {\r
                case HOST_STATE_WaitForDevice:\r
@@ -249,5 +253,7 @@ static void USB_HostTask(void)
 \r
                USB_ResetInterface();\r
        }\r
 \r
                USB_ResetInterface();\r
        }\r
+       \r
+       Pipe_SelectPipe(PrevPipe);\r
 }\r
 #endif\r
 }\r
 #endif\r
index 123a1d2..5367c98 100644 (file)
@@ -50,7 +50,6 @@ uint8_t USB_Host_SendControlRequest(void* BufferPtr)
        if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)\r
          return ReturnStatus;\r
 \r
        if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)\r
          return ReturnStatus;\r
 \r
-       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
        Pipe_SetToken(PIPE_TOKEN_SETUP);\r
        Pipe_ClearErrorFlags();\r
        Pipe_ClearSetupSent();\r
        Pipe_SetToken(PIPE_TOKEN_SETUP);\r
        Pipe_ClearErrorFlags();\r
        Pipe_ClearSetupSent();\r
index 84ee8ae..7ced889 100644 (file)
@@ -95,7 +95,7 @@
                /* Function Prototypes: */\r
                        /** Sends the request stored in the USB_HostRequest global structure to the attached device,\r
                         *  and transfers the data stored in the buffer to the device, or from the device to the buffer\r
                /* Function Prototypes: */\r
                        /** Sends the request stored in the USB_HostRequest global structure to the attached device,\r
                         *  and transfers the data stored in the buffer to the device, or from the device to the buffer\r
-                        *  as requested.\r
+                        *  as requested. The transfer is made on the currently selected pipe.\r
                         *\r
                         *  \param BufferPtr  Pointer to the start of the data buffer if the request has a data stage, or\r
                         *                    NULL if the request transfers no data to or from the device.\r
                         *\r
                         *  \param BufferPtr  Pointer to the start of the data buffer if the request has a data stage, or\r
                         *                    NULL if the request transfers no data to or from the device.\r
index 9aa3b00..49fa25d 100644 (file)
  *\r
  * \section Sec_MigrationXXXXXX Migrating from 090401 to XXXXXX\r
  *\r
  *\r
  * \section Sec_MigrationXXXXXX Migrating from 090401 to XXXXXX\r
  *\r
+ *  <b>Host Mode</b>\r
+ *    - The USB_Host_SendControlRequest() function no longer automatically selects the Control pipe (pipe 0) to allow it to be used on\r
+ *      other control type pipes. Care should be taken to ensure that the Control pipe is always selected before the function is called\r
+ *      in existing projects where the Control pipe is to be operated on.\r
+ *    - The USB Host management task now saves and restores the currently selected pipe before and after the task runs. Projects no longer\r
+ *      need to manage this manually when calling the USB management task.\r
  *\r
  * \section Sec_Migration090401 Migrating from 090209 to 090401\r
  *\r
  *\r
  * \section Sec_Migration090401 Migrating from 090209 to 090401\r
  *\r