Fix issue in CDC device class driver where received data the size of the data endpoin...
authorDean Camera <dean@fourwalledcubicle.com>
Tue, 11 Aug 2009 01:52:15 +0000 (01:52 +0000)
committerDean Camera <dean@fourwalledcubicle.com>
Tue, 11 Aug 2009 01:52:15 +0000 (01:52 +0000)
Further work on the new CDC and HID host mode class drivers.

Reset changelog et. al. to reset development information for the new version currently under development.

14 files changed:
Demos/Host/ClassDriver/CDCHost/CDCHost.c
Demos/Host/ClassDriver/CDCHost/makefile
Demos/Host/ClassDriver/MouseHost/MouseHost.c
LUFA/Doxygen.conf
LUFA/Drivers/USB/Class/Device/CDC.c
LUFA/Drivers/USB/Class/Host/CDC.c
LUFA/Drivers/USB/Class/Host/CDC.h
LUFA/Drivers/USB/Class/Host/HID.c
LUFA/Drivers/USB/Class/Host/HID.h
LUFA/ManPages/ChangeLog.txt
LUFA/ManPages/FutureChanges.txt
LUFA/ManPages/LUFAPoweredProjects.txt
LUFA/ManPages/MigrationInformation.txt
LUFA/Version.h

index cf0a9f3..7aa8dee 100644 (file)
@@ -103,6 +103,13 @@ int main(void)
                                USB_HostState = HOST_STATE_Configured;\r
                                break;\r
                        case HOST_STATE_Configured:\r
+                               if (CDC_Host_BytesReceived(&VirtualSerial_CDC_Interface))\r
+                               {\r
+                                       /* Echo received bytes from the attached device through the USART */\r
+                                       while (CDC_Host_BytesReceived(&VirtualSerial_CDC_Interface))\r
+                                         putchar(CDC_Host_ReceiveByte(&VirtualSerial_CDC_Interface));\r
+                               }\r
+                       \r
                                break;\r
                }\r
        \r
index 4dd06eb..9161af1 100644 (file)
@@ -125,7 +125,6 @@ LUFA_PATH = ../../../..
 # LUFA library compile-time options\r
 LUFA_OPTS  = -D USE_NONSTANDARD_DESCRIPTOR_NAMES\r
 LUFA_OPTS += -D USB_HOST_ONLY\r
-LUFA_OPTS += -D NO_STREAM_CALLBACKS\r
 LUFA_OPTS += -D USE_STATIC_OPTIONS="(USB_OPT_REG_ENABLED | USB_OPT_AUTO_PLL)"\r
 \r
 \r
index 382b899..65fb489 100644 (file)
@@ -105,6 +105,11 @@ int main(void)
                                USB_HostState = HOST_STATE_Configured;\r
                                break;\r
                        case HOST_STATE_Configured:\r
+                               if (HID_Host_ReportReceived(&Mouse_HID_Interface))\r
+                               {\r
+                                       \r
+                               }\r
+                       \r
                                break;\r
                }\r
        \r
index a3903a8..260340c 100644 (file)
@@ -31,7 +31,7 @@ PROJECT_NAME           = "LUFA (Formerly MyUSB) Library"
 # This could be handy for archiving the generated documentation or \r
 # if some version control system is used.\r
 \r
-PROJECT_NUMBER         = 090810\r
+PROJECT_NUMBER         = 000000\r
 \r
 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) \r
 # base path where the generated documentation will be put. \r
index 0d6b378..47290ce 100644 (file)
@@ -161,6 +161,9 @@ uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterface
 {\r
        Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);\r
 \r
+       if (Endpoint_IsOUTReceived() && !(Endpoint_BytesInEndpoint()))\r
+         Endpoint_ClearOUT();\r
+\r
        return Endpoint_BytesInEndpoint();\r
 }\r
 \r
