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.
This commit is contained in:
NicoHood 2015-10-10 12:58:51 +02:00
parent 59bf10efeb
commit 2e6d4c9e2d
7 changed files with 49 additions and 69 deletions

View file

@ -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);
}
}

View file

@ -74,4 +74,7 @@ AbsoluteMouse KEYWORD1
# Constants (LITERAL1)
#######################################
HID_BOOT_PROTOCOL LITERAL1
HID_REPORT_PROTOCOL LITERAL1
#TODO add key definitions like KEY_ENTER

View file

@ -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"

View file

@ -26,8 +26,8 @@ THE SOFTWARE.
#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID-Settings.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/KeyboardAPI.h"

View file

@ -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)
};

View file

@ -26,6 +26,7 @@ THE SOFTWARE.
#include <Arduino.h>
#include "PluggableUSB.h"
#include "HID.h"
#include "HID-Settings.h"
#include "../HID-APIs/KeyboardAPI.h"

View file

@ -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) }