USB_HostRequest renamed to USB_ControlRequest, entire control request header is now...
authorDean Camera <dean@fourwalledcubicle.com>
Wed, 22 Apr 2009 13:03:11 +0000 (13:03 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Wed, 22 Apr 2009 13:03:11 +0000 (13:03 +0000)
The USB_UnhandledControlPacket event has had its parameters removed, in favour of accessing the new USB_ControlRequest structure.

The Endpoint control stream functions now correctly send a ZLP to the host when less data than requested is sent.

43 files changed:
Bootloaders/CDC/BootloaderCDC.c
Bootloaders/DFU/BootloaderDFU.c
Bootloaders/TeensyHID/TeensyHID.c
Demos/Device/AudioInput/AudioInput.c
Demos/Device/AudioOutput/AudioOutput.c
Demos/Device/CDC/CDC.c
Demos/Device/DualCDC/DualCDC.c
Demos/Device/GenericHID/GenericHID.c
Demos/Device/Joystick/Joystick.c
Demos/Device/Keyboard/Keyboard.c
Demos/Device/KeyboardMouse/KeyboardMouse.c
Demos/Device/MassStorage/MassStorage.c
Demos/Device/Mouse/Mouse.c
Demos/Device/RNDISEthernet/RNDISEthernet.c
Demos/Device/USBtoSerial/USBtoSerial.c
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
Demos/OTG/TestApp/TestEvents.c
LUFA/ChangeLog.txt
LUFA/Drivers/USB/Class/ConfigDescriptor.c
LUFA/Drivers/USB/HighLevel/Events.h
LUFA/Drivers/USB/HighLevel/StdRequestType.h
LUFA/Drivers/USB/HighLevel/USBTask.c
LUFA/Drivers/USB/HighLevel/USBTask.h
LUFA/Drivers/USB/LowLevel/DevChapter9.c
LUFA/Drivers/USB/LowLevel/DevChapter9.h
LUFA/Drivers/USB/LowLevel/Endpoint.c
LUFA/Drivers/USB/LowLevel/HostChapter9.c
LUFA/Drivers/USB/LowLevel/HostChapter9.h
LUFA/Drivers/USB/LowLevel/Pipe.c
LUFA/Drivers/USB/LowLevel/Pipe.h
LUFA/MigrationInformation.txt
Projects/Magstripe/Magstripe.c

index 6b69421..708ba35 100644 (file)
@@ -152,13 +152,11 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
 {\r
        uint8_t* LineCodingData = (uint8_t*)&LineCoding;\r
 \r
-       Endpoint_Discard_Word();\r
-\r
        /* Process CDC specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
 \r
@@ -174,7 +172,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
 \r
@@ -192,7 +190,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        \r
                        break;\r
                case REQ_SetControlLineState:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
index 289b4eb..83881f1 100644 (file)
@@ -151,16 +151,10 @@ EVENT_HANDLER(USB_Disconnect)
  */\r
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
-       /* Discard unused wIndex value */\r
-       Endpoint_Discard_Word();\r
-       \r
-       /* Discard unused wValue value */\r
-       Endpoint_Discard_Word();\r
-\r
        /* Get the size of the command and data from the wLength value */\r
-       SentCommand.DataSize = Endpoint_Read_Word_LE();\r
+       SentCommand.DataSize = USB_ControlRequest.wLength;\r
 \r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case DFU_DNLOAD:\r
                        Endpoint_ClearSETUP();\r
index e81c462..cb1407a 100644 (file)
@@ -96,10 +96,10 @@ EVENT_HANDLER(USB_ConfigurationChanged)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        /* Handle HID Class specific requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_SetReport:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
index 45b9971..05094c2 100644 (file)
@@ -131,18 +131,16 @@ EVENT_HANDLER(USB_ConfigurationChanged)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        /* Process General and Audio specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_SetInterface:\r
                        /* Set Interface is not handled by the library, as its function is application-specific */\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))\r
                        {\r
-                               uint16_t wValue = Endpoint_Read_Word_LE();\r
-                               \r
                                Endpoint_ClearSETUP();\r
                                \r
                                /* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */\r
-                               if (wValue)\r
+                               if (USB_ControlRequest.wValue)\r
                                {\r
                                        /* Start audio task */\r
                                        Scheduler_SetTaskMode(USB_Audio_Task, TASK_RUN);\r
index ba9a499..640462d 100644 (file)
@@ -158,18 +158,16 @@ EVENT_HANDLER(USB_ConfigurationChanged)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        /* Process General and Audio specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_SetInterface:\r
                        /* Set Interface is not handled by the library, as its function is application-specific */\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_INTERFACE))\r
                        {\r
-                               uint16_t wValue = Endpoint_Read_Word_LE();\r
-                               \r
                                Endpoint_ClearSETUP();\r
                                \r
                                /* Check if the host is enabling the audio interface (setting AlternateSetting to 1) */\r
-                               if (wValue)\r
+                               if (USB_ControlRequest.wValue)\r
                                {\r
                                        /* Start audio task */\r
                                        Scheduler_SetTaskMode(USB_Audio_Task, TASK_RUN);\r
index fb7d74b..28bce1e 100644 (file)
@@ -160,10 +160,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        uint8_t* LineCodingData = (uint8_t*)&LineCoding;\r
 \r
        /* Process CDC specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {       \r
                                /* Acknowledge the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
@@ -177,7 +177,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                /* Acknowledge the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
@@ -191,18 +191,12 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        \r
                        break;\r
                case REQ_SetControlLineState:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-#if 0\r
                                /* NOTE: Here you can read in the line state mask from the host, to get the current state of the output handshake\r
-                                        lines. The mask is read in from the wValue parameter, and can be masked against the CONTROL_LINE_OUT_* masks\r
-                                        to determine the RTS and DTR line states using the following code:\r
+                                        lines. The mask is read in from the wValue parameter in USB_ControlRequest, and can be masked against the\r
+                                                CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code:\r
                                */\r
-\r
-                               uint16_t wIndex = Endpoint_Read_Word_LE();\r
-                                       \r
-                               // Do something with the given line states in wIndex\r
-#endif\r
                                \r
                                /* Acknowledge the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
index bbcbecc..4185a76 100644 (file)
@@ -198,10 +198,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        LineCodingData = (wIndex == 0) ? (uint8_t*)&LineCoding1 : (uint8_t*)&LineCoding2;\r
 \r
        /* Process CDC specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {       \r
                                /* Acknowledge the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
@@ -215,7 +215,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                /* Acknowledge the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
@@ -229,7 +229,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        \r
                        break;\r
                case REQ_SetControlLineState:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                /* Acknowledge the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
index 207f63c..245ddaa 100644 (file)
@@ -160,10 +160,10 @@ EVENT_HANDLER(USB_ConfigurationChanged)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        /* Handle HID Class specific requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetReport:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
        \r
@@ -180,7 +180,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                \r
                        break;\r
                case REQ_SetReport:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
index e5d23bd..ee4bc6a 100644 (file)
@@ -122,33 +122,20 @@ EVENT_HANDLER(USB_ConfigurationChanged)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        /* Handle HID Class specific requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetReport:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                USB_JoystickReport_Data_t JoystickReportData;\r
                                \r
                                /* Create the next HID report to send to the host */                            \r
                                GetNextReport(&JoystickReportData);\r
-\r
-                               /* Ignore report type and ID number value */\r
-                               Endpoint_Discard_Word();\r
-                               \r
-                               /* Ignore unused Interface number value */\r
-                               Endpoint_Discard_Word();\r
-\r
-                               /* Read in the number of bytes in the report to send to the host */\r
-                               uint16_t wLength = Endpoint_Read_Word_LE();\r
                                \r
-                               /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
-                               if (wLength > sizeof(JoystickReportData))\r
-                                 wLength = sizeof(JoystickReportData);\r
-\r
                                Endpoint_ClearSETUP();\r
        \r
                                /* Write the report data to the control endpoint */\r
-                               Endpoint_Write_Control_Stream_LE(&JoystickReportData, wLength);\r
+                               Endpoint_Write_Control_Stream_LE(&JoystickReportData, sizeof(JoystickReportData));\r
                                \r
                                /* Finalize the stream transfer to send the last packet or clear the host abort */\r
                                Endpoint_ClearOUT();\r
index 6d7ee3f..088943b 100644 (file)
@@ -193,33 +193,20 @@ EVENT_HANDLER(USB_ConfigurationChanged)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        /* Handle HID Class specific requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetReport:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                USB_KeyboardReport_Data_t KeyboardReportData;\r
 \r
                                /* Create the next keyboard report for transmission to the host */\r
                                CreateKeyboardReport(&KeyboardReportData);\r
 \r
-                               /* Ignore report type and ID number value */\r
-                               Endpoint_Discard_Word();\r
-                               \r
-                               /* Ignore unused Interface number value */\r
-                               Endpoint_Discard_Word();\r
-\r
-                               /* Read in the number of bytes in the report to send to the host */\r
-                               uint16_t wLength = Endpoint_Read_Word_LE();\r
-                               \r
-                               /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
-                               if (wLength > sizeof(KeyboardReportData))\r
-                                 wLength = sizeof(KeyboardReportData);\r
-\r
                                Endpoint_ClearSETUP();\r
        \r
                                /* Write the report data to the control endpoint */\r
-                               Endpoint_Write_Control_Stream_LE(&KeyboardReportData, wLength);\r
+                               Endpoint_Write_Control_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));\r
                                \r
                                /* Finalize the stream transfer to send the last packet or clear the host abort */\r
                                Endpoint_ClearOUT();\r
