From a04525d7181b8041fd0eeeec819d685242d28f0e Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 9 Jun 2021 16:04:50 +0200 Subject: [PATCH 1/5] _internal::LEDModeManager: Do not redefine `new` on STM32 We do not need to redefine `new` on STM32, as it is included in the standard library, and defining it ourselves would lead to linking errors. Signed-off-by: Gergely Nagy --- src/kaleidoscope_internal/LEDModeManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kaleidoscope_internal/LEDModeManager.h b/src/kaleidoscope_internal/LEDModeManager.h index 28ea5f49..835ffca6 100644 --- a/src/kaleidoscope_internal/LEDModeManager.h +++ b/src/kaleidoscope_internal/LEDModeManager.h @@ -23,7 +23,7 @@ #include -#ifdef KALEIDOSCOPE_VIRTUAL_BUILD +#if defined(KALEIDOSCOPE_VIRTUAL_BUILD) || defined(ARDUINO_ARCH_STM32) #include #else From f496aaa5d58d545f1fe4ef935bbc2233fd1fc81e Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 10 Jun 2021 11:47:48 +0200 Subject: [PATCH 2/5] hid: Move mouse::stop from base to the specific implementation Instead of doing the stop in the base class, delegate it to the specific implementation. Do this to avoid depending on the exact shape and layout of the mouse report within the base class. Signed-off-by: Gergely Nagy --- src/kaleidoscope/driver/hid/base/Mouse.h | 13 ++----------- src/kaleidoscope/driver/hid/keyboardio/Mouse.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/kaleidoscope/driver/hid/base/Mouse.h b/src/kaleidoscope/driver/hid/base/Mouse.h index 4ff40d8f..268c2bb6 100644 --- a/src/kaleidoscope/driver/hid/base/Mouse.h +++ b/src/kaleidoscope/driver/hid/base/Mouse.h @@ -30,6 +30,7 @@ class NoMouse { void begin() {} void sendReport() {} void move(int8_t x, int8_t y, int8_t vWheel, int8_t hWheel) {} + void stop(bool x, bool y, bool vWheel, bool hWheel) {} void releaseAll() {} void press(uint8_t buttons) {} void release(uint8_t buttons) {} @@ -63,17 +64,7 @@ class Mouse { mouse_.move(x, y, vWheel, hWheel); } void stop(bool x, bool y, bool vWheel = false, bool hWheel = false) { - HID_MouseReport_Data_t report = mouse_.getReport(); - - if (x) - report.xAxis = 0; - if (y) - report.yAxis = 0; - if (vWheel) - report.vWheel = 0; - if (hWheel) - report.hWheel = 0; - move(report.xAxis, report.yAxis, report.vWheel, report.hWheel); + mouse_.stop(x, y, vWheel, hWheel); } void releaseAllButtons() { mouse_.releaseAll(); diff --git a/src/kaleidoscope/driver/hid/keyboardio/Mouse.h b/src/kaleidoscope/driver/hid/keyboardio/Mouse.h index c9328368..a177b468 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/Mouse.h +++ b/src/kaleidoscope/driver/hid/keyboardio/Mouse.h @@ -50,6 +50,20 @@ class MouseWrapper { void move(int8_t x, int8_t y, int8_t vWheel, int8_t hWheel) { Mouse.move(x, y, vWheel, hWheel); } + void stop(bool x, bool y, bool vWheel = false, bool hWheel = false) { + HID_MouseReport_Data_t report = Mouse.getReport(); + + if (x) + report.xAxis = 0; + if (y) + report.yAxis = 0; + if (vWheel) + report.vWheel = 0; + if (hWheel) + report.hWheel = 0; + move(report.xAxis, report.yAxis, report.vWheel, report.hWheel); + } + void releaseAll() { Mouse.releaseAll(); } From 894ca338de59c4439da4abbf99f2672a4e4c51e5 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 10 Jun 2021 12:29:51 +0200 Subject: [PATCH 3/5] driver::hid: Remove Mouse::getReport() This function is completely unused, and should not have been exposed to begin with. Neither in the base class, nor in specific implementations. The `getReport()` method ties us to a specific report datatype, both in name, and in shape. That's not something we want, we'd rather have the base class be HID-library agnostic, which it can't be with `getReport()` present. Luckily, the function is completely unused, and as such, is safe to remove without deprecation. Signed-off-by: Gergely Nagy --- src/kaleidoscope/driver/hid/base/Mouse.h | 4 ---- src/kaleidoscope/driver/hid/keyboardio/Mouse.h | 3 --- 2 files changed, 7 deletions(-) diff --git a/src/kaleidoscope/driver/hid/base/Mouse.h b/src/kaleidoscope/driver/hid/base/Mouse.h index 268c2bb6..ebd71d3c 100644 --- a/src/kaleidoscope/driver/hid/base/Mouse.h +++ b/src/kaleidoscope/driver/hid/base/Mouse.h @@ -35,10 +35,6 @@ class NoMouse { void press(uint8_t buttons) {} void release(uint8_t buttons) {} void click(uint8_t buttons) {} - HID_MouseReport_Data_t getReport() { - static HID_MouseReport_Data_t report; - return report; - } }; struct MouseProps { diff --git a/src/kaleidoscope/driver/hid/keyboardio/Mouse.h b/src/kaleidoscope/driver/hid/keyboardio/Mouse.h index a177b468..f8773cd5 100644 --- a/src/kaleidoscope/driver/hid/keyboardio/Mouse.h +++ b/src/kaleidoscope/driver/hid/keyboardio/Mouse.h @@ -76,9 +76,6 @@ class MouseWrapper { void click(uint8_t buttons) { Mouse.click(buttons); } - HID_MouseReport_Data_t getReport() { - return Mouse.getReport(); - } }; struct MouseProps: public base::MouseProps { From 80e414ace8afbd1285d554a56c5948e044458d88 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 10 Jun 2021 12:36:49 +0200 Subject: [PATCH 4/5] driver::hid: Allow compiling base::Keyboard without KeyboardioHID If `HID_BOOT_PROTOCOL` is undefined, define it ourselves (the value is set by the USB standard, so we can do that). This allows compiling the base class without KeyboardioHID, letting our HID base driver be completely independent of it. Signed-off-by: Gergely Nagy --- src/kaleidoscope/driver/hid/base/Keyboard.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/kaleidoscope/driver/hid/base/Keyboard.h b/src/kaleidoscope/driver/hid/base/Keyboard.h index 0f44b9f5..8363ea6b 100644 --- a/src/kaleidoscope/driver/hid/base/Keyboard.h +++ b/src/kaleidoscope/driver/hid/base/Keyboard.h @@ -20,6 +20,10 @@ #include "kaleidoscope/key_defs.h" +#ifndef HID_BOOT_PROTOCOL +#define HID_BOOT_PROTOCOL 0 +#endif + namespace kaleidoscope { namespace driver { namespace hid { From 2305f49680afc899975efb531dcc7648c85c7dc3 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Thu, 10 Jun 2021 12:47:45 +0200 Subject: [PATCH 5/5] device::Base: Use the Base HID by default, rather than KeyboardioHID To allow us to use any other HID than KeyboardioHID, the base device _must_ use something else (practically, the Base HID), otherwise we'll get a compile error when building on a platform that KeyboardioHID does not support, even if we do not use KeyboardioHID. We get that error, because the base class references it anyway. As such, lets use the base HID as default, and adjust all users of KeyboardioHID to explicitly set that: Virtual, Dygma Raise, and ATmega32U4Keyboard. Everything else derives from the last one, so they're covered with just the change to ATmega32U4Keyboard. Signed-off-by: Gergely Nagy --- .../src/kaleidoscope/device/dygma/Raise.h | 3 +++ src/kaleidoscope/device/ATmega32U4Keyboard.h | 3 +++ src/kaleidoscope/device/Base.h | 6 +++--- src/kaleidoscope/device/virtual/Virtual.h | 3 +++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/plugins/Kaleidoscope-Hardware-Dygma-Raise/src/kaleidoscope/device/dygma/Raise.h b/plugins/Kaleidoscope-Hardware-Dygma-Raise/src/kaleidoscope/device/dygma/Raise.h index 80f1e5ed..28beb92b 100644 --- a/plugins/Kaleidoscope-Hardware-Dygma-Raise/src/kaleidoscope/device/dygma/Raise.h +++ b/plugins/Kaleidoscope-Hardware-Dygma-Raise/src/kaleidoscope/device/dygma/Raise.h @@ -26,6 +26,7 @@ #define CRGB(r,g,b) (cRGB){b, g, r} #include "kaleidoscope/driver/keyscanner/Base.h" +#include "kaleidoscope/driver/hid/Keyboardio.h" #include "kaleidoscope/driver/led/Base.h" #include "kaleidoscope/driver/bootloader/samd/Bossac.h" #include "kaleidoscope/driver/storage/Flash.h" @@ -156,6 +157,8 @@ struct RaiseStorageProps : public kaleidoscope::driver::storage::FlashProps { struct RaiseSideFlasherProps : public kaleidoscope::util::flasher::BaseProps {}; struct RaiseProps : kaleidoscope::device::BaseProps { + typedef kaleidoscope::driver::hid::KeyboardioProps HIDProps; + typedef kaleidoscope::driver::hid::Keyboardio HID; typedef RaiseLEDDriverProps LEDDriverProps; typedef RaiseLEDDriver LEDDriver; typedef RaiseKeyScannerProps KeyScannerProps; diff --git a/src/kaleidoscope/device/ATmega32U4Keyboard.h b/src/kaleidoscope/device/ATmega32U4Keyboard.h index b9ae02ff..f710c12d 100644 --- a/src/kaleidoscope/device/ATmega32U4Keyboard.h +++ b/src/kaleidoscope/device/ATmega32U4Keyboard.h @@ -23,6 +23,7 @@ #include "kaleidoscope/device/Base.h" #include "kaleidoscope/driver/mcu/ATmega32U4.h" +#include "kaleidoscope/driver/hid/Keyboardio.h" #include "kaleidoscope/driver/keyscanner/ATmega.h" #include "kaleidoscope/driver/storage/ATmega32U4EEPROMProps.h" #include "kaleidoscope/driver/storage/AVREEPROM.h" @@ -31,6 +32,8 @@ namespace kaleidoscope { namespace device { struct ATmega32U4KeyboardProps : kaleidoscope::device::BaseProps { + typedef kaleidoscope::driver::hid::KeyboardioProps HIDProps; + typedef kaleidoscope::driver::hid::Keyboardio HID; typedef kaleidoscope::driver::mcu::ATmega32U4Props MCUProps; typedef kaleidoscope::driver::mcu::ATmega32U4 MCU; typedef kaleidoscope::driver::storage::ATmega32U4EEPROMProps StorageProps; diff --git a/src/kaleidoscope/device/Base.h b/src/kaleidoscope/device/Base.h index 5841d780..826a1cb1 100644 --- a/src/kaleidoscope/device/Base.h +++ b/src/kaleidoscope/device/Base.h @@ -25,7 +25,7 @@ #include "kaleidoscope_internal/deprecations.h" #include "kaleidoscope/macro_helpers.h" -#include "kaleidoscope/driver/hid/Keyboardio.h" +#include "kaleidoscope/driver/hid/Base.h" #include "kaleidoscope/driver/keyscanner/None.h" #include "kaleidoscope/driver/led/None.h" #include "kaleidoscope/driver/mcu/None.h" @@ -53,8 +53,8 @@ namespace kaleidoscope { namespace device { struct BaseProps { - typedef kaleidoscope::driver::hid::KeyboardioProps HIDProps; - typedef kaleidoscope::driver::hid::Keyboardio HID; + typedef kaleidoscope::driver::hid::BaseProps HIDProps; + typedef kaleidoscope::driver::hid::Base HID; typedef kaleidoscope::driver::keyscanner::BaseProps KeyScannerProps; typedef kaleidoscope::driver::keyscanner::None KeyScanner; typedef kaleidoscope::driver::led::BaseProps LEDDriverProps; diff --git a/src/kaleidoscope/device/virtual/Virtual.h b/src/kaleidoscope/device/virtual/Virtual.h index 9bc576fc..a6ea731f 100644 --- a/src/kaleidoscope/device/virtual/Virtual.h +++ b/src/kaleidoscope/device/virtual/Virtual.h @@ -22,6 +22,7 @@ #include KALEIDOSCOPE_HARDWARE_H #include "kaleidoscope/driver/bootloader/None.h" +#include "kaleidoscope/driver/hid/Keyboardio.h" #include "kaleidoscope/driver/led/Base.h" namespace kaleidoscope { @@ -110,6 +111,8 @@ class VirtualLEDDriver // the physical keyboard. // struct VirtualProps : public kaleidoscope::DeviceProps { + typedef kaleidoscope::driver::hid::KeyboardioProps HIDProps; + typedef kaleidoscope::driver::hid::Keyboardio HID; typedef typename kaleidoscope::DeviceProps::KeyScannerProps KeyScannerProps; typedef VirtualKeyScanner