index b7a192a..e0e15e1 100644 (file)
@@ -51,6 +51,13 @@ uint8_t CDC_Host_ConfigurePipes(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, uint
        {\r
                return CDC_ENUMERROR_NoCDCInterfaceFound;\r
        }\r
+       \r
+       CDCInterfaceInfo->State.ControlInterfaceNumber =\r
+#if defined(USE_NONSTANDARD_DESCRIPTOR_NAMES)\r
+                         DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_Interface_t).InterfaceNumber;\r
+#else\r
+                         DESCRIPTOR_CAST(ConfigDescriptorData, USB_Descriptor_Interface_t).bInterfaceNumber;\r
+#endif\r
 \r
        while (FoundEndpoints != (CDC_FOUND_DATAPIPE_IN | CDC_FOUND_DATAPIPE_OUT | CDC_FOUND_DATAPIPE_NOTIFICATION))\r
        {\r
@@ -126,6 +133,7 @@ uint8_t CDC_Host_ConfigurePipes(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, uint
                }\r
        }\r
 \r
+       CDCInterfaceInfo->State.Active = true;\r
        return CDC_ENUMERROR_NoError;\r
 }\r
 \r
@@ -190,6 +198,111 @@ static uint8_t DComp_CDC_Host_NextInterfaceCDCDataEndpoint(void* CurrentDescript
 \r
 void CDC_Host_USBTask(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo)\r
 {\r
+       EVENT_CDC_Host_ControLineStateChanged(CDCInterfaceInfo);\r
+}\r
+\r
+uint8_t CDC_Host_SetLineEncoding(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo)\r
+{\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
+       {\r
+               .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
+               .bRequest      = REQ_SetControlLineState,\r
+               .wValue        = 0,\r
+               .wIndex        = CDCInterfaceInfo->State.ControlInterfaceNumber,\r
+               .wLength       = sizeof(CDCInterfaceInfo->State.LineEncoding),\r
+       };\r
+\r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+       \r
+       return USB_Host_SendControlRequest(&CDCInterfaceInfo->State.LineEncoding);\r
+}\r
+\r
+uint8_t CDC_Host_SendControlLineStateChange(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo)\r
+{\r
+       USB_ControlRequest = (USB_Request_Header_t)\r
+       {\r
+               .bmRequestType = (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE),\r
+               .bRequest      = REQ_SetControlLineState,\r
+               .wValue        = CDCInterfaceInfo->State.ControlLineStates.HostToDevice,\r
+               .wIndex        = CDCInterfaceInfo->State.ControlInterfaceNumber,\r
+               .wLength       = 0,\r
+       };\r
+\r
+       Pipe_SelectPipe(PIPE_CONTROLPIPE);\r
+       \r
+       return USB_Host_SendControlRequest(NULL);\r
+}\r
+\r
+void CDC_Host_SendString(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, char* Data, uint16_t Length)\r
+{\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(CDCInterfaceInfo->State.Active))\r
+         return;\r
+\r
+       Pipe_SelectPipe(CDCInterfaceInfo->Config.DataOUTPipeNumber);    \r
+       Pipe_Unfreeze();\r
+       Pipe_Write_Stream_LE(Data, Length, NO_STREAM_CALLBACK); \r
+       Pipe_Freeze();\r
+}\r
+\r
+void CDC_Host_SendByte(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, uint8_t Data)\r
+{\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(CDCInterfaceInfo->State.Active))\r
+         return;\r
+\r
+       Pipe_SelectPipe(CDCInterfaceInfo->Config.DataOUTPipeNumber);    \r
+       Pipe_Unfreeze();\r
+       \r
+       if (!(Pipe_IsReadWriteAllowed()))\r
+       {\r
+               Pipe_ClearOUT();\r
+               Pipe_WaitUntilReady();\r
+       }\r
+\r
+       Pipe_Write_Byte(Data);  \r
+       Pipe_Freeze();\r
+}\r
+\r
+uint16_t CDC_Host_BytesReceived(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo)\r
+{\r
+       uint16_t BytesInPipe = 0;\r
+\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(CDCInterfaceInfo->State.Active))\r
+         return BytesInPipe;\r
+       \r
+       Pipe_SelectPipe(CDCInterfaceInfo->Config.DataINPipeNumber);     \r
+       Pipe_Unfreeze();\r
+\r
+       if (Pipe_IsINReceived() && !(Pipe_BytesInPipe()))\r
+         Pipe_ClearIN();\r
+       \r
+       BytesInPipe = Pipe_BytesInPipe();\r
+       Pipe_Freeze();\r
+       \r
+       return BytesInPipe;\r
+}\r
+\r
+uint8_t CDC_Host_ReceiveByte(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo)\r
+{\r
+       uint8_t ReceivedByte = 0;\r
+\r
+       if ((USB_HostState != HOST_STATE_Configured) || !(CDCInterfaceInfo->State.Active))\r
+         return ReceivedByte;\r
+         \r
+       Pipe_SelectPipe(CDCInterfaceInfo->Config.DataINPipeNumber);     \r
+       Pipe_Unfreeze();\r
+\r
+       ReceivedByte = Pipe_Read_Byte();\r
+       \r
+       if (!(Pipe_BytesInPipe()))\r
+         Pipe_ClearIN();\r
+       \r
+       Pipe_Freeze();\r
+       \r
+       return ReceivedByte;\r
+}\r
+\r
+void CDC_Host_Event_Stub(void)\r
+{\r
 \r
 }\r
 \r
