Use immediate variable expansion in the second-deepest level makefile scripts to...
[pub/USBasp.git] / Demos / Device / LowLevel / DualVirtualSerial / DualVirtualSerial.c
index b1a9d1c..2db6f4e 100644 (file)
@@ -1,13 +1,13 @@
 /*
              LUFA Library
 /*
              LUFA Library
-     Copyright (C) Dean Camera, 2010.
+     Copyright (C) Dean Camera, 2012.
 
   dean [at] fourwalledcubicle [dot] com
 
   dean [at] fourwalledcubicle [dot] com
-      www.fourwalledcubicle.com
+           www.lufa-lib.org
 */
 
 /*
 */
 
 /*
-  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)
+  Copyright 2012  Dean Camera (dean [at] fourwalledcubicle [dot] com)
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
 
   Permission to use, copy, modify, distribute, and sell this
   software and its documentation for any purpose is hereby granted
  *  It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
  *  serial link characteristics and instead sends and receives data in endpoint streams.
  */
  *  It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
  *  serial link characteristics and instead sends and receives data in endpoint streams.
  */
-CDC_LineEncoding_t LineEncoding1 = { .BaudRateBPS = 0,
-                                     .CharFormat  = CDC_LINEENCODING_OneStopBit,
-                                     .ParityType  = CDC_PARITY_None,
-                                     .DataBits    = 8                            };
+static CDC_LineEncoding_t LineEncoding1 = { .BaudRateBPS = 0,
+                                            .CharFormat  = CDC_LINEENCODING_OneStopBit,
+                                            .ParityType  = CDC_PARITY_None,
+                                            .DataBits    = 8                            };
 
 /** Contains the current baud rate and other settings of the second virtual serial port. While this demo does not use
  *  the physical USART and thus does not use these settings, they must still be retained and returned to the host
 
 /** Contains the current baud rate and other settings of the second virtual serial port. While this demo does not use
  *  the physical USART and thus does not use these settings, they must still be retained and returned to the host
@@ -57,10 +57,10 @@ CDC_LineEncoding_t LineEncoding1 = { .BaudRateBPS = 0,
  *  It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
  *  serial link characteristics and instead sends and receives data in endpoint streams.
  */
  *  It is possible to completely ignore these value or use other settings as the host is completely unaware of the physical
  *  serial link characteristics and instead sends and receives data in endpoint streams.
  */
-CDC_LineEncoding_t LineEncoding2 = { .BaudRateBPS = 0,
-                                     .CharFormat  = CDC_LINEENCODING_OneStopBit,
-                                     .ParityType  = CDC_PARITY_None,
-                                     .DataBits    = 8                            };
+static CDC_LineEncoding_t LineEncoding2 = { .BaudRateBPS = 0,
+                                            .CharFormat  = CDC_LINEENCODING_OneStopBit,
+                                            .ParityType  = CDC_PARITY_None,
+                                            .DataBits    = 8                            };
 
 
 /** Main program entry point. This routine configures the hardware required by the application, then
 
 
 /** Main program entry point. This routine configures the hardware required by the application, then
@@ -123,20 +123,14 @@ void EVENT_USB_Device_ConfigurationChanged(void)
        bool ConfigSuccess = true;
 
        /* Setup first CDC Interface's Endpoints */
        bool ConfigSuccess = true;
 
        /* Setup first CDC Interface's Endpoints */
-       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_TX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
-                                                   CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
-       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_RX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
-                                                   CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
-       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
-                                                   CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_TX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_RX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC1_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1);
 
        /* Setup second CDC Interface's Endpoints */
 
        /* Setup second CDC Interface's Endpoints */
-       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_TX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
-                                                   CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
-       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_RX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
-                                                   CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
-       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
-                                                   CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_TX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_RX_EPADDR, EP_TYPE_BULK, CDC_TXRX_EPSIZE, 1);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC2_NOTIFICATION_EPADDR, EP_TYPE_INTERRUPT, CDC_NOTIFICATION_EPSIZE, 1);
 
        /* Reset line encoding baud rates so that the host knows to send new values */
        LineEncoding1.BaudRateBPS = 0;
 
        /* Reset line encoding baud rates so that the host knows to send new values */
        LineEncoding1.BaudRateBPS = 0;
@@ -146,11 +140,11 @@ void EVENT_USB_Device_ConfigurationChanged(void)
        LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
 }
 
        LEDs_SetAllLEDs(ConfigSuccess ? LEDMASK_USB_READY : LEDMASK_USB_ERROR);
 }
 
