aboutsummaryrefslogtreecommitdiff
path: root/libraries/HID/HID.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/HID/HID.cpp')
-rw-r--r--libraries/HID/HID.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/libraries/HID/HID.cpp b/libraries/HID/HID.cpp
index 411529e..21ede26 100644
--- a/libraries/HID/HID.cpp
+++ b/libraries/HID/HID.cpp
@@ -54,9 +54,24 @@ int HID_::getDescriptor(USBSetup& setup)
return -1;
total += res;
}
+
+ // Reset the protocol on reenumeration. Normally the host should not assume the state of the protocol
+ // due to the USB specs, but Windows and Linux just assumes its in report mode.
+ protocol = HID_REPORT_PROTOCOL;
+
return total;
}
+uint8_t HID_::getShortName(char *name)
+{
+ name[0] = 'H';
+ name[1] = 'I';
+ name[2] = 'D';
+ name[3] = 'A' + (descriptorSize & 0x0F);
+ name[4] = 'A' + ((descriptorSize >> 4) & 0x0F);
+ return 5;
+}
+
void HID_::AppendDescriptor(HIDSubDescriptor *node)
{
if (!rootNode) {
@@ -71,10 +86,13 @@ void HID_::AppendDescriptor(HIDSubDescriptor *node)
descriptorSize += node->length;
}
-void HID_::SendReport(uint8_t id, const void* data, int len)
+int HID_::SendReport(uint8_t id, const void* data, int len)
{
- USB_Send(pluggedEndpoint, &id, 1);
- USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
+ auto ret = USB_Send(pluggedEndpoint, &id, 1);
+ if (ret < 0) return ret;
+ auto ret2 = USB_Send(pluggedEndpoint | TRANSFER_RELEASE, data, len);
+ if (ret2 < 0) return ret2;
+ return ret + ret2;
}
bool HID_::setup(USBSetup& setup)
@@ -130,7 +148,7 @@ bool HID_::setup(USBSetup& setup)
HID_::HID_(void) : PluggableUSBModule(1, 1, epType),
rootNode(NULL), descriptorSize(0),
- protocol(1), idle(1)
+ protocol(HID_REPORT_PROTOCOL), idle(1)
{
epType[0] = EP_TYPE_INTERRUPT_IN;
PluggableUSB().plug(this);