},\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
+/** Standard file stream for the CDC interface when set up, so that the virtual CDC COM port can be\r
+ * used like any regular character stream in the C APIs\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
+static FILE USBSerialStream;\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
SetupHardware();\r
\r
+ /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */\r
+ CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream);\r
+\r
LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
\r
for (;;)\r
if ((ReportString != NULL) && (ActionSent == false))\r
{\r
ActionSent = true;\r
- \r
- CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString, strlen(ReportString)); \r
+\r
+ // Write the string to the virtual COM port via the created character stream\r
+ fputs(ReportString, &USBSerialStream);\r
+\r
+ // Alternatively, without the stream:\r
+ // CDC_Device_SendString(&VirtualSerial_CDC_Interface, ReportString, strlen(ReportString));\r
}\r
}\r
\r
#include <avr/wdt.h>\r
#include <avr/power.h>\r
#include <string.h>\r
+ #include <stdio.h>\r
\r
#include "Descriptors.h"\r
\r
.NotificationPipeDoubleBank = false,\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_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
Endpoint_ClearIN();\r
}\r
\r
+void CDC_Device_CreateStream(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, FILE* Stream)\r
+{\r
+ *Stream = (FILE)FDEV_SETUP_STREAM(CDC_Device_putchar, CDC_Device_getchar, _FDEV_SETUP_RW);\r
+ fdev_set_udata(Stream, CDCInterfaceInfo);\r
+}\r
+\r
+static int CDC_Device_putchar(char c, FILE* Stream)\r
+{\r
+ CDC_Device_SendByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream), c);\r
+ return 0;\r
+}\r
+\r
+static int CDC_Device_getchar(FILE* Stream)\r
+{\r
+ if (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))))\r
+ return -1;\r
+\r
+ return CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));\r
+}\r
+\r
#endif\r
#include "../../USB.h"\r
#include "../Common/CDC.h"\r
\r
+ #include <stdio.h>\r
#include <string.h>\r
\r
/* Enable C linkage for C++ Compilers: */\r
*/\r
void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
\r
+ /** Creates a standard characer stream for the given CDC Device instance so that it can be used with all the regular\r
+ * functions in the avr-libc <stdio.h> library that accept a FILE stream as a destination (e.g. fprintf).\r
+ *\r
+ * \note The created stream can be given as stdout if desired to direct the standard output from all <stdio.h> functions\r
+ * to the given CDC interface.\r
+ *\r
+ * \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state\r
+ * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed\r
+ */\r
+ void CDC_Device_CreateStream(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, FILE* Stream);\r
+\r
/* Private Interface - For use in library only: */\r
#if !defined(__DOXYGEN__)\r
/* Function Prototypes: */\r
#if defined(INCLUDE_FROM_CDC_CLASS_DEVICE_C)\r
+ static int CDC_Device_putchar(char c, FILE* Stream);\r
+ static int CDC_Device_getchar(FILE* Stream);\r
+ \r
void CDC_Device_Event_Stub(void);\r
void EVENT_CDC_Device_LineEncodingChanged(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)\r
ATTR_WEAK ATTR_NON_NULL_PTR_ARG(1) ATTR_ALIAS(CDC_Device_Event_Stub);\r
return ReceivedByte;\r
}\r
\r
+void CDC_Host_CreateStream(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, FILE* Stream)\r
+{\r
+ *Stream = (FILE)FDEV_SETUP_STREAM(CDC_Host_putchar, CDC_Host_getchar, _FDEV_SETUP_RW);\r
+ fdev_set_udata(Stream, CDCInterfaceInfo);\r
+}\r
+\r
+static int CDC_Host_putchar(char c, FILE* Stream)\r
+{\r
+ CDC_Host_SendByte((USB_ClassInfo_CDC_Host_t*)fdev_get_udata(Stream), c);\r
+ return 0;\r
+}\r
+\r
+static int CDC_Host_getchar(FILE* Stream)\r
+{\r
+ if (!(CDC_Host_BytesReceived((USB_ClassInfo_CDC_Host_t*)fdev_get_udata(Stream))))\r
+ return -1;\r
+\r
+ return CDC_Host_ReceiveByte((USB_ClassInfo_CDC_Host_t*)fdev_get_udata(Stream));\r
+}\r
+\r
void CDC_Host_Event_Stub(void)\r
{\r
\r
/* Includes: */\r
#include "../../USB.h"\r
#include "../Common/CDC.h"\r
+\r
+ #include <stdio.h>\r
+ #include <string.h>\r
\r
/* Enable C linkage for C++ Compilers: */\r
#if defined(__cplusplus)\r
*/\r
uint8_t CDC_Host_ReceiveByte(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1);\r
\r
+ /** Creates a standard characer stream for the given CDC Device instance so that it can be used with all the regular\r
+ * functions in the avr-libc <stdio.h> library that accept a FILE stream as a destination (e.g. fprintf).\r
+ *\r
+ * \note The created stream can be given as stdout if desired to direct the standard output from all <stdio.h> functions\r
+ * to the given CDC interface.\r
+ *\r
+ * \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state\r
+ * \param[in,out] Stream Pointer to a FILE structure where the created stream should be placed\r
+ */\r
+ void CDC_Host_CreateStream(USB_ClassInfo_CDC_Host_t* CDCInterfaceInfo, FILE* Stream);\r
+\r
/** CDC class driver event for a control line state change on a CDC host interface. This event fires each time the device notifies\r
* the host of a control line state change (containing the virtual serial control line states, such as DCD) and may be hooked in the\r
* user program by declaring a handler function with the same name and parameters listed here. The new control line states\r
\r
/* Function Prototypes: */\r
#if defined(INCLUDE_FROM_CDC_CLASS_HOST_C)\r
+ static int CDC_Host_putchar(char c, FILE* Stream);\r
+ static int CDC_Host_getchar(FILE* Stream);\r
+\r
void CDC_Host_Event_Stub(void);\r
void EVENT_CDC_Host_ControLineStateChanged(USB_ClassInfo_CDC_Host_t* const CDCInterfaceInfo)\r
ATTR_WEAK ATTR_NON_NULL_PTR_ARG(1) ATTR_ALIAS(CDC_Host_Event_Stub);\r
* - Added new HID_HOST_BOOT_PROTOCOL_ONLY compile time token to reduce the size of the HID Host Class driver when\r
* Report protocol is not needed\r
* - Added new MIDI LowLevel and ClassDriver Host demo, add new MIDI Host Class driver\r
- * - Added stdio.h stream examples for the virtual CDC UART in the CDC host demos\r
* - Added new CDC/Mouse ClassDriver device demo\r
* - Added new Joystick Host ClassDriver and LowLevel demos\r
* - Added new Printer Host mode Class driver\r
* - Added new Printer Host mode ClassDriver demo\r
* - Added optional support for double banked endpoints in the Device mode Class drivers\r
+ * - Added new stream creation function to the CDC Class drivers, to easily make standard streams from CDC Class driver instances\r
*\r
* <b>Changed:</b>\r
* - Removed mostly useless "TestApp" demo, as it was mainly useful only for checking for sytax errors in the library\r
* are used within the LUFA demos, and thus may be re-used by derivations of each demo. Free PID values may be\r
* used by future LUFA demo projects.\r
*\r
- * These VID/PID values should not be used in commercial designs under any circumstances. Private projects may\r
- * use the following values freely, but must accept any collisions due to other LUFA derived private projects\r
+ * <b>These VID/PID values should not be used in commercial designs under any circumstances.>/b> Private projects\r
+ * may use the following values freely, but must accept any collisions due to other LUFA derived private projects\r
* sharing identical values. It is suggested that private projects using interfaces compatible with existing\r
* demos share the save VID/PID value.\r
*\r