CtrlReq callback bugfix

This commit is contained in:
Oleg Mazurov 2011-06-06 07:18:31 -06:00
parent cf1611cb48
commit bc40559679
2 changed files with 11 additions and 6 deletions

10
Usb.cpp
View file

@ -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 ); rcode = InTransfer( pep, nak_limit, &read, dataptr );
if (rcode /*&& rcode != hrSTALL*/) if (rcode)
return rcode; return rcode;
// Invoke callback function if inTransfer completed successfuly and callback function pointer is specified // 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 ); ((USBReadParser*)p)->Parse( read, dataptr, total - left );
left -= read; left -= read;
if (read < nbytes)
break;
} }
} }
else //OUT transfer else //OUT transfer
@ -222,14 +225,15 @@ uint8_t USB::InTransfer(EpInfo *pep, uint16_t nak_limit, uint16_t *nbytesptr, ui
if (mem_left < 0) if (mem_left < 0)
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 regWr( rHIRQ, bmRCVDAVIRQ ); // Clear the IRQ & free the buffer
*nbytesptr += pktsize; // add this packet's byte count to total transfer length *nbytesptr += pktsize; // add this packet's byte count to total transfer length
/* The transfer is complete under two conditions: */ /* The transfer is complete under two conditions: */
/* 1. The device sent a short packet (L.T. maxPacketSize) */ /* 1. The device sent a short packet (L.T. maxPacketSize) */
/* 2. 'nbytes' have been transferred. */ /* 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 // Save toggle value
pep->bmRcvToggle = ( regRd( rHRSL ) & bmRCVTOGRD ) ? 1 : 0; pep->bmRcvToggle = ( regRd( rHRSL ) & bmRCVTOGRD ) ? 1 : 0;

View file

@ -2,8 +2,8 @@
//const uint16_t HID::maxHidInterfaces = 3; //const uint16_t HID::maxHidInterfaces = 3;
//const uint16_t HID::maxEpPerInterface = 2; //const uint16_t HID::maxEpPerInterface = 2;
const uint8_t HID::epInterruptInIndex = 0; const uint8_t HID::epInterruptInIndex = 1;
const uint8_t HID::epInterruptOutIndex = 1; const uint8_t HID::epInterruptOutIndex = 2;
HID::HID(USB *p) : HID::HID(USB *p) :
pUsb(p), pUsb(p),
@ -278,6 +278,7 @@ uint8_t HID::Release()
{ {
pUsb->GetAddressPool().FreeAddress(bAddress); pUsb->GetAddressPool().FreeAddress(bAddress);
bNumEP = 1;
bAddress = 0; bAddress = 0;
qNextPollTime = 0; qNextPollTime = 0;
bPollEnable = false; bPollEnable = false;