index 5e0e469..79df489 100644 (file)
                                           */\r
                                struct\r
                                {\r
+                                       bool Active; /**< Indicates if the current interface instance is connected to an attached device */\r
+                                       \r
+                                       uint8_t ControlInterfaceNumber; /**< Interface index of the CDC-ACM control interface within the attached device */\r
+                               \r
                                        uint16_t DataINPipeSize; /**< Size in bytes of the CDC interface's IN data pipe */\r
                                        uint16_t DataOUTPipeSize;  /**< Size in bytes of the CDC interface's OUT data pipe */\r
                                        uint16_t NotificationPipeSize;  /**< Size in bytes of the CDC interface's IN notification endpoint, if used */\r
                        uint8_t CDC_Host_ConfigurePipes(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, uint16_t ConfigDescriptorLength,\r
                                                        uint8_t* DeviceConfigDescriptor);\r
                        \r
-                       void EVENT_CDC_Host_ControLineStateChanged(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo);\r
-                       \r
                        uint8_t CDC_Host_SetLineEncoding(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo);\r
                        uint8_t CDC_Host_SendControlLineStateChange(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo);\r
                        \r
 \r
                /* Function Prototypes: */\r
                        #if defined(INCLUDE_FROM_CDC_CLASS_HOST_C)\r
+                               void CDC_Host_Event_Stub(void);\r
+                               void EVENT_CDC_Host_ControLineStateChanged(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo)\r
+                                                                          ATTR_WEAK ATTR_ALIAS(CDC_Host_Event_Stub);\r
                                static uint8_t DComp_CDC_Host_NextCDCControlInterface(void* CurrentDescriptor);\r
                                static uint8_t DComp_CDC_Host_NextCDCDataInterface(void* CurrentDescriptor);\r
                                static uint8_t DComp_CDC_Host_NextInterfaceCDCDataEndpoint(void* CurrentDescriptor);\r
index 2f66dc2..3a4faff 100644 (file)
@@ -86,6 +86,7 @@ uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo, uint
                }\r
        }\r
 \r
+       HIDInterfaceInfo->State.Active = true;\r
        return HID_ENUMERROR_NoError;\r
 }\r
 \r
@@ -126,4 +127,11 @@ void HID_Host_USBTask(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo)
 \r
 }\r
 \r
+void HID_Host_IsReportReceived(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo)\r
+{\r
+       Pipe_SelectPipe(HIDInterfaceInfo->Config.DataINPipeNumber);\r
+\r
+       return Pipe_IsReadWriteAllowed();\r
+}\r
+\r
 #endif\r
index 344c06f..0386881 100644 (file)
@@ -78,6 +78,8 @@
                                           */\r
                                struct\r
                                {\r
+                                       bool Active; /**< Indicates if the current interface instance is connected to an attached device */\r
+\r
                                        uint16_t DataINPipeSize; /**< Size in bytes of the HID interface's IN data pipe */\r
                                        uint16_t DataOUTPipeSize;  /**< Size in bytes of the HID interface's OUT data pipe */\r
                                } State; /**< State data for the USB class interface within the device. All elements in this section\r
                        void HID_Host_USBTask(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo);\r
                        uint8_t HID_Host_ConfigurePipes(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo, uint16_t ConfigDescriptorLength,\r
                                                        uint8_t* DeviceConfigDescriptor);\r
+\r
+                       void HID_Host_IsReportReceived(USB_ClassInfo_HID_Host_t* HIDInterfaceInfo);\r
                \r
        /* Private Interface - For use in library only: */\r
        #if !defined(__DOXYGEN__)\r
