Renamed USB_Device_SetHighSpeed() to USB_Device_SetFullSpeed() so that the correct...
[pub/USBasp.git] / Demos / Device / ClassDriver / CDC / CDC.c
index cc8abe4..8e3530c 100644 (file)
@@ -55,13 +55,30 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
                                .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,\r
                                .NotificationEndpointSize   = CDC_NOTIFICATION_EPSIZE,\r
                        },\r
-               \r
-               .State =\r
-                       {\r
-                               // Leave all state values to their defaults\r
-                       }\r
        };\r
 \r
+#if 0\r
+/* NOTE: Here you can set up a standard stream using the created virtual serial port, so that the standard stream functions in\r
+ *       <stdio.h> can be used on the virtual serial port (e.g. fprintf(&USBSerial, "Test"); to print a string).\r
+ */\r
+\r
+static int CDC_putchar(char c, FILE *stream)\r
+{\r
+       CDC_Device_SendByte(&VirtualSerial_CDC_Interface, c);\r
+       return 0;\r
+}\r
+\r
+static int CDC_getchar(FILE *stream)\r
+{\r
+       if (!(CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)))\r
+         return -1;\r
+\r
+       return CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);\r
+}\r
+\r
+static FILE USBSerial = FDEV_SETUP_STREAM(CDC_putchar, CDC_getchar, _FDEV_SETUP_RW);\r
+#endif\r
+\r
 /** Main program entry point. This routine contains the overall program flow, including initial\r
  *  setup of all components and the main program loop.\r
  */\r
@@ -74,9 +91,9 @@ int main(void)
        for (;;)\r
        {\r
                CheckJoystickMovement();\r
-               \r
-               uint16_t BytesToDiscard = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface);\r
-               while (BytesToDiscard--)\r
+                \r
+               /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */\r
+               while (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface))\r
                  CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);\r
 \r
                CDC_Device_USBTask(&VirtualSerial_CDC_Interface);\r