diff options
Diffstat (limited to 'cores/arduino/PluggableUSB.cpp')
-rw-r--r-- | cores/arduino/PluggableUSB.cpp | 103 |
1 files changed, 59 insertions, 44 deletions
diff --git a/cores/arduino/PluggableUSB.cpp b/cores/arduino/PluggableUSB.cpp index 857a27f..c489d9f 100644 --- a/cores/arduino/PluggableUSB.cpp +++ b/cores/arduino/PluggableUSB.cpp @@ -23,78 +23,93 @@ #if defined(USBCON) #ifdef PLUGGABLE_USB_ENABLED -#define MAX_MODULES 6 +extern uint8_t _initEndpoints[]; -static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT; -static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT; - -extern u8 _initEndpoints[]; - -//PUSBCallbacks cbs[MAX_MODULES]; -static u8 modules_count = 0; - -static PUSBListNode* rootNode = NULL; +int PluggableUSB_::getInterface(uint8_t* interfaceCount) +{ + int sent = 0; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + int res = node->getInterface(interfaceCount); + if (res < 0) + return -1; + sent += res; + } + return sent; +} -int PUSB_GetInterface(u8* interfaceNum) +int PluggableUSB_::getDescriptor(USBSetup& setup) { - int ret = 0; - PUSBListNode* node = rootNode; - for (u8 i=0; i<modules_count; i++) { - ret = node->cb->getInterface(interfaceNum); - node = node->next; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + int ret = node->getDescriptor(setup); + // ret!=0 -> request has been processed + if (ret) + return ret; } - return ret; + return 0; } -int PUSB_GetDescriptor(int8_t t) +void PluggableUSB_::getShortName(char *iSerialNum) { - int ret = 0; - PUSBListNode* node = rootNode; - for (u8 i=0; i<modules_count && ret == 0; i++) { - ret = node->cb->getDescriptor(t); - node = node->next; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + iSerialNum += node->getShortName(iSerialNum); } - return ret; + *iSerialNum = 0; } -bool PUSB_Setup(USBSetup& setup, u8 j) +bool PluggableUSB_::setup(USBSetup& setup) { - bool ret = false; - PUSBListNode* node = rootNode; - for (u8 i=0; i<modules_count && ret == false; i++) { - ret = node->cb->setup(setup, j); - node = node->next; + PluggableUSBModule* node; + for (node = rootNode; node; node = node->next) { + if (node->setup(setup)) { + return true; + } } - return ret; + return false; } -int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface) +bool PluggableUSB_::plug(PluggableUSBModule *node) { - if (modules_count >= MAX_MODULES) { - return 0; + if ((lastEp + node->numEndpoints) > USB_ENDPOINTS) { + return false; } - if (modules_count == 0) { + if (!rootNode) { rootNode = node; } else { - PUSBListNode *current = rootNode; - while(current->next != NULL) { + PluggableUSBModule *current = rootNode; + while (current->next) { current = current->next; } current->next = node; } - *interface = lastIf; - lastIf += node->cb->numInterfaces; - for ( u8 i = 0; i< node->cb->numEndpoints; i++) { - _initEndpoints[lastEp] = node->cb->endpointType[i]; + node->pluggedInterface = lastIf; + node->pluggedEndpoint = lastEp; + lastIf += node->numInterfaces; + for (uint8_t i = 0; i < node->numEndpoints; i++) { + _initEndpoints[lastEp] = node->endpointType[i]; lastEp++; } - modules_count++; - return lastEp - node->cb->numEndpoints; + return true; // restart USB layer??? } +PluggableUSB_& PluggableUSB() +{ + static PluggableUSB_ obj; + return obj; +} + +PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT), + lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT), + rootNode(NULL) +{ + // Empty +} + #endif -#endif /* if defined(USBCON) */
\ No newline at end of file +#endif /* if defined(USBCON) */ |