USB_HANDLE USBGetNextHandle( uint8_t ep_num, uint8_t ep_dir );
Retrieves the handle to the next endpoint BDT that the USBTransferOnePacket() will use. Useful for initialization and when ping pong buffering will be used on application endpoints.
Will return NULL if the USB device has not yet been configured/the endpoint specified has not yet been initialized by USBEnableEndpoint().
Return Values |
Description |
Returns the USB_HANDLE (a pointer) to the BDT that will be used next time the USBTransferOnePacket() function is called, for the given ep_num and ep_dir |
This API is useful for initializing USB_HANDLEs during initialization of the application firmware. It is also useful when ping-pong buffering is enabled, and the application firmware wishes to arm both the even and odd BDTs for an endpoint simultaneously. In this case, the application firmware for sending data to the host would typically be something like follows:
USB_HANDLE Handle1; USB_HANDLE Handle2; USB_HANDLE* pHandle = &Handle1; uint8_t UserDataBuffer1[64]; uint8_t UserDataBuffer2[64]; uint8_t* pDataBuffer = &UserDataBuffer1[0]; //Add some code that loads UserDataBuffer1[] with useful data to send, //using the pDataBuffer pointer, for example: //for(i = 0; i < 64; i++) //{ // *pDataBuffer++ = [useful data value]; //} //Check if the next USB endpoint BDT is available if(!USBHandleBusy(USBGetNextHandle(ep_num, IN_TO_HOST)) { //The endpoint is available. Send the data. *pHandle = USBTransferOnePacket(ep_num, ep_dir, pDataBuffer, bytecount); //Toggle the handle and buffer pointer for the next transaction if(pHandle == &Handle1) { pHandle = &Handle2; pDataBuffer = &UserDataBuffer2[0]; } else { pHandle = &Handle1; pDataBuffer = &UserDataBuffer1[0]; } } //The firmware can then load the next data buffer (in this case //UserDataBuffer2)with useful data, and send it using the same //process. For example: //Add some code that loads UserDataBuffer2[] with useful data to send, //using the pDataBuffer pointer, for example: //for(i = 0; i < 64; i++) //{ // *pDataBuffer++ = [useful data value]; //} //Check if the next USB endpoint BDT is available if(!USBHandleBusy(USBGetNextHandle(ep_num, IN_TO_HOST)) { //The endpoint is available. Send the data. *pHandle = USBTransferOnePacket(ep_num, ep_dir, pDataBuffer, bytecount); //Toggle the handle and buffer pointer for the next transaction if(pHandle == &Handle1) { pHandle = &Handle2; pDataBuffer = &UserDataBuffer2[0]; } else { pHandle = &Handle1; pDataBuffer = &UserDataBuffer1[0]; } }
MLA - USB Library Help Version : 2.16
![]() |