Added standard stream example to the ClassDriver CDC device demo.
[pub/USBasp.git] / Demos / Device / ClassDriver / CDC / CDC.c
index 3e83ec2..836a6e0 100644 (file)
@@ -57,6 +57,28 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
                        },\r
        };\r
 \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
 /** 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