Skip to content

Commit f051e74

Browse files
cmagliefacchinm
authored andcommitted
USBDevice: factored out a function to release OUT eps
1 parent 2397c45 commit f051e74

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

cores/arduino/USB/SAMD21_USBDevice.h

+11-4
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,15 @@ class USBDevice_SAMD21G18x {
159159
inline void epBank0EnableAutoZLP(ep_t ep) { EP[ep].DeviceDescBank[0].PCKSIZE.bit.AUTO_ZLP = 1; }
160160
inline void epBank1EnableAutoZLP(ep_t ep) { EP[ep].DeviceDescBank[1].PCKSIZE.bit.AUTO_ZLP = 1; }
161161

162+
// USB Device Endpoint transactions helpers
163+
// ----------------------------------------
164+
165+
inline void epReleaseOutBank0(ep_t ep, uint16_t s) {
166+
epBank0SetMultiPacketSize(ep, s);
167+
epBank0SetByteCount(ep, 0);
168+
epBank0ResetReady(ep);
169+
}
170+
162171
private:
163172
// USB Device registers
164173
UsbDevice &usb;
@@ -248,6 +257,7 @@ class DoubleBufferedEPOutHandler : public EPHandler {
248257
usbd.epBank0SetSize(ep, 64);
249258
usbd.epBank0SetType(ep, 3); // BULK OUT
250259
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data0));
260+
usbd.epBank0EnableTransferComplete(ep);
251261

252262
release();
253263
}
@@ -373,10 +383,7 @@ class DoubleBufferedEPOutHandler : public EPHandler {
373383
}
374384

375385
void release() {
376-
// Release OUT EP
377-
usbd.epBank0EnableTransferComplete(ep);
378-
usbd.epBank0SetByteCount(ep, 0);
379-
usbd.epBank0ResetReady(ep);
386+
usbd.epReleaseOutBank0(ep, size);
380387
}
381388

382389
private:

cores/arduino/USB/USBCore.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,7 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
425425
usbd.epBank1SetType(ep, 1); // CONTROL IN
426426

427427
// Release OUT EP
428-
usbd.epBank0SetMultiPacketSize(ep, 64);
429-
usbd.epBank0SetByteCount(ep, 0);
430-
431-
// NAK on endpoint OUT, the bank is full.
432-
usbd.epBank0SetReady(ep);
428+
usbd.epReleaseOutBank0(ep, 64);
433429
}
434430
}
435431

0 commit comments

Comments
 (0)