From 5b409b1da5a287b05a4bb2e21381065316e10bd2 Mon Sep 17 00:00:00 2001 From: Jesse Vincent Date: Wed, 25 Sep 2019 22:31:36 -0700 Subject: [PATCH] Move the keyscanner into the interrupt. This gets us a much more stable keyscan rate, which makes debouncing more accurate. Signed-off-by: Jesse Vincent --- src/kaleidoscope/hardware/ATMegaKeyboard.cpp | 6 ------ src/kaleidoscope/hardware/ATMegaKeyboard.h | 11 +++++------ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/kaleidoscope/hardware/ATMegaKeyboard.cpp b/src/kaleidoscope/hardware/ATMegaKeyboard.cpp index dcfe4681..c6aac7d5 100644 --- a/src/kaleidoscope/hardware/ATMegaKeyboard.cpp +++ b/src/kaleidoscope/hardware/ATMegaKeyboard.cpp @@ -24,7 +24,6 @@ namespace kaleidoscope { namespace hardware { -bool ATMegaKeyboard::do_scan_; uint8_t ATMegaKeyboard::debounce = 3; void ATMegaKeyboard::setup(void) { @@ -97,11 +96,6 @@ void __attribute__((optimize(3))) ATMegaKeyboard::actOnMatrixScan() { } void ATMegaKeyboard::scanMatrix() { - if (do_scan_) { - do_scan_ = false; - // We only want to update our matrix if the timer has expired. - KeyboardHardware.readMatrix(); - } // We ALWAYS want to tell Kaleidoscope about the state of the matrix KeyboardHardware.actOnMatrixScan(); } diff --git a/src/kaleidoscope/hardware/ATMegaKeyboard.h b/src/kaleidoscope/hardware/ATMegaKeyboard.h index cba751c0..5637dce4 100644 --- a/src/kaleidoscope/hardware/ATMegaKeyboard.h +++ b/src/kaleidoscope/hardware/ATMegaKeyboard.h @@ -113,9 +113,9 @@ struct cRGB { typedef MatrixAddr KeyAddr; \ \ static uint16_t previousKeyState_[matrix_rows]; \ - static uint16_t keyState_[matrix_rows]; \ + static volatile uint16_t keyState_[matrix_rows]; \ static uint16_t masks_[matrix_rows]; \ - static uint8_t debounce_matrix_[matrix_rows][matrix_columns]; \ + static volatile uint8_t debounce_matrix_[matrix_rows][matrix_columns]; \ \ ATMEGA_KEYBOARD_MATRIX_ACCESS_METHODS @@ -125,12 +125,12 @@ struct cRGB { 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]; \ + volatile uint16_t BOARD::keyState_[matrix_rows]; \ uint16_t BOARD::masks_[matrix_rows]; \ - uint8_t BOARD::debounce_matrix_[matrix_rows][matrix_columns]; \ + volatile uint8_t BOARD::debounce_matrix_[matrix_rows][matrix_columns]; \ \ ISR(TIMER1_OVF_vect) { \ - BOARD::do_scan_ = true; \ + KeyboardHardware.readMatrix(); \ } namespace kaleidoscope { @@ -150,7 +150,6 @@ class ATMegaKeyboard : public kaleidoscope::Hardware { uint8_t previousPressedKeyswitchCount(); - static bool do_scan_; protected: kaleidoscope::driver::mcu::ATMega32U4 mcu_;