index dab0ec6..ed39769 100644 (file)
@@ -6,6 +6,17 @@
 \r
  /** \page Page_ChangeLog Project Changelog\r
   *\r
+  *  \section Sec_ChangeLogXXXXXX Version XXXXXX\r
+  *\r
+  *  <b>New:</b>\r
+  *\r
+  *  <b>Changed:</b>\r
+  *\r
+  *  <b>Fixed:</b>\r
+  *  - Fixed possible lockup in the CDC device class driver, when the host sends data that is a multiple of the\r
+  *    endpoint's bank\r
+  *\r
+  *\r
   *  \section Sec_ChangeLog090810 Version 090810\r
   *\r
   *  <b>New:</b>\r
index b36e03b..e69103e 100644 (file)
   *  or post your suggestion as an enhancement request to the project bug tracker.\r
   *\r
   *  <b>Targeted for This Release:</b>\r
-  *  - N/A\r
-  *\r
-  *  <b>Targeted for Future Releases:</b>\r
   *  - Host Mode Class Drivers\r
   *     -# Make new host class drivers\r
   *     -# Document new host class drivers\r
   *     -# Convert Host mode demos to class drivers\r
   *     -# Re-enable Host mode Class driver builds after completion\r
   *     -# Update Host mode Class Driver demo .txt files\r
+  *\r
+  *  <b>Targeted for Future Releases:</b>\r
   *  - Add standardized descriptor names to device and host class driver structures\r
   *  - Remake AVRStudio project files\r
   *  - Add detailed overviews of how each demo works\r
index 11d1648..9717491 100644 (file)
@@ -19,8 +19,8 @@
  *  are open design, and all are available for purchase as completed development boards suitable for project development.\r
  *\r
  *  - AVROpendous, an open design/source set of AVR USB development boards: http://avropendous.org/\r
- *  - Benito #7, a no-frills USB board: http://www.dorkbotpdx.org/blog/feurig/benito_7_the_next_big_thing\r
- *  - Bumble-B, yet another AT90USB162 development board: http://fletchtronics.net/\r
+ *  - Benito #7, a no-frills USB board: http://www.dorkbotpdx.org/wiki/benito\r
+ *  - Bumble-B, yet another AT90USB162 development board: http://fletchtronics.net/bumble-b\r
  *  - USB10 AKA "The Ferret", a AT90USB162 development board: http://www.soc-machines.com\r
  *  - USBFoo, an AT90USB162 based development board: http://shop.kernelconcepts.de/product_info.php?products_id=102\r
  *  - Teensy and Teensy++, two other AVR USB development boards: http://www.pjrc.com/teensy/index.html\r
index d1e0c8a..36c7d35 100644 (file)
@@ -10,6 +10,9 @@
  *  to the next version released. It does not indicate all new additions to the library in each version change, only\r
  *  areas relevant to making older projects compatible with the API changes of each new release.\r
  *\r
+ * \section Sec_MigrationXXXXXX Migrating from 090810 to XXXXXX\r
+ * No migration information for this version yet.\r
+ *\r
  * \section Sec_Migration090810 Migrating from 090605 to 090810\r
  *\r
  *  <b>All</b>\r
index 35c5c07..3cb333e 100644 (file)
@@ -41,9 +41,9 @@
        /* Public Interface - May be used in end-application: */\r
                /* Macros: */\r
                        /** Indicates the version number of the library, as an integer. */\r
-                       #define LUFA_VERSION_INTEGER     090810\r
+                       #define LUFA_VERSION_INTEGER     000000\r
 \r
                        /** Indicates the version number of the library, as a string. */\r
-                       #define LUFA_VERSION_STRING      "090810"\r
+                       #define LUFA_VERSION_STRING      "XXXXXX"\r
 \r
 #endif\r