Add CDC Host class driver EVENT_CDC_Host_ControLineStateChanged() event.
[pub/lufa.git] / LUFA / Drivers / USB / Class / Device / CDC.c
index 9ed20e4..a6e5e26 100644 (file)
@@ -39,7 +39,7 @@ void CDC_Device_Event_Stub(void)
 \r
 }\r
 \r
-void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
+void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
 {\r
        if (!(Endpoint_IsSETUPReceived()))\r
          return;\r
@@ -126,12 +126,7 @@ void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)
        if (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
                Endpoint_ClearIN();\r
-\r
-               while (!(Endpoint_IsReadWriteAllowed()))\r
-               {\r
-                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                         return;\r
-               }\r
+               Endpoint_WaitUntilReady();\r
        }       \r
        \r
        Endpoint_ClearIN();\r
@@ -156,12 +151,7 @@ void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, con
        if (!(Endpoint_IsReadWriteAllowed()))\r
        {\r
                Endpoint_ClearIN();\r
-               \r
-               while (!(Endpoint_IsReadWriteAllowed()))\r
-               {\r
-                       if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                         return;               \r
-               }\r
+               Endpoint_WaitUntilReady();\r
        }\r
 \r
        Endpoint_Write_Byte(Data);      \r
@@ -171,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
@@ -202,11 +195,13 @@ void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDC
                        .bRequest      = NOTIF_SerialState,\r
                        .wValue        = 0,\r
                        .wIndex        = 0,\r
-                       .wLength       = sizeof(uint16_t),\r
+                       .wLength       = sizeof(CDCInterfaceInfo->State.ControlLineStates.DeviceToHost),\r
                };\r
 \r
        Endpoint_Write_Stream_LE(&Notification, sizeof(Notification), NO_STREAM_CALLBACK);\r
-       Endpoint_Write_Stream_LE(&CDCInterfaceInfo->State.ControlLineStates.DeviceToHost, sizeof(uint8_t), NO_STREAM_CALLBACK);\r
+       Endpoint_Write_Stream_LE(&CDCInterfaceInfo->State.ControlLineStates.DeviceToHost,\r
+                                sizeof(CDCInterfaceInfo->State.ControlLineStates.DeviceToHost),\r
+                                NO_STREAM_CALLBACK);\r
        Endpoint_ClearIN();\r
 }\r
 \r