From b233867d9fb1acc72570739c3e5a7c8b59ff12bc Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 5 Nov 2019 12:32:06 +0100 Subject: [PATCH 1/7] Move hardware plugins to kaleidoscope::device Move all the hardware plugins from the `kaleidoscope::hardware` namespace to `kaleidoscope::device`, in perparation for deeper changes to come later. This is merely a restructuring, there are no functional changes. The one breaking change is that `ATMegaKeyboard` moved too, and we do not provide any backward compatibility there. Signed-off-by: Gergely Nagy --- src/Kaleidoscope-Hardware-EZ-ErgoDox.h | 4 ++-- src/Kaleidoscope-Hardware-KBDFans-KBD4x.h | 2 +- src/Kaleidoscope-Hardware-Model01.h | 4 ++-- src/Kaleidoscope-Hardware-OLKB-Planck.h | 4 ++-- ...Kaleidoscope-Hardware-SOFTHRUF-Splitography.h | 4 ++-- src/Kaleidoscope-Hardware-Technomancy-Atreus.h | 4 ++-- src/Kaleidoscope-Hardware-Technomancy-Atreus2.h | 2 +- .../{hardware => device}/ATMegaKeyboard.cpp | 4 ++-- .../{hardware => device}/ATMegaKeyboard.h | 4 ++-- .../{hardware => device}/avr/pins_and_ports.h | 0 .../{hardware => device}/ez/ErgoDox.cpp | 8 ++++---- .../{hardware => device}/ez/ErgoDox.h | 12 ++++++------ .../ez/ErgoDox/ErgoDoxScanner.cpp | 10 +++++----- .../ez/ErgoDox/ErgoDoxScanner.h | 4 ++-- .../ez/ErgoDox/i2cmaster.cpp | 2 +- .../{hardware => device}/ez/ErgoDox/i2cmaster.h | 0 .../{hardware => device}/kbdfans/KBD4x.cpp | 4 ++-- .../{hardware => device}/kbdfans/KBD4x.h | 14 +++++++------- .../{hardware => device}/key_indexes.h | 0 .../{hardware => device}/keyboardio/Model01.cpp | 2 +- .../{hardware => device}/keyboardio/Model01.h | 8 ++++---- .../{hardware => device}/olkb/Planck.cpp | 6 +++--- .../{hardware => device}/olkb/Planck.h | 16 ++++++++-------- .../softhruf/Splitography.cpp | 6 +++--- .../{hardware => device}/softhruf/Splitography.h | 16 ++++++++-------- .../{hardware => device}/technomancy/Atreus.cpp | 6 +++--- .../{hardware => device}/technomancy/Atreus.h | 14 +++++++------- .../{hardware => device}/technomancy/Atreus2.cpp | 4 ++-- .../{hardware => device}/technomancy/Atreus2.h | 12 ++++++------ 29 files changed, 88 insertions(+), 88 deletions(-) rename src/kaleidoscope/{hardware => device}/ATMegaKeyboard.cpp (98%) rename src/kaleidoscope/{hardware => device}/ATMegaKeyboard.h (99%) rename src/kaleidoscope/{hardware => device}/avr/pins_and_ports.h (100%) rename src/kaleidoscope/{hardware => device}/ez/ErgoDox.cpp (96%) rename src/kaleidoscope/{hardware => device}/ez/ErgoDox.h (95%) rename src/kaleidoscope/{hardware => device}/ez/ErgoDox/ErgoDoxScanner.cpp (94%) rename src/kaleidoscope/{hardware => device}/ez/ErgoDox/ErgoDoxScanner.h (95%) rename src/kaleidoscope/{hardware => device}/ez/ErgoDox/i2cmaster.cpp (99%) rename src/kaleidoscope/{hardware => device}/ez/ErgoDox/i2cmaster.h (100%) rename src/kaleidoscope/{hardware => device}/kbdfans/KBD4x.cpp (94%) rename src/kaleidoscope/{hardware => device}/kbdfans/KBD4x.h (86%) rename src/kaleidoscope/{hardware => device}/key_indexes.h (100%) rename src/kaleidoscope/{hardware => device}/keyboardio/Model01.cpp (99%) rename src/kaleidoscope/{hardware => device}/keyboardio/Model01.h (97%) rename src/kaleidoscope/{hardware => device}/olkb/Planck.cpp (87%) rename src/kaleidoscope/{hardware => device}/olkb/Planck.h (84%) rename src/kaleidoscope/{hardware => device}/softhruf/Splitography.cpp (89%) rename src/kaleidoscope/{hardware => device}/softhruf/Splitography.h (89%) rename src/kaleidoscope/{hardware => device}/technomancy/Atreus.cpp (92%) rename src/kaleidoscope/{hardware => device}/technomancy/Atreus.h (92%) rename src/kaleidoscope/{hardware => device}/technomancy/Atreus2.cpp (91%) rename src/kaleidoscope/{hardware => device}/technomancy/Atreus2.h (91%) diff --git a/src/Kaleidoscope-Hardware-EZ-ErgoDox.h b/src/Kaleidoscope-Hardware-EZ-ErgoDox.h index d769aba9..b6e180be 100644 --- a/src/Kaleidoscope-Hardware-EZ-ErgoDox.h +++ b/src/Kaleidoscope-Hardware-EZ-ErgoDox.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-EZ-ErgoDox -- ErgoDox hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,4 +17,4 @@ */ #pragma once -#include "kaleidoscope/hardware/ez/ErgoDox.h" +#include "kaleidoscope/device/ez/ErgoDox.h" diff --git a/src/Kaleidoscope-Hardware-KBDFans-KBD4x.h b/src/Kaleidoscope-Hardware-KBDFans-KBD4x.h index 4490cf97..2fbc0fce 100644 --- a/src/Kaleidoscope-Hardware-KBDFans-KBD4x.h +++ b/src/Kaleidoscope-Hardware-KBDFans-KBD4x.h @@ -20,4 +20,4 @@ #define KALEIDOSCOPE_WITH_ATMEGA_KEYBOARD 1 -#include "kaleidoscope/hardware/kbdfans/KBD4x.h" +#include "kaleidoscope/device/kbdfans/KBD4x.h" diff --git a/src/Kaleidoscope-Hardware-Model01.h b/src/Kaleidoscope-Hardware-Model01.h index b2ef4ff6..d7849de6 100644 --- a/src/Kaleidoscope-Hardware-Model01.h +++ b/src/Kaleidoscope-Hardware-Model01.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-Model01 -- Keyboard.io Model01 hardware support for Kaleidoscope - * Copyright (C) 2017-2018 Keyboard.io, Inc + * Copyright (C) 2017-2019 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -17,4 +17,4 @@ #pragma once -#include "kaleidoscope/hardware/keyboardio/Model01.h" +#include "kaleidoscope/device/keyboardio/Model01.h" diff --git a/src/Kaleidoscope-Hardware-OLKB-Planck.h b/src/Kaleidoscope-Hardware-OLKB-Planck.h index cfbd49af..f18a1811 100644 --- a/src/Kaleidoscope-Hardware-OLKB-Planck.h +++ b/src/Kaleidoscope-Hardware-OLKB-Planck.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-OLKB-Planck -- OLKB Planck hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,4 +19,4 @@ #pragma once #define KALEIDOSCOPE_WITH_ATMEGA_KEYBOARD 1 -#include "kaleidoscope/hardware/olkb/Planck.h" +#include "kaleidoscope/device/olkb/Planck.h" diff --git a/src/Kaleidoscope-Hardware-SOFTHRUF-Splitography.h b/src/Kaleidoscope-Hardware-SOFTHRUF-Splitography.h index e6f1447b..cd02b5f9 100644 --- a/src/Kaleidoscope-Hardware-SOFTHRUF-Splitography.h +++ b/src/Kaleidoscope-Hardware-SOFTHRUF-Splitography.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-SOFTHRUF-Splitography -- Splitography hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,4 +19,4 @@ #pragma once #define KALEIDOSCOPE_WITH_ATMEGA_KEYBOARD 1 -#include "kaleidoscope/hardware/softhruf/Splitography.h" +#include "kaleidoscope/device/softhruf/Splitography.h" diff --git a/src/Kaleidoscope-Hardware-Technomancy-Atreus.h b/src/Kaleidoscope-Hardware-Technomancy-Atreus.h index cf6f010e..c4958a7d 100644 --- a/src/Kaleidoscope-Hardware-Technomancy-Atreus.h +++ b/src/Kaleidoscope-Hardware-Technomancy-Atreus.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-Technomancy-Atreus -- Atreus hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,4 +26,4 @@ #define KALEIDOSCOPE_HARDWARE_ATREUS_PINOUT_ASTAR 1 #endif -#include "kaleidoscope/hardware/technomancy/Atreus.h" +#include "kaleidoscope/device/technomancy/Atreus.h" diff --git a/src/Kaleidoscope-Hardware-Technomancy-Atreus2.h b/src/Kaleidoscope-Hardware-Technomancy-Atreus2.h index a9c29eb1..b6b67b67 100644 --- a/src/Kaleidoscope-Hardware-Technomancy-Atreus2.h +++ b/src/Kaleidoscope-Hardware-Technomancy-Atreus2.h @@ -20,4 +20,4 @@ #define KALEIDOSCOPE_WITH_ATMEGA_KEYBOARD 1 -#include "kaleidoscope/hardware/technomancy/Atreus2.h" +#include "kaleidoscope/device/technomancy/Atreus2.h" diff --git a/src/kaleidoscope/hardware/ATMegaKeyboard.cpp b/src/kaleidoscope/device/ATMegaKeyboard.cpp similarity index 98% rename from src/kaleidoscope/hardware/ATMegaKeyboard.cpp rename to src/kaleidoscope/device/ATMegaKeyboard.cpp index c6aac7d5..5a552a5e 100644 --- a/src/kaleidoscope/hardware/ATMegaKeyboard.cpp +++ b/src/kaleidoscope/device/ATMegaKeyboard.cpp @@ -19,10 +19,10 @@ #if KALEIDOSCOPE_WITH_ATMEGA_KEYBOARD -#include "kaleidoscope/hardware/ATMegaKeyboard.h" +#include "kaleidoscope/device/ATMegaKeyboard.h" namespace kaleidoscope { -namespace hardware { +namespace device { uint8_t ATMegaKeyboard::debounce = 3; diff --git a/src/kaleidoscope/hardware/ATMegaKeyboard.h b/src/kaleidoscope/device/ATMegaKeyboard.h similarity index 99% rename from src/kaleidoscope/hardware/ATMegaKeyboard.h rename to src/kaleidoscope/device/ATMegaKeyboard.h index 5637dce4..938af929 100644 --- a/src/kaleidoscope/hardware/ATMegaKeyboard.h +++ b/src/kaleidoscope/device/ATMegaKeyboard.h @@ -25,7 +25,7 @@ #include "kaleidoscope/MatrixAddr.h" #include "kaleidoscope/macro_helpers.h" -#include "kaleidoscope/hardware/avr/pins_and_ports.h" +#include "kaleidoscope/device/avr/pins_and_ports.h" #include @@ -134,7 +134,7 @@ struct cRGB { } namespace kaleidoscope { -namespace hardware { +namespace device { class ATMegaKeyboard : public kaleidoscope::Hardware { public: ATMegaKeyboard(void) {} diff --git a/src/kaleidoscope/hardware/avr/pins_and_ports.h b/src/kaleidoscope/device/avr/pins_and_ports.h similarity index 100% rename from src/kaleidoscope/hardware/avr/pins_and_ports.h rename to src/kaleidoscope/device/avr/pins_and_ports.h diff --git a/src/kaleidoscope/hardware/ez/ErgoDox.cpp b/src/kaleidoscope/device/ez/ErgoDox.cpp similarity index 96% rename from src/kaleidoscope/hardware/ez/ErgoDox.cpp rename to src/kaleidoscope/device/ez/ErgoDox.cpp index 77852f36..db3fc80b 100644 --- a/src/kaleidoscope/hardware/ez/ErgoDox.cpp +++ b/src/kaleidoscope/device/ez/ErgoDox.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-EZ-ErgoDox -- ErgoDox hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * Based on QMK (commit 8cdb4a915) * (C) Jack Humbert, Erez Zukerman, Oleg Kostyuk @@ -29,10 +29,10 @@ #include #include #include -#include "kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.h" +#include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h" namespace kaleidoscope { -namespace hardware { +namespace device { namespace ez { ErgoDoxScanner ErgoDox::scanner_; @@ -264,6 +264,6 @@ uint8_t ErgoDox::pressedKeyswitchCount() { } HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::hardware::ez::ErgoDox &ErgoDox = KeyboardHardware; +kaleidoscope::device::ez::ErgoDox &ErgoDox = KeyboardHardware; #endif diff --git a/src/kaleidoscope/hardware/ez/ErgoDox.h b/src/kaleidoscope/device/ez/ErgoDox.h similarity index 95% rename from src/kaleidoscope/hardware/ez/ErgoDox.h rename to src/kaleidoscope/device/ez/ErgoDox.h index 5e315d18..e6ebf3e5 100644 --- a/src/kaleidoscope/hardware/ez/ErgoDox.h +++ b/src/kaleidoscope/device/ez/ErgoDox.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-EZ-ErgoDox -- ErgoDox hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * Based on QMK (commit 8cdb4a915) * (C) Jack Humbert, Erez Zukerman, Oleg Kostyuk @@ -29,9 +29,9 @@ #include -#include "kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.h" +#include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h" -#define HARDWARE_IMPLEMENTATION kaleidoscope::hardware::ez::ErgoDox +#define HARDWARE_IMPLEMENTATION kaleidoscope::device::ez::ErgoDox #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" @@ -46,7 +46,7 @@ struct cRGB { #include "kaleidoscope/MatrixAddr.h" namespace kaleidoscope { -namespace hardware { +namespace device { namespace ez { class ErgoDox : public kaleidoscope::Hardware { @@ -156,8 +156,8 @@ class ErgoDox : public kaleidoscope::Hardware { } } -#include "kaleidoscope/hardware/key_indexes.h" +#include "kaleidoscope/device/key_indexes.h" -extern kaleidoscope::hardware::ez::ErgoDox &ErgoDox; +extern kaleidoscope::device::ez::ErgoDox &ErgoDox; #endif diff --git a/src/kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.cpp b/src/kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.cpp similarity index 94% rename from src/kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.cpp rename to src/kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.cpp index e7fcb9e3..660171c5 100644 --- a/src/kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.cpp +++ b/src/kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-EZ-ErgoDox -- ErgoDox hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * Based on QMK (commit 8cdb4a915) * (C) Jack Humbert, Erez Zukerman, Oleg Kostyuk @@ -25,10 +25,10 @@ #ifdef ARDUINO_AVR_ERGODOX -#include "kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.h" +#include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h" #include -#include "kaleidoscope/hardware/avr/pins_and_ports.h" -#include "kaleidoscope/hardware/ez/ErgoDox/i2cmaster.h" +#include "kaleidoscope/device/avr/pins_and_ports.h" +#include "kaleidoscope/device/ez/ErgoDox/i2cmaster.h" #define I2C_ADDR 0b0100000 #define I2C_ADDR_WRITE ( (I2C_ADDR<<1) | I2C_WRITE ) @@ -43,7 +43,7 @@ #define OLATB 0x15 namespace kaleidoscope { -namespace hardware { +namespace device { namespace ez { uint8_t ErgoDoxScanner::initExpander() { diff --git a/src/kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.h b/src/kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h similarity index 95% rename from src/kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.h rename to src/kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h index b5249655..77e74285 100644 --- a/src/kaleidoscope/hardware/ez/ErgoDox/ErgoDoxScanner.h +++ b/src/kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-EZ-ErgoDox -- ErgoDox hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * Based on QMK (commit 8cdb4a915) * (C) Jack Humbert, Erez Zukerman, Oleg Kostyuk @@ -30,7 +30,7 @@ #include namespace kaleidoscope { -namespace hardware { +namespace device { namespace ez { class ErgoDoxScanner { diff --git a/src/kaleidoscope/hardware/ez/ErgoDox/i2cmaster.cpp b/src/kaleidoscope/device/ez/ErgoDox/i2cmaster.cpp similarity index 99% rename from src/kaleidoscope/hardware/ez/ErgoDox/i2cmaster.cpp rename to src/kaleidoscope/device/ez/ErgoDox/i2cmaster.cpp index 37ae1714..71400b84 100644 --- a/src/kaleidoscope/hardware/ez/ErgoDox/i2cmaster.cpp +++ b/src/kaleidoscope/device/ez/ErgoDox/i2cmaster.cpp @@ -12,7 +12,7 @@ #include #include -#include "kaleidoscope/hardware/ez/ErgoDox/i2cmaster.h" +#include "kaleidoscope/device/ez/ErgoDox/i2cmaster.h" /* define CPU frequency in Mhz here if not defined in Makefile */ diff --git a/src/kaleidoscope/hardware/ez/ErgoDox/i2cmaster.h b/src/kaleidoscope/device/ez/ErgoDox/i2cmaster.h similarity index 100% rename from src/kaleidoscope/hardware/ez/ErgoDox/i2cmaster.h rename to src/kaleidoscope/device/ez/ErgoDox/i2cmaster.h diff --git a/src/kaleidoscope/hardware/kbdfans/KBD4x.cpp b/src/kaleidoscope/device/kbdfans/KBD4x.cpp similarity index 94% rename from src/kaleidoscope/hardware/kbdfans/KBD4x.cpp rename to src/kaleidoscope/device/kbdfans/KBD4x.cpp index c6bf0507..5f776849 100644 --- a/src/kaleidoscope/hardware/kbdfans/KBD4x.cpp +++ b/src/kaleidoscope/device/kbdfans/KBD4x.cpp @@ -23,7 +23,7 @@ namespace kaleidoscope { -namespace hardware { +namespace device { namespace kbdfans { ATMEGA_KEYBOARD_DATA(KBD4x); @@ -57,6 +57,6 @@ void KBD4x::resetDevice() { } HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::hardware::kbdfans::KBD4x &KBD4x = KeyboardHardware; +kaleidoscope::device::kbdfans::KBD4x &KBD4x = KeyboardHardware; #endif diff --git a/src/kaleidoscope/hardware/kbdfans/KBD4x.h b/src/kaleidoscope/device/kbdfans/KBD4x.h similarity index 86% rename from src/kaleidoscope/hardware/kbdfans/KBD4x.h rename to src/kaleidoscope/device/kbdfans/KBD4x.h index cd5dda9d..722e13a7 100644 --- a/src/kaleidoscope/hardware/kbdfans/KBD4x.h +++ b/src/kaleidoscope/device/kbdfans/KBD4x.h @@ -20,18 +20,18 @@ #ifdef ARDUINO_AVR_KBD4X #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::hardware::kbdfans::KBD4x +#define HARDWARE_IMPLEMENTATION kaleidoscope::device::kbdfans::KBD4x #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" -#include "kaleidoscope/hardware/avr/pins_and_ports.h" +#include "kaleidoscope/device/avr/pins_and_ports.h" -#include "kaleidoscope/hardware/ATMegaKeyboard.h" +#include "kaleidoscope/device/ATMegaKeyboard.h" namespace kaleidoscope { -namespace hardware { +namespace device { namespace kbdfans { -class KBD4x: public kaleidoscope::hardware::ATMegaKeyboard { +class KBD4x: public kaleidoscope::device::ATMegaKeyboard { public: KBD4x(void) { mcu_.disableJTAG(); @@ -67,8 +67,8 @@ class KBD4x: public kaleidoscope::hardware::ATMegaKeyboard { } } -#include "kaleidoscope/hardware/key_indexes.h" +#include "kaleidoscope/device/key_indexes.h" -extern kaleidoscope::hardware::kbdfans::KBD4x &KBD4x; +extern kaleidoscope::device::kbdfans::KBD4x &KBD4x; #endif diff --git a/src/kaleidoscope/hardware/key_indexes.h b/src/kaleidoscope/device/key_indexes.h similarity index 100% rename from src/kaleidoscope/hardware/key_indexes.h rename to src/kaleidoscope/device/key_indexes.h diff --git a/src/kaleidoscope/hardware/keyboardio/Model01.cpp b/src/kaleidoscope/device/keyboardio/Model01.cpp similarity index 99% rename from src/kaleidoscope/hardware/keyboardio/Model01.cpp rename to src/kaleidoscope/device/keyboardio/Model01.cpp index 23ef0c00..917ec434 100644 --- a/src/kaleidoscope/hardware/keyboardio/Model01.cpp +++ b/src/kaleidoscope/device/keyboardio/Model01.cpp @@ -23,7 +23,7 @@ #include namespace kaleidoscope { -namespace hardware { +namespace device { namespace keyboardio { KeyboardioScanner Model01::leftHand(0); diff --git a/src/kaleidoscope/hardware/keyboardio/Model01.h b/src/kaleidoscope/device/keyboardio/Model01.h similarity index 97% rename from src/kaleidoscope/hardware/keyboardio/Model01.h rename to src/kaleidoscope/device/keyboardio/Model01.h index 6ffeb7a2..47654935 100644 --- a/src/kaleidoscope/hardware/keyboardio/Model01.h +++ b/src/kaleidoscope/device/keyboardio/Model01.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-Model01 -- Keyboard.io Model01 hardware support for Kaleidoscope - * Copyright (C) 2017-2018 Keyboard.io, Inc + * Copyright (C) 2017-2019 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software @@ -21,7 +21,7 @@ #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::hardware::keyboardio::Model01 +#define HARDWARE_IMPLEMENTATION kaleidoscope::device::keyboardio::Model01 #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "KeyboardioScanner.h" @@ -33,7 +33,7 @@ #include "kaleidoscope/MatrixAddr.h" namespace kaleidoscope { -namespace hardware { +namespace device { namespace keyboardio { class Model01 : public kaleidoscope::Hardware { @@ -125,7 +125,7 @@ class Model01 : public kaleidoscope::Hardware { } } -#include "kaleidoscope/hardware/key_indexes.h" +#include "kaleidoscope/device/key_indexes.h" #define PER_KEY_DATA_STACKED(dflt, \ r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \ diff --git a/src/kaleidoscope/hardware/olkb/Planck.cpp b/src/kaleidoscope/device/olkb/Planck.cpp similarity index 87% rename from src/kaleidoscope/hardware/olkb/Planck.cpp rename to src/kaleidoscope/device/olkb/Planck.cpp index 5597171f..697643fb 100644 --- a/src/kaleidoscope/hardware/olkb/Planck.cpp +++ b/src/kaleidoscope/device/olkb/Planck.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-OLKB-Planck -- Planck hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify * it under the terms of version 3 of the GNU General Public License as @@ -21,7 +21,7 @@ #include namespace kaleidoscope { -namespace hardware { +namespace device { namespace olkb { ATMEGA_KEYBOARD_DATA(Planck); @@ -32,6 +32,6 @@ constexpr int8_t Planck::led_count; } HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::hardware::olkb::Planck &Planck = KeyboardHardware; +kaleidoscope::device::olkb::Planck &Planck = KeyboardHardware; #endif diff --git a/src/kaleidoscope/hardware/olkb/Planck.h b/src/kaleidoscope/device/olkb/Planck.h similarity index 84% rename from src/kaleidoscope/hardware/olkb/Planck.h rename to src/kaleidoscope/device/olkb/Planck.h index 680527d6..ea9693fe 100644 --- a/src/kaleidoscope/hardware/olkb/Planck.h +++ b/src/kaleidoscope/device/olkb/Planck.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-OLKB-Planck -- Planck hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * This program is free software: you can redistribute it and/or modify * it under the terms of version 3 of the GNU General Public License as @@ -20,18 +20,18 @@ #ifdef ARDUINO_AVR_PLANCK #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::hardware::olkb::Planck +#define HARDWARE_IMPLEMENTATION kaleidoscope::device::olkb::Planck #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" -#include "kaleidoscope/hardware/avr/pins_and_ports.h" +#include "kaleidoscope/device/avr/pins_and_ports.h" -#include "kaleidoscope/hardware/ATMegaKeyboard.h" +#include "kaleidoscope/device/ATMegaKeyboard.h" namespace kaleidoscope { -namespace hardware { +namespace device { namespace olkb { -class Planck: public kaleidoscope::hardware::ATMegaKeyboard { +class Planck: public kaleidoscope::device::ATMegaKeyboard { public: Planck(void) {} @@ -63,8 +63,8 @@ class Planck: public kaleidoscope::hardware::ATMegaKeyboard { } } -#include "kaleidoscope/hardware/key_indexes.h" +#include "kaleidoscope/device/key_indexes.h" -extern kaleidoscope::hardware::olkb::Planck &Planck; +extern kaleidoscope::device::olkb::Planck &Planck; #endif diff --git a/src/kaleidoscope/hardware/softhruf/Splitography.cpp b/src/kaleidoscope/device/softhruf/Splitography.cpp similarity index 89% rename from src/kaleidoscope/hardware/softhruf/Splitography.cpp rename to src/kaleidoscope/device/softhruf/Splitography.cpp index d646551e..74adcf17 100644 --- a/src/kaleidoscope/hardware/softhruf/Splitography.cpp +++ b/src/kaleidoscope/device/softhruf/Splitography.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-SOFTHRUF-Splitography -- Splitography hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * Based on QMK (commit e9a67f8fd) and sdothum's fork (commit 8616b44) * (C) Jack Humbert, Jun Wako, Steven Hum, and others @@ -28,7 +28,7 @@ #include namespace kaleidoscope { -namespace hardware { +namespace device { namespace softhruf { ATMEGA_KEYBOARD_DATA(Splitography); @@ -39,6 +39,6 @@ constexpr int8_t Splitography::led_count; } HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::hardware::softhruf::Splitography &Splitography = KeyboardHardware; +kaleidoscope::device::softhruf::Splitography &Splitography = KeyboardHardware; #endif diff --git a/src/kaleidoscope/hardware/softhruf/Splitography.h b/src/kaleidoscope/device/softhruf/Splitography.h similarity index 89% rename from src/kaleidoscope/hardware/softhruf/Splitography.h rename to src/kaleidoscope/device/softhruf/Splitography.h index 0ab8f2cd..02bd05e0 100644 --- a/src/kaleidoscope/hardware/softhruf/Splitography.h +++ b/src/kaleidoscope/device/softhruf/Splitography.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-SOFTHRUF-Splitography -- Splitography hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * Based on QMK (commit e9a67f8fd) and sdothum's fork (commit 8616b44) * (C) Jack Humbert, Jun Wako, Steven Hum, and others @@ -27,18 +27,18 @@ #ifdef ARDUINO_AVR_SPLITOGRAPHY #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::hardware::softhruf::Splitography +#define HARDWARE_IMPLEMENTATION kaleidoscope::device::softhruf::Splitography #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" -#include "kaleidoscope/hardware/avr/pins_and_ports.h" +#include "kaleidoscope/device/avr/pins_and_ports.h" -#include "kaleidoscope/hardware/ATMegaKeyboard.h" +#include "kaleidoscope/device/ATMegaKeyboard.h" namespace kaleidoscope { -namespace hardware { +namespace device { namespace softhruf { -class Splitography: public kaleidoscope::hardware::ATMegaKeyboard { +class Splitography: public kaleidoscope::device::ATMegaKeyboard { public: Splitography(void) { mcu_.disableJTAG(); @@ -88,8 +88,8 @@ class Splitography: public kaleidoscope::hardware::ATMegaKeyboard { } } -#include "kaleidoscope/hardware/key_indexes.h" +#include "kaleidoscope/device/key_indexes.h" -extern kaleidoscope::hardware::softhruf::Splitography &Splitography; +extern kaleidoscope::device::softhruf::Splitography &Splitography; #endif diff --git a/src/kaleidoscope/hardware/technomancy/Atreus.cpp b/src/kaleidoscope/device/technomancy/Atreus.cpp similarity index 92% rename from src/kaleidoscope/hardware/technomancy/Atreus.cpp rename to src/kaleidoscope/device/technomancy/Atreus.cpp index 61a7c375..41195cfe 100644 --- a/src/kaleidoscope/hardware/technomancy/Atreus.cpp +++ b/src/kaleidoscope/device/technomancy/Atreus.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-Technomancy-Atreus -- Atreus hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * Based on QMK (commit e9a67f8fd) * (C) Jack Humbert, Phil Hagelberg, and others @@ -30,7 +30,7 @@ #include namespace kaleidoscope { -namespace hardware { +namespace device { namespace technomancy { ATMEGA_KEYBOARD_DATA(Atreus); @@ -77,6 +77,6 @@ void Atreus::resetDevice() { } HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::hardware::technomancy::Atreus &Atreus = KeyboardHardware; +kaleidoscope::device::technomancy::Atreus &Atreus = KeyboardHardware; #endif diff --git a/src/kaleidoscope/hardware/technomancy/Atreus.h b/src/kaleidoscope/device/technomancy/Atreus.h similarity index 92% rename from src/kaleidoscope/hardware/technomancy/Atreus.h rename to src/kaleidoscope/device/technomancy/Atreus.h index 46900f68..7b3be9ec 100644 --- a/src/kaleidoscope/hardware/technomancy/Atreus.h +++ b/src/kaleidoscope/device/technomancy/Atreus.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-Hardware-Technomancy-Atreus -- Atreus hardware support for Kaleidoscope - * Copyright (C) 2018 Keyboard.io, Inc + * Copyright (C) 2018, 2019 Keyboard.io, Inc * * Based on QMK (commit e9a67f8fd) * (C) Jack Humbert, Jun Wako, Phil Hagelberg, and others @@ -27,17 +27,17 @@ #ifdef ARDUINO_AVR_ATREUS #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::hardware::technomancy::Atreus +#define HARDWARE_IMPLEMENTATION kaleidoscope::device::technomancy::Atreus #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" -#include "kaleidoscope/hardware/ATMegaKeyboard.h" +#include "kaleidoscope/device/ATMegaKeyboard.h" namespace kaleidoscope { -namespace hardware { +namespace device { namespace technomancy { -class Atreus: public kaleidoscope::hardware::ATMegaKeyboard { +class Atreus: public kaleidoscope::device::ATMegaKeyboard { friend class ATMegaKeyboard; public: Atreus(void) {} @@ -105,8 +105,8 @@ class Atreus: public kaleidoscope::hardware::ATMegaKeyboard { } } -#include "kaleidoscope/hardware/key_indexes.h" +#include "kaleidoscope/device/key_indexes.h" -extern kaleidoscope::hardware::technomancy::Atreus &Atreus; +extern kaleidoscope::device::technomancy::Atreus &Atreus; #endif diff --git a/src/kaleidoscope/hardware/technomancy/Atreus2.cpp b/src/kaleidoscope/device/technomancy/Atreus2.cpp similarity index 91% rename from src/kaleidoscope/hardware/technomancy/Atreus2.cpp rename to src/kaleidoscope/device/technomancy/Atreus2.cpp index f7da0cf1..8198fe86 100644 --- a/src/kaleidoscope/hardware/technomancy/Atreus2.cpp +++ b/src/kaleidoscope/device/technomancy/Atreus2.cpp @@ -22,7 +22,7 @@ #include namespace kaleidoscope { -namespace hardware { +namespace device { namespace technomancy { ATMEGA_KEYBOARD_DATA(Atreus2); @@ -33,6 +33,6 @@ constexpr int8_t Atreus2::led_count; } HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::hardware::technomancy::Atreus2 &Atreus2 = KeyboardHardware; +kaleidoscope::device::technomancy::Atreus2 &Atreus2 = KeyboardHardware; #endif diff --git a/src/kaleidoscope/hardware/technomancy/Atreus2.h b/src/kaleidoscope/device/technomancy/Atreus2.h similarity index 91% rename from src/kaleidoscope/hardware/technomancy/Atreus2.h rename to src/kaleidoscope/device/technomancy/Atreus2.h index a61f6930..8c23fc37 100644 --- a/src/kaleidoscope/hardware/technomancy/Atreus2.h +++ b/src/kaleidoscope/device/technomancy/Atreus2.h @@ -21,17 +21,17 @@ #ifdef ARDUINO_AVR_ATREUS2 #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::hardware::technomancy::Atreus2 +#define HARDWARE_IMPLEMENTATION kaleidoscope::device::technomancy::Atreus2 #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" -#include "kaleidoscope/hardware/ATMegaKeyboard.h" +#include "kaleidoscope/device/ATMegaKeyboard.h" namespace kaleidoscope { -namespace hardware { +namespace device { namespace technomancy { -class Atreus2: public kaleidoscope::hardware::ATMegaKeyboard { +class Atreus2: public kaleidoscope::device::ATMegaKeyboard { friend class ATMegaKeyboard; public: Atreus2(void) {} @@ -82,8 +82,8 @@ class Atreus2: public kaleidoscope::hardware::ATMegaKeyboard { } } -#include "kaleidoscope/hardware/key_indexes.h" +#include "kaleidoscope/device/key_indexes.h" -extern kaleidoscope::hardware::technomancy::Atreus2 &Atreus2; +extern kaleidoscope::device::technomancy::Atreus2 &Atreus2; #endif From 838e93b0f752a123168f123641cb1069119c970e Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 5 Nov 2019 12:37:08 +0100 Subject: [PATCH 2/7] Simplify how key indexes are declared Instead of having to include `device/key_indexes.h` from every single hardware plugin, include it from `Kaleidoscope.h` instead. This also allows us to get rid of the redundant `KeyAddr` typedef, by including `kaleidoscope/KeyAddr.h` from `key_indexes.h` instead. Signed-off-by: Gergely Nagy --- src/kaleidoscope/Kaleidoscope.h | 1 + src/kaleidoscope/device/ez/ErgoDox.h | 2 -- src/kaleidoscope/device/kbdfans/KBD4x.h | 2 -- src/kaleidoscope/device/key_indexes.h | 2 +- src/kaleidoscope/device/keyboardio/Model01.h | 2 -- src/kaleidoscope/device/olkb/Planck.h | 2 -- src/kaleidoscope/device/softhruf/Splitography.h | 2 -- src/kaleidoscope/device/technomancy/Atreus.h | 2 -- src/kaleidoscope/device/technomancy/Atreus2.h | 2 -- 9 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/kaleidoscope/Kaleidoscope.h b/src/kaleidoscope/Kaleidoscope.h index a43eb4fe..f383f158 100644 --- a/src/kaleidoscope/Kaleidoscope.h +++ b/src/kaleidoscope/Kaleidoscope.h @@ -37,6 +37,7 @@ void setup(); #include #include KALEIDOSCOPE_HARDWARE_H +#include "kaleidoscope/device/key_indexes.h" extern HARDWARE_IMPLEMENTATION KeyboardHardware; diff --git a/src/kaleidoscope/device/ez/ErgoDox.h b/src/kaleidoscope/device/ez/ErgoDox.h index e6ebf3e5..7994cee3 100644 --- a/src/kaleidoscope/device/ez/ErgoDox.h +++ b/src/kaleidoscope/device/ez/ErgoDox.h @@ -156,8 +156,6 @@ class ErgoDox : public kaleidoscope::Hardware { } } -#include "kaleidoscope/device/key_indexes.h" - extern kaleidoscope::device::ez::ErgoDox &ErgoDox; #endif diff --git a/src/kaleidoscope/device/kbdfans/KBD4x.h b/src/kaleidoscope/device/kbdfans/KBD4x.h index 722e13a7..569d1107 100644 --- a/src/kaleidoscope/device/kbdfans/KBD4x.h +++ b/src/kaleidoscope/device/kbdfans/KBD4x.h @@ -67,8 +67,6 @@ class KBD4x: public kaleidoscope::device::ATMegaKeyboard { } } -#include "kaleidoscope/device/key_indexes.h" - extern kaleidoscope::device::kbdfans::KBD4x &KBD4x; #endif diff --git a/src/kaleidoscope/device/key_indexes.h b/src/kaleidoscope/device/key_indexes.h index e000c44c..d13f2d32 100644 --- a/src/kaleidoscope/device/key_indexes.h +++ b/src/kaleidoscope/device/key_indexes.h @@ -17,7 +17,7 @@ #pragma once -typedef HARDWARE_IMPLEMENTATION::KeyAddr KeyAddr; +#include "kaleidoscope/KeyAddr.h" /* To be used by the hardware implementations, `keyIndex` tells us the index of * a key, from which we can figure out the row and column as needed. The index diff --git a/src/kaleidoscope/device/keyboardio/Model01.h b/src/kaleidoscope/device/keyboardio/Model01.h index 47654935..d55ed79b 100644 --- a/src/kaleidoscope/device/keyboardio/Model01.h +++ b/src/kaleidoscope/device/keyboardio/Model01.h @@ -125,8 +125,6 @@ class Model01 : public kaleidoscope::Hardware { } } -#include "kaleidoscope/device/key_indexes.h" - #define PER_KEY_DATA_STACKED(dflt, \ r0c0, r0c1, r0c2, r0c3, r0c4, r0c5, r0c6, \ r1c0, r1c1, r1c2, r1c3, r1c4, r1c5, r1c6, \ diff --git a/src/kaleidoscope/device/olkb/Planck.h b/src/kaleidoscope/device/olkb/Planck.h index ea9693fe..4a051de8 100644 --- a/src/kaleidoscope/device/olkb/Planck.h +++ b/src/kaleidoscope/device/olkb/Planck.h @@ -63,8 +63,6 @@ class Planck: public kaleidoscope::device::ATMegaKeyboard { } } -#include "kaleidoscope/device/key_indexes.h" - extern kaleidoscope::device::olkb::Planck &Planck; #endif diff --git a/src/kaleidoscope/device/softhruf/Splitography.h b/src/kaleidoscope/device/softhruf/Splitography.h index 02bd05e0..d31de004 100644 --- a/src/kaleidoscope/device/softhruf/Splitography.h +++ b/src/kaleidoscope/device/softhruf/Splitography.h @@ -88,8 +88,6 @@ class Splitography: public kaleidoscope::device::ATMegaKeyboard { } } -#include "kaleidoscope/device/key_indexes.h" - extern kaleidoscope::device::softhruf::Splitography &Splitography; #endif diff --git a/src/kaleidoscope/device/technomancy/Atreus.h b/src/kaleidoscope/device/technomancy/Atreus.h index 7b3be9ec..b97f5f4b 100644 --- a/src/kaleidoscope/device/technomancy/Atreus.h +++ b/src/kaleidoscope/device/technomancy/Atreus.h @@ -105,8 +105,6 @@ class Atreus: public kaleidoscope::device::ATMegaKeyboard { } } -#include "kaleidoscope/device/key_indexes.h" - extern kaleidoscope::device::technomancy::Atreus &Atreus; #endif diff --git a/src/kaleidoscope/device/technomancy/Atreus2.h b/src/kaleidoscope/device/technomancy/Atreus2.h index 8c23fc37..d3fbc072 100644 --- a/src/kaleidoscope/device/technomancy/Atreus2.h +++ b/src/kaleidoscope/device/technomancy/Atreus2.h @@ -82,8 +82,6 @@ class Atreus2: public kaleidoscope::device::ATMegaKeyboard { } } -#include "kaleidoscope/device/key_indexes.h" - extern kaleidoscope::device::technomancy::Atreus2 &Atreus2; #endif From 129d37ef0406a6ca8e792292eea1a598ececed27 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 5 Nov 2019 12:46:42 +0100 Subject: [PATCH 3/7] Deprecate named hardware objects Some boards used to provide the device object under an alias named after the device itself. For the sake of consistency, we do not want to provide these aliases in the future. As such, deprecate them, and update all users to use `KeyboardHardware` instead. Signed-off-by: Gergely Nagy --- examples/Devices/KBDFans/KBD4x/KBD4x.ino | 2 +- examples/Devices/Technomancy/Atreus/Atreus.ino | 2 +- src/kaleidoscope/device/ez/ErgoDox.h | 2 +- src/kaleidoscope/device/kbdfans/KBD4x.h | 2 +- src/kaleidoscope/device/olkb/Planck.h | 2 +- src/kaleidoscope/device/softhruf/Splitography.h | 2 +- src/kaleidoscope/device/technomancy/Atreus.h | 2 +- src/kaleidoscope/device/technomancy/Atreus2.h | 2 +- src/kaleidoscope_internal/deprecations.h | 4 ++++ 9 files changed, 12 insertions(+), 8 deletions(-) diff --git a/examples/Devices/KBDFans/KBD4x/KBD4x.ino b/examples/Devices/KBDFans/KBD4x/KBD4x.ino index b0b24974..820adbf5 100644 --- a/examples/Devices/KBDFans/KBD4x/KBD4x.ino +++ b/examples/Devices/KBDFans/KBD4x/KBD4x.ino @@ -78,7 +78,7 @@ KALEIDOSCOPE_INIT_PLUGINS(Macros); const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { switch (macroIndex) { case RESET: - KBD4x.resetDevice(); + KeyboardHardware.resetDevice(); break; default: break; diff --git a/examples/Devices/Technomancy/Atreus/Atreus.ino b/examples/Devices/Technomancy/Atreus/Atreus.ino index 373f09ac..c6380c6b 100644 --- a/examples/Devices/Technomancy/Atreus/Atreus.ino +++ b/examples/Devices/Technomancy/Atreus/Atreus.ino @@ -83,7 +83,7 @@ KALEIDOSCOPE_INIT_PLUGINS(Macros); const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { switch (macroIndex) { case RESET: - Atreus.resetDevice(); + KeyboardHardware.resetDevice(); break; default: break; diff --git a/src/kaleidoscope/device/ez/ErgoDox.h b/src/kaleidoscope/device/ez/ErgoDox.h index 7994cee3..cc431aef 100644 --- a/src/kaleidoscope/device/ez/ErgoDox.h +++ b/src/kaleidoscope/device/ez/ErgoDox.h @@ -156,6 +156,6 @@ class ErgoDox : public kaleidoscope::Hardware { } } -extern kaleidoscope::device::ez::ErgoDox &ErgoDox; +extern kaleidoscope::device::ez::ErgoDox DEPRECATED(NAMED_HARDWARE) &ErgoDox; #endif diff --git a/src/kaleidoscope/device/kbdfans/KBD4x.h b/src/kaleidoscope/device/kbdfans/KBD4x.h index 569d1107..08b34f12 100644 --- a/src/kaleidoscope/device/kbdfans/KBD4x.h +++ b/src/kaleidoscope/device/kbdfans/KBD4x.h @@ -67,6 +67,6 @@ class KBD4x: public kaleidoscope::device::ATMegaKeyboard { } } -extern kaleidoscope::device::kbdfans::KBD4x &KBD4x; +extern kaleidoscope::device::kbdfans::KBD4x DEPRECATED(NAMED_HARDWARE) &KBD4x; #endif diff --git a/src/kaleidoscope/device/olkb/Planck.h b/src/kaleidoscope/device/olkb/Planck.h index 4a051de8..6393bf7f 100644 --- a/src/kaleidoscope/device/olkb/Planck.h +++ b/src/kaleidoscope/device/olkb/Planck.h @@ -63,6 +63,6 @@ class Planck: public kaleidoscope::device::ATMegaKeyboard { } } -extern kaleidoscope::device::olkb::Planck &Planck; +extern kaleidoscope::device::olkb::Planck DEPRECATED(NAMED_HARDWARE) &Planck; #endif diff --git a/src/kaleidoscope/device/softhruf/Splitography.h b/src/kaleidoscope/device/softhruf/Splitography.h index d31de004..9c67d080 100644 --- a/src/kaleidoscope/device/softhruf/Splitography.h +++ b/src/kaleidoscope/device/softhruf/Splitography.h @@ -88,6 +88,6 @@ class Splitography: public kaleidoscope::device::ATMegaKeyboard { } } -extern kaleidoscope::device::softhruf::Splitography &Splitography; +extern kaleidoscope::device::softhruf::Splitography DEPRECATED(NAMED_HARDWARE) &Splitography; #endif diff --git a/src/kaleidoscope/device/technomancy/Atreus.h b/src/kaleidoscope/device/technomancy/Atreus.h index b97f5f4b..535883b1 100644 --- a/src/kaleidoscope/device/technomancy/Atreus.h +++ b/src/kaleidoscope/device/technomancy/Atreus.h @@ -105,6 +105,6 @@ class Atreus: public kaleidoscope::device::ATMegaKeyboard { } } -extern kaleidoscope::device::technomancy::Atreus &Atreus; +extern kaleidoscope::device::technomancy::Atreus DEPRECATED(NAMED_HARDWARE) &Atreus; #endif diff --git a/src/kaleidoscope/device/technomancy/Atreus2.h b/src/kaleidoscope/device/technomancy/Atreus2.h index d3fbc072..e707a6e3 100644 --- a/src/kaleidoscope/device/technomancy/Atreus2.h +++ b/src/kaleidoscope/device/technomancy/Atreus2.h @@ -82,6 +82,6 @@ class Atreus2: public kaleidoscope::device::ATMegaKeyboard { } } -extern kaleidoscope::device::technomancy::Atreus2 &Atreus2; +extern kaleidoscope::device::technomancy::Atreus2 DEPRECATED(NAMED_HARDWARE) &Atreus2; #endif diff --git a/src/kaleidoscope_internal/deprecations.h b/src/kaleidoscope_internal/deprecations.h index 8e53baae..852e92c7 100644 --- a/src/kaleidoscope_internal/deprecations.h +++ b/src/kaleidoscope_internal/deprecations.h @@ -26,3 +26,7 @@ "------------------------------------------------------------------------\n" \ /* Messages */ + +#define _DEPRECATED_MESSAGE_NAMED_HARDWARE __NL__ \ + "Named hardware objects are deprecated, please use `KeyboardHardware`\n" __NL__ \ + "instead." From 0c8f998b9f8186d823578f2ac49a2ef4d6cd33fd Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 6 Nov 2019 00:24:02 +0100 Subject: [PATCH 4/7] Redesign how the hardware objects are defined Instead of having to define `HARDWARE_IMPLEMENTATION` to the class name of the device, and define `KeyboardHardware` from within the plugin, let all devices set `kaleidoscope::Device` to their own class via a typedef. Furthermore, instead of `KeyboardHardware`, use `Kaleidoscope.device()` instead. This makes device plugins a little bit simpler, and our naming more consistent. Because some parts of the firmware need to access the device object before the `Kaleidoscope` object is available, we can't make it a member of that. For this reason, the device object is `kaleidoscope_internal::device`, and `Kaleidoscope.device()` wraps it. In general, the wrapper should be used. But if access to the device is required before `Kaleidoscope` is available, then that's also available. The `Kaleidoscope` object grew a few more wrappers: `storage()` and `serialPort()`, so that one doesn't need to use `Kaleidoscope.device()` directly, but can use the wrappers, which are noticably shorter to write. Signed-off-by: Gergely Nagy --- doc/plugin/CycleTimeReport.md | 2 +- doc/plugin/EEPROM-Settings.md | 2 +- doc/plugin/Leader.md | 6 +- doc/plugin/Syster.md | 6 +- examples/Devices/KBDFans/KBD4x/KBD4x.ino | 2 +- .../Devices/Keyboardio/Model01/Model01.ino | 2 +- examples/Devices/OLKB/Planck/Planck.ino | 4 +- .../SOFTHRUF/Splitography/Splitography.ino | 2 +- .../Devices/Technomancy/Atreus/Atreus.ino | 2 +- .../CycleTimeReport/CycleTimeReport.ino | 2 +- .../EEPROM-Keymap-Programmer.ino | 2 +- .../EEPROM-Settings/EEPROM-Settings.ino | 10 ++-- examples/Features/HostOS/HostOS.ino | 6 +- examples/Features/Steno/Steno.ino | 2 +- examples/Keystrokes/Leader/Leader.ino | 4 +- examples/Keystrokes/Syster/Syster.ino | 4 +- src/kaleidoscope/Hardware.h | 2 +- src/kaleidoscope/Kaleidoscope.cpp | 6 +- src/kaleidoscope/Kaleidoscope.h | 34 ++++++++--- src/kaleidoscope/KeyAddr.h | 4 +- src/kaleidoscope/device/ATMegaKeyboard.cpp | 60 +++++++++---------- src/kaleidoscope/device/ATMegaKeyboard.h | 2 +- src/kaleidoscope/device/ez/ErgoDox.cpp | 27 ++++----- src/kaleidoscope/device/ez/ErgoDox.h | 4 +- src/kaleidoscope/device/kbdfans/KBD4x.cpp | 3 +- src/kaleidoscope/device/kbdfans/KBD4x.h | 5 +- src/kaleidoscope/device/key_indexes.h | 11 ++-- .../device/keyboardio/Model01.cpp | 4 +- src/kaleidoscope/device/keyboardio/Model01.h | 4 +- src/kaleidoscope/device/olkb/Planck.cpp | 3 +- src/kaleidoscope/device/olkb/Planck.h | 5 +- .../device/softhruf/Splitography.cpp | 3 +- .../device/softhruf/Splitography.h | 4 +- .../device/technomancy/Atreus.cpp | 3 +- src/kaleidoscope/device/technomancy/Atreus.h | 4 +- .../device/technomancy/Atreus2.cpp | 3 +- src/kaleidoscope/device/technomancy/Atreus2.h | 4 +- src/kaleidoscope/key_events.cpp | 4 +- src/kaleidoscope/keymaps.h | 4 +- src/kaleidoscope/layers.cpp | 8 +-- src/kaleidoscope/layers.h | 7 ++- src/kaleidoscope/plugin/DynamicMacros.cpp | 32 +++++----- .../plugin/EEPROM-Keymap-Programmer.cpp | 4 +- src/kaleidoscope/plugin/EEPROM-Keymap.cpp | 14 ++--- src/kaleidoscope/plugin/EEPROM-Settings.cpp | 16 ++--- src/kaleidoscope/plugin/Escape-OneShot.cpp | 2 +- src/kaleidoscope/plugin/FingerPainter.cpp | 8 +-- src/kaleidoscope/plugin/FocusSerial.cpp | 22 +++---- src/kaleidoscope/plugin/FocusSerial.h | 24 ++++---- src/kaleidoscope/plugin/GeminiPR.cpp | 2 +- src/kaleidoscope/plugin/HardwareTestMode.cpp | 26 ++++---- src/kaleidoscope/plugin/Heatmap.h | 2 +- src/kaleidoscope/plugin/HostOS.cpp | 4 +- .../plugin/LED-AlphaSquare/Effect.cpp | 4 +- src/kaleidoscope/plugin/LED-Palette-Theme.cpp | 26 ++++---- src/kaleidoscope/plugin/LED-Stalker.h | 2 +- src/kaleidoscope/plugin/LED-Wavepool.cpp | 2 +- src/kaleidoscope/plugin/LED-Wavepool.h | 2 +- src/kaleidoscope/plugin/LEDControl.cpp | 12 ++-- src/kaleidoscope/plugin/LEDEffect-Chase.cpp | 12 ++-- src/kaleidoscope/plugin/MagicCombo.cpp | 4 +- src/kaleidoscope/plugin/Model01-TestMode.cpp | 44 +++++++------- src/kaleidoscope/plugin/TapDance.cpp | 6 +- src/kaleidoscope/plugin/TypingBreaks.cpp | 10 ++-- src/kaleidoscope_internal/device.cpp | 21 +++++++ src/kaleidoscope_internal/device.h | 21 +++++++ 66 files changed, 329 insertions(+), 269 deletions(-) create mode 100644 src/kaleidoscope_internal/device.cpp create mode 100644 src/kaleidoscope_internal/device.h diff --git a/doc/plugin/CycleTimeReport.md b/doc/plugin/CycleTimeReport.md index 8578318f..e696bae1 100644 --- a/doc/plugin/CycleTimeReport.md +++ b/doc/plugin/CycleTimeReport.md @@ -17,7 +17,7 @@ the box, without any further configuration: KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport); void setup (void) { - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); Kaleidoscope.setup (); } ``` diff --git a/doc/plugin/EEPROM-Settings.md b/doc/plugin/EEPROM-Settings.md index 1969c30b..fd7ac222 100644 --- a/doc/plugin/EEPROM-Settings.md +++ b/doc/plugin/EEPROM-Settings.md @@ -43,7 +43,7 @@ void setup () { return; } - KeyboardHardware.storage().get(settingsBase, testSettings); + Kaleidoscope.storage().get(settingsBase, testSettings); } ``` diff --git a/doc/plugin/Leader.md b/doc/plugin/Leader.md index d6335795..83ae196e 100644 --- a/doc/plugin/Leader.md +++ b/doc/plugin/Leader.md @@ -32,11 +32,11 @@ dictionary: #include static void leaderA(uint8_t seq_index) { - KeyboardHardware.serialPort().println("leaderA"); + Kaleidoscope.serialPort().println("leaderA"); } static void leaderTX(uint8_t seq_index) { - KeyboardHardware.serialPort().println("leaderTX"); + Kaleidoscope.serialPort().println("leaderTX"); } static const kaleidoscope::Leader::dictionary_t leader_dictionary[] PROGMEM = @@ -46,7 +46,7 @@ static const kaleidoscope::Leader::dictionary_t leader_dictionary[] PROGMEM = KALEIDOSCOPE_INIT_PLUGINS(Leader); void setup() { - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); Kaleidoscope.setup(); diff --git a/doc/plugin/Syster.md b/doc/plugin/Syster.md index 52910d9b..4255226a 100644 --- a/doc/plugin/Syster.md +++ b/doc/plugin/Syster.md @@ -34,8 +34,8 @@ void systerAction(kaleidoscope::plugin::Syster::action_t action, const char *sym kaleidoscope::hid::sendKeyboardReport (); break; case kaleidoscope::plugin::Syster::SymbolAction: - KeyboardHardware.serialPort().print ("systerAction: symbol="); - KeyboardHardware.serialPort().println (symbol); + Kaleidoscope.serialPort().print ("systerAction: symbol="); + Kaleidoscope.serialPort().println (symbol); if (strcmp (symbol, "coffee") == 0) { Unicode.type (0x2615); } @@ -46,7 +46,7 @@ void systerAction(kaleidoscope::plugin::Syster::action_t action, const char *sym KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, HostOS, Unicode, Syster); void setup() { - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); Kaleidoscope.setup (); } ``` diff --git a/examples/Devices/KBDFans/KBD4x/KBD4x.ino b/examples/Devices/KBDFans/KBD4x/KBD4x.ino index 820adbf5..bb7d433d 100644 --- a/examples/Devices/KBDFans/KBD4x/KBD4x.ino +++ b/examples/Devices/KBDFans/KBD4x/KBD4x.ino @@ -78,7 +78,7 @@ KALEIDOSCOPE_INIT_PLUGINS(Macros); const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { switch (macroIndex) { case RESET: - KeyboardHardware.resetDevice(); + Kaleidoscope.device().resetDevice(); break; default: break; diff --git a/examples/Devices/Keyboardio/Model01/Model01.ino b/examples/Devices/Keyboardio/Model01/Model01.ino index 26d4d50b..775261c1 100644 --- a/examples/Devices/Keyboardio/Model01/Model01.ino +++ b/examples/Devices/Keyboardio/Model01/Model01.ino @@ -86,7 +86,7 @@ static kaleidoscope::plugin::LEDSolidColor solidViolet(70, 0, 60); const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { if (macroIndex == 1 && keyToggledOn(keyState)) { - KeyboardHardware.serialPort().print("Keyboard.IO keyboard driver v0.00"); + Kaleidoscope.serialPort().print("Keyboard.IO keyboard driver v0.00"); return MACRO(I(25), D(LeftShift), T(M), U(LeftShift), T(O), T(D), T(E), T(L), T(Spacebar), diff --git a/examples/Devices/OLKB/Planck/Planck.ino b/examples/Devices/OLKB/Planck/Planck.ino index 8d936504..6fd163de 100644 --- a/examples/Devices/OLKB/Planck/Planck.ino +++ b/examples/Devices/OLKB/Planck/Planck.ino @@ -31,7 +31,7 @@ enum { _QWERTY, /* *INDENT-OFF* */ -KEYMAPS( +KEYMAPS( /* Qwerty * ,-----------------------------------------------------------------------------------. @@ -167,7 +167,7 @@ KALEIDOSCOPE_INIT_PLUGINS(Macros); void setup() { Kaleidoscope.setup(); - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); } void loop() { diff --git a/examples/Devices/SOFTHRUF/Splitography/Splitography.ino b/examples/Devices/SOFTHRUF/Splitography/Splitography.ino index 005cadf1..d0a83bd7 100644 --- a/examples/Devices/SOFTHRUF/Splitography/Splitography.ino +++ b/examples/Devices/SOFTHRUF/Splitography/Splitography.ino @@ -50,7 +50,7 @@ KEYMAPS( KALEIDOSCOPE_INIT_PLUGINS(GeminiPR); void setup() { - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); Kaleidoscope.setup(); } diff --git a/examples/Devices/Technomancy/Atreus/Atreus.ino b/examples/Devices/Technomancy/Atreus/Atreus.ino index c6380c6b..72fda7f8 100644 --- a/examples/Devices/Technomancy/Atreus/Atreus.ino +++ b/examples/Devices/Technomancy/Atreus/Atreus.ino @@ -83,7 +83,7 @@ KALEIDOSCOPE_INIT_PLUGINS(Macros); const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { switch (macroIndex) { case RESET: - KeyboardHardware.resetDevice(); + Kaleidoscope.device().resetDevice(); break; default: break; diff --git a/examples/Features/CycleTimeReport/CycleTimeReport.ino b/examples/Features/CycleTimeReport/CycleTimeReport.ino index 99025e32..4248e90d 100644 --- a/examples/Features/CycleTimeReport/CycleTimeReport.ino +++ b/examples/Features/CycleTimeReport/CycleTimeReport.ino @@ -43,7 +43,7 @@ KEYMAPS( KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport); void setup() { - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); Kaleidoscope.setup(); } diff --git a/examples/Features/EEPROM/EEPROM-Keymap-Programmer/EEPROM-Keymap-Programmer.ino b/examples/Features/EEPROM/EEPROM-Keymap-Programmer/EEPROM-Keymap-Programmer.ino index 83eb0524..10345d12 100644 --- a/examples/Features/EEPROM/EEPROM-Keymap-Programmer/EEPROM-Keymap-Programmer.ino +++ b/examples/Features/EEPROM/EEPROM-Keymap-Programmer/EEPROM-Keymap-Programmer.ino @@ -56,7 +56,7 @@ KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, Macros); void setup() { - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); Kaleidoscope.setup(); diff --git a/examples/Features/EEPROM/EEPROM-Settings/EEPROM-Settings.ino b/examples/Features/EEPROM/EEPROM-Settings/EEPROM-Settings.ino index 3f3f1fb5..93d3eccd 100644 --- a/examples/Features/EEPROM/EEPROM-Settings/EEPROM-Settings.ino +++ b/examples/Features/EEPROM/EEPROM-Settings/EEPROM-Settings.ino @@ -42,16 +42,16 @@ KEYMAPS( KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings); void setup() { - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); Kaleidoscope.setup(); - while (!KeyboardHardware.serialPort()) { + while (!Kaleidoscope.serialPort()) { } - KeyboardHardware.serialPort().println(EEPROMSettings.isValid() ? F("valid EEPROM settings") : F("invalid EEPROM settings")); - KeyboardHardware.serialPort().println(EEPROMSettings.crc(), HEX); - KeyboardHardware.serialPort().println(EEPROMSettings.version()); + Kaleidoscope.serialPort().println(EEPROMSettings.isValid() ? F("valid EEPROM settings") : F("invalid EEPROM settings")); + Kaleidoscope.serialPort().println(EEPROMSettings.crc(), HEX); + Kaleidoscope.serialPort().println(EEPROMSettings.version()); } void loop() { diff --git a/examples/Features/HostOS/HostOS.ino b/examples/Features/HostOS/HostOS.ino index 1e25fa6f..575b2c6b 100644 --- a/examples/Features/HostOS/HostOS.ino +++ b/examples/Features/HostOS/HostOS.ino @@ -43,12 +43,12 @@ KEYMAPS( KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, HostOS); void setup() { - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); Kaleidoscope.setup(); - KeyboardHardware.serialPort().print("Host OS id is: "); - KeyboardHardware.serialPort().println(HostOS.os(), DEC); + Kaleidoscope.serialPort().print("Host OS id is: "); + Kaleidoscope.serialPort().println(HostOS.os(), DEC); } void loop() { diff --git a/examples/Features/Steno/Steno.ino b/examples/Features/Steno/Steno.ino index da416c46..91f4e709 100644 --- a/examples/Features/Steno/Steno.ino +++ b/examples/Features/Steno/Steno.ino @@ -61,7 +61,7 @@ KEYMAPS( KALEIDOSCOPE_INIT_PLUGINS(GeminiPR); void setup() { - KeyboardHardware.serialPort().begin(9600); + Kaleidoscope.serialPort().begin(9600); Kaleidoscope.setup(); } diff --git a/examples/Keystrokes/Leader/Leader.ino b/examples/Keystrokes/Leader/Leader.ino index a4ecbe3d..90d4b72a 100644 --- a/examples/Keystrokes/Leader/Leader.ino +++ b/examples/Keystrokes/Leader/Leader.ino @@ -40,11 +40,11 @@ KEYMAPS( // *INDENT-ON* static void leaderTestA(uint8_t seq_index) { - KeyboardHardware.serialPort().println(F("leaderTestA")); + Kaleidoscope.serialPort().println(F("leaderTestA")); } static void leaderTestAA(uint8_t seq_index) { - KeyboardHardware.serialPort().println(F("leaderTestAA")); + Kaleidoscope.serialPort().println(F("leaderTestAA")); } static const kaleidoscope::plugin::Leader::dictionary_t leader_dictionary[] PROGMEM = diff --git a/examples/Keystrokes/Syster/Syster.ino b/examples/Keystrokes/Syster/Syster.ino index 35695d16..75748bec 100644 --- a/examples/Keystrokes/Syster/Syster.ino +++ b/examples/Keystrokes/Syster/Syster.ino @@ -56,8 +56,8 @@ void systerAction(kaleidoscope::plugin::Syster::action_t action, const char *sym kaleidoscope::hid::sendKeyboardReport(); break; case kaleidoscope::plugin::Syster::SymbolAction: - KeyboardHardware.serialPort().print("systerAction: symbol="); - KeyboardHardware.serialPort().println(symbol); + Kaleidoscope.serialPort().print("systerAction: symbol="); + Kaleidoscope.serialPort().println(symbol); if (strcmp(symbol, "coffee") == 0) { Unicode.type(0x2615); } diff --git a/src/kaleidoscope/Hardware.h b/src/kaleidoscope/Hardware.h index 21c9a148..6fcbdee0 100644 --- a/src/kaleidoscope/Hardware.h +++ b/src/kaleidoscope/Hardware.h @@ -246,7 +246,7 @@ class Hardware { * * Because different hardware has different ways to accomplish this, the * hardware plugin must provide these functions. Kaleidoscope will wrap them, - * so user code does not have to deal with KeyboardHardware. + * so user code does not have to deal with `Kaleidoscope.device()`. * @{ */ /** diff --git a/src/kaleidoscope/Kaleidoscope.cpp b/src/kaleidoscope/Kaleidoscope.cpp index 7d980283..02a7aaaf 100644 --- a/src/kaleidoscope/Kaleidoscope.cpp +++ b/src/kaleidoscope/Kaleidoscope.cpp @@ -34,11 +34,11 @@ Kaleidoscope_::setup(void) { // // TODO(anyone): Figure out a way we can get rid of this, and fix the bug // properly. - KeyboardHardware.serialPort().begin(9600); + device().serialPort().begin(9600); kaleidoscope::Hooks::onSetup(); - KeyboardHardware.setup(); + device().setup(); kaleidoscope::hid::initializeKeyboard(); kaleidoscope::hid::initializeConsumerControl(); @@ -57,7 +57,7 @@ Kaleidoscope_::loop(void) { kaleidoscope::Hooks::beforeEachCycle(); - KeyboardHardware.scanMatrix(); + device().scanMatrix(); kaleidoscope::Hooks::beforeReportingState(); diff --git a/src/kaleidoscope/Kaleidoscope.h b/src/kaleidoscope/Kaleidoscope.h index f383f158..87fae103 100644 --- a/src/kaleidoscope/Kaleidoscope.h +++ b/src/kaleidoscope/Kaleidoscope.h @@ -38,8 +38,9 @@ void setup(); #include KALEIDOSCOPE_HARDWARE_H #include "kaleidoscope/device/key_indexes.h" +#include "kaleidoscope_internal/device.h" -extern HARDWARE_IMPLEMENTATION KeyboardHardware; +static constexpr kaleidoscope::Device &KeyboardHardware = kaleidoscope_internal::device; #ifdef PER_KEY_DATA_STACKED #define KEYMAP_STACKED(...) { PER_KEY_DATA_STACKED(XXX, __VA_ARGS__) } @@ -49,9 +50,9 @@ extern HARDWARE_IMPLEMENTATION KeyboardHardware; #define KEYMAP(...) { PER_KEY_DATA(XXX, __VA_ARGS__) } #endif -#define ROWS (KeyboardHardware.matrix_rows) -#define COLS (KeyboardHardware.matrix_columns) -#define LED_COUNT (KeyboardHardware.led_count) +static constexpr uint8_t ROWS = kaleidoscope_internal::device.matrix_rows; +static constexpr uint8_t COLS = kaleidoscope_internal::device.matrix_columns; +static constexpr uint8_t LED_COUNT = kaleidoscope_internal::device.led_count; #include "kaleidoscope/KeyAddr.h" #include "kaleidoscope/key_events.h" @@ -108,13 +109,17 @@ class Kaleidoscope_ { void setup(void); void loop(void); - static constexpr bool has_leds = (KeyboardHardware.led_count > 0); + static constexpr kaleidoscope::Device &device() { + return kaleidoscope_internal::device; + } + + static constexpr bool has_leds = (kaleidoscope_internal::device.led_count > 0); /** Detaching from / attaching to the host. * * These two functions wrap the hardware plugin's similarly named functions. * We wrap them, because we'd like plugins and user-code not having to use - * `KeyboardHardware` directly. + * `Kaleidoscope.device()` directly. * * The methods themselves implement detaching from / attaching to the host, * without rebooting the device, and remaining powered in between. @@ -123,10 +128,23 @@ class Kaleidoscope_ { * detach and attach. */ void detachFromHost() { - KeyboardHardware.detachFromHost(); + device().detachFromHost(); } void attachToHost() { - KeyboardHardware.attachToHost(); + device().attachToHost(); + } + + /** Wrapper functions for some device features. + * + * The next three functions wrap methods of the device plugin, to make using + * them in user sketches easier, and require less typing. + */ + auto serialPort() -> decltype(device().serialPort()) & { + return device().serialPort(); + } + + auto storage() -> decltype(device().storage()) & { + return device().storage(); } /** Returns the timer as it was at the start of the cycle. diff --git a/src/kaleidoscope/KeyAddr.h b/src/kaleidoscope/KeyAddr.h index 2ac66d73..3762b0b5 100644 --- a/src/kaleidoscope/KeyAddr.h +++ b/src/kaleidoscope/KeyAddr.h @@ -18,6 +18,4 @@ #include KALEIDOSCOPE_HARDWARE_H -extern HARDWARE_IMPLEMENTATION KeyboardHardware; - -typedef HARDWARE_IMPLEMENTATION::KeyAddr KeyAddr; +typedef kaleidoscope::Device::KeyAddr KeyAddr; diff --git a/src/kaleidoscope/device/ATMegaKeyboard.cpp b/src/kaleidoscope/device/ATMegaKeyboard.cpp index 5a552a5e..655a5f6a 100644 --- a/src/kaleidoscope/device/ATMegaKeyboard.cpp +++ b/src/kaleidoscope/device/ATMegaKeyboard.cpp @@ -29,14 +29,14 @@ uint8_t ATMegaKeyboard::debounce = 3; void ATMegaKeyboard::setup(void) { wdt_disable(); - for (uint8_t i = 0; i < KeyboardHardware.matrix_columns; i++) { - DDR_INPUT(KeyboardHardware.matrix_col_pins[i]); - ENABLE_PULLUP(KeyboardHardware.matrix_col_pins[i]); + for (uint8_t i = 0; i < Kaleidoscope.device().matrix_columns; i++) { + DDR_INPUT(Kaleidoscope.device().matrix_col_pins[i]); + ENABLE_PULLUP(Kaleidoscope.device().matrix_col_pins[i]); } - for (uint8_t i = 0; i < KeyboardHardware.matrix_rows; i++) { - DDR_OUTPUT(KeyboardHardware.matrix_row_pins[i]); - OUTPUT_HIGH(KeyboardHardware.matrix_row_pins[i]); + for (uint8_t i = 0; i < Kaleidoscope.device().matrix_rows; i++) { + DDR_OUTPUT(Kaleidoscope.device().matrix_row_pins[i]); + OUTPUT_HIGH(Kaleidoscope.device().matrix_row_pins[i]); } /* Set up Timer1 for 1700usec */ @@ -51,24 +51,24 @@ void ATMegaKeyboard::setup(void) { } void __attribute__((optimize(3))) ATMegaKeyboard::readMatrix(void) { - for (uint8_t current_row = 0; current_row < KeyboardHardware.matrix_rows; current_row++) { + for (uint8_t current_row = 0; current_row < Kaleidoscope.device().matrix_rows; current_row++) { uint16_t mask, cols; - mask = KeyboardHardware.debounceMaskForRow(current_row); + mask = Kaleidoscope.device().debounceMaskForRow(current_row); - OUTPUT_TOGGLE(KeyboardHardware.matrix_row_pins[current_row]); - cols = (KeyboardHardware.readCols() & mask) | (KeyboardHardware.keyState_[current_row] & ~mask); - OUTPUT_TOGGLE(KeyboardHardware.matrix_row_pins[current_row]); - KeyboardHardware.debounceRow(cols ^ KeyboardHardware.keyState_[current_row], current_row); - KeyboardHardware.keyState_[current_row] = cols; + OUTPUT_TOGGLE(Kaleidoscope.device().matrix_row_pins[current_row]); + cols = (Kaleidoscope.device().readCols() & mask) | (Kaleidoscope.device().keyState_[current_row] & ~mask); + OUTPUT_TOGGLE(Kaleidoscope.device().matrix_row_pins[current_row]); + Kaleidoscope.device().debounceRow(cols ^ Kaleidoscope.device().keyState_[current_row], current_row); + Kaleidoscope.device().keyState_[current_row] = cols; } } uint8_t ATMegaKeyboard::pressedKeyswitchCount() { uint8_t count = 0; - for (int8_t r = 0; r < KeyboardHardware.matrix_rows; r++) { - count += __builtin_popcount(KeyboardHardware.keyState_[r]); + for (int8_t r = 0; r < Kaleidoscope.device().matrix_rows; r++) { + count += __builtin_popcount(Kaleidoscope.device().keyState_[r]); } return count; } @@ -76,28 +76,28 @@ uint8_t ATMegaKeyboard::pressedKeyswitchCount() { uint8_t ATMegaKeyboard::previousPressedKeyswitchCount() { uint8_t count = 0; - for (int8_t r = 0; r < KeyboardHardware.matrix_rows; r++) { - count += __builtin_popcount(KeyboardHardware.previousKeyState_[r]); + for (int8_t r = 0; r < Kaleidoscope.device().matrix_rows; r++) { + count += __builtin_popcount(Kaleidoscope.device().previousKeyState_[r]); } return count; } void __attribute__((optimize(3))) ATMegaKeyboard::actOnMatrixScan() { - for (byte row = 0; row < KeyboardHardware.matrix_rows; row++) { - for (byte col = 0; col < KeyboardHardware.matrix_columns; col++) { - uint8_t keyState = (bitRead(KeyboardHardware.previousKeyState_[row], col) << 0) | - (bitRead(KeyboardHardware.keyState_[row], col) << 1); + for (byte row = 0; row < Kaleidoscope.device().matrix_rows; row++) { + for (byte col = 0; col < Kaleidoscope.device().matrix_columns; col++) { + uint8_t keyState = (bitRead(Kaleidoscope.device().previousKeyState_[row], col) << 0) | + (bitRead(Kaleidoscope.device().keyState_[row], col) << 1); if (keyState) { handleKeyswitchEvent(Key_NoKey, ::KeyAddr(row, col), keyState); } } - KeyboardHardware.previousKeyState_[row] = KeyboardHardware.keyState_[row]; + Kaleidoscope.device().previousKeyState_[row] = Kaleidoscope.device().keyState_[row]; } } void ATMegaKeyboard::scanMatrix() { // We ALWAYS want to tell Kaleidoscope about the state of the matrix - KeyboardHardware.actOnMatrixScan(); + Kaleidoscope.device().actOnMatrixScan(); } /* @@ -116,9 +116,9 @@ void ATMegaKeyboard::scanMatrix() { __attribute__((optimize("no-unroll-loops"))) uint16_t ATMegaKeyboard::readCols() { uint16_t results = 0x00 ; - for (uint8_t i = 0; i < KeyboardHardware.matrix_columns; i++) { + for (uint8_t i = 0; i < Kaleidoscope.device().matrix_columns; i++) { asm("NOP"); // We need to pause a beat before reading or we may read before the pin is hot - results |= (!READ_PIN(KeyboardHardware.matrix_col_pins[i]) << i); + results |= (!READ_PIN(Kaleidoscope.device().matrix_col_pins[i]) << i); } return results; } @@ -126,9 +126,9 @@ uint16_t ATMegaKeyboard::readCols() { uint16_t ATMegaKeyboard::debounceMaskForRow(uint8_t row) { uint16_t result = 0; - for (uint16_t c = 0; c < KeyboardHardware.matrix_columns; ++c) { - if (KeyboardHardware.debounce_matrix_[row][c]) { - --KeyboardHardware.debounce_matrix_[row][c]; + for (uint16_t c = 0; c < Kaleidoscope.device().matrix_columns; ++c) { + if (Kaleidoscope.device().debounce_matrix_[row][c]) { + --Kaleidoscope.device().debounce_matrix_[row][c]; } else { result |= _BV(c); } @@ -137,9 +137,9 @@ uint16_t ATMegaKeyboard::debounceMaskForRow(uint8_t row) { } void ATMegaKeyboard::debounceRow(uint16_t change, uint8_t row) { - for (uint16_t i = 0; i < KeyboardHardware.matrix_columns; ++i) { + for (uint16_t i = 0; i < Kaleidoscope.device().matrix_columns; ++i) { if (change & _BV(i)) { - KeyboardHardware.debounce_matrix_[row][i] = debounce; + Kaleidoscope.device().debounce_matrix_[row][i] = debounce; } } } diff --git a/src/kaleidoscope/device/ATMegaKeyboard.h b/src/kaleidoscope/device/ATMegaKeyboard.h index 938af929..8846b72c 100644 --- a/src/kaleidoscope/device/ATMegaKeyboard.h +++ b/src/kaleidoscope/device/ATMegaKeyboard.h @@ -130,7 +130,7 @@ struct cRGB { volatile uint8_t BOARD::debounce_matrix_[matrix_rows][matrix_columns]; \ \ ISR(TIMER1_OVF_vect) { \ - KeyboardHardware.readMatrix(); \ + Kaleidoscope.device().readMatrix(); \ } namespace kaleidoscope { diff --git a/src/kaleidoscope/device/ez/ErgoDox.cpp b/src/kaleidoscope/device/ez/ErgoDox.cpp index db3fc80b..6bc45b6c 100644 --- a/src/kaleidoscope/device/ez/ErgoDox.cpp +++ b/src/kaleidoscope/device/ez/ErgoDox.cpp @@ -36,10 +36,10 @@ namespace device { namespace ez { ErgoDoxScanner ErgoDox::scanner_; -uint8_t ErgoDox::previousKeyState_[ROWS]; -uint8_t ErgoDox::keyState_[ROWS]; -uint8_t ErgoDox::masks_[ROWS]; -uint8_t ErgoDox::debounce_matrix_[ROWS][COLS]; +uint8_t ErgoDox::previousKeyState_[matrix_rows]; +uint8_t ErgoDox::keyState_[matrix_rows]; +uint8_t ErgoDox::masks_[matrix_rows]; +uint8_t ErgoDox::debounce_matrix_[matrix_rows][matrix_columns]; uint8_t ErgoDox::debounce = 5; static bool do_scan_ = 1; @@ -96,20 +96,20 @@ void __attribute__((optimize(3))) ErgoDox::readMatrix() { scanner_.reattachExpanderOnError(); - for (uint8_t row = 0; row < ROWS / 2; row++) { + for (uint8_t row = 0; row < matrix_rows / 2; row++) { scanner_.selectExtenderRow(row); scanner_.toggleATMegaRow(row); readMatrixRow(row); - readMatrixRow(row + ROWS / 2); + readMatrixRow(row + matrix_rows / 2); scanner_.toggleATMegaRow(row); } } void __attribute__((optimize(3))) ErgoDox::actOnMatrixScan() { - for (byte row = 0; row < ROWS; row++) { - for (byte col = 0; col < COLS; col++) { + for (byte row = 0; row < matrix_rows; row++) { + for (byte col = 0; col < matrix_columns; col++) { uint8_t keyState = (bitRead(previousKeyState_[row], col) << 0) | (bitRead(keyState_[row], col) << 1); if (keyState) @@ -205,7 +205,7 @@ void ErgoDox::resetDevice() { uint8_t ErgoDox::debounceMaskForRow(uint8_t row) { uint8_t result = 0; - for (uint8_t c = 0; c < COLS; ++c) { + for (uint8_t c = 0; c < matrix_columns; ++c) { if (debounce_matrix_[row][c]) { --debounce_matrix_[row][c]; } else { @@ -216,7 +216,7 @@ uint8_t ErgoDox::debounceMaskForRow(uint8_t row) { } void ErgoDox::debounceRow(uint8_t change, uint8_t row) { - for (uint8_t i = 0; i < COLS; ++i) { + for (uint8_t i = 0; i < matrix_columns; ++i) { if (change & (1 << i)) { debounce_matrix_[row][i] = debounce; } @@ -244,7 +244,7 @@ bool ErgoDox::wasKeyswitchPressed(uint8_t keyIndex) { uint8_t ErgoDox::previousPressedKeyswitchCount() { uint8_t count = 0; - for (uint8_t r = 0; r < ROWS; r++) { + for (uint8_t r = 0; r < matrix_rows; r++) { count += __builtin_popcount(previousKeyState_[r]); } return count; @@ -253,7 +253,7 @@ uint8_t ErgoDox::previousPressedKeyswitchCount() { uint8_t ErgoDox::pressedKeyswitchCount() { uint8_t count = 0; - for (uint8_t r = 0; r < ROWS; r++) { + for (uint8_t r = 0; r < matrix_rows; r++) { count += __builtin_popcount(keyState_[r]); } return count; @@ -263,7 +263,6 @@ uint8_t ErgoDox::pressedKeyswitchCount() { } } -HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::device::ez::ErgoDox &ErgoDox = KeyboardHardware; +kaleidoscope::device::ez::ErgoDox &ErgoDox = kaleidoscope_internal::device; #endif diff --git a/src/kaleidoscope/device/ez/ErgoDox.h b/src/kaleidoscope/device/ez/ErgoDox.h index cc431aef..424d6a39 100644 --- a/src/kaleidoscope/device/ez/ErgoDox.h +++ b/src/kaleidoscope/device/ez/ErgoDox.h @@ -31,7 +31,6 @@ #include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h" -#define HARDWARE_IMPLEMENTATION kaleidoscope::device::ez::ErgoDox #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" @@ -154,6 +153,9 @@ class ErgoDox : public kaleidoscope::Hardware { r0c13, r1c13, r2c13, r3c13, r4c13, dflt } } + +typedef kaleidoscope::device::ez::ErgoDox Device; + } extern kaleidoscope::device::ez::ErgoDox DEPRECATED(NAMED_HARDWARE) &ErgoDox; diff --git a/src/kaleidoscope/device/kbdfans/KBD4x.cpp b/src/kaleidoscope/device/kbdfans/KBD4x.cpp index 5f776849..3cbc7268 100644 --- a/src/kaleidoscope/device/kbdfans/KBD4x.cpp +++ b/src/kaleidoscope/device/kbdfans/KBD4x.cpp @@ -56,7 +56,6 @@ void KBD4x::resetDevice() { } } -HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::device::kbdfans::KBD4x &KBD4x = KeyboardHardware; +kaleidoscope::device::kbdfans::KBD4x &KBD4x = kaleidoscope_internal::device; #endif diff --git a/src/kaleidoscope/device/kbdfans/KBD4x.h b/src/kaleidoscope/device/kbdfans/KBD4x.h index 08b34f12..faedf0cd 100644 --- a/src/kaleidoscope/device/kbdfans/KBD4x.h +++ b/src/kaleidoscope/device/kbdfans/KBD4x.h @@ -20,7 +20,6 @@ #ifdef ARDUINO_AVR_KBD4X #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::device::kbdfans::KBD4x #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" @@ -63,8 +62,10 @@ class KBD4x: public kaleidoscope::device::ATMegaKeyboard { R2C0, R2C1, R2C2, R2C3, R2C4, R2C5, R2C6, R2C7, R2C8, R2C9, R2C10, R2C11, \ R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C5, R3C7, R3C8, R3C9, R3C10, R3C11 } - } + +typedef kaleidoscope::device::kbdfans::KBD4x Device; + } extern kaleidoscope::device::kbdfans::KBD4x DEPRECATED(NAMED_HARDWARE) &KBD4x; diff --git a/src/kaleidoscope/device/key_indexes.h b/src/kaleidoscope/device/key_indexes.h index d13f2d32..b74eeca9 100644 --- a/src/kaleidoscope/device/key_indexes.h +++ b/src/kaleidoscope/device/key_indexes.h @@ -25,13 +25,10 @@ * zero as a sentinel. This is important, because when we initialize arrays with * fewer elements than the declared array size, the remaining elements will be * zero. We can use this to avoid having to explicitly add a sentinel in - * user-facing code. - * - * We're using a macro instead of a constexpr so that it is evaluated lazily, - * when `HARDWARE_IMPLEMENTATION` can be properly resolved. - */ -#define keyIndex(row,col) \ - (uint8_t)(KeyAddr(row, col).toInt() + 1) + * user-facing code. */ +constexpr uint8_t keyIndex(uint8_t row, uint8_t col) { + return KeyAddr(row, col).toInt() + 1; +} constexpr uint8_t R0C0 = keyIndex(0, 0); constexpr uint8_t R0C1 = keyIndex(0, 1); diff --git a/src/kaleidoscope/device/keyboardio/Model01.cpp b/src/kaleidoscope/device/keyboardio/Model01.cpp index 917ec434..a3507d5c 100644 --- a/src/kaleidoscope/device/keyboardio/Model01.cpp +++ b/src/kaleidoscope/device/keyboardio/Model01.cpp @@ -86,7 +86,7 @@ void Model01::enableHardwareTestMode() { PORTB |= (1 << 0); // Disable the debouncer on the ATTinys - KeyboardHardware.setKeyscanInterval(2); + Kaleidoscope.device().setKeyscanInterval(2); } @@ -335,7 +335,5 @@ uint8_t Model01::previousPressedKeyswitchCount() { } } -HARDWARE_IMPLEMENTATION KeyboardHardware; - #endif #endif diff --git a/src/kaleidoscope/device/keyboardio/Model01.h b/src/kaleidoscope/device/keyboardio/Model01.h index d55ed79b..f8e9cbc9 100644 --- a/src/kaleidoscope/device/keyboardio/Model01.h +++ b/src/kaleidoscope/device/keyboardio/Model01.h @@ -21,7 +21,6 @@ #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::device::keyboardio::Model01 #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "KeyboardioScanner.h" @@ -123,6 +122,9 @@ class Model01 : public kaleidoscope::Hardware { } } + +typedef kaleidoscope::device::keyboardio::Model01 Device; + } #define PER_KEY_DATA_STACKED(dflt, \ diff --git a/src/kaleidoscope/device/olkb/Planck.cpp b/src/kaleidoscope/device/olkb/Planck.cpp index 697643fb..ab9fa631 100644 --- a/src/kaleidoscope/device/olkb/Planck.cpp +++ b/src/kaleidoscope/device/olkb/Planck.cpp @@ -31,7 +31,6 @@ constexpr int8_t Planck::led_count; } } -HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::device::olkb::Planck &Planck = KeyboardHardware; +kaleidoscope::device::olkb::Planck &Planck = kaleidoscope_internal::device; #endif diff --git a/src/kaleidoscope/device/olkb/Planck.h b/src/kaleidoscope/device/olkb/Planck.h index 6393bf7f..39bac427 100644 --- a/src/kaleidoscope/device/olkb/Planck.h +++ b/src/kaleidoscope/device/olkb/Planck.h @@ -20,7 +20,6 @@ #ifdef ARDUINO_AVR_PLANCK #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::device::olkb::Planck #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" @@ -59,8 +58,10 @@ class Planck: public kaleidoscope::device::ATMegaKeyboard { R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11 } - } + +typedef kaleidoscope::device::olkb::Planck Device; + } extern kaleidoscope::device::olkb::Planck DEPRECATED(NAMED_HARDWARE) &Planck; diff --git a/src/kaleidoscope/device/softhruf/Splitography.cpp b/src/kaleidoscope/device/softhruf/Splitography.cpp index 74adcf17..148b5680 100644 --- a/src/kaleidoscope/device/softhruf/Splitography.cpp +++ b/src/kaleidoscope/device/softhruf/Splitography.cpp @@ -38,7 +38,6 @@ constexpr int8_t Splitography::led_count; } } -HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::device::softhruf::Splitography &Splitography = KeyboardHardware; +kaleidoscope::device::softhruf::Splitography &Splitography = kaleidoscope_internal::device; #endif diff --git a/src/kaleidoscope/device/softhruf/Splitography.h b/src/kaleidoscope/device/softhruf/Splitography.h index 9c67d080..6441e015 100644 --- a/src/kaleidoscope/device/softhruf/Splitography.h +++ b/src/kaleidoscope/device/softhruf/Splitography.h @@ -27,7 +27,6 @@ #ifdef ARDUINO_AVR_SPLITOGRAPHY #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::device::softhruf::Splitography #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" @@ -86,6 +85,9 @@ class Splitography: public kaleidoscope::device::ATMegaKeyboard { } } + +typedef kaleidoscope::device::softhruf::Splitography Device; + } extern kaleidoscope::device::softhruf::Splitography DEPRECATED(NAMED_HARDWARE) &Splitography; diff --git a/src/kaleidoscope/device/technomancy/Atreus.cpp b/src/kaleidoscope/device/technomancy/Atreus.cpp index 41195cfe..971e3d8a 100644 --- a/src/kaleidoscope/device/technomancy/Atreus.cpp +++ b/src/kaleidoscope/device/technomancy/Atreus.cpp @@ -76,7 +76,6 @@ void Atreus::resetDevice() { } } -HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::device::technomancy::Atreus &Atreus = KeyboardHardware; +kaleidoscope::device::technomancy::Atreus &Atreus = kaleidoscope_internal::device; #endif diff --git a/src/kaleidoscope/device/technomancy/Atreus.h b/src/kaleidoscope/device/technomancy/Atreus.h index 535883b1..e0accf57 100644 --- a/src/kaleidoscope/device/technomancy/Atreus.h +++ b/src/kaleidoscope/device/technomancy/Atreus.h @@ -27,7 +27,6 @@ #ifdef ARDUINO_AVR_ATREUS #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::device::technomancy::Atreus #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" @@ -103,6 +102,9 @@ class Atreus: public kaleidoscope::device::ATMegaKeyboard { R3C0, R3C1, R3C2, R3C3, R3C4, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11 } } + +typedef kaleidoscope::device::technomancy::Atreus Device; + } extern kaleidoscope::device::technomancy::Atreus DEPRECATED(NAMED_HARDWARE) &Atreus; diff --git a/src/kaleidoscope/device/technomancy/Atreus2.cpp b/src/kaleidoscope/device/technomancy/Atreus2.cpp index 8198fe86..13ba5daa 100644 --- a/src/kaleidoscope/device/technomancy/Atreus2.cpp +++ b/src/kaleidoscope/device/technomancy/Atreus2.cpp @@ -32,7 +32,6 @@ constexpr int8_t Atreus2::led_count; } } -HARDWARE_IMPLEMENTATION KeyboardHardware; -kaleidoscope::device::technomancy::Atreus2 &Atreus2 = KeyboardHardware; +kaleidoscope::device::technomancy::Atreus2 &Atreus2 = kaleidoscope_internal::device; #endif diff --git a/src/kaleidoscope/device/technomancy/Atreus2.h b/src/kaleidoscope/device/technomancy/Atreus2.h index e707a6e3..f94f9e39 100644 --- a/src/kaleidoscope/device/technomancy/Atreus2.h +++ b/src/kaleidoscope/device/technomancy/Atreus2.h @@ -21,7 +21,6 @@ #ifdef ARDUINO_AVR_ATREUS2 #include -#define HARDWARE_IMPLEMENTATION kaleidoscope::device::technomancy::Atreus2 #include "Kaleidoscope-HIDAdaptor-KeyboardioHID.h" #include "kaleidoscope/macro_helpers.h" @@ -80,6 +79,9 @@ class Atreus2: public kaleidoscope::device::ATMegaKeyboard { R3C0, R3C1, R3C2, R3C3, R3C4, R3C5, R3C6, R3C7, R3C8, R3C9, R3C10, R3C11 } } + +typedef kaleidoscope::device::technomancy::Atreus2 Device; + } extern kaleidoscope::device::technomancy::Atreus2 DEPRECATED(NAMED_HARDWARE) &Atreus2; diff --git a/src/kaleidoscope/key_events.cpp b/src/kaleidoscope/key_events.cpp index 008be924..d57c6bc8 100644 --- a/src/kaleidoscope/key_events.cpp +++ b/src/kaleidoscope/key_events.cpp @@ -96,9 +96,9 @@ void handleKeyswitchEvent(Key mappedKey, KeyAddr key_addr, uint8_t keyState) { * See layers.cpp for an example that masks keys, and the reason why it does * so. */ - if (KeyboardHardware.isKeyMasked(key_addr)) { + if (Kaleidoscope.device().isKeyMasked(key_addr)) { if (keyToggledOff(keyState)) { - KeyboardHardware.unMaskKey(key_addr); + Kaleidoscope.device().unMaskKey(key_addr); } else { return; } diff --git a/src/kaleidoscope/keymaps.h b/src/kaleidoscope/keymaps.h index 8f502787..638a779e 100644 --- a/src/kaleidoscope/keymaps.h +++ b/src/kaleidoscope/keymaps.h @@ -18,7 +18,7 @@ #include "kaleidoscope/key_defs.h" -extern const Key keymaps_linear[][ROWS * COLS]; +extern const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns]; namespace kaleidoscope { @@ -58,7 +58,7 @@ class Keymaps2DInterface { }; KeymapRow operator[](uint8_t row) { - return KeymapRow(keymap_layer_ + row * COLS); + return KeymapRow(keymap_layer_ + row * kaleidoscope_internal::device.matrix_columns); } }; diff --git a/src/kaleidoscope/layers.cpp b/src/kaleidoscope/layers.cpp index 102ffdce..7cc06ad0 100644 --- a/src/kaleidoscope/layers.cpp +++ b/src/kaleidoscope/layers.cpp @@ -33,13 +33,13 @@ __attribute__((weak)) uint8_t layer_count = 0; __attribute__((weak)) -extern const Key keymaps_linear[][ROWS * COLS] = {}; +extern const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] = {}; namespace kaleidoscope { uint32_t Layer_::layer_state_; uint8_t Layer_::top_active_layer_; -Key Layer_::live_composite_keymap_[KeyboardHardware.numKeys()]; -uint8_t Layer_::active_layers_[KeyboardHardware.numKeys()]; +Key Layer_::live_composite_keymap_[Kaleidoscope.device().numKeys()]; +uint8_t Layer_::active_layers_[Kaleidoscope.device().numKeys()]; Key(*Layer_::getKey)(uint8_t layer, KeyAddr key_addr) = Layer.getKeyFromPROGMEM; void Layer_::handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) { @@ -111,7 +111,7 @@ void Layer_::updateLiveCompositeKeymap(KeyAddr key_addr) { } void Layer_::updateActiveLayers(void) { - memset(active_layers_, 0, KeyboardHardware.numKeys()); + memset(active_layers_, 0, Kaleidoscope.device().numKeys()); for (auto key_addr : KeyAddr::all()) { int8_t layer = top_active_layer_; diff --git a/src/kaleidoscope/layers.h b/src/kaleidoscope/layers.h index 14b25dfb..5a94d7c6 100644 --- a/src/kaleidoscope/layers.h +++ b/src/kaleidoscope/layers.h @@ -20,12 +20,13 @@ #include "kaleidoscope/key_defs.h" #include "kaleidoscope/keymaps.h" #include KALEIDOSCOPE_HARDWARE_H +#include "kaleidoscope_internal/device.h" // Macro for defining the keymap. This should be used in the sketch // file (*.ino) to define the keymap[] array that holds the user's // layers. It also computes the number of layers in that keymap. #define KEYMAPS(layers...) __NL__ \ - const Key keymaps_linear[][ROWS*COLS] PROGMEM = { layers }; __NL__ \ + const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] PROGMEM = { layers }; __NL__ \ uint8_t layer_count __NL__ \ = sizeof(keymaps_linear) / sizeof(*keymaps_linear); __NL__ \ __NL__ \ @@ -134,8 +135,8 @@ class Layer_ { private: static uint32_t layer_state_; static uint8_t top_active_layer_; - static Key live_composite_keymap_[KeyboardHardware.numKeys()]; - static uint8_t active_layers_[KeyboardHardware.numKeys()]; + static Key live_composite_keymap_[kaleidoscope_internal::device.numKeys()]; + static uint8_t active_layers_[kaleidoscope_internal::device.numKeys()]; static void handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState); static void updateTopActiveLayer(void); diff --git a/src/kaleidoscope/plugin/DynamicMacros.cpp b/src/kaleidoscope/plugin/DynamicMacros.cpp index 565eb763..bf0bdc67 100644 --- a/src/kaleidoscope/plugin/DynamicMacros.cpp +++ b/src/kaleidoscope/plugin/DynamicMacros.cpp @@ -49,7 +49,7 @@ static void playKeyCode(Key key, uint8_t keyStates, bool explicit_report) { static void readKeyCodeAndPlay(uint16_t pos, uint8_t flags, uint8_t keyStates, bool explicit_report) { Key key; key.flags = flags; - key.keyCode = KeyboardHardware.storage().read(pos++); + key.keyCode = Kaleidoscope.storage().read(pos++); playKeyCode(key, keyStates, explicit_report); } @@ -63,7 +63,7 @@ void DynamicMacros::updateDynamicMacroCache(void) { map_[0] = 0; while (pos < storage_base_ + storage_size_) { - macro = KeyboardHardware.storage().read(pos++); + macro = Kaleidoscope.storage().read(pos++); switch (macro) { case MACRO_ACTION_STEP_EXPLICIT_REPORT: case MACRO_ACTION_STEP_IMPLICIT_REPORT: @@ -91,8 +91,8 @@ void DynamicMacros::updateDynamicMacroCache(void) { previous_macro_ended = false; uint8_t keyCode, flags; do { - flags = KeyboardHardware.storage().read(pos++); - keyCode = KeyboardHardware.storage().read(pos++); + flags = Kaleidoscope.storage().read(pos++); + keyCode = Kaleidoscope.storage().read(pos++); } while (!(flags == 0 && keyCode == 0)); break; } @@ -101,7 +101,7 @@ void DynamicMacros::updateDynamicMacroCache(void) { previous_macro_ended = false; uint8_t keyCode, flags; do { - keyCode = KeyboardHardware.storage().read(pos++); + keyCode = Kaleidoscope.storage().read(pos++); } while (keyCode != 0); break; } @@ -128,7 +128,7 @@ void DynamicMacros::play(uint8_t macro_id) { pos = storage_base_ + map_[macro_id]; while (true) { - switch (macro = KeyboardHardware.storage().read(pos++)) { + switch (macro = Kaleidoscope.storage().read(pos++)) { case MACRO_ACTION_STEP_EXPLICIT_REPORT: explicit_report = true; break; @@ -140,23 +140,23 @@ void DynamicMacros::play(uint8_t macro_id) { kaleidoscope::hid::sendMouseReport(); break; case MACRO_ACTION_STEP_INTERVAL: - interval = KeyboardHardware.storage().read(pos++); + interval = Kaleidoscope.storage().read(pos++); break; case MACRO_ACTION_STEP_WAIT: { - uint8_t wait = KeyboardHardware.storage().read(pos++); + uint8_t wait = Kaleidoscope.storage().read(pos++); delay(wait); break; } case MACRO_ACTION_STEP_KEYDOWN: - flags = KeyboardHardware.storage().read(pos++); + flags = Kaleidoscope.storage().read(pos++); readKeyCodeAndPlay(pos++, flags, IS_PRESSED, explicit_report); break; case MACRO_ACTION_STEP_KEYUP: - flags = KeyboardHardware.storage().read(pos++); + flags = Kaleidoscope.storage().read(pos++); readKeyCodeAndPlay(pos++, flags, WAS_PRESSED, explicit_report); break; case MACRO_ACTION_STEP_TAP: - flags = KeyboardHardware.storage().read(pos++); + flags = Kaleidoscope.storage().read(pos++); readKeyCodeAndPlay(pos++, flags, IS_PRESSED | WAS_PRESSED, false); break; @@ -173,8 +173,8 @@ void DynamicMacros::play(uint8_t macro_id) { case MACRO_ACTION_STEP_TAP_SEQUENCE: { uint8_t keyCode; do { - flags = KeyboardHardware.storage().read(pos++); - keyCode = KeyboardHardware.storage().read(pos++); + flags = Kaleidoscope.storage().read(pos++); + keyCode = Kaleidoscope.storage().read(pos++); playKeyCode(Key(keyCode, flags), IS_PRESSED | WAS_PRESSED, false); delay(interval); } while (!(flags == 0 && keyCode == 0)); @@ -183,7 +183,7 @@ void DynamicMacros::play(uint8_t macro_id) { case MACRO_ACTION_STEP_TAP_CODE_SEQUENCE: { uint8_t keyCode; do { - keyCode = KeyboardHardware.storage().read(pos++); + keyCode = Kaleidoscope.storage().read(pos++); playKeyCode(Key(keyCode, 0), IS_PRESSED | WAS_PRESSED, false); delay(interval); } while (keyCode != 0); @@ -221,7 +221,7 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) { if (::Focus.isEOL()) { for (uint16_t i = 0; i < storage_size_; i++) { uint8_t b; - b = KeyboardHardware.storage().read(storage_base_ + i); + b = Kaleidoscope.storage().read(storage_base_ + i); ::Focus.send(b); } } else { @@ -231,7 +231,7 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) { uint8_t b; ::Focus.read(b); - KeyboardHardware.storage().update(storage_base_ + pos++, b); + Kaleidoscope.storage().update(storage_base_ + pos++, b); } updateDynamicMacroCache(); } diff --git a/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.cpp b/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.cpp index 0c4874b8..512e8ce9 100644 --- a/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.cpp +++ b/src/kaleidoscope/plugin/EEPROM-Keymap-Programmer.cpp @@ -56,10 +56,10 @@ EventHandlerResult EEPROMKeymapProgrammer::onKeyswitchEvent(Key &mapped_key, Key if (state_ == WAIT_FOR_KEY) { if (keyToggledOn(key_state)) { - update_position_ = Layer.top() * KeyboardHardware.numKeys() + key_addr.toInt(); + update_position_ = Layer.top() * Kaleidoscope.device().numKeys() + key_addr.toInt(); } if (keyToggledOff(key_state)) { - if ((uint16_t)(Layer.top() * KeyboardHardware.numKeys() + key_addr.toInt()) == update_position_) + if ((uint16_t)(Layer.top() * Kaleidoscope.device().numKeys() + key_addr.toInt()) == update_position_) nextState(); } return EventHandlerResult::EVENT_CONSUMED; diff --git a/src/kaleidoscope/plugin/EEPROM-Keymap.cpp b/src/kaleidoscope/plugin/EEPROM-Keymap.cpp index f2e26faf..7b56da83 100644 --- a/src/kaleidoscope/plugin/EEPROM-Keymap.cpp +++ b/src/kaleidoscope/plugin/EEPROM-Keymap.cpp @@ -44,7 +44,7 @@ void EEPROMKeymap::setup(uint8_t max) { void EEPROMKeymap::max_layers(uint8_t max) { max_layers_ = max; - keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * KeyboardHardware.numKeys() * 2); + keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * Kaleidoscope.device().numKeys() * 2); } Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) { @@ -53,10 +53,10 @@ Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) { if (layer >= max_layers_) return Key_NoKey; - uint16_t pos = ((layer * KeyboardHardware.numKeys()) + key_addr.toInt()) * 2; + uint16_t pos = ((layer * Kaleidoscope.device().numKeys()) + key_addr.toInt()) * 2; - key.flags = KeyboardHardware.storage().read(keymap_base_ + pos); - key.keyCode = KeyboardHardware.storage().read(keymap_base_ + pos + 1); + key.flags = Kaleidoscope.storage().read(keymap_base_ + pos); + key.keyCode = Kaleidoscope.storage().read(keymap_base_ + pos + 1); return key; } @@ -77,8 +77,8 @@ uint16_t EEPROMKeymap::keymap_base(void) { } void EEPROMKeymap::updateKey(uint16_t base_pos, Key key) { - KeyboardHardware.storage().update(keymap_base_ + base_pos * 2, key.flags); - KeyboardHardware.storage().update(keymap_base_ + base_pos * 2 + 1, key.keyCode); + Kaleidoscope.storage().update(keymap_base_ + base_pos * 2, key.flags); + Kaleidoscope.storage().update(keymap_base_ + base_pos * 2 + 1, key.keyCode); } void EEPROMKeymap::dumpKeymap(uint8_t layers, Key(*getkey)(uint8_t, KeyAddr)) { @@ -150,7 +150,7 @@ EventHandlerResult EEPROMKeymap::onFocusEvent(const char *command) { } else { uint16_t i = 0; - while (!::Focus.isEOL() && (i < (uint16_t)KeyboardHardware.numKeys() * max_layers_)) { + while (!::Focus.isEOL() && (i < (uint16_t)Kaleidoscope.device().numKeys() * max_layers_)) { Key k; ::Focus.read(k); diff --git a/src/kaleidoscope/plugin/EEPROM-Settings.cpp b/src/kaleidoscope/plugin/EEPROM-Settings.cpp index 52a82b1d..f987fb2b 100644 --- a/src/kaleidoscope/plugin/EEPROM-Settings.cpp +++ b/src/kaleidoscope/plugin/EEPROM-Settings.cpp @@ -28,7 +28,7 @@ bool EEPROMSettings::sealed_; uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings); EventHandlerResult EEPROMSettings::onSetup() { - KeyboardHardware.storage().get(0, settings_); + Kaleidoscope.storage().get(0, settings_); /* If the version is undefined, set up sensible defaults. */ if (settings_.version == VERSION_UNDEFINED) { @@ -49,7 +49,7 @@ EventHandlerResult EEPROMSettings::onSetup() { * not able to catch all writes yet. For the sake of consistency, if we * encounter a firmware with no version defined, we'll set sensible * defaults. */ - KeyboardHardware.storage().put(0, settings_); + Kaleidoscope.storage().put(0, settings_); } return EventHandlerResult::OK; } @@ -146,7 +146,7 @@ uint16_t EEPROMSettings::used(void) { } void EEPROMSettings::update(void) { - KeyboardHardware.storage().put(0, settings_); + Kaleidoscope.storage().put(0, settings_); is_valid_ = true; } @@ -220,22 +220,22 @@ EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) { switch (sub_command) { case CONTENTS: { if (::Focus.isEOL()) { - for (uint16_t i = 0; i < KeyboardHardware.storage().length(); i++) { - uint8_t d = KeyboardHardware.storage().read(i); + for (uint16_t i = 0; i < Kaleidoscope.storage().length(); i++) { + uint8_t d = Kaleidoscope.storage().read(i); ::Focus.send(d); } } else { - for (uint16_t i = 0; i < KeyboardHardware.storage().length() && !::Focus.isEOL(); i++) { + for (uint16_t i = 0; i < Kaleidoscope.storage().length() && !::Focus.isEOL(); i++) { uint8_t d; ::Focus.read(d); - KeyboardHardware.storage().update(i, d); + Kaleidoscope.storage().update(i, d); } } break; } case FREE: - ::Focus.send(KeyboardHardware.storage().length() - ::EEPROMSettings.used()); + ::Focus.send(Kaleidoscope.storage().length() - ::EEPROMSettings.used()); break; } diff --git a/src/kaleidoscope/plugin/Escape-OneShot.cpp b/src/kaleidoscope/plugin/Escape-OneShot.cpp index 7f110307..34c1ecf1 100644 --- a/src/kaleidoscope/plugin/Escape-OneShot.cpp +++ b/src/kaleidoscope/plugin/Escape-OneShot.cpp @@ -32,7 +32,7 @@ EventHandlerResult EscapeOneShot::onKeyswitchEvent(Key &mapped_key, KeyAddr key_ return EventHandlerResult::OK; } - KeyboardHardware.maskKey(key_addr); + Kaleidoscope.device().maskKey(key_addr); ::OneShot.cancel(true); return EventHandlerResult::EVENT_CONSUMED; diff --git a/src/kaleidoscope/plugin/FingerPainter.cpp b/src/kaleidoscope/plugin/FingerPainter.cpp index e720ef58..661a4bc5 100644 --- a/src/kaleidoscope/plugin/FingerPainter.cpp +++ b/src/kaleidoscope/plugin/FingerPainter.cpp @@ -58,7 +58,7 @@ EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_ // TODO: The following works only for keyboards with LEDs for each key. - uint8_t color_index = ::LEDPaletteTheme.lookupColorIndexAtPosition(color_base_, KeyboardHardware.getLedIndex(key_addr)); + uint8_t color_index = ::LEDPaletteTheme.lookupColorIndexAtPosition(color_base_, Kaleidoscope.device().getLedIndex(key_addr)); // Find the next color in the palette that is different. // But do not loop forever! @@ -75,7 +75,7 @@ EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_ new_color = ::LEDPaletteTheme.lookupPaletteColor(color_index); } - ::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, KeyboardHardware.getLedIndex(key_addr), color_index); + ::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, Kaleidoscope.device().getLedIndex(key_addr), color_index); return EventHandlerResult::EVENT_CONSUMED; } @@ -100,8 +100,8 @@ EventHandlerResult FingerPainter::onFocusEvent(const char *command) { return EventHandlerResult::OK; if (sub_command == CLEAR) { - for (uint16_t i = 0; i < KeyboardHardware.numKeys() / 2; i++) { - KeyboardHardware.storage().update(color_base_ + i, 0); + for (uint16_t i = 0; i < Kaleidoscope.device().numKeys() / 2; i++) { + Kaleidoscope.storage().update(color_base_ + i, 0); } return EventHandlerResult::OK; } diff --git a/src/kaleidoscope/plugin/FocusSerial.cpp b/src/kaleidoscope/plugin/FocusSerial.cpp index 9b3efd66..7467b658 100644 --- a/src/kaleidoscope/plugin/FocusSerial.cpp +++ b/src/kaleidoscope/plugin/FocusSerial.cpp @@ -27,20 +27,20 @@ namespace plugin { char FocusSerial::command_[32]; void FocusSerial::drain(void) { - if (KeyboardHardware.serialPort().available()) - while (KeyboardHardware.serialPort().peek() != '\n') - KeyboardHardware.serialPort().read(); + if (Kaleidoscope.serialPort().available()) + while (Kaleidoscope.serialPort().peek() != '\n') + Kaleidoscope.serialPort().read(); } EventHandlerResult FocusSerial::beforeReportingState() { - if (KeyboardHardware.serialPort().available() == 0) + if (Kaleidoscope.serialPort().available() == 0) return EventHandlerResult::OK; uint8_t i = 0; do { - command_[i++] = KeyboardHardware.serialPort().read(); + command_[i++] = Kaleidoscope.serialPort().read(); - if (KeyboardHardware.serialPort().peek() == '\n') + if (Kaleidoscope.serialPort().peek() == '\n') break; } while (command_[i - 1] != ' ' && i < 32); if (command_[i - 1] == ' ') @@ -50,12 +50,12 @@ EventHandlerResult FocusSerial::beforeReportingState() { Kaleidoscope.onFocusEvent(command_); - KeyboardHardware.serialPort().println(F("\r\n.")); + Kaleidoscope.serialPort().println(F("\r\n.")); drain(); - if (KeyboardHardware.serialPort().peek() == '\n') - KeyboardHardware.serialPort().read(); + if (Kaleidoscope.serialPort().peek() == '\n') + Kaleidoscope.serialPort().read(); return EventHandlerResult::OK; } @@ -65,7 +65,7 @@ bool FocusSerial::handleHelp(const char *command, if (strcmp_P(command, PSTR("help")) != 0) return false; - KeyboardHardware.serialPort().println((const __FlashStringHelper *)help_message); + Kaleidoscope.serialPort().println((const __FlashStringHelper *)help_message); return true; } @@ -75,7 +75,7 @@ EventHandlerResult FocusSerial::onFocusEvent(const char *command) { } void FocusSerial::printBool(bool b) { - KeyboardHardware.serialPort().print((b) ? F("true") : F("false")); + Kaleidoscope.serialPort().print((b) ? F("true") : F("false")); } } diff --git a/src/kaleidoscope/plugin/FocusSerial.h b/src/kaleidoscope/plugin/FocusSerial.h index 1aeb6ef9..2c2235e6 100644 --- a/src/kaleidoscope/plugin/FocusSerial.h +++ b/src/kaleidoscope/plugin/FocusSerial.h @@ -37,12 +37,12 @@ class FocusSerial : public kaleidoscope::Plugin { } void send(const bool b) { printBool(b); - KeyboardHardware.serialPort().print(SEPARATOR); + Kaleidoscope.serialPort().print(SEPARATOR); } template void send(V v) { - KeyboardHardware.serialPort().print(v); - KeyboardHardware.serialPort().print(SEPARATOR); + Kaleidoscope.serialPort().print(v); + Kaleidoscope.serialPort().print(SEPARATOR); } template void send(Var v, const Vars&... vars) { @@ -53,31 +53,31 @@ class FocusSerial : public kaleidoscope::Plugin { void sendRaw() {} template void sendRaw(Var v, const Vars&... vars) { - KeyboardHardware.serialPort().print(v); + Kaleidoscope.serialPort().print(v); sendRaw(vars...); } const char peek() { - return KeyboardHardware.serialPort().peek(); + return Kaleidoscope.serialPort().peek(); } void read(Key &key) { - key.raw = KeyboardHardware.serialPort().parseInt(); + key.raw = Kaleidoscope.serialPort().parseInt(); } void read(cRGB &color) { - color.r = KeyboardHardware.serialPort().parseInt(); - color.g = KeyboardHardware.serialPort().parseInt(); - color.b = KeyboardHardware.serialPort().parseInt(); + color.r = Kaleidoscope.serialPort().parseInt(); + color.g = Kaleidoscope.serialPort().parseInt(); + color.b = Kaleidoscope.serialPort().parseInt(); } void read(uint8_t &u8) { - u8 = KeyboardHardware.serialPort().parseInt(); + u8 = Kaleidoscope.serialPort().parseInt(); } void read(uint16_t &u16) { - u16 = KeyboardHardware.serialPort().parseInt(); + u16 = Kaleidoscope.serialPort().parseInt(); } bool isEOL() { - return KeyboardHardware.serialPort().peek() == '\n'; + return Kaleidoscope.serialPort().peek() == '\n'; } static constexpr char COMMENT = '#'; diff --git a/src/kaleidoscope/plugin/GeminiPR.cpp b/src/kaleidoscope/plugin/GeminiPR.cpp index 637db5b6..4225a5bc 100644 --- a/src/kaleidoscope/plugin/GeminiPR.cpp +++ b/src/kaleidoscope/plugin/GeminiPR.cpp @@ -39,7 +39,7 @@ EventHandlerResult GeminiPR::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, if (keys_held_ == 0) { state_[0] |= 0x80; - KeyboardHardware.serialPort().write(state_, sizeof(state_)); + Kaleidoscope.serialPort().write(state_, sizeof(state_)); memset(state_, 0, sizeof(state_)); } } diff --git a/src/kaleidoscope/plugin/HardwareTestMode.cpp b/src/kaleidoscope/plugin/HardwareTestMode.cpp index 8b7e9f26..9a6fb17e 100644 --- a/src/kaleidoscope/plugin/HardwareTestMode.cpp +++ b/src/kaleidoscope/plugin/HardwareTestMode.cpp @@ -32,9 +32,9 @@ void HardwareTestMode::setActionKey(uint8_t key) { void HardwareTestMode::waitForKeypress() { while (1) { - KeyboardHardware.readMatrix(); - if (KeyboardHardware.isKeyswitchPressed(actionKey) && - ! KeyboardHardware.wasKeyswitchPressed(actionKey)) { + Kaleidoscope.device().readMatrix(); + if (Kaleidoscope.device().isKeyswitchPressed(actionKey) && + ! Kaleidoscope.device().wasKeyswitchPressed(actionKey)) { break; } } @@ -76,7 +76,7 @@ void HardwareTestMode::testLeds(void) { void HardwareTestMode::testMatrix() { // Reset bad keys from previous tests. - chatter_data state[KeyboardHardware.numKeys()] = {0, 0, 0}; + chatter_data state[Kaleidoscope.device().numKeys()] = {0, 0, 0}; constexpr cRGB red = CRGB(201, 0, 0); constexpr cRGB blue = CRGB(0, 0, 201); @@ -84,12 +84,12 @@ void HardwareTestMode::testMatrix() { constexpr cRGB yellow = CRGB(201, 100, 0); while (1) { - KeyboardHardware.readMatrix(); + Kaleidoscope.device().readMatrix(); for (auto key_addr : KeyAddr::all()) { uint8_t keynum = key_addr.toInt(); // If the key is toggled on - if (KeyboardHardware.isKeyswitchPressed(key_addr) && ! KeyboardHardware.wasKeyswitchPressed(key_addr)) { + if (Kaleidoscope.device().isKeyswitchPressed(key_addr) && ! Kaleidoscope.device().wasKeyswitchPressed(key_addr)) { // And it's too soon (in terms of cycles between changes) state[keynum].tested = 1; if (state[keynum].cyclesSinceStateChange < CHATTER_CYCLE_LIMIT) { @@ -100,19 +100,19 @@ void HardwareTestMode::testMatrix() { state[keynum].cyclesSinceStateChange++; } // If the key is held down - if (KeyboardHardware.isKeyswitchPressed(key_addr) && KeyboardHardware.wasKeyswitchPressed(key_addr)) { - KeyboardHardware.setCrgbAt(key_addr, green); + if (Kaleidoscope.device().isKeyswitchPressed(key_addr) && Kaleidoscope.device().wasKeyswitchPressed(key_addr)) { + Kaleidoscope.device().setCrgbAt(key_addr, green); } // If we triggered chatter detection ever on this key else if (state[keynum].bad == 1) { - KeyboardHardware.setCrgbAt(key_addr, red); + Kaleidoscope.device().setCrgbAt(key_addr, red); } else if (state[keynum].tested == 0) { - KeyboardHardware.setCrgbAt(key_addr, yellow); + Kaleidoscope.device().setCrgbAt(key_addr, yellow); } // If the key is not currently pressed and was not just released and is not marked bad - else if (! KeyboardHardware.isKeyswitchPressed(key_addr)) { - KeyboardHardware.setCrgbAt(key_addr, blue); + else if (! Kaleidoscope.device().isKeyswitchPressed(key_addr)) { + Kaleidoscope.device().setCrgbAt(key_addr, blue); } } ::LEDControl.syncLeds(); @@ -124,7 +124,7 @@ void HardwareTestMode::runTests() { // out and send a new report kaleidoscope::hid::releaseAllKeys(); kaleidoscope::hid::sendKeyboardReport(); - KeyboardHardware.enableHardwareTestMode(); + Kaleidoscope.device().enableHardwareTestMode(); testLeds(); testMatrix(); } diff --git a/src/kaleidoscope/plugin/Heatmap.h b/src/kaleidoscope/plugin/Heatmap.h index efba28ac..99736e1b 100644 --- a/src/kaleidoscope/plugin/Heatmap.h +++ b/src/kaleidoscope/plugin/Heatmap.h @@ -59,7 +59,7 @@ class Heatmap : public Plugin, const Heatmap *parent_; - uint16_t heatmap_[KeyboardHardware.numKeys()]; + uint16_t heatmap_[Kaleidoscope.device().numKeys()]; uint16_t highest_; uint16_t last_heatmap_comp_time_; diff --git a/src/kaleidoscope/plugin/HostOS.cpp b/src/kaleidoscope/plugin/HostOS.cpp index 4e8f75c1..cb1a1e9b 100644 --- a/src/kaleidoscope/plugin/HostOS.cpp +++ b/src/kaleidoscope/plugin/HostOS.cpp @@ -33,14 +33,14 @@ EventHandlerResult HostOS::onSetup(void) { return EventHandlerResult::OK; } - os_ = (hostos::Type)KeyboardHardware.storage().read(eeprom_slice_); + os_ = (hostos::Type)Kaleidoscope.storage().read(eeprom_slice_); return EventHandlerResult::OK; } void HostOS::os(hostos::Type new_os) { os_ = new_os; - KeyboardHardware.storage().update(eeprom_slice_, os_); + Kaleidoscope.storage().update(eeprom_slice_, os_); } } diff --git a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp index e17a9f99..d54e32d3 100644 --- a/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp +++ b/src/kaleidoscope/plugin/LED-AlphaSquare/Effect.cpp @@ -48,7 +48,7 @@ void AlphaSquareEffect::TransientLEDMode::refreshAt(KeyAddr key_addr) { uint8_t display_col = 2; Key key = last_key_left_; - if (key_addr.col() < COLS / 2) { + if (key_addr.col() < Kaleidoscope.device().matrix_columns / 2) { timed_out = Kaleidoscope.hasTimeExpired(start_time_left_, length); } else { key = last_key_right_; @@ -81,7 +81,7 @@ EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, KeyAddr k Key prev_key = this_led_mode->last_key_left_; - if (key_addr.col() < COLS / 2) { + if (key_addr.col() < Kaleidoscope.device().matrix_columns / 2) { this_led_mode->last_key_left_ = mappedKey; this_led_mode->start_time_left_ = Kaleidoscope.millisAtCycleStart(); } else { diff --git a/src/kaleidoscope/plugin/LED-Palette-Theme.cpp b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp index 70804e79..3d780a2c 100644 --- a/src/kaleidoscope/plugin/LED-Palette-Theme.cpp +++ b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp @@ -28,16 +28,16 @@ uint16_t LEDPaletteTheme::reserveThemes(uint8_t max_themes) { if (!palette_base_) palette_base_ = ::EEPROMSettings.requestSlice(16 * sizeof(cRGB)); - return ::EEPROMSettings.requestSlice(max_themes * KeyboardHardware.led_count / 2); + return ::EEPROMSettings.requestSlice(max_themes * Kaleidoscope.device().led_count / 2); } void LEDPaletteTheme::updateHandler(uint16_t theme_base, uint8_t theme) { if (!Kaleidoscope.has_leds) return; - uint16_t map_base = theme_base + (theme * KeyboardHardware.led_count / 2); + uint16_t map_base = theme_base + (theme * Kaleidoscope.device().led_count / 2); - for (uint8_t pos = 0; pos < KeyboardHardware.led_count; pos++) { + for (uint8_t pos = 0; pos < Kaleidoscope.device().led_count; pos++) { cRGB color = lookupColorAtPosition(map_base, pos); ::LEDControl.setCrgbAt(pos, color); } @@ -47,8 +47,8 @@ void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_ if (!Kaleidoscope.has_leds) return; - uint16_t map_base = theme_base + (theme * KeyboardHardware.led_count / 2); - uint8_t pos = KeyboardHardware.getLedIndex(key_addr); + uint16_t map_base = theme_base + (theme * Kaleidoscope.device().led_count / 2); + uint8_t pos = Kaleidoscope.device().getLedIndex(key_addr); cRGB color = lookupColorAtPosition(map_base, pos); ::LEDControl.setCrgbAt(key_addr, color); @@ -58,7 +58,7 @@ void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_ const uint8_t LEDPaletteTheme::lookupColorIndexAtPosition(uint16_t map_base, uint16_t position) { uint8_t color_index; - color_index = KeyboardHardware.storage().read(map_base + position / 2); + color_index = Kaleidoscope.storage().read(map_base + position / 2); if (position % 2) color_index &= ~0xf0; else @@ -76,7 +76,7 @@ const cRGB LEDPaletteTheme::lookupColorAtPosition(uint16_t map_base, uint16_t po const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) { cRGB color; - KeyboardHardware.storage().get(palette_base_ + color_index * sizeof(cRGB), color); + Kaleidoscope.storage().get(palette_base_ + color_index * sizeof(cRGB), color); color.r ^= 0xff; color.g ^= 0xff; color.b ^= 0xff; @@ -87,7 +87,7 @@ const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) { void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t position, uint8_t color_index) { uint8_t indexes; - indexes = KeyboardHardware.storage().read(map_base + position / 2); + indexes = Kaleidoscope.storage().read(map_base + position / 2); if (position % 2) { uint8_t other = indexes >> 4; indexes = (other << 4) + color_index; @@ -95,7 +95,7 @@ void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t pos uint8_t other = indexes & ~0xf0; indexes = (color_index << 4) + other; } - KeyboardHardware.storage().update(map_base + position / 2, indexes); + Kaleidoscope.storage().update(map_base + position / 2, indexes); } EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { @@ -129,7 +129,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { color.g ^= 0xff; color.b ^= 0xff; - KeyboardHardware.storage().put(palette_base_ + i * sizeof(color), color); + Kaleidoscope.storage().put(palette_base_ + i * sizeof(color), color); i++; } @@ -151,11 +151,11 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command, if (strcmp_P(command, expected_command) != 0) return EventHandlerResult::OK; - uint16_t max_index = (max_themes * KeyboardHardware.led_count) / 2; + uint16_t max_index = (max_themes * Kaleidoscope.device().led_count) / 2; if (::Focus.isEOL()) { for (uint16_t pos = 0; pos < max_index; pos++) { - uint8_t indexes = KeyboardHardware.storage().read(theme_base + pos); + uint8_t indexes = Kaleidoscope.storage().read(theme_base + pos); ::Focus.send((uint8_t)(indexes >> 4), indexes & ~0xf0); } @@ -171,7 +171,7 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command, uint8_t indexes = (idx1 << 4) + idx2; - KeyboardHardware.storage().update(theme_base + pos, indexes); + Kaleidoscope.storage().update(theme_base + pos, indexes); pos++; } diff --git a/src/kaleidoscope/plugin/LED-Stalker.h b/src/kaleidoscope/plugin/LED-Stalker.h index 47ad0263..66da6bbd 100644 --- a/src/kaleidoscope/plugin/LED-Stalker.h +++ b/src/kaleidoscope/plugin/LED-Stalker.h @@ -61,7 +61,7 @@ class StalkerEffect : public Plugin, const StalkerEffect *parent_; uint16_t step_start_time_; - uint8_t map_[KeyboardHardware.numKeys()]; + uint8_t map_[Kaleidoscope.device().numKeys()]; friend class StalkerEffect; }; diff --git a/src/kaleidoscope/plugin/LED-Wavepool.cpp b/src/kaleidoscope/plugin/LED-Wavepool.cpp index 1c24fe49..c97a6026 100644 --- a/src/kaleidoscope/plugin/LED-Wavepool.cpp +++ b/src/kaleidoscope/plugin/LED-Wavepool.cpp @@ -31,7 +31,7 @@ uint16_t WavepoolEffect::idle_timeout = 5000; // 5 seconds int16_t WavepoolEffect::ripple_hue = WavepoolEffect::rainbow_hue; // automatic hue // map native keyboard coordinates (16x4) into geometric space (14x5) -PROGMEM const uint8_t WavepoolEffect::TransientLEDMode::rc2pos[KeyboardHardware.numKeys()] = { +PROGMEM const uint8_t WavepoolEffect::TransientLEDMode::rc2pos[Kaleidoscope.device().numKeys()] = { 0, 1, 2, 3, 4, 5, 6, 59, 66, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 34, 60, 65, 35, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 48, 61, 64, 49, 36, 37, 38, 39, 40, 41, diff --git a/src/kaleidoscope/plugin/LED-Wavepool.h b/src/kaleidoscope/plugin/LED-Wavepool.h index c715e048..77cae328 100644 --- a/src/kaleidoscope/plugin/LED-Wavepool.h +++ b/src/kaleidoscope/plugin/LED-Wavepool.h @@ -66,7 +66,7 @@ class WavepoolEffect : public Plugin, uint8_t frames_since_event_; int8_t surface_[2][WP_WID * WP_HGT]; uint8_t page_; - static PROGMEM const uint8_t rc2pos[KeyboardHardware.numKeys()]; + static PROGMEM const uint8_t rc2pos[Kaleidoscope.device().numKeys()]; void raindrop(uint8_t x, uint8_t y, int8_t *page); uint8_t wp_rand(); diff --git a/src/kaleidoscope/plugin/LEDControl.cpp b/src/kaleidoscope/plugin/LEDControl.cpp index 4cf49bf3..52788754 100644 --- a/src/kaleidoscope/plugin/LEDControl.cpp +++ b/src/kaleidoscope/plugin/LEDControl.cpp @@ -96,31 +96,31 @@ void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) { } void LEDControl::set_all_leds_to(cRGB color) { - for (int8_t i = 0; i < LED_COUNT; i++) { + for (int8_t i = 0; i < Kaleidoscope.device().led_count; i++) { setCrgbAt(i, color); } } void LEDControl::setCrgbAt(int8_t led_index, cRGB crgb) { - KeyboardHardware.setCrgbAt(led_index, crgb); + Kaleidoscope.device().setCrgbAt(led_index, crgb); } void LEDControl::setCrgbAt(KeyAddr key_addr, cRGB color) { - KeyboardHardware.setCrgbAt(key_addr, color); + Kaleidoscope.device().setCrgbAt(key_addr, color); } cRGB LEDControl::getCrgbAt(int8_t led_index) { - return KeyboardHardware.getCrgbAt(led_index); + return Kaleidoscope.device().getCrgbAt(led_index); } cRGB LEDControl::getCrgbAt(KeyAddr key_addr) { - return KeyboardHardware.getCrgbAt(KeyboardHardware.getLedIndex(key_addr)); + return Kaleidoscope.device().getCrgbAt(Kaleidoscope.device().getLedIndex(key_addr)); } void LEDControl::syncLeds(void) { if (paused) return; - KeyboardHardware.syncLeds(); + Kaleidoscope.device().syncLeds(); } kaleidoscope::EventHandlerResult LEDControl::onSetup() { diff --git a/src/kaleidoscope/plugin/LEDEffect-Chase.cpp b/src/kaleidoscope/plugin/LEDEffect-Chase.cpp index 66ccfe82..15afceab 100644 --- a/src/kaleidoscope/plugin/LEDEffect-Chase.cpp +++ b/src/kaleidoscope/plugin/LEDEffect-Chase.cpp @@ -33,12 +33,12 @@ void LEDChaseEffect::TransientLEDMode::update(void) { int8_t pos2 = pos_ - (direction_ * parent_->distance_); // First, we turn off the LEDs that were turned on in the previous update. - // `pos_` is always in the valid range (0 <= pos_ < LED_COUNT), but after it + // `pos_` is always in the valid range (0 <= pos_ < Kaleidoscope.device().led_count), but after it // changes direction, for the first few updates, `pos2` will be out of bounds. // Since it's an unsigned integer, even when it would have a value below zero, // it underflows and so one test is good for both ends of the range. ::LEDControl.setCrgbAt(pos_, CRGB(0, 0, 0)); - if (pos2 < LED_COUNT) + if (pos2 < Kaleidoscope.device().led_count) ::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 0)); // Next, we adjust the red light's position. If the direction hasn't changed (the red @@ -46,20 +46,20 @@ void LEDChaseEffect::TransientLEDMode::update(void) { // one. If the new position puts it out of bounds, we reverse the direction, and bring // it back in bounds. When this happens, the blue light "jumps" behind the red one, and // will be out of bounds. The simplest way to do this is to assign it a value that is - // known to be invalid (LED_COUNT). + // known to be invalid (Kaleidoscope.device().led_count). pos_ += direction_; - if (pos_ < LED_COUNT && pos_ > 0) { + if (pos_ < Kaleidoscope.device().led_count && pos_ > 0) { pos2 += direction_; } else { direction_ = -direction_; pos_ += direction_; - pos2 = LED_COUNT; + pos2 = Kaleidoscope.device().led_count; } // Last, we turn on the LEDs at their new positions. As before, the blue light (pos2) is // only set if it's in the valid LED range. ::LEDControl.setCrgbAt(pos_, CRGB(255, 0, 0)); - if (pos2 < LED_COUNT) + if (pos2 < Kaleidoscope.device().led_count) ::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 255)); } diff --git a/src/kaleidoscope/plugin/MagicCombo.cpp b/src/kaleidoscope/plugin/MagicCombo.cpp index 44dbf8d0..934bee1c 100644 --- a/src/kaleidoscope/plugin/MagicCombo.cpp +++ b/src/kaleidoscope/plugin/MagicCombo.cpp @@ -34,12 +34,12 @@ EventHandlerResult MagicCombo::beforeReportingState() { if (comboKey == 0) break; - match &= KeyboardHardware.isKeyswitchPressed(comboKey); + match &= Kaleidoscope.device().isKeyswitchPressed(comboKey); if (!match) break; } - if (j != KeyboardHardware.pressedKeyswitchCount()) + if (j != Kaleidoscope.device().pressedKeyswitchCount()) match = false; if (match && Kaleidoscope.hasTimeExpired(start_time_, min_interval)) { diff --git a/src/kaleidoscope/plugin/Model01-TestMode.cpp b/src/kaleidoscope/plugin/Model01-TestMode.cpp index 46dc1387..9ab1fc21 100644 --- a/src/kaleidoscope/plugin/Model01-TestMode.cpp +++ b/src/kaleidoscope/plugin/Model01-TestMode.cpp @@ -33,10 +33,10 @@ constexpr uint8_t HELD = 3; constexpr uint8_t RELEASED = 0; EventHandlerResult TestMode::beforeReportingState() { - if (KeyboardHardware.isKeyswitchPressed(R0C0) && - KeyboardHardware.isKeyswitchPressed(R0C6) && - KeyboardHardware.isKeyswitchPressed(R3C6) && - KeyboardHardware.pressedKeyswitchCount() == 3) { + if (Kaleidoscope.device().isKeyswitchPressed(R0C0) && + Kaleidoscope.device().isKeyswitchPressed(R0C6) && + Kaleidoscope.device().isKeyswitchPressed(R3C6) && + Kaleidoscope.device().pressedKeyswitchCount() == 3) { run_tests(); } return EventHandlerResult::OK; @@ -44,13 +44,13 @@ EventHandlerResult TestMode::beforeReportingState() { void TestMode::waitForKeypress() { for (uint8_t temp = 0; temp < 8; temp++) { - KeyboardHardware.readMatrix(); + Kaleidoscope.device().readMatrix(); } while (1) { - KeyboardHardware.readMatrix(); - if (KeyboardHardware.isKeyswitchPressed(R3C6) - && KeyboardHardware.pressedKeyswitchCount() == 1 - && KeyboardHardware.previousLeftHandState.all == 0) { + Kaleidoscope.device().readMatrix(); + if (Kaleidoscope.device().isKeyswitchPressed(R3C6) + && Kaleidoscope.device().pressedKeyswitchCount() == 1 + && Kaleidoscope.device().previousLeftHandState.all == 0) { break; } } @@ -117,13 +117,13 @@ void TestMode::handleKeyEvent(side_data_t *side, keydata_t *oldState, keydata_t // If the key is held down if (keyState == HELD) { - KeyboardHardware.setCrgbAt(key_addr_col_shifted, green); + Kaleidoscope.device().setCrgbAt(key_addr_col_shifted, green); } else if (bitRead(side->badKeys, key_addr_col_shifted.toInt()) == 1) { // If we triggered chatter detection ever on this key - KeyboardHardware.setCrgbAt(key_addr_col_shifted, red); + Kaleidoscope.device().setCrgbAt(key_addr_col_shifted, red); } else if (keyState == TOGGLED_OFF) { // If the key was just released - KeyboardHardware.setCrgbAt(key_addr_col_shifted, blue); + Kaleidoscope.device().setCrgbAt(key_addr_col_shifted, blue); } } @@ -138,16 +138,16 @@ void TestMode::testMatrix() { // Clear out the key event buffer so we don't get messed up information from // taps during LED test mode. while (1) { - KeyboardHardware.readMatrix(); - if (KeyboardHardware.isKeyswitchPressed(R0C0) && - KeyboardHardware.isKeyswitchPressed(R0C6) && - KeyboardHardware.isKeyswitchPressed(R3C6) && - KeyboardHardware.pressedKeyswitchCount() == 3) { + Kaleidoscope.device().readMatrix(); + if (Kaleidoscope.device().isKeyswitchPressed(R0C0) && + Kaleidoscope.device().isKeyswitchPressed(R0C6) && + Kaleidoscope.device().isKeyswitchPressed(R3C6) && + Kaleidoscope.device().pressedKeyswitchCount() == 3) { break; } for (auto key_addr : KeyAddr::all()) { - handleKeyEvent(&left, &(KeyboardHardware.previousLeftHandState), &(KeyboardHardware.leftHandState), key_addr, 7); - handleKeyEvent(&right, &(KeyboardHardware.previousRightHandState), &(KeyboardHardware.rightHandState), key_addr, 15); + handleKeyEvent(&left, &(Kaleidoscope.device().previousLeftHandState), &(Kaleidoscope.device().leftHandState), key_addr, 7); + handleKeyEvent(&right, &(Kaleidoscope.device().previousRightHandState), &(Kaleidoscope.device().rightHandState), key_addr, 15); } ::LEDControl.syncLeds(); } @@ -159,13 +159,13 @@ void TestMode::toggle_programming_leds_on() { } void TestMode::run_tests() { - // KeyboardHardware.serialPort().println("Running tests"); + // Kaleidoscope.device().serialPort().println("Running tests"); toggle_programming_leds_on(); // Disable debouncing - KeyboardHardware.setKeyscanInterval(2); + Kaleidoscope.device().setKeyscanInterval(2); test_leds(); testMatrix(); - // KeyboardHardware.serialPort().println("Done running tests"); + // Kaleidoscope.device().serialPort().println("Done running tests"); } } diff --git a/src/kaleidoscope/plugin/TapDance.cpp b/src/kaleidoscope/plugin/TapDance.cpp index 30e7acbe..ad5c2c4e 100644 --- a/src/kaleidoscope/plugin/TapDance.cpp +++ b/src/kaleidoscope/plugin/TapDance.cpp @@ -38,7 +38,7 @@ void TapDance::interrupt(KeyAddr key_addr) { last_tap_dance_key_ = Key_NoKey; - KeyboardHardware.maskKey(key_addr); + Kaleidoscope.device().maskKey(key_addr); kaleidoscope::hid::sendKeyboardReport(); kaleidoscope::hid::releaseAllKeys(); @@ -118,8 +118,8 @@ EventHandlerResult TapDance::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, if (keyToggledOn(keyState)) interrupt(key_addr); - if (KeyboardHardware.isKeyMasked(key_addr)) { - KeyboardHardware.unMaskKey(key_addr); + if (Kaleidoscope.device().isKeyMasked(key_addr)) { + Kaleidoscope.device().unMaskKey(key_addr); return EventHandlerResult::EVENT_CONSUMED; } return EventHandlerResult::OK; diff --git a/src/kaleidoscope/plugin/TypingBreaks.cpp b/src/kaleidoscope/plugin/TypingBreaks.cpp index e3692bdf..3aef63a3 100644 --- a/src/kaleidoscope/plugin/TypingBreaks.cpp +++ b/src/kaleidoscope/plugin/TypingBreaks.cpp @@ -91,7 +91,7 @@ EventHandlerResult TypingBreaks::onKeyswitchEvent(Key &mapped_key, KeyAddr key_a // counters if need be. if (keyToggledOn(key_state)) { - if (key_addr.col() <= COLS / 2) + if (key_addr.col() <= Kaleidoscope.device().matrix_columns / 2) left_hand_keys_++; else right_hand_keys_++; @@ -107,12 +107,12 @@ EventHandlerResult TypingBreaks::onSetup() { // If idleTime is max, assume that EEPROM is uninitialized, and store the // defaults. uint32_t idle_time; - KeyboardHardware.storage().get(settings_base_, idle_time); + Kaleidoscope.storage().get(settings_base_, idle_time); if (idle_time == 0xffffffff) { - KeyboardHardware.storage().put(settings_base_, settings); + Kaleidoscope.storage().put(settings_base_, settings); } - KeyboardHardware.storage().get(settings_base_, settings); + Kaleidoscope.storage().get(settings_base_, settings); return EventHandlerResult::OK; } @@ -192,7 +192,7 @@ EventHandlerResult TypingBreaks::onFocusEvent(const char *command) { break; } - KeyboardHardware.storage().put(settings_base_, settings); + Kaleidoscope.storage().put(settings_base_, settings); return EventHandlerResult::EVENT_CONSUMED; } diff --git a/src/kaleidoscope_internal/device.cpp b/src/kaleidoscope_internal/device.cpp new file mode 100644 index 00000000..c86de8c1 --- /dev/null +++ b/src/kaleidoscope_internal/device.cpp @@ -0,0 +1,21 @@ +/* kaleidoscope_internal::device - Global device object for internal use + * Copyright (C) 2019 Keyboard.io, Inc. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#include + +namespace kaleidoscope_internal { +kaleidoscope::Device device; +} diff --git a/src/kaleidoscope_internal/device.h b/src/kaleidoscope_internal/device.h new file mode 100644 index 00000000..7ed95819 --- /dev/null +++ b/src/kaleidoscope_internal/device.h @@ -0,0 +1,21 @@ +/* kaleidoscope_internal::device - Global device object for internal use + * Copyright (C) 2019 Keyboard.io, Inc. + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free Software + * Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +#pragma once + +namespace kaleidoscope_internal { +extern kaleidoscope::Device device; +} From 4dcc23b82ff60943560958d86ecf5dddd3e10af0 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 6 Nov 2019 00:24:59 +0100 Subject: [PATCH 5/7] Deprecate a few older symbols `KeyboardHardware`, `ROWS`, `COLS`, and `LED_COUNT` have been deprecated. Signed-off-by: Gergely Nagy --- src/kaleidoscope/Kaleidoscope.h | 9 +++++---- src/kaleidoscope_internal/deprecations.h | 22 +++++++++++++++++++--- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/kaleidoscope/Kaleidoscope.h b/src/kaleidoscope/Kaleidoscope.h index 87fae103..eca0f9ae 100644 --- a/src/kaleidoscope/Kaleidoscope.h +++ b/src/kaleidoscope/Kaleidoscope.h @@ -39,8 +39,9 @@ void setup(); #include KALEIDOSCOPE_HARDWARE_H #include "kaleidoscope/device/key_indexes.h" #include "kaleidoscope_internal/device.h" +#include "kaleidoscope_internal/deprecations.h" -static constexpr kaleidoscope::Device &KeyboardHardware = kaleidoscope_internal::device; +static constexpr DEPRECATED(KEYBOARDHARDWARE) kaleidoscope::Device &KeyboardHardware = kaleidoscope_internal::device; #ifdef PER_KEY_DATA_STACKED #define KEYMAP_STACKED(...) { PER_KEY_DATA_STACKED(XXX, __VA_ARGS__) } @@ -50,9 +51,9 @@ static constexpr kaleidoscope::Device &KeyboardHardware = kaleidoscope_internal: #define KEYMAP(...) { PER_KEY_DATA(XXX, __VA_ARGS__) } #endif -static constexpr uint8_t ROWS = kaleidoscope_internal::device.matrix_rows; -static constexpr uint8_t COLS = kaleidoscope_internal::device.matrix_columns; -static constexpr uint8_t LED_COUNT = kaleidoscope_internal::device.led_count; +static constexpr DEPRECATED(ROWS) uint8_t ROWS = kaleidoscope_internal::device.matrix_rows; +static constexpr DEPRECATED(COLS) uint8_t COLS = kaleidoscope_internal::device.matrix_columns; +static constexpr DEPRECATED(LED_COUNT) uint8_t LED_COUNT = kaleidoscope_internal::device.led_count; #include "kaleidoscope/KeyAddr.h" #include "kaleidoscope/key_events.h" diff --git a/src/kaleidoscope_internal/deprecations.h b/src/kaleidoscope_internal/deprecations.h index 852e92c7..835a20f2 100644 --- a/src/kaleidoscope_internal/deprecations.h +++ b/src/kaleidoscope_internal/deprecations.h @@ -27,6 +27,22 @@ /* Messages */ -#define _DEPRECATED_MESSAGE_NAMED_HARDWARE __NL__ \ - "Named hardware objects are deprecated, please use `KeyboardHardware`\n" __NL__ \ - "instead." +#define _DEPRECATED_MESSAGE_NAMED_HARDWARE __NL__ \ + "Named hardware objects are deprecated, please use\n" __NL__ \ + "`Kaleidoscope.device()` instead." + +#define _DEPRECATED_MESSAGE_KEYBOARDHARDWARE \ + "`KeyboardHardware` is deprecated, please use\n" __NL__ \ + "`Kaleidoscope.device()` instead" + +#define _DEPRECATED_MESSAGE_ROWS \ + "The `ROWS` macro is deprecated, please use\n" __NL__ \ + "`Kaleidoscope.device().matrix_rows` instead." + +#define _DEPRECATED_MESSAGE_COLS \ + "The `COLS` macro is deprecated, please use \n" __NL__ \ + "`Kaleidoscope.device().matrix_columns` instead." + +#define _DEPRECATED_MESSAGE_LED_COUNT \ + "The `LED_COUNT` macro is deprecated, please use \n" __NL__ \ + "`Kaleidoscope.device().led_count` instead." From e6c25db24cb34f2a88c578737d34c0797c39c83d Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 5 Nov 2019 13:39:22 +0100 Subject: [PATCH 6/7] Model01-TestMode: Deprecate and turn into a no-op Deprecate Model01-TestMode, in favour of the newer HardwareTestMode plugin. We also turn it into a no-op, so that we don't need to update it for API changes coming in the near future. The Model01 example has been updated to use the newer HardwareTestMode instead. Signed-off-by: Gergely Nagy --- .../Devices/Keyboardio/Model01/Model01.ino | 25 ++- src/kaleidoscope/plugin/Model01-TestMode.cpp | 178 ------------------ src/kaleidoscope/plugin/Model01-TestMode.h | 24 +-- 3 files changed, 28 insertions(+), 199 deletions(-) delete mode 100644 src/kaleidoscope/plugin/Model01-TestMode.cpp diff --git a/examples/Devices/Keyboardio/Model01/Model01.ino b/examples/Devices/Keyboardio/Model01/Model01.ino index 775261c1..28625508 100644 --- a/examples/Devices/Keyboardio/Model01/Model01.ino +++ b/examples/Devices/Keyboardio/Model01/Model01.ino @@ -22,12 +22,13 @@ #include "Kaleidoscope-Macros.h" #include "Kaleidoscope-LEDControl.h" #include "Kaleidoscope-NumPad.h" +#include "Kaleidoscope-HardwareTestMode.h" +#include "Kaleidoscope-MagicCombo.h" #include "Kaleidoscope-LEDEffect-SolidColor.h" #include "Kaleidoscope-LEDEffect-Breathe.h" #include "Kaleidoscope-LEDEffect-Chase.h" #include "Kaleidoscope-LEDEffect-Rainbow.h" -#include "Kaleidoscope-Model01-TestMode.h" #define NUMPAD_KEYMAP 2 @@ -96,12 +97,30 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { return MACRO_NONE; } -KALEIDOSCOPE_INIT_PLUGINS(TestMode, +/** + * This enters the hardware test mode + */ +static void enterHardwareTestMode(uint8_t combo_index) { + HardwareTestMode.runTests(); +} + + +/** Magic combo list, a list of key combo and action pairs the firmware should + * recognise. + */ +USE_MAGIC_COMBOS({ + .action = enterHardwareTestMode, + // Left Fn + Prog + LED + .keys = { R3C6, R0C0, R0C6 } +}); + +KALEIDOSCOPE_INIT_PLUGINS(HardwareTestMode, LEDControl, LEDOff, solidRed, solidOrange, solidYellow, solidGreen, solidBlue, solidIndigo, solidViolet, LEDBreatheEffect, LEDRainbowEffect, LEDChaseEffect, NumPad, Macros, - MouseKeys); + MouseKeys, + MagicCombo); void setup() { Kaleidoscope.setup(); diff --git a/src/kaleidoscope/plugin/Model01-TestMode.cpp b/src/kaleidoscope/plugin/Model01-TestMode.cpp deleted file mode 100644 index 9ab1fc21..00000000 --- a/src/kaleidoscope/plugin/Model01-TestMode.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* Kaleidoscope-Model01-TestMode - A factory test mode for the Model 01. - * Copyright (C) 2017-2018 Keyboard.io, Inc. - * - * This program is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by the Free Software - * Foundation, version 3. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more - * details. - * - * You should have received a copy of the GNU General Public License along with - * this program. If not, see . - */ - -#ifndef KALEIDOSCOPE_VIRTUAL_BUILD - -#if ARDUINO_AVR_MODEL01 - -#include "Kaleidoscope.h" -#include "Kaleidoscope-Model01-TestMode.h" -#include "Kaleidoscope-LEDEffect-Rainbow.h" -#include "kaleidoscope_internal/LEDModeManager.h" - -namespace kaleidoscope { -namespace plugin { - -constexpr uint8_t CHATTER_CYCLE_LIMIT = 30; -constexpr uint8_t TOGGLED_OFF = 2; -constexpr uint8_t TOGGLED_ON = 1; -constexpr uint8_t HELD = 3; -constexpr uint8_t RELEASED = 0; - -EventHandlerResult TestMode::beforeReportingState() { - if (Kaleidoscope.device().isKeyswitchPressed(R0C0) && - Kaleidoscope.device().isKeyswitchPressed(R0C6) && - Kaleidoscope.device().isKeyswitchPressed(R3C6) && - Kaleidoscope.device().pressedKeyswitchCount() == 3) { - run_tests(); - } - return EventHandlerResult::OK; -} - -void TestMode::waitForKeypress() { - for (uint8_t temp = 0; temp < 8; temp++) { - Kaleidoscope.device().readMatrix(); - } - while (1) { - Kaleidoscope.device().readMatrix(); - if (Kaleidoscope.device().isKeyswitchPressed(R3C6) - && Kaleidoscope.device().pressedKeyswitchCount() == 1 - && Kaleidoscope.device().previousLeftHandState.all == 0) { - break; - } - } -} - -void TestMode::set_leds(cRGB color) { - ::LEDControl.set_all_leds_to(color); - ::LEDControl.syncLeds(); - waitForKeypress(); -} - -void TestMode::test_leds(void) { - constexpr cRGB red = CRGB(201, 0, 0); - constexpr cRGB blue = CRGB(0, 0, 201); - constexpr cRGB green = CRGB(0, 201, 0); - constexpr cRGB brightWhite = CRGB(160, 160, 160); - - // make all the LEDs bright red - set_leds(red); - // make all the LEDs bright green - set_leds(green); - // make all the LEDs bright blue - set_leds(blue); - // make all the LEDs bright white (1.6A) - set_leds(brightWhite); - - // This works under the assumption that LEDRainbowEffect - // has been registered with KALEIDOSCOPE_INIT_PLUGINS in - // the sketch. Otherwise LEDRainbowEffect would not be - // known to LEDControl. - // - ::LEDControl.activate(&::LEDRainbowEffect); - - // rainbow for 10 seconds - for (auto i = 0; i < 1000; i++) { - ::LEDControl.update(); - ::LEDControl.syncLeds(); - } - waitForKeypress(); -} - - - -void TestMode::handleKeyEvent(side_data_t *side, keydata_t *oldState, keydata_t *newState, KeyAddr key_addr, uint8_t col_offset) { - - constexpr cRGB red = CRGB(201, 0, 0); - constexpr cRGB blue = CRGB(0, 0, 201); - constexpr cRGB green = CRGB(0, 201, 0); - - auto keynum = key_addr.toInt(); - - const uint8_t keyState = ((bitRead(oldState->all, keynum) << 1) | - (bitRead(newState->all, keynum) << 0)); - if (keyState == TOGGLED_ON) { - if (side->cyclesSinceStateChange[keynum] < CHATTER_CYCLE_LIMIT) { - bitSet(side->badKeys, keynum); - } - side->cyclesSinceStateChange[keynum] = 0; - } else if (side->cyclesSinceStateChange[keynum] <= CHATTER_CYCLE_LIMIT) { - side->cyclesSinceStateChange[keynum]++; - } - - auto key_addr_col_shifted = KeyAddr(key_addr.row(), col_offset - key_addr.col()); - - // If the key is held down - if (keyState == HELD) { - Kaleidoscope.device().setCrgbAt(key_addr_col_shifted, green); - } else if (bitRead(side->badKeys, key_addr_col_shifted.toInt()) == 1) { - // If we triggered chatter detection ever on this key - Kaleidoscope.device().setCrgbAt(key_addr_col_shifted, red); - } else if (keyState == TOGGLED_OFF) { - // If the key was just released - Kaleidoscope.device().setCrgbAt(key_addr_col_shifted, blue); - } -} - - -void TestMode::testMatrix() { - // Reset bad keys from previous tests. - side_data_t left = {{0}, 0}; - side_data_t right = {{0}, 0}; - - - ::LEDControl.set_all_leds_to(200, 0, 0); - // Clear out the key event buffer so we don't get messed up information from - // taps during LED test mode. - while (1) { - Kaleidoscope.device().readMatrix(); - if (Kaleidoscope.device().isKeyswitchPressed(R0C0) && - Kaleidoscope.device().isKeyswitchPressed(R0C6) && - Kaleidoscope.device().isKeyswitchPressed(R3C6) && - Kaleidoscope.device().pressedKeyswitchCount() == 3) { - break; - } - for (auto key_addr : KeyAddr::all()) { - handleKeyEvent(&left, &(Kaleidoscope.device().previousLeftHandState), &(Kaleidoscope.device().leftHandState), key_addr, 7); - handleKeyEvent(&right, &(Kaleidoscope.device().previousRightHandState), &(Kaleidoscope.device().rightHandState), key_addr, 15); - } - ::LEDControl.syncLeds(); - } -} - -void TestMode::toggle_programming_leds_on() { - PORTD |= (1 << 5); - PORTB |= (1 << 0); -} - -void TestMode::run_tests() { - // Kaleidoscope.device().serialPort().println("Running tests"); - toggle_programming_leds_on(); - // Disable debouncing - Kaleidoscope.device().setKeyscanInterval(2); - test_leds(); - testMatrix(); - // Kaleidoscope.device().serialPort().println("Done running tests"); -} - -} -} - -kaleidoscope::plugin::TestMode TestMode; - -#endif - -#endif diff --git a/src/kaleidoscope/plugin/Model01-TestMode.h b/src/kaleidoscope/plugin/Model01-TestMode.h index 38a37c22..127c6bb1 100644 --- a/src/kaleidoscope/plugin/Model01-TestMode.h +++ b/src/kaleidoscope/plugin/Model01-TestMode.h @@ -24,30 +24,18 @@ #include #include "Kaleidoscope.h" +#include "kaleidoscope_internal/deprecations.h" + +#define _DEPRECATED_MESSAGE_MODEL01_TESTMODE \ + "The Model01-specific TestMode plugin has been deprecated in favour of\n" __NL__ \ + "the more generic HardwareTestMode. Please migrate to the new one." namespace kaleidoscope { namespace plugin { class TestMode : public kaleidoscope::Plugin { public: - typedef struct { - uint8_t cyclesSinceStateChange[32]; - uint32_t badKeys; - - } side_data_t; - - TestMode(void) {} - - EventHandlerResult beforeReportingState(); - - private: - static void run_tests(); - static void test_leds(); - static void testMatrix(); - static void toggle_programming_leds_on(); - static void handleKeyEvent(side_data_t *side, keydata_t *oldState, keydata_t *newState, KeyAddr key_addr, uint8_t col_offset); - static void waitForKeypress(); - static void set_leds(cRGB color); + DEPRECATED(MODEL01_TESTMODE) EventHandlerResult beforeReportingState() {}; }; } } From d4674d428d5762870dd58ce5c5c25bb84c6191a5 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 3 Nov 2019 10:27:47 +0100 Subject: [PATCH 7/7] examples: Simplify some of the examples Instead of using `Kaleidoscope.serialPort()` in every example, introduce a helper variable in some cases, to make the coder nicer to read. Signed-off-by: Gergely Nagy --- .../EEPROM/EEPROM-Settings/EEPROM-Settings.ino | 12 +++++++----- examples/Features/HostOS/HostOS.ino | 8 +++++--- examples/Keystrokes/Leader/Leader.ino | 6 ++++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/examples/Features/EEPROM/EEPROM-Settings/EEPROM-Settings.ino b/examples/Features/EEPROM/EEPROM-Settings/EEPROM-Settings.ino index 93d3eccd..81e3f3f6 100644 --- a/examples/Features/EEPROM/EEPROM-Settings/EEPROM-Settings.ino +++ b/examples/Features/EEPROM/EEPROM-Settings/EEPROM-Settings.ino @@ -42,16 +42,18 @@ KEYMAPS( KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings); void setup() { - Kaleidoscope.serialPort().begin(9600); + auto &serial_port = Kaleidoscope.serialPort(); + + serial_port.begin(9600); Kaleidoscope.setup(); - while (!Kaleidoscope.serialPort()) { + while (!serial_port) { } - Kaleidoscope.serialPort().println(EEPROMSettings.isValid() ? F("valid EEPROM settings") : F("invalid EEPROM settings")); - Kaleidoscope.serialPort().println(EEPROMSettings.crc(), HEX); - Kaleidoscope.serialPort().println(EEPROMSettings.version()); + serial_port.println(EEPROMSettings.isValid() ? F("valid EEPROM settings") : F("invalid EEPROM settings")); + serial_port.println(EEPROMSettings.crc(), HEX); + serial_port.println(EEPROMSettings.version()); } void loop() { diff --git a/examples/Features/HostOS/HostOS.ino b/examples/Features/HostOS/HostOS.ino index 575b2c6b..8803f9d7 100644 --- a/examples/Features/HostOS/HostOS.ino +++ b/examples/Features/HostOS/HostOS.ino @@ -43,12 +43,14 @@ KEYMAPS( KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, HostOS); void setup() { - Kaleidoscope.serialPort().begin(9600); + auto &serial_port = Kaleidoscope.serialPort(); + + serial_port.begin(9600); Kaleidoscope.setup(); - Kaleidoscope.serialPort().print("Host OS id is: "); - Kaleidoscope.serialPort().println(HostOS.os(), DEC); + serial_port.print("Host OS id is: "); + serial_port.println(HostOS.os(), DEC); } void loop() { diff --git a/examples/Keystrokes/Leader/Leader.ino b/examples/Keystrokes/Leader/Leader.ino index 90d4b72a..fc6f65c2 100644 --- a/examples/Keystrokes/Leader/Leader.ino +++ b/examples/Keystrokes/Leader/Leader.ino @@ -39,12 +39,14 @@ KEYMAPS( ) // *INDENT-ON* +auto &serial_port = Kaleidoscope.serialPort(); + static void leaderTestA(uint8_t seq_index) { - Kaleidoscope.serialPort().println(F("leaderTestA")); + serial_port.println(F("leaderTestA")); } static void leaderTestAA(uint8_t seq_index) { - Kaleidoscope.serialPort().println(F("leaderTestAA")); + serial_port.println(F("leaderTestAA")); } static const kaleidoscope::plugin::Leader::dictionary_t leader_dictionary[] PROGMEM =