Fix broken MagStripe demo due to the HID Class driver changes.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / CDC.c
index 816a5f1..c968d7f 100644 (file)
@@ -143,11 +143,11 @@ uint8_t CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
        Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);\r
 \r
        if (!(Endpoint_IsReadWriteAllowed()))\r
-       {\r
-               uint8_t ErrorCode;\r
-       \r
+       {       \r
                Endpoint_ClearIN();\r
 \r
+               uint8_t ErrorCode;\r
+\r
                if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError)\r
                  return ErrorCode;\r
        }\r
@@ -161,20 +161,26 @@ uint8_t CDC_Device_Flush(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
        if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))\r
          return ENDPOINT_READYWAIT_NoError;\r
 \r
+       uint8_t ErrorCode;\r
+\r
        Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber);\r
+\r
+       if (!(Endpoint_BytesInEndpoint()))\r
+         return ENDPOINT_READYWAIT_NoError;\r
+       \r
+       bool BankFull = !(Endpoint_IsReadWriteAllowed());\r
        \r
-       if (Endpoint_BytesInEndpoint())\r
+       Endpoint_ClearIN();\r
+       \r
+       if (BankFull)\r
        {\r
-               uint8_t ErrorCode;\r
-\r
-               Endpoint_ClearIN();\r
-               \r
                if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError)\r
                  return ErrorCode;\r
+\r
+               Endpoint_ClearIN();\r
        }\r
        \r
-       Endpoint_ClearIN();\r
-       return Endpoint_WaitUntilReady();\r
+       return ENDPOINT_READYWAIT_NoError;\r
 }\r
 \r
 uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)\r
@@ -221,7 +227,7 @@ void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDC
                        .wLength       = sizeof(CDCInterfaceInfo->State.ControlLineStates.DeviceToHost),\r
                };\r
 \r
-       Endpoint_Write_Stream_LE(&Notification, sizeof(Notification), NO_STREAM_CALLBACK);\r
+       Endpoint_Write_Stream_LE(&Notification, sizeof(USB_Request_Header_t), NO_STREAM_CALLBACK);\r
        Endpoint_Write_Stream_LE(&CDCInterfaceInfo->State.ControlLineStates.DeviceToHost,\r
                                 sizeof(CDCInterfaceInfo->State.ControlLineStates.DeviceToHost),\r
                                 NO_STREAM_CALLBACK);\r