1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

Further tweaks. Will start trying to get reliable communication with larger report size tomorrow

git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@1159 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
peabody124 2010-07-27 07:56:50 +00:00 committed by peabody124
parent 840f7ff456
commit fe616df48d
3 changed files with 36 additions and 13 deletions

View File

@ -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;
}

View File

@ -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,

View File

@ -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 */