Changed over manual loops waiting for endpoints to be ready to use the library Endpoi...
[pub/USBasp.git] / Demos / Device / LowLevel / CDC / CDC.c
index 9ee744e..12cd8c4 100644 (file)
@@ -62,11 +62,8 @@ static int CDC_putchar(char c, FILE *stream)
        if (!(LineEncoding.BaudRateBPS))\r
          return -1;\r
        \r
-       while (!(Endpoint_IsReadWriteAllowed()))\r
-       {\r
-               if (USB_DeviceState != DEVICE_STATE_Configured)\r
-                 return -1;\r
-       }\r
+       if (Endpoint_WaitUntilReady())\r
+         return -1;\r
 \r
        Endpoint_Write_Byte(c);\r
        Endpoint_ClearIN();\r
@@ -85,11 +82,8 @@ static int CDC_getchar(FILE *stream)
        \r
        for (;;)\r
        {\r
-               while (!(Endpoint_IsReadWriteAllowed()))\r
-               {\r
-                       if (USB_DeviceState != DEVICE_STATE_Configured)\r
-                         return -1;\r
-               }\r
+               if (Endpoint_WaitUntilReady())\r
+                 return -1;\r
        \r
                if (!(Endpoint_BytesInEndpoint()))\r
                {\r
@@ -327,11 +321,7 @@ void CDC_Task(void)
                if (IsFull)\r
                {\r
                        /* Wait until the endpoint is ready for another packet */\r
-                       while (!(Endpoint_IsINReady()))\r
-                       {\r
-                               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
-                                 return;\r
-                       }\r
+                       Endpoint_WaitUntilReady();\r
                        \r
                        /* Send an empty packet to ensure that the host does not buffer data sent to it */\r
                        Endpoint_ClearIN();\r