Skip to content
Snippets Groups Projects
Commit b2ddb226 authored by Cristian Maglie's avatar Cristian Maglie
Browse files

USB: Added interface to possibly setup dynamic USB EP Handler

parent 34bf5421
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,12 @@ extern "C" void UDD_Handler(void) {
USBDevice.ISRHandler();
}
class EPHandler {
public:
virtual void handleEndpoint() = 0;
virtual uint32_t recv(void *_data, uint32_t len) = 0;
virtual uint32_t available() const = 0;
};
const uint16_t STRING_LANGUAGE[2] = {
......@@ -88,6 +94,8 @@ uint8_t udd_ep_out_cache_buffer[7][64];
static __attribute__((__aligned__(4))) //__attribute__((__section__(".bss_hram0")))
uint8_t udd_ep_in_cache_buffer[7][64];
static EPHandler *epHandlers[7];
//==================================================================
// Send a USB descriptor string. The string is stored as a
......@@ -532,7 +540,11 @@ uint32_t USBDeviceClass::recvControl(void *_data, uint32_t len)
// Number of bytes, assumes a rx endpoint
uint32_t USBDeviceClass::available(uint32_t ep)
{
return usbd.epBank0ByteCount(ep);
if (epHandlers[ep]) {
return epHandlers[ep]->available();
} else {
return usbd.epBank0ByteCount(ep);
}
}
// Non Blocking receive
......@@ -542,6 +554,10 @@ uint32_t USBDeviceClass::recv(uint32_t ep, void *_data, uint32_t len)
if (!_usbConfiguration)
return -1;
if (epHandlers[ep]) {
return epHandlers[ep]->recv(_data, len);
}
if (available(ep) < len)
len = available(ep);
......@@ -891,7 +907,11 @@ void USBDeviceClass::ISRHandler()
if (usbd.epBank0IsTransferComplete(i) ||
usbd.epBank1IsTransferComplete(i))
{
handleEndpoint(i);
if (epHandlers[i]) {
epHandlers[i]->handleEndpoint();
} else {
handleEndpoint(i);
}
}
ept_int &= ~(1 << i);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment