aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@arduino.cc>2015-09-29 16:40:27 +0200
committerCristian Maglie <c.maglie@arduino.cc>2015-10-02 11:59:22 +0200
commit7302965552a77c1af000e3870848b3cc35670c51 (patch)
tree90cbf977f606bfe0dc4cdd465a655e83283aa210
parent2aaef8cdad53b645cf8b2a6a0b2194115b970cfa (diff)
[PUSB] PUSBCallback struct has been merged into PUSBListNode
This slightly simplifies PluggableUSB API.
-rw-r--r--cores/arduino/PluggableUSB.cpp16
-rw-r--r--cores/arduino/PluggableUSB.h9
-rw-r--r--libraries/HID/HID.cpp18
3 files changed, 18 insertions, 25 deletions
diff --git a/cores/arduino/PluggableUSB.cpp b/cores/arduino/PluggableUSB.cpp
index 857a27f..9597adc 100644
--- a/cores/arduino/PluggableUSB.cpp
+++ b/cores/arduino/PluggableUSB.cpp
@@ -40,7 +40,7 @@ int PUSB_GetInterface(u8* interfaceNum)
int ret = 0;
PUSBListNode* node = rootNode;
for (u8 i=0; i<modules_count; i++) {
- ret = node->cb->getInterface(interfaceNum);
+ ret = node->getInterface(interfaceNum);
node = node->next;
}
return ret;
@@ -51,7 +51,7 @@ int PUSB_GetDescriptor(int8_t t)
int ret = 0;
PUSBListNode* node = rootNode;
for (u8 i=0; i<modules_count && ret == 0; i++) {
- ret = node->cb->getDescriptor(t);
+ ret = node->getDescriptor(t);
node = node->next;
}
return ret;
@@ -62,7 +62,7 @@ bool PUSB_Setup(USBSetup& setup, u8 j)
bool ret = false;
PUSBListNode* node = rootNode;
for (u8 i=0; i<modules_count && ret == false; i++) {
- ret = node->cb->setup(setup, j);
+ ret = node->setup(setup, j);
node = node->next;
}
return ret;
@@ -85,16 +85,16 @@ int8_t PUSB_AddFunction(PUSBListNode *node, u8* interface)
}
*interface = lastIf;
- lastIf += node->cb->numInterfaces;
- for ( u8 i = 0; i< node->cb->numEndpoints; i++) {
- _initEndpoints[lastEp] = node->cb->endpointType[i];
+ lastIf += node->numInterfaces;
+ for ( u8 i = 0; i< node->numEndpoints; i++) {
+ _initEndpoints[lastEp] = node->endpointType[i];
lastEp++;
}
modules_count++;
- return lastEp - node->cb->numEndpoints;
+ return lastEp - node->numEndpoints;
// restart USB layer???
}
#endif
-#endif /* if defined(USBCON) */ \ No newline at end of file
+#endif /* if defined(USBCON) */
diff --git a/cores/arduino/PluggableUSB.h b/cores/arduino/PluggableUSB.h
index 33108db..9210d7c 100644
--- a/cores/arduino/PluggableUSB.h
+++ b/cores/arduino/PluggableUSB.h
@@ -25,21 +25,18 @@
#if defined(USBCON)
-typedef struct __attribute__((packed))
-{
+class PUSBListNode {
+public:
+ PUSBListNode() { }
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;
-class PUSBListNode {
public:
PUSBListNode *next = NULL;
- PUSBCallbacks *cb;
- PUSBListNode(PUSBCallbacks *ncb) {cb = ncb;}
};
int8_t PUSB_AddFunction(PUSBListNode *node, u8 *interface);
diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp
index 42e0ee5..24e6f5c 100644
--- a/libraries/HID/HID.cpp
+++ b/libraries/HID/HID.cpp
@@ -133,19 +133,15 @@ bool HID_Setup(USBSetup& setup, uint8_t i)
HID_::HID_(void)
{
static uint8_t endpointType[1];
-
endpointType[0] = EP_TYPE_INTERRUPT_IN;
- static PUSBCallbacks cb = {
- .setup = &HID_Setup,
- .getInterface = &HID_GetInterface,
- .getDescriptor = &HID_GetDescriptor,
- .numEndpoints = 1,
- .numInterfaces = 1,
- .endpointType = endpointType,
- };
-
- static PUSBListNode node(&cb);
+ static PUSBListNode node;
+ node.setup = &HID_Setup,
+ node.getInterface = &HID_GetInterface,
+ node.getDescriptor = &HID_GetDescriptor,
+ node.numEndpoints = 1,
+ node.numInterfaces = 1,
+ node.endpointType = endpointType,
HID_ENDPOINT_INT = PUSB_AddFunction(&node, &HID_INTERFACE);
}