From a6ca5b82e7a1ecea61b77a771b0f4aa2545edf1a Mon Sep 17 00:00:00 2001 From: peabody124 Date: Thu, 16 Sep 2010 20:23:02 +0000 Subject: [PATCH] OP-155 Flight/HID: Make the HID stall when buffer full. Not sure the consequences on ground (i.e. if it handles the stall correctly) git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1665 ebee16cc-31ac-478f-84a7-5cbb03baadba --- flight/PiOS/STM32F10x/pios_usb_hid.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/flight/PiOS/STM32F10x/pios_usb_hid.c b/flight/PiOS/STM32F10x/pios_usb_hid.c index c3a0408c9..4ee4bf6ce 100644 --- a/flight/PiOS/STM32F10x/pios_usb_hid.c +++ b/flight/PiOS/STM32F10x/pios_usb_hid.c @@ -284,7 +284,12 @@ int32_t PIOS_USB_HID_TxBufferPutMore(uint8_t id, const uint8_t *buffer, uint16_t */ int32_t PIOS_USB_HID_RxBufferGet(uint8_t id) { - return bufferGetFromFront(&rxBuffer); + uint8_t read = bufferGetFromFront(&rxBuffer); + // If endpoint was stalled and there is now space make it valid + if((GetEPRxStatus(ENDP1) == EP_RX_STALL) && (bufferRemainingSpace(&rxBuffer) > 62)) { + SetEPRxStatus(ENDP1, EP_RX_VALID); + } + return read; } /** @@ -327,7 +332,13 @@ void PIOS_USB_HID_EP1_OUT_Callback(void) #else bufferAddChunkToEnd(&rxBuffer, &rx_buffer[2], rx_buffer[1]); #endif - SetEPRxStatus(ENDP1, EP_RX_VALID); + + // Only reactivate endpoint if available space in buffer + if(bufferRemainingSpace(&rxBuffer) > 62) { + SetEPRxStatus(ENDP1, EP_RX_VALID); + } else { + SetEPRxStatus(ENDP1, EP_RX_STALL); + } } #endif