-/** Event handler for the USB_UnhandledControlRequest event. This is used to catch standard and class specific
- *  control requests that are not handled internally by the USB library (including the CDC control commands,
- *  which are all issued via the control endpoint), so that they can be handled appropriately for the application.
+/** Event handler for the USB_ControlRequest event. This is used to catch and process control requests sent to
+ *  the device from the USB host before passing along unhandled control requests to the library for processing
+ *  internally.
  */
  */
-void EVENT_USB_Device_UnhandledControlRequest(void)
+void EVENT_USB_Device_ControlRequest(void)
 {
        /* Determine which interface's Line Coding data is being set from the wIndex parameter */
        void* LineEncodingData = (USB_ControlRequest.wIndex == 0) ? &LineEncoding1 : &LineEncoding2;
 {
        /* Determine which interface's Line Coding data is being set from the wIndex parameter */
        void* LineEncodingData = (USB_ControlRequest.wIndex == 0) ? &LineEncoding1 : &LineEncoding2;
@@ -224,10 +218,10 @@ void CDC1_Task(void)
                ActionSent = true;
 
                /* Select the Serial Tx Endpoint */
                ActionSent = true;
 
                /* Select the Serial Tx Endpoint */
-               Endpoint_SelectEndpoint(CDC1_TX_EPNUM);
+               Endpoint_SelectEndpoint(CDC1_TX_EPADDR);
 
                /* Write the String to the Endpoint */
 
                /* Write the String to the Endpoint */
-               Endpoint_Write_Stream_LE(ReportString, strlen(ReportString));
+               Endpoint_Write_Stream_LE(ReportString, strlen(ReportString), NULL);
 
                /* Finalize the stream transfer to send the last packet */
                Endpoint_ClearIN();
 
                /* Finalize the stream transfer to send the last packet */
                Endpoint_ClearIN();
@@ -240,7 +234,7 @@ void CDC1_Task(void)
        }
 
        /* Select the Serial Rx Endpoint */
        }
 
        /* Select the Serial Rx Endpoint */
-       Endpoint_SelectEndpoint(CDC1_RX_EPNUM);
+       Endpoint_SelectEndpoint(CDC1_RX_EPADDR);
 
        /* Throw away any received data from the host */
        if (Endpoint_IsOUTReceived())
 
        /* Throw away any received data from the host */
        if (Endpoint_IsOUTReceived())
@@ -257,7 +251,7 @@ void CDC2_Task(void)
          return;
 
        /* Select the Serial Rx Endpoint */
          return;
 
        /* Select the Serial Rx Endpoint */
-       Endpoint_SelectEndpoint(CDC2_RX_EPNUM);
+       Endpoint_SelectEndpoint(CDC2_RX_EPADDR);
 
        /* Check to see if any data has been received */
        if (Endpoint_IsOUTReceived())
 
        /* Check to see if any data has been received */
        if (Endpoint_IsOUTReceived())
@@ -269,16 +263,16 @@ void CDC2_Task(void)
                uint16_t DataLength = Endpoint_BytesInEndpoint();
 
                /* Read in the incoming packet into the buffer */
                uint16_t DataLength = Endpoint_BytesInEndpoint();
 
                /* Read in the incoming packet into the buffer */
-               Endpoint_Read_Stream_LE(&Buffer, DataLength);
+               Endpoint_Read_Stream_LE(&Buffer, DataLength, NULL);
 
                /* Finalize the stream transfer to send the last packet */
                Endpoint_ClearOUT();
 
                /* Select the Serial Tx Endpoint */
 
                /* Finalize the stream transfer to send the last packet */
                Endpoint_ClearOUT();
 
                /* Select the Serial Tx Endpoint */
-               Endpoint_SelectEndpoint(CDC2_TX_EPNUM);
+               Endpoint_SelectEndpoint(CDC2_TX_EPADDR);
 
                /* Write the received data to the endpoint */
 
                /* Write the received data to the endpoint */
-               Endpoint_Write_Stream_LE(&Buffer, DataLength);
+               Endpoint_Write_Stream_LE(&Buffer, DataLength, NULL);
 
                /* Finalize the stream transfer to send the last packet */
                Endpoint_ClearIN();
 
                /* Finalize the stream transfer to send the last packet */
                Endpoint_ClearIN();