Changed all Device mode LowLevel demos and Device Class drivers so that the control...
[pub/USBasp.git] / Demos / Device / LowLevel / VirtualSerial / VirtualSerial.c
index 64b3a2c..9189ef3 100644 (file)
@@ -105,33 +105,21 @@ void EVENT_USB_Device_Disconnect(void)
  */
 void EVENT_USB_Device_ConfigurationChanged(void)
 {
-       /* Indicate USB connected and ready */
-       LEDs_SetAllLEDs(LEDMASK_USB_READY);
+       bool ConfigSuccess = true;
+
+       /* Setup CDC Data Endpoints */
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
+                                                   CDC_NOTIFICATION_EPSIZE, ENDPOINT_BANK_SINGLE);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_IN,
+                                                   CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
+       ConfigSuccess &= Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK, ENDPOINT_DIR_OUT,
+                                                   CDC_TXRX_EPSIZE, ENDPOINT_BANK_SINGLE);
 
-       /* Setup CDC Notification, Rx and Tx Endpoints */
-       if (!(Endpoint_ConfigureEndpoint(CDC_NOTIFICATION_EPNUM, EP_TYPE_INTERRUPT,
-                                            ENDPOINT_DIR_IN, CDC_NOTIFICATION_EPSIZE,
-                                        ENDPOINT_BANK_SINGLE)))
-       {
-               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
-       }
-       
-       if (!(Endpoint_ConfigureEndpoint(CDC_TX_EPNUM, EP_TYPE_BULK,
-                                            ENDPOINT_DIR_IN, CDC_TXRX_EPSIZE,
-                                        ENDPOINT_BANK_SINGLE)))
-       {
-               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
-       }
-       
-       if (!(Endpoint_ConfigureEndpoint(CDC_RX_EPNUM, EP_TYPE_BULK,
-                                            ENDPOINT_DIR_OUT, CDC_TXRX_EPSIZE,
-                                        ENDPOINT_BANK_SINGLE)))
-       {
-               LEDs_SetAllLEDs(LEDMASK_USB_ERROR);
-       }
-       
        /* Reset line encoding baud rate so that the host knows to send new values */
        LineEncoding.BaudRateBPS = 0;
+
+       /* Indicate endpoint configuration success or failure */
+       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
@@ -146,13 +134,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                case REQ_GetLineEncoding:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
                        {       
-                               /* Acknowledge the SETUP packet, ready for data transfer */
                                Endpoint_ClearSETUP();
 
                                /* Write the line coding data to the control endpoint */
                                Endpoint_Write_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t));
-                               
-                               /* Finalize the stream transfer to send the last packet or clear the host abort */
                                Endpoint_ClearOUT();
                        }
                        
@@ -160,13 +145,10 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                case REQ_SetLineEncoding:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
                        {
-                               /* Acknowledge the SETUP packet, ready for data transfer */
                                Endpoint_ClearSETUP();
 
                                /* Read the line coding data in from the host into the global struct */
                                Endpoint_Read_Control_Stream_LE(&LineEncoding, sizeof(CDC_Line_Coding_t));
-
-                               /* Finalize the stream transfer to clear the last packet from the host */
                                Endpoint_ClearIN();
                        }
        
@@ -174,15 +156,13 @@ void EVENT_USB_Device_UnhandledControlRequest(void)
                case REQ_SetControlLineState:
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
                        {
-                               /* Acknowledge the SETUP packet, ready for data transfer */
                                Endpoint_ClearSETUP();
-                               
+                               Endpoint_ClearStatusStage();
+
                                /* NOTE: Here you can read in the line state mask from the host, to get the current state of the output handshake
                                         lines. The mask is read in from the wValue parameter in USB_ControlRequest, and can be masked against the
                                                 CONTROL_LINE_OUT_* masks to determine the RTS and DTR line states using the following code:
                                */
-                               
-                               Endpoint_ClearStatusStage();
                        }
        
                        break;