Added stdio.h stream examples for the virtual CDC UART in the CDC host demos.
[pub/USBasp.git] / Demos / Host / ClassDriver / CDCHost / CDCHost.c
index fd12137..99c0c81 100644 (file)
@@ -50,6 +50,27 @@ USB_ClassInfo_CDC_Host_t VirtualSerial_CDC_Interface =
                        },\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_Host_SendByte(&VirtualSerial_CDC_Interface, c);\r
+       return 0;\r
+}\r
+\r
+static int CDC_getchar(FILE *stream)\r
+{\r
+       if (!(CDC_Host_BytesReceived(&VirtualSerial_CDC_Interface)))\r
+         return -1;\r
+\r
+       return CDC_Host_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 configures the hardware required by the application, then\r
  *  enters a loop to run the application tasks in sequence.\r