X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/7f9f97c792dee6875fbca9806422bdd7d6c5a657..7d51e51c79c3af7791f4c3e8c7e5e8196a2c3f93:/LUFA/Drivers/USB/Class/Device/CDC.c diff --git a/LUFA/Drivers/USB/Class/Device/CDC.c b/LUFA/Drivers/USB/Class/Device/CDC.c index c274853de..4cdea9485 100644 --- a/LUFA/Drivers/USB/Class/Device/CDC.c +++ b/LUFA/Drivers/USB/Class/Device/CDC.c @@ -28,10 +28,12 @@ this software. */ +#define __INCLUDE_FROM_USB_DRIVER #include "../../HighLevel/USBMode.h" #if defined(USB_CAN_BE_DEVICE) -#define INCLUDE_FROM_CDC_CLASS_DEVICE_C +#define __INCLUDE_FROM_CDC_CLASS_DEVICE_C +#define __INCLUDE_FROM_CDC_DRIVER #include "CDC.h" void CDC_Device_Event_Stub(void) @@ -190,10 +192,17 @@ uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterface Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber); - if (Endpoint_IsOUTReceived() && !(Endpoint_BytesInEndpoint())) - Endpoint_ClearOUT(); + if (Endpoint_IsOUTReceived()) + { + if (!(Endpoint_BytesInEndpoint())) + Endpoint_ClearOUT(); - return Endpoint_BytesInEndpoint(); + return Endpoint_BytesInEndpoint(); + } + else + { + return 0; + } } uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) @@ -263,6 +272,9 @@ static int CDC_Device_getchar_Blocking(FILE* Stream) { while (!(CDC_Device_BytesReceived((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(); }