Skip to content

Commit 1fdbc69

Browse files
cmagliefacchinm
authored andcommitted
USBDevice: simplified handling of endpoints
The previous way was a lot more complicated for a very little perfomance benefit.
1 parent bebea1a commit 1fdbc69

File tree

2 files changed

+9
-29
lines changed

2 files changed

+9
-29
lines changed

cores/arduino/USB/USBAPI.h

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class USBDeviceClass {
8585
// Generic EndPoint API
8686
void initEndpoints(void);
8787
void initEP(uint32_t ep, uint32_t type);
88-
void handleEndpoint(uint8_t ep);
8988

9089
uint32_t send(uint32_t ep, const void *data, uint32_t len);
9190
void sendZlp(uint32_t ep);

cores/arduino/USB/USBCore.cpp

+9-28
Original file line numberDiff line numberDiff line change
@@ -257,14 +257,6 @@ void USBDeviceClass::standby() {
257257
usbd.noRunInStandby();
258258
}
259259

260-
261-
void USBDeviceClass::handleEndpoint(uint8_t ep)
262-
{
263-
#if defined(PLUGGABLE_USB_ENABLED)
264-
PluggableUSB().handleEndpoint(ep);
265-
#endif
266-
}
267-
268260
void USBDeviceClass::init()
269261
{
270262
#ifdef PIN_LED_TXL
@@ -879,28 +871,17 @@ void USBDeviceClass::ISRHandler()
879871

880872
} // end Received Setup handler
881873

882-
uint8_t i=0;
883-
uint8_t ept_int = usbd.epInterruptSummary() & 0xFE; // Remove endpoint number 0 (setup)
884-
while (ept_int != 0)
885-
{
886-
// Check if endpoint has a pending interrupt
887-
if ((ept_int & (1 << i)) != 0)
888-
{
889-
// Endpoint Transfer Complete (0/1) Interrupt
890-
if (usbd.epBank0IsTransferComplete(i) ||
891-
usbd.epBank1IsTransferComplete(i))
892-
{
893-
if (epHandlers[i]) {
894-
epHandlers[i]->handleEndpoint();
895-
} else {
896-
handleEndpoint(i);
897-
}
874+
for (int i = 1; i < USB_EPT_NUM; i++) {
875+
// Endpoint Transfer Complete (0/1) Interrupt
876+
if (usbd.epBank0IsTransferComplete(i) || usbd.epBank1IsTransferComplete(i)) {
877+
if (epHandlers[i]) {
878+
epHandlers[i]->handleEndpoint();
879+
} else {
880+
#if defined(PLUGGABLE_USB_ENABLED)
881+
PluggableUSB().handleEndpoint(i);
882+
#endif
898883
}
899-
ept_int &= ~(1 << i);
900884
}
901-
i++;
902-
if (i > USB_EPT_NUM)
903-
break; // fire exit
904885
}
905886
}
906887

0 commit comments

Comments
 (0)