From 2cc3bb605b85401d6bb963ede181a9b586f10e68 Mon Sep 17 00:00:00 2001 From: Nico Date: Fri, 9 Oct 2015 22:10:45 +0200 Subject: [PATCH 1/4] [PUSB] Minor Style change --- hardware/arduino/avr/cores/arduino/USBCore.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hardware/arduino/avr/cores/arduino/USBCore.h b/hardware/arduino/avr/cores/arduino/USBCore.h index 530abec7222..4e08d711b56 100644 --- a/hardware/arduino/avr/cores/arduino/USBCore.h +++ b/hardware/arduino/avr/cores/arduino/USBCore.h @@ -49,9 +49,9 @@ #define REQUEST_OTHER 0x03 #define REQUEST_RECIPIENT 0x03 -#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_CLASS + REQUEST_INTERFACE) -#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE + REQUEST_CLASS + REQUEST_INTERFACE) -#define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST + REQUEST_STANDARD + REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_CLASS_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_CLASS | REQUEST_INTERFACE) +#define REQUEST_HOSTTODEVICE_CLASS_INTERFACE (REQUEST_HOSTTODEVICE | REQUEST_CLASS | REQUEST_INTERFACE) +#define REQUEST_DEVICETOHOST_STANDARD_INTERFACE (REQUEST_DEVICETOHOST | REQUEST_STANDARD | REQUEST_INTERFACE) // Class requests From 14ddc8b0bf24496788a845c66a0ef87b4a63c4f9 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 10 Oct 2015 12:49:45 +0200 Subject: [PATCH 2/4] Added official HID definitions Since the HID library adds some general HID definitions and structs, it is very useful to also include this in a custom library. If you dupe the information you have problems of redeclaration. Having those defintions inside the official HID library is essential for a good working additional HID API. --- hardware/arduino/avr/libraries/HID/HID.cpp | 2 +- hardware/arduino/avr/libraries/HID/HID.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 972053d05f4..841de4afcdc 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -30,7 +30,7 @@ int HID_::getInterface(uint8_t* interfaceCount) { *interfaceCount += 1; // uses 1 HIDDescriptor hidInterface = { - D_INTERFACE(pluggedInterface, 1, 3, 0, 0), + D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_NONE, HID_PROTOCOL_NONE), D_HIDREPORT(descriptorSize), D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) }; diff --git a/hardware/arduino/avr/libraries/HID/HID.h b/hardware/arduino/avr/libraries/HID/HID.h index b282c20d5aa..77a9f24c555 100644 --- a/hardware/arduino/avr/libraries/HID/HID.h +++ b/hardware/arduino/avr/libraries/HID/HID.h @@ -40,6 +40,20 @@ #define HID_REPORT_DESCRIPTOR_TYPE 0x22 #define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 +// HID subclass HID1.11 Page 8 4.2 Subclass +#define HID_SUBCLASS_NONE 0 +#define HID_SUBCLASS_BOOT_INTERFACE 1 + +// HID Keyboard/Mouse bios compatible protocols HID1.11 Page 9 4.3 Protocols +#define HID_PROTOCOL_NONE 0 +#define HID_PROTOCOL_KEYBOARD 1 +#define HID_PROTOCOL_MOUSE 2 + +// Normal or bios protocol (Keyboard/Mouse) HID1.11 Page 54 7.2.5 Get_Protocol Request +// "protocol" variable is used for this purpose. +#define HID_BOOT_PROTOCOL 0 +#define HID_REPORT_PROTOCOL 1 + typedef struct { uint8_t len; // 9 From 5e813b314bac1bdcaf583a90899bcc0351cfb4f7 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 10 Oct 2015 13:11:31 +0200 Subject: [PATCH 3/4] [PHID] Added some hints for further optional implementations --- hardware/arduino/avr/libraries/HID/HID.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 841de4afcdc..8da7d2c96e2 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -101,6 +101,8 @@ bool HID_::setup(USBSetup& setup) if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE) { if (request == HID_SET_PROTOCOL) { + // The USB Host tells us if we are in boot or report mode. + // This only works with a real boot compatible device. protocol = setup.wValueL; return true; } @@ -110,6 +112,13 @@ bool HID_::setup(USBSetup& setup) } if (request == HID_SET_REPORT) { + //uint8_t reportID = setup.wValueL; + //uint16_t length = setup.wLength; + //uint8_t data[length]; + // Make sure to not read more data than USB_EP_SIZE. + // You can read multiple times through a loop. + // The first byte (may!) contain the reportID on a multreport. + //USB_RecvControl(data, length); } } From e69021550eb4f88c0027d5ec64a39a2512eadc37 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sun, 11 Oct 2015 14:39:36 +0200 Subject: [PATCH 4/4] [PHID] Added missing GET_IDLE Request --- hardware/arduino/avr/libraries/HID/HID.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hardware/arduino/avr/libraries/HID/HID.cpp b/hardware/arduino/avr/libraries/HID/HID.cpp index 8da7d2c96e2..cce3834da07 100644 --- a/hardware/arduino/avr/libraries/HID/HID.cpp +++ b/hardware/arduino/avr/libraries/HID/HID.cpp @@ -96,6 +96,9 @@ bool HID_::setup(USBSetup& setup) // TODO: Send8(protocol); return true; } + if (request == HID_GET_IDLE) { + // TODO: Send8(idle); + } } if (requestType == REQUEST_HOSTTODEVICE_CLASS_INTERFACE)