From a683e6eab18c87769b744a4c83120d584ad24bf4 Mon Sep 17 00:00:00 2001 From: NicoHood Date: Sat, 19 Sep 2015 16:46:08 +0200 Subject: [PATCH] Added boot protocol for mouse --- src/HID-Project.h | 14 ++++++++++++++ src/ImprovedMouse.cpp | 9 +++++++++ src/PluggableHID/HID.cpp | 4 +++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/HID-Project.h b/src/HID-Project.h index b3a5562..e5d5b8c 100644 --- a/src/HID-Project.h +++ b/src/HID-Project.h @@ -33,8 +33,13 @@ THE SOFTWARE. #error "This is not an USB AVR or you use an old version of the IDE." #endif +//================================================================================ +// Settings +//================================================================================ + #define HID_KEYBOARD_LEDS_ENABLED #define USE_BOOT_KEYBOARD_PROTOCOL +//#define USE_BOOT_MOUSE_PROTOCOL //#define LAYOUT_US_ENGLISH //#define LAYOUT_CANADIAN_FRENCH @@ -60,6 +65,10 @@ THE SOFTWARE. //#define LAYOUT_UNITED_KINGDOM //#define LAYOUT_US_INTERNATIONAL +//================================================================================ +// Definitions and Helpers +//================================================================================ + // Default US keyboard layout #if !defined(LAYOUT_CANADIAN_FRENCH) && !defined(LAYOUT_CANADIAN_MULTILINGUAL) \ && !defined(LAYOUT_DANISH) && !defined(LAYOUT_FINNISH) && !defined(LAYOUT_FRENCH) \ @@ -107,6 +116,11 @@ THE SOFTWARE. #define HID_REPORTID_TEENSY_KEYBOARD 9 #endif +#if defined(USE_BOOT_KEYBOARD_PROTOCOL) && defined(USE_BOOT_MOUSE_PROTOCOL) +// Technically it is possible but not within this (simpler) API. +#error "You cannot use a boot compatible keyboard and mouse at the same time." +#endif + #include "HID.h" #include "HID-Tables.h" diff --git a/src/ImprovedMouse.cpp b/src/ImprovedMouse.cpp index 483feb1..46740bb 100644 --- a/src/ImprovedMouse.cpp +++ b/src/ImprovedMouse.cpp @@ -91,6 +91,15 @@ void Mouse_::move(signed char x, signed char y, signed char wheel) report.xAxis = x; report.yAxis = y; report.wheel = wheel; +#if defined(USE_BOOT_MOUSE_PROTOCOL) + if(getProtocol() != 1){ + // Do not send the wheel information. + // It should be discarded by the host, + // but to be sure we better leave it out. + SendRawReport(&report, sizeof(report)-1); + } + else +#endif SendReport(&report, sizeof(report)); } diff --git a/src/PluggableHID/HID.cpp b/src/PluggableHID/HID.cpp index 0377414..17fa0b0 100644 --- a/src/PluggableHID/HID.cpp +++ b/src/PluggableHID/HID.cpp @@ -59,6 +59,8 @@ int HID_::HID_GetInterface(u8* interfaceNum) { #if defined(USE_BOOT_KEYBOARD_PROTOCOL) D_INTERFACE(HID_INTERFACE,1,3,1,1), +#elif defined(USE_BOOT_MOUSE_PROTOCOL) + D_INTERFACE(HID_INTERFACE,1,3,1,2), #else D_INTERFACE(HID_INTERFACE,1,3,0,0), #endif @@ -102,7 +104,7 @@ void HID_::SendReport(u8 id, const void* data, int len) { // Only send report ID if it exists if(id){ -#if defined(USE_BOOT_KEYBOARD_PROTOCOL) +#if defined(USE_BOOT_KEYBOARD_PROTOCOL) || defined(USE_BOOT_MOUSE_PROTOCOL) // Do not send a normal report while in Bootloader mode. if(_hid_protocol != 1){ return;