[PUSB] Fixed check for available endpoints
The check for available slot in PluggableUSB is done on the endpoint and not on the number of plugged modules. The modulesCount field is no longer useful and it has been removed.
This commit is contained in:
parent
c0f9296ae5
commit
e42d7d6221
|
@ -23,58 +23,56 @@
|
||||||
#if defined(USBCON)
|
#if defined(USBCON)
|
||||||
#ifdef PLUGGABLE_USB_ENABLED
|
#ifdef PLUGGABLE_USB_ENABLED
|
||||||
|
|
||||||
#define MAX_MODULES 6
|
// TODO: set correct value for different CPUs
|
||||||
|
#define MAX_EP 6
|
||||||
|
|
||||||
extern uint8_t _initEndpoints[];
|
extern uint8_t _initEndpoints[];
|
||||||
|
|
||||||
//PUSBCallbacks cbs[MAX_MODULES];
|
|
||||||
|
|
||||||
PluggableUSB_ PluggableUSB;
|
PluggableUSB_ PluggableUSB;
|
||||||
|
|
||||||
int PluggableUSB_::getInterface(uint8_t* interfaceNum)
|
int PluggableUSB_::getInterface(uint8_t* interfaceNum)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
PUSBListNode* node = rootNode;
|
PUSBListNode* node;
|
||||||
for (uint8_t i=0; i<modulesCount; i++) {
|
for (node = rootNode; node; node = node->next) {
|
||||||
ret = node->getInterface(interfaceNum);
|
ret = node->getInterface(interfaceNum);
|
||||||
node = node->next;
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int PluggableUSB_::getDescriptor(int8_t t)
|
int PluggableUSB_::getDescriptor(int8_t t)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
PUSBListNode* node;
|
||||||
PUSBListNode* node = rootNode;
|
for (node = rootNode; node; node = node->next) {
|
||||||
for (uint8_t i=0; i<modulesCount && ret == 0; i++) {
|
int ret = node->getDescriptor(t);
|
||||||
ret = node->getDescriptor(t);
|
if (ret)
|
||||||
node = node->next;
|
return ret;
|
||||||
}
|
}
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluggableUSB_::setup(USBSetup& setup, uint8_t j)
|
bool PluggableUSB_::setup(USBSetup& setup, uint8_t j)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
PUSBListNode* node;
|
||||||
PUSBListNode* node = rootNode;
|
for (node = rootNode; node; node = node->next) {
|
||||||
for (uint8_t i=0; i<modulesCount && ret == false; i++) {
|
if (node->setup(setup, j)) {
|
||||||
ret = node->setup(setup, j);
|
return true;
|
||||||
node = node->next;
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PluggableUSB_::plug(PUSBListNode *node)
|
bool PluggableUSB_::plug(PUSBListNode *node)
|
||||||
{
|
{
|
||||||
if (modulesCount >= MAX_MODULES) {
|
if ((lastEp + node->numEndpoints) >= MAX_EP) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modulesCount == 0) {
|
if (!rootNode) {
|
||||||
rootNode = node;
|
rootNode = node;
|
||||||
} else {
|
} else {
|
||||||
PUSBListNode *current = rootNode;
|
PUSBListNode *current = rootNode;
|
||||||
while(current->next != NULL) {
|
while (current->next) {
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
current->next = node;
|
current->next = node;
|
||||||
|
@ -83,18 +81,17 @@ bool PluggableUSB_::plug(PUSBListNode *node)
|
||||||
node->pluggedInterface = lastIf;
|
node->pluggedInterface = lastIf;
|
||||||
node->pluggedEndpoint = lastEp;
|
node->pluggedEndpoint = lastEp;
|
||||||
lastIf += node->numInterfaces;
|
lastIf += node->numInterfaces;
|
||||||
for (uint8_t i=0; i<node->numEndpoints; i++) {
|
for (uint8_t i = 0; i < node->numEndpoints; i++) {
|
||||||
_initEndpoints[lastEp] = node->endpointType[i];
|
_initEndpoints[lastEp] = node->endpointType[i];
|
||||||
lastEp++;
|
lastEp++;
|
||||||
}
|
}
|
||||||
modulesCount++;
|
|
||||||
return true;
|
return true;
|
||||||
// restart USB layer???
|
// restart USB layer???
|
||||||
}
|
}
|
||||||
|
|
||||||
PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT),
|
PluggableUSB_::PluggableUSB_() : lastIf(CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT),
|
||||||
lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT),
|
lastEp(CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT),
|
||||||
modulesCount(0), rootNode(NULL)
|
rootNode(NULL)
|
||||||
{
|
{
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,7 +63,6 @@ public:
|
||||||
private:
|
private:
|
||||||
uint8_t lastIf;
|
uint8_t lastIf;
|
||||||
uint8_t lastEp;
|
uint8_t lastEp;
|
||||||
uint8_t modulesCount;
|
|
||||||
PUSBListNode* rootNode;
|
PUSBListNode* rootNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue