rework PUSBCallbacks initialization
This commit is contained in:
parent
3e516e93c4
commit
d269ed2854
|
@ -28,12 +28,6 @@
|
||||||
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
|
static u8 lastIf = CDC_ACM_INTERFACE + CDC_INTERFACE_COUNT;
|
||||||
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
|
static u8 lastEp = CDC_FIRST_ENDPOINT + CDC_ENPOINT_COUNT;
|
||||||
|
|
||||||
class PUSBListNode {
|
|
||||||
public:
|
|
||||||
PUSBListNode *next = NULL;
|
|
||||||
PUSBCallbacks cb;
|
|
||||||
};
|
|
||||||
|
|
||||||
extern u8 _initEndpoints[];
|
extern u8 _initEndpoints[];
|
||||||
|
|
||||||
//PUSBCallbacks cbs[MAX_MODULES];
|
//PUSBCallbacks cbs[MAX_MODULES];
|
||||||
|
@ -47,7 +41,7 @@ int8_t PUSB_GetInterface(u8* interfaceNum)
|
||||||
int8_t ret = 0;
|
int8_t ret = 0;
|
||||||
PUSBListNode* node = rootNode;
|
PUSBListNode* node = rootNode;
|
||||||
for (u8 i=0; i<modules_count; i++) {
|
for (u8 i=0; i<modules_count; i++) {
|
||||||
ret = node->cb.getInterface(interfaceNum);
|
ret = node->cb->getInterface(interfaceNum);
|
||||||
node = node->next;
|
node = node->next;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -58,7 +52,7 @@ int8_t PUSB_GetDescriptor(int8_t t)
|
||||||
int8_t ret = 0;
|
int8_t ret = 0;
|
||||||
PUSBListNode* node = rootNode;
|
PUSBListNode* node = rootNode;
|
||||||
for (u8 i=0; i<modules_count && ret == 0; i++) {
|
for (u8 i=0; i<modules_count && ret == 0; i++) {
|
||||||
ret = node->cb.getDescriptor(t);
|
ret = node->cb->getDescriptor(t);
|
||||||
node = node->next;
|
node = node->next;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -69,24 +63,18 @@ bool PUSB_Setup(Setup& setup, u8 j)
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
PUSBListNode* node = rootNode;
|
PUSBListNode* node = rootNode;
|
||||||
for (u8 i=0; i<modules_count && ret == false; i++) {
|
for (u8 i=0; i<modules_count && ret == false; i++) {
|
||||||
ret = node->cb.setup(setup, j);
|
ret = node->cb->setup(setup, j);
|
||||||
node = node->next;
|
node = node->next;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
|
int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface)
|
||||||
{
|
{
|
||||||
if (modules_count >= MAX_MODULES) {
|
if (modules_count >= MAX_MODULES) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
PUSBListNode *node = new PUSBListNode;
|
|
||||||
|
|
||||||
node->cb.setup = cb->setup;
|
|
||||||
node->cb.getInterface = cb->getInterface;
|
|
||||||
node->cb.getDescriptor = cb->getDescriptor;
|
|
||||||
|
|
||||||
if (modules_count == 0) {
|
if (modules_count == 0) {
|
||||||
rootNode = node;
|
rootNode = node;
|
||||||
lastNode = node;
|
lastNode = node;
|
||||||
|
@ -95,13 +83,13 @@ int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8* interface)
|
||||||
}
|
}
|
||||||
|
|
||||||
*interface = lastIf;
|
*interface = lastIf;
|
||||||
lastIf += cb->numInterfaces;
|
lastIf += node->cb->numInterfaces;
|
||||||
for ( u8 i = 0; i< cb->numEndpoints; i++) {
|
for ( u8 i = 0; i< node->cb->numEndpoints; i++) {
|
||||||
_initEndpoints[lastEp] = cb->endpointType[i];
|
_initEndpoints[lastEp] = node->cb->endpointType[i];
|
||||||
lastEp++;
|
lastEp++;
|
||||||
}
|
}
|
||||||
modules_count++;
|
modules_count++;
|
||||||
return lastEp - cb->numEndpoints;
|
return lastEp - node->cb->numEndpoints;
|
||||||
// restart USB layer???
|
// restart USB layer???
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ typedef struct
|
||||||
int8_t (*getDescriptor)(int8_t t);
|
int8_t (*getDescriptor)(int8_t t);
|
||||||
int8_t numEndpoints;
|
int8_t numEndpoints;
|
||||||
int8_t numInterfaces;
|
int8_t numInterfaces;
|
||||||
u8 endpointType[];
|
uint8_t *endpointType;
|
||||||
} PUSBCallbacks;
|
} PUSBCallbacks;
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
@ -41,7 +41,14 @@ typedef struct
|
||||||
u8 firstEndpoint;
|
u8 firstEndpoint;
|
||||||
} PUSBReturn;
|
} PUSBReturn;
|
||||||
|
|
||||||
int8_t PUSB_AddFunction(PUSBCallbacks *cb, u8 *interface);
|
class PUSBListNode {
|
||||||
|
public:
|
||||||
|
PUSBListNode *next = NULL;
|
||||||
|
PUSBCallbacks *cb;
|
||||||
|
PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;}
|
||||||
|
};
|
||||||
|
|
||||||
|
int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface);
|
||||||
|
|
||||||
int8_t PUSB_GetInterface(u8* interfaceNum);
|
int8_t PUSB_GetInterface(u8* interfaceNum);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue