Skip to content

Commit 49a29a9

Browse files
cmaglieturmary
authored andcommitted
USBDevice: factored out a function to release OUT eps
1 parent e0e677e commit 49a29a9

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

cores/arduino/USB/PluggableUSB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PluggableUSBModule {
3535
virtual bool setup(USBSetup& setup) = 0;
3636
virtual int getInterface(uint8_t* interfaceCount) = 0;
3737
virtual int getDescriptor(USBSetup& setup) = 0;
38-
virtual void handleEndpoint(int ep) {/* Do nothing */}
38+
virtual void handleEndpoint(int ep) { (void)ep;/* Do nothing */}
3939
virtual uint8_t getShortName(char *name) { name[0] = 'A'+pluggedInterface; return 1; }
4040

4141
uint8_t pluggedInterface;

cores/arduino/USB/SAMD21_USBDevice.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,15 @@ class USBDevice_SAMD21G18x {
180180
inline void epBank0EnableAutoZLP(ep_t ep) { EP[ep].DeviceDescBank[0].PCKSIZE.bit.AUTO_ZLP = 1; }
181181
inline void epBank1EnableAutoZLP(ep_t ep) { EP[ep].DeviceDescBank[1].PCKSIZE.bit.AUTO_ZLP = 1; }
182182

183+
// USB Device Endpoint transactions helpers
184+
// ----------------------------------------
185+
186+
inline void epReleaseOutBank0(ep_t ep, uint16_t s) {
187+
epBank0SetMultiPacketSize(ep, s);
188+
epBank0SetByteCount(ep, 0);
189+
epBank0ResetReady(ep);
190+
}
191+
183192
private:
184193
// USB Device registers
185194
UsbDevice &usb;
@@ -243,6 +252,7 @@ class DoubleBufferedEPOutHandler : public EPHandler {
243252
usbd.epBank0SetType(ep, 3); // BULK OUT
244253

245254
usbd.epBank0SetAddress(ep, const_cast<uint8_t *>(data0));
255+
usbd.epBank0EnableTransferComplete(ep);
246256

247257
release();
248258
}
@@ -394,11 +404,7 @@ class DoubleBufferedEPOutHandler : public EPHandler {
394404
}
395405

396406
void release() {
397-
// Release OUT EP
398-
usbd.epBank0EnableTransferComplete(ep);
399-
usbd.epBank0SetMultiPacketSize(ep, size);
400-
usbd.epBank0SetByteCount(ep, 0);
401-
usbd.epBank0ResetReady(ep);
407+
usbd.epReleaseOutBank0(ep, size);
402408
}
403409

404410
private:

cores/arduino/USB/USBCore.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,11 +542,7 @@ void USBDeviceClass::initEP(uint32_t ep, uint32_t config)
542542
usbd.epBank1SetType(ep, 1); // CONTROL IN
543543

544544
// Release OUT EP
545-
usbd.epBank0SetMultiPacketSize(ep, 64);
546-
usbd.epBank0SetByteCount(ep, 0);
547-
548-
// NAK on endpoint OUT, the bank is full.
549-
usbd.epBank0SetReady(ep);
545+
usbd.epReleaseOutBank0(ep, 64);
550546
}
551547
}
552548

0 commit comments

Comments
 (0)