@@ -227,7 +214,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                \r
                        break;\r
                case REQ_SetReport:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
@@ -250,7 +237,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_GetProtocol:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
@@ -267,15 +254,12 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetProtocol:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               /* Read in the wValue parameter containing the new protocol mode */\r
-                               uint16_t wValue = Endpoint_Read_Word_LE();\r
-                                                               \r
                                Endpoint_ClearSETUP();\r
 \r
                                /* Set or clear the flag depending on what the host indicates that the current Protocol should be */\r
-                               UsingReportProtocol = (wValue != 0x0000);\r
+                               UsingReportProtocol = (USB_ControlRequest.wValue != 0x0000);\r
 \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
@@ -284,15 +268,12 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetIdle:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               /* Read in the wValue parameter containing the idle period */\r
-                               uint16_t wValue = Endpoint_Read_Word_LE();\r
-                               \r
                                Endpoint_ClearSETUP();\r
                                \r
                                /* Get idle period in MSB */\r
-                               IdleCount = (wValue >> 8);\r
+                               IdleCount = (USB_ControlRequest.wValue >> 8);\r
                                \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
@@ -301,7 +282,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_GetIdle:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {               \r
                                Endpoint_ClearSETUP();\r
                                \r
index 9cae69a..a85a378 100644 (file)
@@ -139,17 +139,13 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        uint8_t  ReportSize;\r
 \r
        /* Handle HID Class specific requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetReport:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               Endpoint_Discard_Word();\r
-                       \r
-                               uint16_t wIndex = Endpoint_Read_Word_LE();\r
-                               \r
                                /* Determine if it is the mouse or the keyboard data that is being requested */\r
-                               if (!(wIndex))\r
+                               if (!(USB_ControlRequest.wIndex))\r
                                {\r
                                        ReportData = (uint8_t*)&KeyboardReportData;\r
                                        ReportSize = sizeof(KeyboardReportData);\r
@@ -160,17 +156,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                        ReportSize = sizeof(MouseReportData);\r
                                }\r
 \r
-                               /* Read in the number of bytes in the report to send to the host */\r
-                               uint16_t wLength = Endpoint_Read_Word_LE();\r
-                               \r
-                               /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
-                               if (wLength > ReportSize)\r
-                                 wLength = ReportSize;\r
-\r
                                Endpoint_ClearSETUP();\r
        \r
                                /* Write the report data to the control endpoint */\r
-                               Endpoint_Write_Control_Stream_LE(ReportData, wLength);\r
+                               Endpoint_Write_Control_Stream_LE(ReportData, ReportSize);\r
 \r
                                /* Clear the report data afterwards */\r
                                memset(ReportData, 0, ReportSize);\r
@@ -181,7 +170,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                \r
                        break;\r
                case REQ_SetReport:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
index 8c7db93..e2c2424 100644 (file)
@@ -148,10 +148,10 @@ EVENT_HANDLER(USB_ConfigurationChanged)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        /* Process UFI specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_MassStorageReset:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
 \r
@@ -165,7 +165,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
 \r
                        break;\r
                case REQ_GetMaxLUN:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
 \r
index 0959a4a..2e5f05b 100644 (file)
@@ -183,33 +183,20 @@ EVENT_HANDLER(USB_ConfigurationChanged)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        /* Handle HID Class specific requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetReport:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                USB_MouseReport_Data_t MouseReportData;\r
 \r
                                /* Create the next mouse report for transmission to the host */\r
                                CreateMouseReport(&MouseReportData);\r
 \r
-                               /* Ignore report type and ID number value */\r
-                               Endpoint_Discard_Word();\r
-                               \r
-                               /* Ignore unused Interface number value */\r
-                               Endpoint_Discard_Word();\r
-\r
-                               /* Read in the number of bytes in the report to send to the host */\r
-                               uint16_t wLength = Endpoint_Read_Word_LE();\r
-                               \r
-                               /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
-                               if (wLength > sizeof(MouseReportData))\r
-                                 wLength = sizeof(MouseReportData);\r
-\r
                                Endpoint_ClearSETUP();\r
        \r
                                /* Write the report data to the control endpoint */\r
-                               Endpoint_Write_Control_Stream_LE(&MouseReportData, wLength);\r
+                               Endpoint_Write_Control_Stream_LE(&MouseReportData, sizeof(MouseReportData));\r
                                \r
                                /* Clear the report data afterwards */\r
                                memset(&MouseReportData, 0, sizeof(MouseReportData));\r
@@ -220,7 +207,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                \r
                        break;\r
                case REQ_GetProtocol:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
@@ -237,15 +224,12 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetProtocol:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               /* Read in the wValue parameter containing the new protocol mode */\r
-                               uint16_t wValue = Endpoint_Read_Word_LE();\r
-                               \r
                                Endpoint_ClearSETUP();\r
                                \r
                                /* Set or clear the flag depending on what the host indicates that the current Protocol should be */\r
-                               UsingReportProtocol = (wValue != 0x0000);\r
+                               UsingReportProtocol = (USB_ControlRequest.wValue != 0x0000);\r
                                \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
@@ -254,15 +238,12 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetIdle:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               /* Read in the wValue parameter containing the idle period */\r
-                               uint16_t wValue = Endpoint_Read_Word_LE();\r
-                               \r
                                Endpoint_ClearSETUP();\r
                                \r
                                /* Get idle period in MSB */\r
-                               IdleCount = (wValue >> 8);\r
+                               IdleCount = (USB_ControlRequest.wValue >> 8);\r
                                \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
@@ -271,7 +252,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_GetIdle:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {               \r
                                Endpoint_ClearSETUP();\r
                                \r
index ec8eb7b..7b81ad8 100644 (file)
@@ -150,10 +150,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        uint16_t wLength = Endpoint_Read_Word_LE();\r
 \r
        /* Process RNDIS class commands */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_SendEncapsulatedCommand:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                /* Clear the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
@@ -170,7 +170,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_GetEncapsulatedResponse:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                /* Check if a response to the last message is ready */\r
                                if (!(MessageHeader->MessageLength))\r
@@ -180,15 +180,11 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                                        MessageHeader->MessageLength = 1;\r
                                }\r
 \r
-                               /* Check if less than the requested number of bytes to transfer */\r
-                               if (MessageHeader->MessageLength < wLength)\r
-                                 wLength = MessageHeader->MessageLength;\r
-\r
                                /* Clear the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
                                \r
                                /* Write the message response data to the endpoint */\r
-                               Endpoint_Write_Control_Stream_LE(RNDISMessageBuffer, wLength);\r
+                               Endpoint_Write_Control_Stream_LE(RNDISMessageBuffer, MessageHeader->MessageLength);\r
                                \r
                                /* Finalize the stream transfer to send the last packet or clear the host abort */\r
                                Endpoint_ClearOUT();\r
index e1c22fc..dbf4b1b 100644 (file)
@@ -153,10 +153,10 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        uint8_t* LineCodingData = (uint8_t*)&LineCoding;\r
 \r
        /* Process CDC specific control requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {       \r
                                /* Acknowledge the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
@@ -170,7 +170,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetLineEncoding:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                /* Acknowledge the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
@@ -187,18 +187,12 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
        \r
                        break;\r
                case REQ_SetControlLineState:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-#if 0\r
                                /* NOTE: Here you can read in the line state mask from the host, to get the current state of the output handshake\r
-                                        lines. The mask is read in from the wValue parameter, and can be masked against the CONTROL_LINE_OUT_* masks\r
-                                        to determine the RTS and DTR line states using the following code:\r
+                                        lines. The mask is read in from the wValue parameter in USB_ControlRequest, and can be masked against the\r
+                                                CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code:\r
                                */\r
-\r
-                               uint16_t wIndex = Endpoint_Read_Word_LE();\r
-                                       \r
-                               // Do something with the given line states in wIndex\r
-#endif\r
                                \r
                                /* Acknowledge the SETUP packet, ready for data transfer */\r
                                Endpoint_ClearSETUP();\r
index aa99964..b499a27 100644 (file)
@@ -181,7 +181,7 @@ TASK(USB_CDC_Host)
        {\r
                case HOST_STATE_Addressed:\r
                        /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_SetConfiguration,\r
index f0d1967..9f419ad 100644 (file)
@@ -257,7 +257,7 @@ void WriteNextReport(uint8_t* ReportOUTData, uint8_t ReportIndex, uint8_t Report
        else\r
        {\r
                /* Class specific request to send a HID report to the device */\r
-               USB_HostRequest = (USB_Host_Request_Header_t)\r
+               USB_ControlRequest = (USB_Request_Header_t)\r
                        {\r
                                .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
                                .bRequest      = REQ_SetReport,\r
@@ -286,7 +286,7 @@ TASK(USB_HID_Host)
        {\r
                case HOST_STATE_Addressed:\r
                        /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_SetConfiguration,\r
index bc75bd3..f17f950 100644 (file)
@@ -253,7 +253,7 @@ TASK(USB_Keyboard_Host)
        {\r
                case HOST_STATE_Addressed:\r
                        /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_SetConfiguration,\r
@@ -303,7 +303,7 @@ TASK(USB_Keyboard_Host)
                        }\r
                \r
                        /* HID class request to set the keyboard protocol to the Boot Protocol */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
                                        .bRequest      = REQ_SetProtocol,\r
index 14b8038..6ac1f5a 100644 (file)
@@ -47,7 +47,7 @@ uint8_t GetHIDReportData(void)
        /* Create a buffer big enough to hold the entire returned HID report */\r
        uint8_t HIDReportData[HIDReportSize];\r
        \r
-       USB_HostRequest = (USB_Host_Request_Header_t)\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
                {\r
                        .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),\r
                        .bRequest      = REQ_GetDescriptor,\r
index 76ad5f2..9eb3d10 100644 (file)
@@ -184,7 +184,7 @@ TASK(USB_Keyboard_Host)
        {\r
                case HOST_STATE_Addressed:\r
                        /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_SetConfiguration,\r
index 9352562..c55a167 100644 (file)
@@ -155,7 +155,7 @@ TASK(USB_MassStore_Host)
        {\r
                case HOST_STATE_Addressed:\r
                        /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_SetConfiguration,\r
index 864edf3..d4df205 100644 (file)
@@ -250,7 +250,7 @@ static uint8_t MassStore_GetReturnedStatus(void)
  */\r
 uint8_t MassStore_ClearPipeStall(const uint8_t EndpointNum)\r
 {\r
-       USB_HostRequest = (USB_Host_Request_Header_t)\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
                {\r
                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),\r
                        .bRequest      = REQ_ClearFeature,\r
@@ -272,7 +272,7 @@ uint8_t MassStore_ClearPipeStall(const uint8_t EndpointNum)
  */\r
 uint8_t MassStore_MassStorageReset(void)\r
 {\r
-       USB_HostRequest = (USB_Host_Request_Header_t)\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
                {\r
                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
                        .bRequest      = REQ_MassStorageReset,\r
@@ -298,7 +298,7 @@ uint8_t MassStore_GetMaxLUN(uint8_t* const MaxLUNIndex)
 {\r
        uint8_t ErrorCode;\r
 \r
-       USB_HostRequest = (USB_Host_Request_Header_t)\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
                {\r
                        .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE),\r
                        .bRequest      = REQ_GetMaxLUN,\r
index a11ecc8..3c858a8 100644 (file)
@@ -248,7 +248,7 @@ TASK(USB_Mouse_Host)
        {\r
                case HOST_STATE_Addressed:\r
                        /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_SetConfiguration,\r
@@ -298,7 +298,7 @@ TASK(USB_Mouse_Host)
                        }\r
                \r
                        /* HID class request to set the mouse protocol to the Boot Protocol */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
                                        .bRequest      = REQ_SetProtocol,\r
index 68d6580..4d89590 100644 (file)
@@ -47,7 +47,7 @@ uint8_t GetHIDReportData(void)
        /* Create a buffer big enough to hold the entire returned HID report */\r
        uint8_t HIDReportData[HIDReportSize];\r
        \r
-       USB_HostRequest = (USB_Host_Request_Header_t)\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
                {\r
                        .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE),\r
                        .bRequest      = REQ_GetDescriptor,\r
index df063da..58a189f 100644 (file)
@@ -185,7 +185,7 @@ TASK(USB_Mouse_Host)
        {\r
                case HOST_STATE_Addressed:      \r
                        /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_SetConfiguration,\r
index 233e5b1..49ab0df 100644 (file)
@@ -263,7 +263,7 @@ bool SImage_IsEventReceived(void)
  */\r
 uint8_t SImage_ClearPipeStall(const uint8_t EndpointNum)\r
 {\r
-       USB_HostRequest = (USB_Host_Request_Header_t)\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
                {\r
                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT),\r
                        .bRequest      = REQ_ClearFeature,\r
index 4b196c3..ca5292b 100644 (file)
@@ -151,7 +151,7 @@ TASK(USB_SImage_Host)
        {\r
                case HOST_STATE_Addressed:\r
                        /* Standard request to set the device configuration to configuration 1 */\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_SetConfiguration,\r
index 8f05b82..1751477 100644 (file)
@@ -193,8 +193,9 @@ EVENT_HANDLER(USB_DeviceError)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        puts_P(PSTR(EVENT_PREFIX "Ctrl Request\r\n"));\r
-       printf_P(PSTR(" -- Req Data %d\r\n"), bRequest);\r
-       printf_P(PSTR(" -- Req Type %d\r\n"), bmRequestType);\r
+       printf_P(PSTR(" -- Req Data %d\r\n"), USB_ControlRequest.bRequest);\r
+       printf_P(PSTR(" -- Req Type %d\r\n"), USB_ControlRequest.bmRequestType);\r
+       printf_P(PSTR(" -- Req Length %d\r\n"), USB_ControlRequest.wLength);\r
 }\r
 \r
 /** Event handler for the USB_ConfigurationChanged event. When fired, the event is logged to the USART. */\r
index f0c33e0..3825cd3 100644 (file)
   *  - Capitalised the "Descriptor_Search" and "Descriptor_Search_Comp" prefixes of the values in the DSearch_Return_ErrorCodes_t and\r
   *    DSearch_Comp_Return_ErrorCodes_t enums\r
   *  - Changed over all deprecated GCC structure tag initializers to the standardized C99 format (thanks to Mike Alexander)\r
+  *  - USB_HostRequest renamed to USB_ControlRequest, entire control request header is now read into USB_ControlRequest in Device mode\r
+  *    rather than having the library pass only partially read header data to the application\r
+  *  - The USB_UnhandledControlPacket event has had its parameters removed, in favour of accessing the new USB_ControlRequest structure\r
+  *  - The Endpoint control stream functions now correctly send a ZLP to the host when less data than requested is sent\r
   *    \r
   *\r
   *  \section Sec_ChangeLog090401 Version 090401\r
index dd782c8..367b28a 100644 (file)
@@ -35,7 +35,7 @@ uint8_t USB_GetDeviceConfigDescriptor(uint16_t* const ConfigSizePtr, void* Buffe
 {\r
        uint8_t ErrorCode;\r
 \r
-       USB_HostRequest = (USB_Host_Request_Header_t)\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
                {\r
                        .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),\r
                        .bRequest      = REQ_GetDescriptor,\r
@@ -60,7 +60,7 @@ uint8_t USB_GetDeviceConfigDescriptor(uint16_t* const ConfigSizePtr, void* Buffe
        }\r
        else\r
        {\r
-               USB_HostRequest.wLength = *ConfigSizePtr;\r
+               USB_ControlRequest.wLength = *ConfigSizePtr;\r
                \r
                ErrorCode      = USB_Host_SendControlRequest(BufferPtr);                                \r
        }\r
index 9638afe..73a804c 100644 (file)
                         *        parameters (wValue, wIndex, wLength, and Data) remain in the control endpoint bank until\r
                         *        read out by the user application for processing.\r
                         */\r
-                       void USB_UnhandledControlPacket(const uint8_t bRequest, const uint8_t bmRequestType);\r
+                       void USB_UnhandledControlPacket(void);\r
 \r
                        /** Event for USB configuration number changed. This event fires when a the USB host changes the\r
                         *  selected configuration number while in device mode. This event should be hooked in device\r
                        #endif\r
                        \r
                        #if defined(USB_CAN_BE_DEVICE)\r
-                               #define USB_UnhandledControlPacket_P    (const uint8_t bRequest, const uint8_t bmRequestType)\r
+                               #define USB_UnhandledControlPacket_P    (void)\r
                                #define USB_ConfigurationChanged_P      (void)\r
                                #define USB_Suspend_P                   (void)\r
                                #define USB_WakeUp_P                    (void)\r
index 27c1794..6f21489 100644 (file)
                         */\r
                        #define FEATURE_REMOTE_WAKEUP           0x01\r
 \r
+               /* Type Defines: */\r
+                       /** Type define for a standard USB control request.\r
+                        *\r
+                        *  \see The USB 2.0 specification for more information on standard control requests.\r
+                        */\r
+                       typedef struct\r
+                       {\r
+                               uint8_t  bmRequestType; /**< Type of the request. */\r
+                               uint8_t  bRequest; /**< Request command code. */\r
+                               uint16_t wValue; /**< wValue parameter of the request. */\r
+                               uint16_t wIndex; /**< wIndex parameter of the request. */\r
+                               uint16_t wLength; /**< Length of the data to transfer in bytes. */\r
+                       } USB_Request_Header_t;\r
+\r
                /* Enums: */\r
                        /** Enumeration for the various standard request commands. These commands are applicable when the\r
                         *  request type is REQTYPE_STANDARD (with the exception of REQ_GetDescriptor, which is always\r
index e1c0659..aa04c56 100644 (file)
 #define  INCLUDE_FROM_USBTASK_C\r
 #include "USBTask.h"\r
 \r
-volatile bool      USB_IsSuspended;\r
-volatile bool      USB_IsConnected;\r
-volatile bool      USB_IsInitialized;\r
+volatile bool        USB_IsSuspended;\r
+volatile bool        USB_IsConnected;\r
+volatile bool        USB_IsInitialized;\r
+USB_Request_Header_t USB_ControlRequest;\r
 \r
 #if defined(USB_CAN_BE_HOST)\r
 volatile uint8_t   USB_HostState;\r
@@ -169,7 +170,7 @@ static void USB_HostTask(void)
                        USB_HostState = HOST_STATE_Default;\r
                        break;\r
                case HOST_STATE_Default:\r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_GetDescriptor,\r
@@ -214,7 +215,7 @@ static void USB_HostTask(void)
 \r
                        Pipe_SetInfiniteINRequests();\r
                        \r
-                       USB_HostRequest = (USB_Host_Request_Header_t)\r
+                       USB_ControlRequest = (USB_Request_Header_t)\r
                                {\r
                                        .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE),\r
                                        .bRequest      = REQ_SetAddress,\r
index 833fd9e..7e88ce8 100644 (file)
@@ -40,6 +40,7 @@
                \r
                #include "../../../Scheduler/Scheduler.h"\r
                #include "../LowLevel/LowLevel.h"\r
+               #include "StdRequestType.h"\r
                #include "USBMode.h"\r
                #include "Events.h"\r
                #include "StdDescriptors.h"\r
                         */\r
                        extern volatile bool USB_IsInitialized;\r
 \r
+                       /** Structure containing the last received Control request when in Device mode (for use in user-applications\r
+                        *  inside of the USB_UnhandledControlPacket() event, or for filling up with a control request to issue when\r
+                        *  in Host mode before calling USB_Host_SendControlRequest().\r
+                        *\r
+                        *  \ingroup Group_USBManagement\r
+                        */\r
+                        extern USB_Request_Header_t USB_ControlRequest;\r
+                       \r
                        #if defined(USB_CAN_BE_DEVICE) || defined(__DOXYGEN__)\r
                        /** Indicates if the USB interface is currently suspended by the host when in device mode. When suspended,\r
                         *  the device should consume minimal power, and cannot communicate to the host. If Remote Wakeup is\r
index 3f2805c..bf2b127 100644 (file)
@@ -41,17 +41,19 @@ bool    USB_CurrentlySelfPowered;
 \r
 void USB_Device_ProcessControlPacket(void)\r
 {\r
-       uint8_t bmRequestType  = Endpoint_Read_Byte();\r
-       uint8_t bRequest       = Endpoint_Read_Byte();\r
-       bool    RequestHandled = false; \r
+       bool     RequestHandled = false;\r
+       uint8_t* RequestHeader  = (uint8_t*)&USB_ControlRequest;\r
        \r
-       switch (bRequest)\r
+       for (uint8_t RequestHeaderByte = 0; RequestHeaderByte < sizeof(USB_Request_Header_t); RequestHeaderByte++)\r
+         *(RequestHeader++) = Endpoint_Read_Byte();\r
+       \r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetStatus:\r
-                       if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||\r
-                           (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT)))\r
+                       if ((USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||\r
+                           (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT)))\r
                        {\r
-                               USB_Device_GetStatus(bmRequestType);\r
+                               USB_Device_GetStatus();\r
                                RequestHandled = true;\r
                        }\r
 \r
@@ -59,16 +61,16 @@ void USB_Device_ProcessControlPacket(void)
 #if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
                case REQ_ClearFeature:\r
                case REQ_SetFeature:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_ENDPOINT))\r
                        {\r
-                               USB_Device_ClearSetFeature(bRequest, bmRequestType);\r
+                               USB_Device_ClearSetFeature();\r
                                RequestHandled = true;\r
                        }\r
 \r
                        break;\r
 #endif\r
                case REQ_SetAddress:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))\r
                        {\r
                                USB_Device_SetAddress();\r
                                RequestHandled = true;\r
@@ -76,8 +78,8 @@ void USB_Device_ProcessControlPacket(void)
 \r
                        break;\r
                case REQ_GetDescriptor:\r
-                       if ((bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||\r
-                           (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE)))\r
+                       if ((USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE)) ||\r
+                           (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_INTERFACE)))\r
                        {\r
                                USB_Device_GetDescriptor();\r
                                RequestHandled = true;\r
@@ -85,7 +87,7 @@ void USB_Device_ProcessControlPacket(void)
                        \r
                        break;\r
                case REQ_GetConfiguration:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE))\r
                        {\r
                                USB_Device_GetConfiguration();\r
                                RequestHandled = true;\r
@@ -93,7 +95,7 @@ void USB_Device_ProcessControlPacket(void)
 \r
                        break;\r
                case REQ_SetConfiguration:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_STANDARD | REQREC_DEVICE))\r
                        {\r
                                USB_Device_SetConfiguration();\r
                                RequestHandled = true;\r
@@ -103,7 +105,7 @@ void USB_Device_ProcessControlPacket(void)
        }\r
 \r
        if (!(RequestHandled))\r
-         RAISE_EVENT(USB_UnhandledControlPacket, bRequest, bmRequestType);\r
+         RAISE_EVENT(USB_UnhandledControlPacket);\r
          \r
        if (Endpoint_IsSETUPReceived())\r
        {\r
@@ -114,8 +116,6 @@ void USB_Device_ProcessControlPacket(void)
 \r
 static void USB_Device_SetAddress(void)\r
 {\r
-       uint8_t wValue_LSB = Endpoint_Read_Byte();\r
-\r
        Endpoint_ClearSETUP();\r
        \r
        while (!(Endpoint_IsINReady()));\r
@@ -124,28 +124,27 @@ static void USB_Device_SetAddress(void)
        \r
        while (!(Endpoint_IsINReady()));\r
 \r
-       UDADDR = ((1 << ADDEN) | (wValue_LSB & 0x7F));\r
+       UDADDR = ((1 << ADDEN) | (USB_ControlRequest.wValue & 0x7F));\r
 \r
        return;\r
 }\r
 \r
 static void USB_Device_SetConfiguration(void)\r
 {\r
-       uint8_t wValue_LSB        = Endpoint_Read_Byte();\r
        bool    AlreadyConfigured = (USB_ConfigurationNumber != 0);\r
 \r
 #if defined(USE_SINGLE_DEVICE_CONFIGURATION)\r
-       if (wValue_LSB > 1)\r
+       if (USB_ControlRequest.wValue > 1)\r
 #else\r
        USB_Descriptor_Device_t* DevDescriptorPtr;\r
 \r
        if ((USB_GetDescriptor((DTYPE_Device << 8), 0, (void*)&DevDescriptorPtr) == NO_DESCRIPTOR) ||\r
        #if defined(USE_RAM_DESCRIPTORS)\r
-           (wValue_LSB > DevDescriptorPtr->NumberOfConfigurations))\r
+           (USB_ControlRequest.wValue > DevDescriptorPtr->NumberOfConfigurations))\r
        #elif defined (USE_EEPROM_DESCRIPTORS)\r
-           (wValue_LSB > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
+           (USB_ControlRequest.wValue > eeprom_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
        #else\r
-           (wValue_LSB > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
+           (USB_ControlRequest.wValue > pgm_read_byte(&DevDescriptorPtr->NumberOfConfigurations)))\r
        #endif\r
 #endif\r
        {\r
@@ -154,7 +153,7 @@ static void USB_Device_SetConfiguration(void)
        \r
        Endpoint_ClearSETUP();\r
 \r
-       USB_ConfigurationNumber = wValue_LSB;\r
+       USB_ConfigurationNumber = USB_ControlRequest.wValue;\r
 \r
        Endpoint_ClearIN();\r
 \r
@@ -178,24 +177,23 @@ void USB_Device_GetConfiguration(void)
 \r
 static void USB_Device_GetDescriptor(void)\r
 {\r
-       uint16_t wValue  = Endpoint_Read_Word_LE();\r
-       uint16_t wIndex  = Endpoint_Read_Word_LE();\r
-       uint16_t wLength = Endpoint_Read_Word_LE();\r
-       \r
        void*    DescriptorPointer;\r
        uint16_t DescriptorSize;\r
        \r
-       bool     SendZLP;\r
-       \r
-       if ((DescriptorSize = USB_GetDescriptor(wValue, wIndex, &DescriptorPointer)) == NO_DESCRIPTOR)\r
+       if ((DescriptorSize = USB_GetDescriptor(USB_ControlRequest.wValue, USB_ControlRequest.wIndex, &DescriptorPointer)) == NO_DESCRIPTOR)\r
          return;\r
        \r
-       Endpoint_ClearSETUP();  \r
+       Endpoint_ClearSETUP();\r
+       \r
+       #if defined(USE_RAM_DESCRIPTORS)\r
+       Endpoint_Write_Control_Stream_LE(DescriptorPointer, DescriptorSize);\r
+       #else\r
+       bool     SendZLP;\r
        \r
-       if (wLength > DescriptorSize)\r
-         wLength = DescriptorSize;\r
+       if (USB_ControlRequest.wLength > DescriptorSize)\r
+         USB_ControlRequest.wLength = DescriptorSize;\r
        \r
-       while (wLength)\r
+       while (USB_ControlRequest.wLength)\r
        {\r
                while (!(Endpoint_IsINReady()))\r
                {\r
@@ -206,17 +204,15 @@ static void USB_Device_GetDescriptor(void)
                        }               \r
                }\r
                \r
-               while (wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
+               while (USB_ControlRequest.wLength && (Endpoint_BytesInEndpoint() < USB_ControlEndpointSize))\r
                {\r
-                       #if defined(USE_RAM_DESCRIPTORS)\r
-                       Endpoint_Write_Byte(*((uint8_t*)DescriptorPointer++));\r
-                       #elif defined (USE_EEPROM_DESCRIPTORS)\r
+                       #if defined (USE_EEPROM_DESCRIPTORS)\r
                        Endpoint_Write_Byte(eeprom_read_byte(DescriptorPointer++));                     \r
                        #else\r
                        Endpoint_Write_Byte(pgm_read_byte(DescriptorPointer++));\r
                        #endif\r
                        \r
-                       wLength--;\r
+                       USB_ControlRequest.wLength--;\r
                }\r
                \r
                SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
@@ -230,20 +226,16 @@ static void USB_Device_GetDescriptor(void)
        }\r
 \r
        while (!(Endpoint_IsOUTReceived()));\r
+       #endif\r
+       \r
        Endpoint_ClearOUT();\r
 }\r
 \r
-static void USB_Device_GetStatus(const uint8_t bmRequestType)\r
+static void USB_Device_GetStatus(void)\r
 {\r
        uint8_t CurrentStatus = 0;\r
 \r
-       Endpoint_Discard_Word();\r
-\r
-#if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
-       uint8_t wIndex_LSB = Endpoint_Read_Byte();\r
-#endif\r
-       \r
-       switch (bmRequestType)\r
+       switch (USB_ControlRequest.bmRequestType)\r
        {\r
                case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_DEVICE):\r
                        if (USB_CurrentlySelfPowered)\r
@@ -255,15 +247,16 @@ static void USB_Device_GetStatus(const uint8_t bmRequestType)
                        break;\r
 #if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
                case (REQDIR_DEVICETOHOST | REQTYPE_STANDARD | REQREC_ENDPOINT):\r
-                       Endpoint_SelectEndpoint(wIndex_LSB);\r
+                       Endpoint_SelectEndpoint(USB_ControlRequest.wIndex);\r
 \r
                        CurrentStatus = Endpoint_IsStalled();\r
 \r
+                       Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);                      \r
+\r
                        break;\r
 #endif\r
        }\r
-       \r
-       Endpoint_SelectEndpoint(ENDPOINT_CONTROLEP);                      \r
+\r
        Endpoint_ClearSETUP();\r
 \r
        Endpoint_Write_Word_LE(CurrentStatus);\r
@@ -275,17 +268,14 @@ static void USB_Device_GetStatus(const uint8_t bmRequestType)
 }\r
 \r
 #if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
-static void USB_Device_ClearSetFeature(const uint8_t bRequest, const uint8_t bmRequestType)\r
-{\r
-       uint16_t wValue = Endpoint_Read_Word_LE();\r
-       uint16_t wIndex = Endpoint_Read_Word_LE();\r
-       \r
-       switch (bmRequestType & CONTROL_REQTYPE_RECIPIENT)\r
+static void USB_Device_ClearSetFeature(void)\r
+{      \r
+       switch (USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_RECIPIENT)\r
        {\r
                case REQREC_ENDPOINT:\r
-                       if (wValue == FEATURE_ENDPOINT_HALT)\r
+                       if (USB_ControlRequest.wValue == FEATURE_ENDPOINT_HALT)\r
                        {\r
-                               uint8_t EndpointIndex = (wIndex & ENDPOINT_EPNUM_MASK);\r
+                               uint8_t EndpointIndex = (USB_ControlRequest.wIndex & ENDPOINT_EPNUM_MASK);\r
                                \r
                                if (EndpointIndex != ENDPOINT_CONTROLEP)\r
                                {\r
@@ -293,7 +283,7 @@ static void USB_Device_ClearSetFeature(const uint8_t bRequest, const uint8_t bmR
 \r
                                        if (Endpoint_IsEnabled())\r
                                        {                               \r
-                                               if (bRequest == REQ_ClearFeature)\r
+                                               if (USB_ControlRequest.bRequest == REQ_ClearFeature)\r
                                                {\r
                                                        Endpoint_ClearStall();\r
                                                        Endpoint_ResetFIFO(EndpointIndex);\r
index 23b7b46..10a9193 100644 (file)
@@ -39,6 +39,7 @@
                #include "../HighLevel/StdDescriptors.h"\r
                #include "../HighLevel/Events.h"\r
                #include "../HighLevel/StdRequestType.h"\r
+               #include "../HighLevel/USBTask.h"\r
                #include "LowLevel.h"\r
 \r
        /* Enable C linkage for C++ Compilers: */\r
                                static void USB_Device_SetConfiguration(void);\r
                                static void USB_Device_GetConfiguration(void);\r
                                static void USB_Device_GetDescriptor(void);\r
-                               static void USB_Device_GetStatus(const uint8_t bmRequestType);\r
+                               static void USB_Device_GetStatus(void);\r
                                #if !defined(FEATURELESS_CONTROL_ONLY_DEVICE)\r
-                               static void USB_Device_ClearSetFeature(const uint8_t bRequest, const uint8_t bmRequestType);\r
+                               static void USB_Device_ClearSetFeature(void);\r
                                #endif\r
                        #endif\r
        #endif\r
index e196b6a..efa1a2d 100644 (file)
@@ -292,8 +292,9 @@ uint8_t Endpoint_Read_Stream_BE(void* Buffer, uint16_t Length
 \r
 uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)\r
 {\r
-       uint8_t* DataStream = (uint8_t*)Buffer;\r
-       bool     SendZLP    = true;\r
+       uint8_t* DataStream    = (uint8_t*)Buffer;\r
+       bool     LastPacketFull = false;\r
+       bool     ShortTransfer = (Length < USB_ControlRequest.wLength);\r
        \r
        while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
@@ -306,14 +307,14 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+               LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
                Endpoint_ClearIN();\r
        }\r
        \r
        if (Endpoint_IsOUTReceived())\r
          return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
        \r
-       if (SendZLP)\r
+       if (LastPacketFull || ShortTransfer)\r
        {\r
                while (!(Endpoint_IsINReady()));\r
                Endpoint_ClearIN();\r
@@ -326,8 +327,9 @@ uint8_t Endpoint_Write_Control_Stream_LE(const void* Buffer, uint16_t Length)
 \r
 uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)\r
 {\r
-       uint8_t* DataStream = (uint8_t*)(Buffer + Length - 1);\r
-       bool     SendZLP    = true;\r
+       uint8_t* DataStream     = (uint8_t*)(Buffer + Length - 1);\r
+       bool     LastPacketFull = false;\r
+       bool     ShortTransfer  = (Length < USB_ControlRequest.wLength);\r
        \r
        while (Length && !(Endpoint_IsOUTReceived()))\r
        {\r
@@ -340,14 +342,14 @@ uint8_t Endpoint_Write_Control_Stream_BE(const void* Buffer, uint16_t Length)
                        Length--;\r
                }\r
                \r
-               SendZLP = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
+               LastPacketFull = (Endpoint_BytesInEndpoint() == USB_ControlEndpointSize);\r
                Endpoint_ClearIN();\r
        }\r
        \r
        if (Endpoint_IsOUTReceived())\r
          return ENDPOINT_RWCSTREAM_ERROR_HostAborted;\r
        \r
-       if (SendZLP)\r
+       if (LastPacketFull || ShortTransfer)\r
        {\r
                while (!(Endpoint_IsINReady()));\r
                Endpoint_ClearIN();\r
index dfc3f44..ee51cf3 100644 (file)
 #define  INCLUDE_FROM_HOSTCHAPTER9_C\r
 #include "HostChapter9.h"\r
 \r
-USB_Host_Request_Header_t USB_HostRequest;\r
-\r
 uint8_t USB_Host_SendControlRequest(void* BufferPtr)\r
 {\r
-       uint8_t* HeaderStream   = (uint8_t*)&USB_HostRequest;\r
+       uint8_t* HeaderStream   = (uint8_t*)&USB_ControlRequest;\r
        uint8_t* DataStream     = (uint8_t*)BufferPtr;\r
        bool     BusSuspended   = USB_Host_IsBusSuspended();\r
        uint8_t  ReturnStatus   = HOST_SENDCONTROL_Successful;\r
-       uint16_t DataLen        = USB_HostRequest.wLength;\r
+       uint16_t DataLen        = USB_ControlRequest.wLength;\r
 \r
        USB_Host_ResumeBus();\r
        \r
@@ -55,7 +53,7 @@ uint8_t USB_Host_SendControlRequest(void* BufferPtr)
 \r
        Pipe_Unfreeze();\r
 \r
-       for (uint8_t HeaderByte = 0; HeaderByte < sizeof(USB_Host_Request_Header_t); HeaderByte++)\r
+       for (uint8_t HeaderByte = 0; HeaderByte < sizeof(USB_Request_Header_t); HeaderByte++)\r
          Pipe_Write_Byte(*(HeaderStream++));\r
 \r
        Pipe_ClearSETUP();\r
@@ -68,7 +66,7 @@ uint8_t USB_Host_SendControlRequest(void* BufferPtr)
        if ((ReturnStatus = USB_Host_WaitMS(1)) != HOST_WAITERROR_Successful)\r
          goto End_Of_Control_Send;\r
 \r
-       if ((USB_HostRequest.bmRequestType & CONTROL_REQTYPE_DIRECTION) == REQDIR_DEVICETOHOST)\r
+       if ((USB_ControlRequest.bmRequestType & CONTROL_REQTYPE_DIRECTION) == REQDIR_DEVICETOHOST)\r
        {\r
                Pipe_SetToken(PIPE_TOKEN_IN);\r
                \r
index c2c4ece..cbb5ba5 100644 (file)
                #endif\r
 \r
        /* Public Interface - May be used in end-application: */\r
-               /* Type Defines: */\r
-                       /** Type define for a standard USB control request.\r
-                        *\r
-                        *  \see StdRequestType.h for information on the request type and data.\r
-                        *  \see The USB 2.0 specification for more information on standard control requests.\r
-                        *\r
-                        *  \ingroup Group_PipeControlReq\r
-                        */\r
-                       typedef struct\r
-                       {\r
-                               uint8_t  bmRequestType; /**< Type of the request. */\r
-                               uint8_t  bRequest; /**< Request command code. */\r
-                               uint16_t wValue; /**< wValue parameter of the request. */\r
-                               uint16_t wIndex; /**< wIndex parameter of the request. */\r
-                               uint16_t wLength; /**< Length of the data to transfer in bytes. */\r
-                       } USB_Host_Request_Header_t;\r
-\r
                /* Enums: */\r
                        /** Enum for the USB_Host_SendControlRequest() return code, indicating the reason for the error\r
                         *  if the transfer of the request is unsuccessful.\r
                                HOST_SENDCONTROL_SoftwareTimeOut  = 4, /**< The request or data transfer timed out. */\r
                        };\r
                        \r
-               /* Global Variables: */\r
-                       /** Global for the request to send via the USB_Host_SendControlRequest() function. This\r
-                        *  global should be filled with the correct control request data before sending the request to\r
-                        *  the attached device while in host mode.\r
-                        *\r
-                        *  \ingroup Group_PipeControlReq\r
-                        */\r
-                       extern USB_Host_Request_Header_t USB_HostRequest;\r
-                       \r
                /* Function Prototypes: */\r
-                       /** Sends the request stored in the USB_HostRequest global structure to the attached device,\r
+                       /** Sends the request stored in the USB_ControlRequest 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. The transfer is made on the currently selected pipe.\r
                         *\r
index 5850fcf..ff4318c 100644 (file)
@@ -37,7 +37,7 @@
 \r
 uint8_t USB_ControlPipeSize = PIPE_CONTROLPIPE_DEFAULT_SIZE;\r
 \r
-bool Pipe_ConfigurePipe(const uint8_t  Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,\r
+bool Pipe_ConfigurePipe(const uint8_t Number, const uint8_t Type, const uint8_t Token, const uint8_t EndpointNumber,\r
                                                const uint16_t Size, const uint8_t Banks)\r
 {\r
        Pipe_SelectPipe(Number);\r
index 3f512c0..25121ca 100644 (file)
                                 *  is an IN direction and no packet (or an empty packet) has been received, or if the pipe is an OUT\r
                                 *  direction and the pipe bank is full.\r
                                 *\r
+                                *  \note This function is not valid on CONTROL type pipes.\r
+                                *\r
                                 *  \ingroup Group_PipePacketManagement\r
                                 *  \r
                                 *  \return Boolean true if the currently selected pipe may be read from or written to, depending on its direction\r
index 576ba64..efec274 100644 (file)
@@ -33,6 +33,9 @@
  *    - The Endpoint_ClearSetupReceived() macro has been renamed to Endpoint_ClearSETUP().\r
  *    - All endpoint read/write/discard aliases which did not have an explicitly endianness specifier (such as Endpoint_Read_Word()) have\r
  *      been removed for clarity. Existing projects should use the "_LE" suffix on such calls to use the explicit Little Endian versions.\r
+ *    - The USB_UnhandledControlPacket event no longer has any parameters. User code should no longer attempt to read in the remainder of\r
+ *      the Control Request header as all Control Request header data is now preloaded by the library and made available in the\r
+ *      USB_ControlRequest structure.\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
@@ -61,6 +64,8 @@
  *      and SetReportItemInfo() has been renamed to USB_GetHIDReportItemInfo().\r
  *    - The values of the DSearch_Return_ErrorCodes_t and DSearch_Comp_Return_ErrorCodes_t enums have had their respective "Descriptor_Search"\r
  *      and "Descriptor_Search_Comp" prefixes changed to all caps.\r
+ *    - The USB_HostRequest global has been renamed to USB_ControlRequest, and is used in Device mode also. The USB_Host_Request_Header_t\r
+ *      structure type has been renamed to USB_Request_Header_t.\r
  *\r
  * \section Sec_Migration090401 Migrating from 090209 to 090401\r
  *\r
index 94eed31..24172d8 100644 (file)
@@ -155,33 +155,20 @@ EVENT_HANDLER(USB_ConfigurationChanged)
 EVENT_HANDLER(USB_UnhandledControlPacket)\r
 {\r
        /* Handle HID Class specific requests */\r
-       switch (bRequest)\r
+       switch (USB_ControlRequest.bRequest)\r
        {\r
                case REQ_GetReport:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                USB_KeyboardReport_Data_t KeyboardReportData;\r
 \r
                                /* Create the next keyboard report for transmission to the host */\r
                                GetNextReport(&KeyboardReportData);\r
 \r
-                               /* Ignore report type and ID number value */\r
-                               Endpoint_Discard_Word();\r
-                               \r
-                               /* Ignore unused Interface number value */\r
-                               Endpoint_Discard_Word();\r
-\r
-                               /* Read in the number of bytes in the report to send to the host */\r
-                               uint16_t wLength = Endpoint_Read_Word_LE();\r
-                               \r
-                               /* If trying to send more bytes than exist to the host, clamp the value at the report size */\r
-                               if (wLength > sizeof(KeyboardReportData))\r
-                                 wLength = sizeof(KeyboardReportData);\r
-\r
                                Endpoint_ClearSETUP();\r
        \r
                                /* Write the report data to the control endpoint */\r
-                               Endpoint_Write_Control_Stream_LE(&KeyboardReportData, wLength);\r
+                               Endpoint_Write_Control_Stream_LE(&KeyboardReportData, sizeof(KeyboardReportData));\r
                                \r
                                /* Finalize the stream transfer to send the last packet or clear the host abort */\r
                                Endpoint_ClearOUT();\r
@@ -189,7 +176,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                \r
                        break;\r
                case REQ_GetProtocol:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                \r
@@ -206,15 +193,12 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetProtocol:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               /* Read in the wValue parameter containing the new protocol mode */\r
-                               uint16_t wValue = Endpoint_Read_Word_LE();\r
-                               \r
                                Endpoint_ClearSETUP();\r
 \r
                                /* Set or clear the flag depending on what the host indicates that the current Protocol should be */\r
-                               UsingReportProtocol = (wValue != 0x0000);\r
+                               UsingReportProtocol = (USB_ControlRequest.wValue != 0x0000);\r
                                \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
@@ -223,15 +207,12 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_SetIdle:\r
-                       if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {\r
-                               /* Read in the wValue parameter containing the idle period */\r
-                               uint16_t wValue = Endpoint_Read_Word_LE();\r
-                               \r
                                Endpoint_ClearSETUP();\r
                                \r
                                /* Get idle period in MSB */\r
-                               IdleCount = (wValue >> 8);\r
+                               IdleCount = (USB_ControlRequest.wValue >> 8);\r
                                \r
                                /* Acknowledge status stage */\r
                                while (!(Endpoint_IsINReady()));\r
@@ -240,7 +221,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket)
                        \r
                        break;\r
                case REQ_GetIdle:\r
-                       if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))\r
                        {               \r
                                Endpoint_ClearSETUP();\r
                                \r