@@ -46,6 +46,12 @@ extern "C" void UDD_Handler(void) {
46
46
USBDevice.ISRHandler ();
47
47
}
48
48
49
+ class EPHandler {
50
+ public:
51
+ virtual void handleEndpoint () = 0;
52
+ virtual uint32_t recv (void *_data, uint32_t len) = 0;
53
+ virtual uint32_t available () const = 0;
54
+ };
49
55
50
56
51
57
const uint16_t STRING_LANGUAGE[2 ] = {
@@ -88,6 +94,8 @@ uint8_t udd_ep_out_cache_buffer[7][64];
88
94
static __attribute__ ((__aligned__(4 ))) // __attribute__((__section__(".bss_hram0")))
89
95
uint8_t udd_ep_in_cache_buffer[7][64];
90
96
97
+ static EPHandler *epHandlers[7 ];
98
+
91
99
// ==================================================================
92
100
93
101
// Send a USB descriptor string. The string is stored as a
@@ -532,7 +540,11 @@ uint32_t USBDeviceClass::recvControl(void *_data, uint32_t len)
532
540
// Number of bytes, assumes a rx endpoint
533
541
uint32_t USBDeviceClass::available (uint32_t ep)
534
542
{
535
- return usbd.epBank0ByteCount (ep);
543
+ if (epHandlers[ep]) {
544
+ return epHandlers[ep]->available ();
545
+ } else {
546
+ return usbd.epBank0ByteCount (ep);
547
+ }
536
548
}
537
549
538
550
// Non Blocking receive
@@ -542,6 +554,10 @@ uint32_t USBDeviceClass::recv(uint32_t ep, void *_data, uint32_t len)
542
554
if (!_usbConfiguration)
543
555
return -1 ;
544
556
557
+ if (epHandlers[ep]) {
558
+ return epHandlers[ep]->recv (_data, len);
559
+ }
560
+
545
561
if (available (ep) < len)
546
562
len = available (ep);
547
563
@@ -891,7 +907,11 @@ void USBDeviceClass::ISRHandler()
891
907
if (usbd.epBank0IsTransferComplete (i) ||
892
908
usbd.epBank1IsTransferComplete (i))
893
909
{
894
- handleEndpoint (i);
910
+ if (epHandlers[i]) {
911
+ epHandlers[i]->handleEndpoint ();
912
+ } else {
913
+ handleEndpoint (i);
914
+ }
895
915
}
896
916
ept_int &= ~(1 << i);
897
917
}
0 commit comments