diff --git a/Usb.cpp b/Usb.cpp index 6cc60fe3..60e2af9e 100644 --- a/Usb.cpp +++ b/Usb.cpp @@ -153,7 +153,7 @@ uint8_t USB::ctrlReq( uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequ rcode = InTransfer( pep, nak_limit, &read, dataptr ); - if (rcode /*&& rcode != hrSTALL*/) + if (rcode) return rcode; // Invoke callback function if inTransfer completed successfuly and callback function pointer is specified @@ -161,6 +161,9 @@ uint8_t USB::ctrlReq( uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequ ((USBReadParser*)p)->Parse( read, dataptr, total - left ); left -= read; + + if (read < nbytes) + break; } } else //OUT transfer @@ -222,15 +225,16 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui if (mem_left < 0) mem_left = 0; - data = bytesRd( rRCVFIFO, (pktsize > mem_left) ? mem_left : pktsize, data ); + data = bytesRd( rRCVFIFO, ((pktsize > mem_left) ? mem_left : pktsize), data ); regWr( rHIRQ, bmRCVDAVIRQ ); // Clear the IRQ & free the buffer *nbytesptr += pktsize; // add this packet's byte count to total transfer length + /* The transfer is complete under two conditions: */ /* 1. The device sent a short packet (L.T. maxPacketSize) */ /* 2. 'nbytes' have been transferred. */ - if (( pktsize < maxpktsize ) || (*nbytesptr >= nbytes )) // have we transferred 'nbytes' bytes? - { + if (/*pktsize == 6 ||*/ ( pktsize < maxpktsize ) || (*nbytesptr >= nbytes )) // have we transferred 'nbytes' bytes? + { // Save toggle value pep->bmRcvToggle = ( regRd( rHRSL ) & bmRCVTOGRD ) ? 1 : 0; diff --git a/hid.cpp b/hid.cpp index 5b756453..4ebfd182 100644 --- a/hid.cpp +++ b/hid.cpp @@ -2,8 +2,8 @@ //const uint16_t HID::maxHidInterfaces = 3; //const uint16_t HID::maxEpPerInterface = 2; -const uint8_t HID::epInterruptInIndex = 0; -const uint8_t HID::epInterruptOutIndex = 1; +const uint8_t HID::epInterruptInIndex = 1; +const uint8_t HID::epInterruptOutIndex = 2; HID::HID(USB *p) : pUsb(p), @@ -278,6 +278,7 @@ uint8_t HID::Release() { pUsb->GetAddressPool().FreeAddress(bAddress); + bNumEP = 1; bAddress = 0; qNextPollTime = 0; bPollEnable = false;