int32_t libusbdev_Read_DataEp(uint8_t *pBuf, uint32_t buf_len) { int32_t ret = -1; /* Queue read request */ if (libusbdev_QueueReadReq_DataEp(pBuf, buf_len) == LPC_OK) { /* wait for Rx to complete */ while ( (ret = libusbdev_QueueReadDone()) == -1) { /* Sleep until next IRQ happens */ __WFI(); } } return ret; } |
ErrorCode_t libusbdev_QueueReadReq_DataEp(uint8_t *pBuf, uint32_t buf_len) { LUSB_CTRL_T *pUSB = (LUSB_CTRL_T *) &g_lusb; ErrorCode_t ret = ERR_FAILED; /* Check if a read request is pending */ if (pUSB->pRxBuf == 0) { /* Queue the read request */ pUSB->pRxBuf = pBuf; pUSB->rxBuffLen = buf_len; USBD_API->hw->ReadReqEP(pUSB->hUsb, LUSB_DATAOUT_EP, pBuf, buf_len); ret = LPC_OK; } return ret; } |
int32_t libusbdev_QueueReadDone(void) { LUSB_CTRL_T *pUSB = (LUSB_CTRL_T *) &g_lusb; /* A read request is pending */ if (pUSB->pRxBuf) { return -1; } /* if data received return the length */ return pUSB->rxBuffLen; } |
ErrorCode_t lusb_BulkDataOUT_Hdlr(USBD_HANDLE_T hUsb, void *data, uint32_t event) { LUSB_CTRL_T *pUSB = (LUSB_CTRL_T *) data; int32_t receivedBytes; /* We received a transfer from the USB host. */ if (event == USB_EVT_OUT) { pUSB->rxBuffLen = USBD_API->hw->ReadEP(hUsb, LUSB_DATAOUT_EP, pUSB->pRxBuf); pUSB->pRxBuf = 0; } return LPC_OK; } |