From 1643829f9aca9995ca417b0d3ccd632293b36f16 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Fri, 16 Nov 2018 11:29:02 +0100 Subject: [PATCH] hardware::ATMegaKeyboard: Abstract away the data declarations Signed-off-by: Gergely Nagy --- src/kaleidoscope/hardware/ATMegaKeyboard.cpp | 3 +-- src/kaleidoscope/hardware/ATMegaKeyboard.h | 20 ++++++++++++++++--- src/kaleidoscope/hardware/olkb/Planck.cpp | 12 +---------- .../hardware/technomancy/Atreus.cpp | 13 +----------- 4 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/kaleidoscope/hardware/ATMegaKeyboard.cpp b/src/kaleidoscope/hardware/ATMegaKeyboard.cpp index 56e47a06..52dd1192 100644 --- a/src/kaleidoscope/hardware/ATMegaKeyboard.cpp +++ b/src/kaleidoscope/hardware/ATMegaKeyboard.cpp @@ -23,6 +23,7 @@ namespace kaleidoscope { namespace hardware { +bool ATMegaKeyboard::do_scan_; uint8_t ATMegaKeyboard::debounce = 3; void ATMegaKeyboard::setup(void) { @@ -137,8 +138,6 @@ bool ATMegaKeyboard::isKeyMasked(byte row, byte col) { return bitRead(KeyboardHardware.masks_[row], col); } -bool ATMegaKeyboard::do_scan_; - uint16_t ATMegaKeyboard::readCols() { uint16_t results = 0x00 ; for (uint8_t i = 0; i < KeyboardHardware.matrix_columns; i++) { diff --git a/src/kaleidoscope/hardware/ATMegaKeyboard.h b/src/kaleidoscope/hardware/ATMegaKeyboard.h index 0aba7203..d87a4cbd 100644 --- a/src/kaleidoscope/hardware/ATMegaKeyboard.h +++ b/src/kaleidoscope/hardware/ATMegaKeyboard.h @@ -38,17 +38,31 @@ struct cRGB { #define ROW_PIN_LIST(...) __VA_ARGS__ #define COL_PIN_LIST(...) __VA_ARGS__ -#define ATMEGA_KEYBOARD_CONFIG( ROW_PINS_, COL_PINS_) \ +#define ATMEGA_KEYBOARD_CONFIG(ROW_PINS_, COL_PINS_) \ static const int8_t matrix_rows = NUM_ARGS(ROW_PINS_); \ static const int8_t matrix_columns = NUM_ARGS(COL_PINS_); \ - static constexpr uint8_t matrix_row_pins[matrix_rows] = ROW_PINS_ ; \ - static constexpr uint8_t matrix_col_pins[matrix_columns] = COL_PINS_ ;\ + static constexpr uint8_t matrix_row_pins[matrix_rows] = ROW_PINS_; \ + static constexpr uint8_t matrix_col_pins[matrix_columns] = COL_PINS_; \ \ static uint16_t previousKeyState_[matrix_rows]; \ static uint16_t keyState_[matrix_rows]; \ static uint16_t masks_[matrix_rows]; \ static uint8_t debounce_matrix_[matrix_rows][matrix_columns]; +#define ATMEGA_KEYBOARD_DATA(BOARD) \ + const int8_t BOARD::matrix_rows; \ + const int8_t BOARD::matrix_columns; \ + constexpr uint8_t BOARD::matrix_row_pins[matrix_rows]; \ + constexpr uint8_t BOARD::matrix_col_pins[matrix_columns]; \ + uint16_t BOARD::previousKeyState_[matrix_rows]; \ + uint16_t BOARD::keyState_[matrix_rows]; \ + uint16_t BOARD::masks_[matrix_rows]; \ + uint8_t BOARD::debounce_matrix_[matrix_rows][matrix_columns]; \ + \ + ISR(TIMER1_OVF_vect) { \ + BOARD::do_scan_ = true; \ + } + namespace kaleidoscope { namespace hardware { class ATMegaKeyboard { diff --git a/src/kaleidoscope/hardware/olkb/Planck.cpp b/src/kaleidoscope/hardware/olkb/Planck.cpp index 3df528a1..5597171f 100644 --- a/src/kaleidoscope/hardware/olkb/Planck.cpp +++ b/src/kaleidoscope/hardware/olkb/Planck.cpp @@ -24,19 +24,9 @@ namespace kaleidoscope { namespace hardware { namespace olkb { -const int8_t Planck::matrix_rows; -const int8_t Planck::matrix_columns; -constexpr uint8_t Planck::matrix_row_pins[matrix_rows]; -constexpr uint8_t Planck::matrix_col_pins[matrix_columns]; +ATMEGA_KEYBOARD_DATA(Planck); constexpr int8_t Planck::led_count; -uint16_t Planck::previousKeyState_[matrix_rows]; -uint16_t Planck::keyState_[matrix_rows]; -uint16_t Planck::masks_[matrix_rows]; -uint8_t Planck::debounce_matrix_[matrix_rows][matrix_columns]; -ISR(TIMER1_OVF_vect) { - Planck::do_scan_ = true; -} } } } diff --git a/src/kaleidoscope/hardware/technomancy/Atreus.cpp b/src/kaleidoscope/hardware/technomancy/Atreus.cpp index 8a25b7f7..46b44af3 100644 --- a/src/kaleidoscope/hardware/technomancy/Atreus.cpp +++ b/src/kaleidoscope/hardware/technomancy/Atreus.cpp @@ -33,19 +33,8 @@ namespace kaleidoscope { namespace hardware { namespace technomancy { -const int8_t Atreus::matrix_rows; -const int8_t Atreus::matrix_columns; -constexpr uint8_t Atreus::matrix_row_pins[matrix_rows]; -constexpr uint8_t Atreus::matrix_col_pins[matrix_columns]; +ATMEGA_KEYBOARD_DATA(Atreus); constexpr int8_t Atreus::led_count; -uint16_t Atreus::previousKeyState_[matrix_rows]; -uint16_t Atreus::keyState_[matrix_rows]; -uint16_t Atreus::masks_[matrix_rows]; -uint8_t Atreus::debounce_matrix_[matrix_rows][matrix_columns]; - -ISR(TIMER1_OVF_vect) { - Atreus::do_scan_ = true; -} // Atreus-specific stuff