Remove incomplete MIDIToneGenerator project.
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / CDC.c
index 453d21d..a5a296d 100644 (file)
@@ -65,8 +65,9 @@ void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* const CDCInter
                        {
                                Endpoint_ClearSETUP();
                                Endpoint_Read_Control_Stream_LE(&CDCInterfaceInfo->State.LineEncoding, sizeof(CDCInterfaceInfo->State.LineEncoding));
                        {
                                Endpoint_ClearSETUP();
                                Endpoint_Read_Control_Stream_LE(&CDCInterfaceInfo->State.LineEncoding, sizeof(CDCInterfaceInfo->State.LineEncoding));
-                               EVENT_CDC_Device_LineEncodingChanged(CDCInterfaceInfo);
                                Endpoint_ClearIN();
                                Endpoint_ClearIN();
+
+                               EVENT_CDC_Device_LineEncodingChanged(CDCInterfaceInfo);
                        }
        
                        break;
                        }
        
                        break;
@@ -74,11 +75,11 @@ void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* const CDCInter
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
                        {                               
                                Endpoint_ClearSETUP();
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
                        {                               
                                Endpoint_ClearSETUP();
-                               
+                               Endpoint_ClearStatusStage();
+
                                CDCInterfaceInfo->State.ControlLineStates.HostToDevice = USB_ControlRequest.wValue;
                                CDCInterfaceInfo->State.ControlLineStates.HostToDevice = USB_ControlRequest.wValue;
-                               EVENT_CDC_Device_ControLineStateChanged(CDCInterfaceInfo);
 
 
-                               Endpoint_ClearStatusStage();
+                               EVENT_CDC_Device_ControLineStateChanged(CDCInterfaceInfo);
                        }
        
                        break;
                        }
        
                        break;
@@ -86,10 +87,9 @@ void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* const CDCInter
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
                        {                               
                                Endpoint_ClearSETUP();
                        if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
                        {                               
                                Endpoint_ClearSETUP();
-                               
-                               EVENT_CDC_Device_BreakSent(CDCInterfaceInfo, (uint8_t)USB_ControlRequest.wValue);
-
                                Endpoint_ClearStatusStage();
                                Endpoint_ClearStatusStage();
+
+                               EVENT_CDC_Device_BreakSent(CDCInterfaceInfo, (uint8_t)USB_ControlRequest.wValue);
                        }
 
                        break;
                        }
 
                        break;
@@ -128,17 +128,12 @@ void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
 {
        if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
          return;
 {
        if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
          return;
-
-       Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);
-
-       if (Endpoint_IsOUTReceived() && !(Endpoint_BytesInEndpoint()))
-         Endpoint_ClearOUT();
          
        CDC_Device_Flush(CDCInterfaceInfo);
 }
 
 uint8_t CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
          
        CDC_Device_Flush(CDCInterfaceInfo);
 }
 
 uint8_t CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo,
-                              char* const Data,
+                              const char* const Data,
                               const uint16_t Length)
 {
        if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
                               const uint16_t Length)
 {
        if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
@@ -222,19 +217,25 @@ uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterface
        }
 }
 
        }
 }
 
-uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
+int16_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
 {
        if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
 {
        if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS))
-         return 0;
+         return -1;
+
+       int16_t ReceivedByte = -1;
 
        Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);
        
 
        Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);
        
-       uint8_t DataByte = Endpoint_Read_Byte();
+       if (Endpoint_IsOUTReceived())
+       {
+               if (Endpoint_BytesInEndpoint())
+                 ReceivedByte = Endpoint_Read_Byte();
        
        
-       if (!(Endpoint_BytesInEndpoint()))
-         Endpoint_ClearOUT();
-         
-       return DataByte;
+               if (!(Endpoint_BytesInEndpoint()))
+                 Endpoint_ClearOUT();
+       }
+       
+       return ReceivedByte;
 }
 
 void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
 }
 
 void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo)
@@ -282,24 +283,28 @@ static int CDC_Device_putchar(char c,
 
 static int CDC_Device_getchar(FILE* Stream)
 {
 
 static int CDC_Device_getchar(FILE* Stream)
 {
-       if (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))))
+       int16_t ReceivedByte = CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
+
+       if (ReceivedByte < 0)
          return _FDEV_EOF;
 
          return _FDEV_EOF;
 
-       return CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
+       return ReceivedByte;
 }
 
 static int CDC_Device_getchar_Blocking(FILE* Stream)
 {
 }
 
 static int CDC_Device_getchar_Blocking(FILE* Stream)
 {
-       while (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))))
+       int16_t ReceivedByte;
+       
+       while ((ReceivedByte = CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))) < 0)
        {
                if (USB_DeviceState == DEVICE_STATE_Unattached)
                  return _FDEV_EOF;
        
                CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
        {
                if (USB_DeviceState == DEVICE_STATE_Unattached)
                  return _FDEV_EOF;
        
                CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
-               USB_USBTask();
+               USB_USBTask();  
        }
 
        }
 
-       return CDC_Device_ReceiveByte((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));
+       return ReceivedByte;
 }
 
 #endif
 }
 
 #endif