Seperated out parts of the PrinterHost incomplete demo into a seperate Lib subdirectory.
[pub/USBasp.git] / Demos / Device / LowLevel / USBtoSerial / USBtoSerial.c
index ee4208f..c48c33c 100644 (file)
@@ -113,21 +113,30 @@ void EVENT_USB_Disconnect(void)
  */\r
 void EVENT_USB_ConfigurationChanged(void)\r
 {\r
  */\r
 void EVENT_USB_ConfigurationChanged(void)\r
 {\r
-       /* Setup CDC Notification, Rx and Tx Endpoints */\r
-       Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,\r
-                                      ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,\r
-                                  ENDPOINT_BANK_SINGLE);\r
-\r
-       Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK,\r
-                                      ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,\r
-                                  ENDPOINT_BANK_SINGLE);\r
-\r
-       Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK,\r
-                                      ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,\r
-                                  ENDPOINT_BANK_SINGLE);\r
-\r
        /* Indicate USB connected and ready */\r
        LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
        /* Indicate USB connected and ready */\r
        LEDs_SetAllLEDs(LEDMASK_USB_READY);\r
+\r
+       /* Setup CDC Notification, Rx and Tx Endpoints */\r
+       if (!(Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,\r
+                                            ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,\r
+                                        ENDPOINT_BANK_SINGLE)))\r
+       {\r
+               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+       }\r
+       \r
+       if (!(Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK,\r
+                                            ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,\r
+                                        ENDPOINT_BANK_SINGLE)))\r
+       {\r
+               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+       }                                                          \r
+\r
+       if (!(Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK,\r
+                                            ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,\r
+                                        ENDPOINT_BANK_SINGLE)))\r
+       {\r
+               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);\r
+       }\r
 }\r
 \r
 /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific\r
 }\r
 \r
 /** Event handler for the USB_UnhandledControlPacket event. This is used to catch standard and class specific\r
@@ -228,7 +237,7 @@ void CDC_Task(void)
                if (Endpoint_IsOUTReceived())\r
                {\r
                        /* Read the bytes in from the endpoint into the buffer while space is available */\r
                if (Endpoint_IsOUTReceived())\r
                {\r
                        /* Read the bytes in from the endpoint into the buffer while space is available */\r
-                       while (Endpoint_BytesInEndpoint() && (BUFF_STATICSIZE - Rx_Buffer.Elements))\r
+                       while (Endpoint_BytesInEndpoint() && (Rx_Buffer.Elements != BUFF_STATICSIZE))\r
                        {\r
                                /* Store each character from the endpoint */\r
                                Buffer_StoreElement(&Rx_Buffer, Endpoint_Read_Byte());\r
                        {\r
                                /* Store each character from the endpoint */\r
                                Buffer_StoreElement(&Rx_Buffer, Endpoint_Read_Byte());\r
@@ -256,7 +265,7 @@ void CDC_Task(void)
                        while (!(Endpoint_IsReadWriteAllowed()));\r
                        \r
                        /* Write the bytes from the buffer to the endpoint while space is available */\r
                        while (!(Endpoint_IsReadWriteAllowed()));\r
                        \r
                        /* Write the bytes from the buffer to the endpoint while space is available */\r
-                       while (Tx_Buffer.Elements && (Endpoint_BytesInEndpoint() < CDC_TXRX_EPSIZE))\r
+                       while (Tx_Buffer.Elements && Endpoint_IsReadWriteAllowed())\r
                        {\r
                                /* Write each byte retreived from the buffer to the endpoint */\r
                                Endpoint_Write_Byte(Buffer_GetElement(&Tx_Buffer));\r
                        {\r
                                /* Write each byte retreived from the buffer to the endpoint */\r
                                Endpoint_Write_Byte(Buffer_GetElement(&Tx_Buffer));\r