From 2e6d4c9e2d2943d33db243d6e417632553ff481e Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 10 Oct 2015 12:58:51 +0200 Subject: [PATCH] Improved Boot Keyboard, added example HID Driver got removed, now relies on the internal IDE definitions. The PR is opened at Github, but will merged hopefully soon. --- examples/BootKeyboard/BootKeyboard.ino | 43 +++++++++++++++++ keywords.txt | 3 ++ src/HID-Project.h | 1 - src/MultiReport/ImprovedKeyboard.h | 2 +- src/SingleReport/BootKeyboard.cpp | 3 +- src/SingleReport/BootKeyboard.h | 1 + src/SingleReport/HID-Driver.h | 65 -------------------------- 7 files changed, 49 insertions(+), 69 deletions(-) create mode 100644 examples/BootKeyboard/BootKeyboard.ino delete mode 100644 src/SingleReport/HID-Driver.h diff --git a/examples/BootKeyboard/BootKeyboard.ino b/examples/BootKeyboard/BootKeyboard.ino new file mode 100644 index 0000000..4283132 --- /dev/null +++ b/examples/BootKeyboard/BootKeyboard.ino @@ -0,0 +1,43 @@ +/* + Copyright (c) 2014-2015 NicoHood + See the readme for credit to other people. + + BootKeyboard example + + Shows that keyboard works even in bios. + Led indicats if we are in bios. + + See HID Project documentation for more information. + https://github.com/NicoHood/HID/wiki/Keyboard-API +*/ + +#include "HID-Project.h" + +const int pinLed = LED_BUILTIN; +const int pinButton = 2; + +void setup() { + pinMode(pinLed, OUTPUT); + pinMode(pinButton, INPUT_PULLUP); + + // Sends a clean report to the host. This is important on any Arduino type. + BootKeyboard.begin(); +} + + +void loop() { + // Light led if keyboard uses the boot protocol (normally while in bios) + // Keep in mind that on a 16u2 and Arduino Micro HIGH and LOW for TX/RX Leds are inverted. + if (BootKeyboard.getProtocol() == HID_BOOT_PROTOCOL) + digitalWrite(pinLed, HIGH); + else + digitalWrite(pinLed, LOW); + + // Trigger caps lock manually via button + if (!digitalRead(pinButton)) { + BootKeyboard.write(KEY_ENTER); + + // Simple debounce + delay(300); + } +} diff --git a/keywords.txt b/keywords.txt index 805d1a4..bf69108 100644 --- a/keywords.txt +++ b/keywords.txt @@ -74,4 +74,7 @@ AbsoluteMouse KEYWORD1 # Constants (LITERAL1) ####################################### +HID_BOOT_PROTOCOL LITERAL1 +HID_REPORT_PROTOCOL LITERAL1 + #TODO add key definitions like KEY_ENTER diff --git a/src/HID-Project.h b/src/HID-Project.h index 53c953d..3a0a51c 100644 --- a/src/HID-Project.h +++ b/src/HID-Project.h @@ -37,7 +37,6 @@ THE SOFTWARE. #error HID Project can only be used with an USB MCU. #endif - // Include all HID libraries (.a linkage required to work) properly //#include "AbsoluteMouse.h" //#include "ImprovedMouse.h" diff --git a/src/MultiReport/ImprovedKeyboard.h b/src/MultiReport/ImprovedKeyboard.h index b6b9ab2..3e024d8 100644 --- a/src/MultiReport/ImprovedKeyboard.h +++ b/src/MultiReport/ImprovedKeyboard.h @@ -26,8 +26,8 @@ THE SOFTWARE. #include #include "PluggableUSB.h" -#include "HID-Settings.h" #include "HID.h" +#include "HID-Settings.h" #include "../HID-APIs/KeyboardAPI.h" diff --git a/src/SingleReport/BootKeyboard.cpp b/src/SingleReport/BootKeyboard.cpp index 96c393f..ee5edf2 100644 --- a/src/SingleReport/BootKeyboard.cpp +++ b/src/SingleReport/BootKeyboard.cpp @@ -22,7 +22,6 @@ THE SOFTWARE. */ #include "BootKeyboard.h" -#include "HID-Driver.h" static const uint8_t _hidReportDescriptorKeyboard[] PROGMEM = { // Keyboard @@ -81,7 +80,7 @@ int BootKeyboard_::getInterface(uint8_t* interfaceCount) { *interfaceCount += 1; // uses 1 HIDDescriptor hidInterface = { - D_INTERFACE(pluggedInterface, 1, 3, 1, 1), // Boot compatible keyboard + D_INTERFACE(pluggedInterface, 1, USB_DEVICE_CLASS_HUMAN_INTERFACE, HID_SUBCLASS_BOOT_INTERFACE, HID_PROTOCOL_KEYBOARD), D_HIDREPORT(sizeof(_hidReportDescriptorKeyboard)), D_ENDPOINT(USB_ENDPOINT_IN(pluggedEndpoint), USB_ENDPOINT_TYPE_INTERRUPT, USB_EP_SIZE, 0x01) }; diff --git a/src/SingleReport/BootKeyboard.h b/src/SingleReport/BootKeyboard.h index fdad4f3..8f2ebdd 100644 --- a/src/SingleReport/BootKeyboard.h +++ b/src/SingleReport/BootKeyboard.h @@ -26,6 +26,7 @@ THE SOFTWARE. #include #include "PluggableUSB.h" +#include "HID.h" #include "HID-Settings.h" #include "../HID-APIs/KeyboardAPI.h" diff --git a/src/SingleReport/HID-Driver.h b/src/SingleReport/HID-Driver.h deleted file mode 100644 index 3c36f27..0000000 --- a/src/SingleReport/HID-Driver.h +++ /dev/null @@ -1,65 +0,0 @@ -/* -Copyright (c) 2014-2015 NicoHood -See the readme for credit to other people. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. -*/ - -// Include guard -#pragma once - -// HID 'Driver' -// ------------ -#define HID_GET_REPORT 0x01 -#define HID_GET_IDLE 0x02 -#define HID_GET_PROTOCOL 0x03 -#define HID_SET_REPORT 0x09 -#define HID_SET_IDLE 0x0A -#define HID_SET_PROTOCOL 0x0B - -#define HID_HID_DESCRIPTOR_TYPE 0x21 -#define HID_REPORT_DESCRIPTOR_TYPE 0x22 -#define HID_PHYSICAL_DESCRIPTOR_TYPE 0x23 - -// Keyboard/Mouse protocols (normal or bios) HID1.11 Page 54 7.2.5 Get_Protocol Request -#define HID_BOOT_PROTOCOL 0 -#define HID_REPORT_PROTOCOL 1 - -typedef struct -{ - uint8_t len; // 9 - uint8_t dtype; // 0x21 - uint8_t addr; - uint8_t versionL; // 0x101 - uint8_t versionH; // 0x101 - uint8_t country; - uint8_t desctype; // 0x22 report - uint8_t descLenL; - uint8_t descLenH; -} HIDDescDescriptor; - -typedef struct -{ - InterfaceDescriptor hid; - HIDDescDescriptor desc; - EndpointDescriptor in; -} HIDDescriptor; - -#define D_HIDREPORT(length) { 9, 0x21, 0x01, 0x01, 0, 1, 0x22, lowByte(length), highByte(length) } -