Added new RNDISHost Host LowLevel demo. Fixed misnamed Pipe_SetPipeToken() macro...
[pub/USBasp.git] / Demos / Device / ClassDriver / CDC / CDC.c
index 4f64646..8940ae0 100644 (file)
@@ -44,40 +44,26 @@ USB_ClassInfo_CDC_Device_t VirtualSerial_CDC_Interface =
        {\r
                .Config =\r
                        {\r
        {\r
                .Config =\r
                        {\r
-                               .ControlInterfaceNumber     = 0,\r
+                               .ControlInterfaceNumber         = 0,\r
 \r
 \r
-                               .DataINEndpointNumber       = CDC_TX_EPNUM,\r
-                               .DataINEndpointSize         = CDC_TXRX_EPSIZE,\r
+                               .DataINEndpointNumber           = CDC_TX_EPNUM,\r
+                               .DataINEndpointSize             = CDC_TXRX_EPSIZE,\r
+                               .DataINEndpointDoubleBank       = false,\r
 \r
 \r
-                               .DataOUTEndpointNumber      = CDC_RX_EPNUM,\r
-                               .DataOUTEndpointSize        = CDC_TXRX_EPSIZE,\r
+                               .DataOUTEndpointNumber          = CDC_RX_EPNUM,\r
+                               .DataOUTEndpointSize            = CDC_TXRX_EPSIZE,\r
+                               .DataOUTEndpointDoubleBank      = false,\r
 \r
 \r
-                               .NotificationEndpointNumber = CDC_NOTIFICATION_EPNUM,\r
-                               .NotificationEndpointSize   = CDC_NOTIFICATION_EPSIZE,\r
+                               .NotificationEndpointNumber     = CDC_NOTIFICATION_EPNUM,\r
+                               .NotificationEndpointSize       = CDC_NOTIFICATION_EPSIZE,\r
+                               .NotificationEndpointDoubleBank = false,\r
                        },\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
+/** 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
-\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
 /** Main program entry point. This routine contains the overall program flow, including initial\r
  *  setup of all components and the main program loop.\r
@@ -86,6 +72,9 @@ int main(void)
 {\r
        SetupHardware();\r
        \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
        LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY);\r
 \r
        for (;;)\r
@@ -124,33 +113,28 @@ void CheckJoystickMovement(void)
        char*       ReportString  = NULL;\r
        static bool ActionSent    = false;\r
        \r
        char*       ReportString  = NULL;\r
        static bool ActionSent    = false;\r
        \r
-       char* const JoystickStrings[] =\r
-               {\r
-                       "Joystick Up\r\n",\r
-                       "Joystick Down\r\n",\r
-                       "Joystick Left\r\n",\r
-                       "Joystick Right\r\n",\r
-                       "Joystick Pressed\r\n",\r
-               };\r
-\r
        if (JoyStatus_LCL & JOY_UP)\r
        if (JoyStatus_LCL & JOY_UP)\r
-         ReportString = JoystickStrings[0];\r
+         ReportString = "Joystick Up\r\n";\r
        else if (JoyStatus_LCL & JOY_DOWN)\r
        else if (JoyStatus_LCL & JOY_DOWN)\r
-         ReportString = JoystickStrings[1];\r
+         ReportString = "Joystick Down\r\n";\r
        else if (JoyStatus_LCL & JOY_LEFT)\r
        else if (JoyStatus_LCL & JOY_LEFT)\r
-         ReportString = JoystickStrings[2];\r
+         ReportString = "Joystick Left\r\n";\r
        else if (JoyStatus_LCL & JOY_RIGHT)\r
        else if (JoyStatus_LCL & JOY_RIGHT)\r
-         ReportString = JoystickStrings[3];\r
+         ReportString = "Joystick Right\r\n";\r
        else if (JoyStatus_LCL & JOY_PRESS)\r
        else if (JoyStatus_LCL & JOY_PRESS)\r
-         ReportString = JoystickStrings[4];\r
+         ReportString = "Joystick Pressed\r\n";\r
        else\r
          ActionSent = false;\r
          \r
        if ((ReportString != NULL) && (ActionSent == false))\r
        {\r
                ActionSent = true;\r
        else\r
          ActionSent = false;\r
          \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
        }\r
 }\r
 \r