diff --git a/plugins/Kaleidoscope-Hardware-GD32-Eval/src/kaleidoscope/device/gd32/eval/KeyScanner.cpp b/plugins/Kaleidoscope-Hardware-GD32-Eval/src/kaleidoscope/device/gd32/eval/KeyScanner.cpp index d95efafd..147259fb 100644 --- a/plugins/Kaleidoscope-Hardware-GD32-Eval/src/kaleidoscope/device/gd32/eval/KeyScanner.cpp +++ b/plugins/Kaleidoscope-Hardware-GD32-Eval/src/kaleidoscope/device/gd32/eval/KeyScanner.cpp @@ -117,6 +117,32 @@ void KeyScanner::actOnMatrixScan() { } } +bool KeyScanner::isKeyswitchPressed(KeyAddr key_addr) { + return (bitRead(matrix_state_[key_addr.col()].current, key_addr.row()) != 0); +} + +uint8_t KeyScanner::pressedKeyswitchCount() { + uint8_t count = 0; + + for (int8_t c = 0; c < _KeyScannerProps::matrix_columns; c++) { + count += __builtin_popcount(matrix_state_[r].current); + } + return count; +} + +bool KeyScanner::wasKeyswitchPressed(KeyAddr key_addr) { + return (bitRead(matrix_state_[key_addr.col()].previous, key_addr.row()) != 0); +} + +uint8_t KeyScanner::previousPressedKeyswitchCount() { + uint8_t count = 0; + + for (int8_t c = 0; c < _KeyScannerProps::matrix_columns; c++) { + count += __builtin_popcount(matrix_state_[r].previous); + } + return count; +} + } // namespace eval } // namespace gd32 } // namespace device diff --git a/plugins/Kaleidoscope-Hardware-GD32-Eval/src/kaleidoscope/device/gd32/eval/KeyScanner.h b/plugins/Kaleidoscope-Hardware-GD32-Eval/src/kaleidoscope/device/gd32/eval/KeyScanner.h index 650f6b27..ab3a6268 100644 --- a/plugins/Kaleidoscope-Hardware-GD32-Eval/src/kaleidoscope/device/gd32/eval/KeyScanner.h +++ b/plugins/Kaleidoscope-Hardware-GD32-Eval/src/kaleidoscope/device/gd32/eval/KeyScanner.h @@ -48,23 +48,11 @@ class KeyScanner: public kaleidoscope::driver::keyscanner::Base static void readMatrix(); static void actOnMatrixScan(); - static bool isKeyswitchPressed(KeyAddr key_addr) { - //return bitRead(keyState, key_addr.col()); - return false; - } - static uint8_t pressedKeyswitchCount() { - //return __builtin_popcount(keyState); - return 0; - } - - static bool wasKeyswitchPressed(KeyAddr key_addr) { - //return bitRead(previousKeyState, key_addr.col()); - return false; - } - static uint8_t previousPressedKeyswitchCount() { - //return __builtin_popcount(previousKeyState); - return 0; - } + static bool isKeyswitchPressed(KeyAddr key_addr); + static uint8_t pressedKeyswitchCount(); + + static bool wasKeyswitchPressed(KeyAddr key_addr); + static uint8_t previousPressedKeyswitchCount(); private: /* each of these variables are storing the state for a row of keys