diff options
Diffstat (limited to 'cores/arduino/PluggableUSB.h')
-rw-r--r-- | cores/arduino/PluggableUSB.h | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/cores/arduino/PluggableUSB.h b/cores/arduino/PluggableUSB.h index d89040e..507f0df 100644 --- a/cores/arduino/PluggableUSB.h +++ b/cores/arduino/PluggableUSB.h @@ -25,38 +25,49 @@ #if defined(USBCON) -typedef struct __attribute__((packed)) -{ - bool (*setup)(USBSetup& setup, u8 i); - int (*getInterface)(u8* interfaceNum); - int (*getDescriptor)(int8_t t); - int8_t numEndpoints; - int8_t numInterfaces; - uint8_t *endpointType; -} PUSBCallbacks; - -typedef struct -{ - u8 interface; - u8 firstEndpoint; -} PUSBReturn; - -class PUSBListNode { +class PluggableUSBModule { public: - PUSBListNode *next = NULL; - PUSBCallbacks *cb; - PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;} -}; + PluggableUSBModule(uint8_t numEps, uint8_t numIfs, uint8_t *epType) : + numEndpoints(numEps), numInterfaces(numIfs), endpointType(epType) + { } + +protected: + virtual bool setup(USBSetup& setup) = 0; + virtual int getInterface(uint8_t* interfaceCount) = 0; + virtual int getDescriptor(USBSetup& setup) = 0; + virtual uint8_t getShortName(char *name) { name[0] = 'A'+pluggedInterface; return 1; } + + uint8_t pluggedInterface; + uint8_t pluggedEndpoint; -int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface); + const uint8_t numEndpoints; + const uint8_t numInterfaces; + const uint8_t *endpointType; -int PUSB_GetInterface(u8* interfaceNum); + PluggableUSBModule *next = NULL; -int PUSB_GetDescriptor(int8_t t); + friend class PluggableUSB_; +}; -bool PUSB_Setup(USBSetup& setup, u8 i); +class PluggableUSB_ { +public: + PluggableUSB_(); + bool plug(PluggableUSBModule *node); + int getInterface(uint8_t* interfaceCount); + int getDescriptor(USBSetup& setup); + bool setup(USBSetup& setup); + void getShortName(char *iSerialNum); + +private: + uint8_t lastIf; + uint8_t lastEp; + PluggableUSBModule* rootNode; +}; -void PUSB_Begin(); +// Replacement for global singleton. +// This function prevents static-initialization-order-fiasco +// https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use +PluggableUSB_& PluggableUSB(); #endif |