X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/f896c00c48f04fb9273555ab8d9b1af99f865d25..a789619fbe2cd07347816cc5c168e8f904acca86:/Demos/Device/ClassDriver/CDC/CDC.c diff --git a/Demos/Device/ClassDriver/CDC/CDC.c b/Demos/Device/ClassDriver/CDC/CDC.c index 8ecfb7b37..8e3530ca2 100644 --- a/Demos/Device/ClassDriver/CDC/CDC.c +++ b/Demos/Device/ClassDriver/CDC/CDC.c @@ -55,13 +55,30 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface = .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM, .NotificationEndpointSize = CDC_NOTIFICATION_EPSIZE, }, - - .State = - { - // Leave all state values to their defaults - } }; +#if 0 +/* NOTE: Here you can set up a standard stream using the created virtual serial port, so that the standard stream functions in + * can be used on the virtual serial port (e.g. fprintf(&USBSerial, "Test"); to print a string). + */ + +static int CDC_putchar(char c, FILE *stream) +{ + CDC_Device_SendByte(&VirtualSerial_CDC_Interface, c); + return 0; +} + +static int CDC_getchar(FILE *stream) +{ + if (!(CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface))) + return -1; + + return CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); +} + +static FILE USBSerial = FDEV_SETUP_STREAM(CDC_putchar, CDC_getchar, _FDEV_SETUP_RW); +#endif + /** Main program entry point. This routine contains the overall program flow, including initial * setup of all components and the main program loop. */ @@ -74,9 +91,9 @@ int main(void) for (;;) { CheckJoystickMovement(); - - uint16_t BytesToDiscard = CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface); - while (BytesToDiscard--) + + /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */ + while (CDC_Device_BytesReceived(&VirtualSerial_CDC_Interface)) CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); @@ -107,7 +124,7 @@ void CheckJoystickMovement(void) char* ReportString = NULL; static bool ActionSent = false; - char* JoystickStrings[] = + char* const JoystickStrings[] = { "Joystick Up\r\n", "Joystick Down\r\n",