Change over instances of "make" in the makefiles to "$(MAKE)" to allow for the make...
[pub/USBasp.git] / LUFA / Drivers / USB / Class / Device / CDC.c
index e9457f7..f0c6edb 100644 (file)
@@ -1,13 +1,13 @@
 /*\r
              LUFA Library\r
 /*\r
              LUFA Library\r
-     Copyright (C) Dean Camera, 2009.\r
+     Copyright (C) Dean Camera, 2010.\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
               \r
   dean [at] fourwalledcubicle [dot] com\r
       www.fourwalledcubicle.com\r
 */\r
 \r
 /*\r
-  Copyright 2009  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
+  Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com)\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
 \r
   Permission to use, copy, modify, distribute, and sell this \r
   software and its documentation for any purpose is hereby granted\r
   this software.\r
 */\r
 \r
   this software.\r
 */\r
 \r
+#define  __INCLUDE_FROM_USB_DRIVER\r
 #include "../../HighLevel/USBMode.h"\r
 #if defined(USB_CAN_BE_DEVICE)\r
 \r
 #include "../../HighLevel/USBMode.h"\r
 #if defined(USB_CAN_BE_DEVICE)\r
 \r
-#define  INCLUDE_FROM_CDC_CLASS_DEVICE_C\r
+#define  __INCLUDE_FROM_CDC_CLASS_DEVICE_C\r
+#define  __INCLUDE_FROM_CDC_DRIVER\r
 #include "CDC.h"\r
 \r
 void CDC_Device_Event_Stub(void)\r
 #include "CDC.h"\r
 \r
 void CDC_Device_Event_Stub(void)\r
@@ -63,9 +65,8 @@ void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* CDCInterfaceIn
                        {\r
                                Endpoint_ClearSETUP();\r
                                Endpoint_Read_Control_Stream_LE(&CDCInterfaceInfo->State.LineEncoding, sizeof(CDCInterfaceInfo->State.LineEncoding));\r
                        {\r
                                Endpoint_ClearSETUP();\r
                                Endpoint_Read_Control_Stream_LE(&CDCInterfaceInfo->State.LineEncoding, sizeof(CDCInterfaceInfo->State.LineEncoding));\r
-                               Endpoint_ClearIN();\r
-\r
                                EVENT_CDC_Device_LineEncodingChanged(CDCInterfaceInfo);\r
                                EVENT_CDC_Device_LineEncodingChanged(CDCInterfaceInfo);\r
+                               Endpoint_ClearIN();\r
                        }\r
        \r
                        break;\r
                        }\r
        \r
                        break;\r
@@ -75,13 +76,23 @@ void CDC_Device_ProcessControlRequest(USB_ClassInfo_CDC_Device_t* CDCInterfaceIn
                                Endpoint_ClearSETUP();\r
                                \r
                                CDCInterfaceInfo->State.ControlLineStates.HostToDevice = USB_ControlRequest.wValue;\r
                                Endpoint_ClearSETUP();\r
                                \r
                                CDCInterfaceInfo->State.ControlLineStates.HostToDevice = USB_ControlRequest.wValue;\r
-                               \r
                                EVENT_CDC_Device_ControLineStateChanged(CDCInterfaceInfo);\r
 \r
                                Endpoint_ClearStatusStage();\r
                        }\r
        \r
                        break;\r
                                EVENT_CDC_Device_ControLineStateChanged(CDCInterfaceInfo);\r
 \r
                                Endpoint_ClearStatusStage();\r
                        }\r
        \r
                        break;\r
+               case REQ_SendBreak:\r
+                       if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))\r
+                       {                               \r
+                               Endpoint_ClearSETUP();\r
+                               \r
+                               EVENT_CDC_Device_BreakSent(CDCInterfaceInfo, (uint8_t)USB_ControlRequest.wValue);\r
+\r
+                               Endpoint_ClearStatusStage();\r
+                       }\r
+\r
+                       break;\r
        }\r
 }\r
 \r
        }\r
 }\r
 \r
@@ -190,10 +201,22 @@ uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterface
 \r
        Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);\r
 \r
 \r
        Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber);\r
 \r
-       if (Endpoint_IsOUTReceived() && !(Endpoint_BytesInEndpoint()))\r
-         Endpoint_ClearOUT();\r
-\r
-       return Endpoint_BytesInEndpoint();\r
+       if (Endpoint_IsOUTReceived())\r
+       {\r
+               if (!(Endpoint_BytesInEndpoint()))\r
+               {\r
+                       Endpoint_ClearOUT();\r
+                       return 0;\r
+               }\r
+               else\r
+               {\r
+                       return Endpoint_BytesInEndpoint();\r
+               }\r
+       }\r
+       else\r
+       {\r
+               return 0;\r
+       }\r
 }\r
 \r
 uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
 }\r
 \r
 uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo)\r
@@ -263,6 +286,9 @@ static int CDC_Device_getchar_Blocking(FILE* Stream)
 {\r
        while (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))))\r
        {\r
 {\r
        while (!(CDC_Device_BytesReceived((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream))))\r
        {\r
+               if (USB_DeviceState == DEVICE_STATE_Unattached)\r
+                 return _FDEV_EOF;\r
+       \r
                CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));\r
                USB_USBTask();\r
        }\r
                CDC_Device_USBTask((USB_ClassInfo_CDC_Device_t*)fdev_get_udata(Stream));\r
                USB_USBTask();\r
        }\r