[PUSB] PUSBCallback struct has been merged into PUSBListNode

This slightly simplifies PluggableUSB API.
This commit is contained in:
Cristian Maglie 2015-09-29 16:40:27 +02:00
parent 2aaef8cdad
commit 7302965552
3 changed files with 18 additions and 25 deletions

View File

@ -40,7 +40,7 @@ int PUSB_GetInterface(u8* interfaceNum)
int ret = 0; int 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->getInterface(interfaceNum);
node = node->next; node = node->next;
} }
return ret; return ret;
@ -51,7 +51,7 @@ int PUSB_GetDescriptor(int8_t t)
int ret = 0; int 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->getDescriptor(t);
node = node->next; node = node->next;
} }
return ret; return ret;
@ -62,7 +62,7 @@ bool PUSB_Setup(USBSetup& 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->setup(setup, j);
node = node->next; node = node->next;
} }
return ret; return ret;
@ -85,16 +85,16 @@ int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface)
} }
*interface = lastIf; *interface = lastIf;
lastIf += node->cb->numInterfaces; lastIf += node->numInterfaces;
for ( u8 i = 0; i< node->cb->numEndpoints; i++) { for ( u8 i = 0; i< node->numEndpoints; i++) {
_initEndpoints[lastEp] = node->cb->endpointType[i]; _initEndpoints[lastEp] = node->endpointType[i];
lastEp++; lastEp++;
} }
modules_count++; modules_count++;
return lastEp - node->cb->numEndpoints; return lastEp - node->numEndpoints;
// restart USB layer??? // restart USB layer???
} }
#endif #endif
#endif /* if defined(USBCON) */ #endif /* if defined(USBCON) */

View File

@ -25,21 +25,18 @@
#if defined(USBCON) #if defined(USBCON)
typedef struct __attribute__((packed)) class PUSBListNode {
{ public:
PUSBListNode() { }
bool (*setup)(USBSetup& setup, u8 i); bool (*setup)(USBSetup& setup, u8 i);
int (*getInterface)(u8* interfaceNum); int (*getInterface)(u8* interfaceNum);
int (*getDescriptor)(int8_t t); int (*getDescriptor)(int8_t t);
int8_t numEndpoints; int8_t numEndpoints;
int8_t numInterfaces; int8_t numInterfaces;
uint8_t *endpointType; uint8_t *endpointType;
} PUSBCallbacks;
class PUSBListNode {
public: public:
PUSBListNode *next = NULL; PUSBListNode *next = NULL;
PUSBCallbacks *cb;
PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;}
}; };
int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface); int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface);

View File

@ -133,19 +133,15 @@ bool HID_Setup(USBSetup& setup, uint8_t i)
HID_::HID_(void) HID_::HID_(void)
{ {
static uint8_t endpointType[1]; static uint8_t endpointType[1];
endpointType[0] = EP_TYPE_INTERRUPT_IN; endpointType[0] = EP_TYPE_INTERRUPT_IN;
static PUSBCallbacks cb = { static PUSBListNode node;
.setup = &HID_Setup, node.setup = &HID_Setup,
.getInterface = &HID_GetInterface, node.getInterface = &HID_GetInterface,
.getDescriptor = &HID_GetDescriptor, node.getDescriptor = &HID_GetDescriptor,
.numEndpoints = 1, node.numEndpoints = 1,
.numInterfaces = 1, node.numInterfaces = 1,
.endpointType = endpointType, node.endpointType = endpointType,
};
static PUSBListNode node(&cb);
HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE); HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE);
} }