From e918d977b1d4465d525ee0f742dbdeec20f7885c Mon Sep 17 00:00:00 2001 From: Dean Camera Date: Thu, 10 Sep 2009 06:41:57 +0000 Subject: Prevent the CDC Device Class driver from sending empty IN packets on every service task call - only send termination packets when data is in the endpoint. --- LUFA/Drivers/USB/Class/Device/CDC.c | 26 ++++++++++++++++---------- LUFA/Drivers/USB/Class/Device/CDC.h | 4 +--- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'LUFA/Drivers/USB/Class/Device') diff --git a/LUFA/Drivers/USB/Class/Device/CDC.c b/LUFA/Drivers/USB/Class/Device/CDC.c index 816a5f13d..aaa821e10 100644 --- a/LUFA/Drivers/USB/Class/Device/CDC.c +++ b/LUFA/Drivers/USB/Class/Device/CDC.c @@ -143,11 +143,11 @@ uint8_t CDC_Device_SendByte(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo, Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); if (!(Endpoint_IsReadWriteAllowed())) - { - uint8_t ErrorCode; - + { Endpoint_ClearIN(); + uint8_t ErrorCode; + if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError) return ErrorCode; } @@ -161,20 +161,26 @@ uint8_t CDC_Device_Flush(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) if ((USB_DeviceState != DEVICE_STATE_Configured) || !(CDCInterfaceInfo->State.LineEncoding.BaudRateBPS)) return ENDPOINT_READYWAIT_NoError; + uint8_t ErrorCode; + Endpoint_SelectEndpoint(CDCInterfaceInfo->Config.DataINEndpointNumber); + + if (!(Endpoint_BytesInEndpoint())) + return ENDPOINT_READYWAIT_NoError; + + bool BankFull = !(Endpoint_IsReadWriteAllowed()); - if (Endpoint_BytesInEndpoint()) + Endpoint_ClearIN(); + + if (BankFull) { - uint8_t ErrorCode; - - Endpoint_ClearIN(); - if ((ErrorCode = Endpoint_WaitUntilReady()) != ENDPOINT_READYWAIT_NoError) return ErrorCode; + + Endpoint_ClearIN(); } - Endpoint_ClearIN(); - return Endpoint_WaitUntilReady(); + return ENDPOINT_READYWAIT_NoError; } uint16_t CDC_Device_BytesReceived(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) diff --git a/LUFA/Drivers/USB/Class/Device/CDC.h b/LUFA/Drivers/USB/Class/Device/CDC.h index 5905474ce..605c3b7e9 100644 --- a/LUFA/Drivers/USB/Class/Device/CDC.h +++ b/LUFA/Drivers/USB/Class/Device/CDC.h @@ -192,10 +192,8 @@ /** Flushes any data waiting to be sent, ensuring that the send buffer is cleared. * * \param[in,out] CDCInterfaceInfo Pointer to a structure containing a CDC Class configuration and state. - * - * \return A value from the \ref Endpoint_WaitUntilReady_ErrorCodes_t enum */ - uint8_t CDC_Device_Flush(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); + void CDC_Device_Flush(USB_ClassInfo_CDC_Device_t* const CDCInterfaceInfo) ATTR_NON_NULL_PTR_ARG(1); /** Sends a Serial Control Line State Change notification to the host. This should be called when the virtual serial * control lines (DCD, DSR, etc.) have changed states, or to give BREAK notfications to the host. Line states persist -- cgit v1.2.3