diff options
Diffstat (limited to 'libraries/HID')
-rw-r--r-- | libraries/HID/HID.cpp | 26 | ||||
-rw-r--r-- | libraries/HID/HID.h | 8 |
2 files changed, 29 insertions, 5 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); diff --git a/libraries/HID/HID.h b/libraries/HID/HID.h index ba08da7..93c4bd5 100644 --- a/libraries/HID/HID.h +++ b/libraries/HID/HID.h @@ -54,6 +54,11 @@ #define HID_BOOT_PROTOCOL 0 #define HID_REPORT_PROTOCOL 1 +// HID Request Type HID1.11 Page 51 7.2.1 Get_Report Request +#define HID_REPORT_TYPE_INPUT 1 +#define HID_REPORT_TYPE_OUTPUT 2 +#define HID_REPORT_TYPE_FEATURE 3 + typedef struct { uint8_t len; // 9 @@ -88,7 +93,7 @@ class HID_ : public PluggableUSBModule public: HID_(void); int begin(void); - void SendReport(uint8_t id, const void* data, int len); + int SendReport(uint8_t id, const void* data, int len); void AppendDescriptor(HIDSubDescriptor* node); protected: @@ -96,6 +101,7 @@ protected: int getInterface(uint8_t* interfaceCount); int getDescriptor(USBSetup& setup); bool setup(USBSetup& setup); + uint8_t getShortName(char* name); private: uint8_t epType[1]; |