X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/67f390fe746ccc4d1dceac23f590eb1723cb7ff2..ab2ae13d81427ddddbd24e8ba6bdfbd2f05ff958:/LUFA/Drivers/USB/Class/Device/CDC.c?ds=inline diff --git a/LUFA/Drivers/USB/Class/Device/CDC.c b/LUFA/Drivers/USB/Class/Device/CDC.c index 12b55938c..0359afe4d 100644 --- a/LUFA/Drivers/USB/Class/Device/CDC.c +++ b/LUFA/Drivers/USB/Class/Device/CDC.c @@ -78,8 +78,7 @@ void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_Device_t* CDCInterfaceInf EVENT_CDC_Device_ControLineStateChanged(CDCInterfaceInfo); - while (!(Endpoint_IsINReady())); - Endpoint_ClearIN(); + Endpoint_ClearStatusStage(); } break; @@ -88,6 +87,8 @@ void CDC_Device_ProcessControlPacket(USB_ClassInfo_CDC_Device_t* CDCInterfaceInf bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) { + memset(&CDCInterfaceInfo->State, 0x00, sizeof(CDCInterfaceInfo->State)); + if (!(Endpoint_ConfigureEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber, EP_TYPE_BULK, ENDPOINT_DIR_IN, CDCInterfaceInfo->Config.DataINEndpointSize, ENDPOINT_BANK_SINGLE))) @@ -114,7 +115,7 @@ bool CDC_Device_ConfigureEndpoints(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) { - if (!(USB_IsConnected) || !(USB_ConfigurationNumber)) + if (USB_DeviceState != DEVICE_STATE_Configured) return; Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); @@ -125,7 +126,12 @@ void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) if (!(Endpoint_IsReadWriteAllowed())) { Endpoint_ClearIN(); - while (!(Endpoint_IsReadWriteAllowed())); + + while (!(Endpoint_IsReadWriteAllowed())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } } Endpoint_ClearIN(); @@ -133,7 +139,7 @@ void CDC_Device_USBTask(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) void CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, char* const Data, const uint16_t Length) { - if (!(USB_IsConnected)) + if (USB_DeviceState != DEVICE_STATE_Configured) return; Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); @@ -142,7 +148,7 @@ void CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, c void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, const uint8_t Data) { - if (!(USB_IsConnected)) + if (USB_DeviceState != DEVICE_STATE_Configured) return; Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); @@ -150,7 +156,12 @@ void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, con if (!(Endpoint_IsReadWriteAllowed())) { Endpoint_ClearIN(); - while (!(Endpoint_IsReadWriteAllowed())); + + while (!(Endpoint_IsReadWriteAllowed())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } } Endpoint_Write_Byte(Data); @@ -165,7 +176,7 @@ uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterface uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) { - if (!(USB_IsConnected)) + if (USB_DeviceState != DEVICE_STATE_Configured) return 0; Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber); @@ -180,7 +191,7 @@ uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) void CDC_Device_SendControlLineStateChange(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) { - if (!(USB_IsConnected)) + if (USB_DeviceState != DEVICE_STATE_Configured) return; Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.NotificationEndpointNumber);