X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/00d0883507efdc17688abafa75e81bf62f83d777..ab2ae13d81427ddddbd24e8ba6bdfbd2f05ff958:/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 fc6ea93fb..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)) + if (USB_DeviceState != DEVICE_STATE_Configured) return; Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); @@ -125,24 +126,29 @@ 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(); } -void CDC_Device_SendString(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, char* Data, uint16_t Length) +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); Endpoint_Write_Stream_LE(Data, Length, NO_STREAM_CALLBACK); } -void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, uint8_t Data) +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,13 +156,18 @@ void CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo, uint8_t D if (!(Endpoint_IsReadWriteAllowed())) { Endpoint_ClearIN(); - while (!(Endpoint_IsReadWriteAllowed())); + + while (!(Endpoint_IsReadWriteAllowed())) + { + if (USB_DeviceState == DEVICE_STATE_Unattached) + return; + } } Endpoint_Write_Byte(Data); } -uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) +uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) { Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataOUTEndpointNumber); @@ -165,7 +176,7 @@ uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) 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); @@ -178,9 +189,9 @@ uint8_t CDC_Device_ReceiveByte(USB_ClassInfo_CDC_Device_t* CDCInterfaceInfo) return DataByte; } -void CDC_Device_SendControlLineStateChange(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);