diff --git a/flight/PiOS/STM32F10x/pios_usb_hid.c b/flight/PiOS/STM32F10x/pios_usb_hid.c index a2e4754ec..750350457 100644 --- a/flight/PiOS/STM32F10x/pios_usb_hid.c +++ b/flight/PiOS/STM32F10x/pios_usb_hid.c @@ -51,6 +51,10 @@ static volatile uint8_t rx_buffer_ix; static uint8_t transfer_possible = 0; static uint8_t rx_buffer[PIOS_USB_HID_DATA_LENGTH] = {0}; +static uint8_t transmit_remaining; +static uint8_t *p_tx_buffer; +static uint8_t tx_buffer[PIOS_USB_HID_DATA_LENGTH] = {0}; + /** * Initialises USB COM layer * \param[in] mode currently only mode 0 supported @@ -83,7 +87,7 @@ int32_t PIOS_USB_HID_Init(uint32_t mode) USB_Init(); PIOS_LED_On(LED2); - + return 0; /* No error */ } @@ -117,6 +121,28 @@ int32_t PIOS_USB_HID_CheckAvailable(uint8_t id) return transfer_possible ? 1 : 0; } +/** + * Transmits the next byte in the buffer in report 1 + */ +void PIOS_USB_HID_TxNextByte() +{ + uint8_t buf[2]; + if( transmit_remaining > 0 ) { + transmit_remaining--; + buf[0] = 1; // report ID 1 + buf[1] = *p_tx_buffer; + p_tx_buffer++; + + UserToPMABufferCopy((uint8_t*) buf, GetEPTxAddr(EP1_IN & 0x7F), 2); + SetEPTxCount((EP1_IN & 0x7F), 2); + + /* Send Buffer */ + SetEPTxValid(ENDP1); + + PIOS_LED_Toggle( LED2 ); + } +} + /** * Puts more than one byte onto the transmit buffer (used for atomic sends) * \param[in] *buffer pointer to buffer which should be transmitted @@ -130,18 +156,14 @@ int32_t PIOS_USB_HID_TxBufferPutMoreNonBlocking(uint8_t id, const uint8_t *buffe if(len > PIOS_USB_HID_DATA_LENGTH) { /* Cannot send all requested bytes */ return -1; - } - - /* Copy bytes to be transmitted into transmit buffer */ - UserToPMABufferCopy((uint8_t*) buffer, GetEPTxAddr(EP1_IN & 0x7F), len); - SetEPTxCount((EP1_IN & 0x7F), len); - - /* Send Buffer */ - SetEPTxValid(ENDP1); - - PIOS_LED_Toggle( LED2 ); + } + + memcpy(&tx_buffer[0], buffer, len); + transmit_remaining = len; + p_tx_buffer = tx_buffer; + + PIOS_USB_HID_TxNextByte(); - /* No error */ return 0; } diff --git a/flight/PiOS/STM32F10x/pios_usb_hid_istr.c b/flight/PiOS/STM32F10x/pios_usb_hid_istr.c index 13d282247..1b0aded03 100644 --- a/flight/PiOS/STM32F10x/pios_usb_hid_istr.c +++ b/flight/PiOS/STM32F10x/pios_usb_hid_istr.c @@ -32,7 +32,7 @@ __IO uint8_t bIntPackSOF = 0; /* SOFs received between 2 consecutive packets */ /* function pointers to non-control endpoints service routines */ void (*pEpInt_IN[7])(void) = { - EP1_IN_Callback, + PIOS_USB_HID_TxNextByte, EP2_IN_Callback, EP3_IN_Callback, EP4_IN_Callback, diff --git a/flight/PiOS/inc/pios_usb_hid.h b/flight/PiOS/inc/pios_usb_hid.h index 35ff7299a..adaf7c00e 100644 --- a/flight/PiOS/inc/pios_usb_hid.h +++ b/flight/PiOS/inc/pios_usb_hid.h @@ -52,6 +52,7 @@ extern int32_t PIOS_USB_HID_RxBufferUsed(uint8_t id); extern int32_t PIOS_USB_HID_CB_Data_Setup(uint8_t RequestNo); extern int32_t PIOS_USB_HID_CB_NoData_Setup(uint8_t RequestNo); extern void PIOS_USB_HID_EP1_OUT_Callback(void); +extern void PIOS_USB_HID_TxNextByte(void); #endif /* PIOS_USB_HID_H */