aboutsummaryrefslogtreecommitdiff
path: root/libraries/HID
diff options
context:
space:
mode:
authorNicoHood <NicoHood@users.noreply.github.com>2015-10-07 19:02:40 +0200
committerNicoHood <NicoHood@users.noreply.github.com>2015-10-07 19:02:40 +0200
commitdfe89ddd015f072e279d38354d60e4882c15bdb0 (patch)
treea00dea9638a58afd0d47226d018f29b51cc7218f /libraries/HID
parent4a1921932de509ea64c8521ab610f7bb1160884c (diff)
[PUSB] Made getDescriptor() and setup() more flexible
Alternatively we can only pass the wIndex to getDescriptor but I suggest to just pass the pointer aka reference of the whole setup. In guess (havent tested this) that this results in more or less the code size but its a) idential with the other functions and b) we late have more flexibility here. The Code got a quick SerialKeyboard.ino test
Diffstat (limited to 'libraries/HID')
-rw-r--r--libraries/HID/HID.cpp29
-rw-r--r--libraries/HID/HID.h4
2 files changed, 16 insertions, 17 deletions
diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp
index b6b9cea..500eec9 100644
--- a/libraries/HID/HID.cpp
+++ b/libraries/HID/HID.cpp
@@ -38,22 +38,21 @@ int HID_::getInterface(uint8_t* interfaceCount)
return USB_SendControl(0, &hidInterface, sizeof(hidInterface));
}
-int HID_::getDescriptor(int8_t type)
+int HID_::getDescriptor(USBSetup& setup)
{
- if (HID_REPORT_DESCRIPTOR_TYPE == type) {
- int total = 0;
- HIDDescriptorListNode* node;
- for (node = rootNode; node; node = node->next) {
- int res = USB_SendControl(TRANSFER_PGM, node->data, node->length);
- if (res == -1)
- return -1;
- total += res;
- }
- return total;
+ if (interface() != setup.wIndex) {
+ return 0;
}
- // Ignored
- return 0;
+ int total = 0;
+ HIDDescriptorListNode* node;
+ for (node = rootNode; node; node = node->next) {
+ int res = USB_SendControl(TRANSFER_PGM, node->data, node->length);
+ if (res == -1)
+ return -1;
+ total += res;
+ }
+ return total;
}
void HID_::AppendDescriptor(HIDDescriptorListNode *node)
@@ -76,9 +75,9 @@ void HID_::SendReport(uint8_t id, const void* data, int len)
USB_Send(endpoint() | TRANSFER_RELEASE, data, len);
}
-bool HID_::setup(USBSetup& setup, uint8_t interfaceNum)
+bool HID_::setup(USBSetup& setup)
{
- if (interface() != interfaceNum) {
+ if (interface() != setup.wIndex) {
return false;
}
diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h
index e54e45e..b282c20 100644
--- a/libraries/HID/HID.h
+++ b/libraries/HID/HID.h
@@ -80,8 +80,8 @@ public:
protected:
// Implementation of the PUSBListNode
int getInterface(uint8_t* interfaceCount);
- int getDescriptor(int8_t type);
- bool setup(USBSetup& setup, uint8_t interfaceNum);
+ int getDescriptor(USBSetup& setup);
+ bool setup(USBSetup& setup);
private:
uint8_t epType[1];