From ae6daa0e5c070b6c5fe2616ca009b48887ef0edb Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Fri, 6 Mar 2015 22:18:15 -0800 Subject: [PATCH] Adding DebounceThrottleDiv define to slow down the debounce rate. By default: DebounceThrottleDiv = 0; This is the default infinity behaviour right now (may be changed in the future). Increasing DebounceThrottleDiv will increase the scan rate divider. DebounceThrottleDiv = 1; # Scans half as much DebounceThrottleDiv = 2; # Scans a quarter as much DebounceThrottleDiv = 3; # Scans an eigth as much etc. For ARM based uCs (like the Infinity) the maximum divider is 32. --- Scan/MatrixARM/capabilities.kll | 14 ++++++++++++++ Scan/MatrixARM/matrix_scan.c | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/Scan/MatrixARM/capabilities.kll b/Scan/MatrixARM/capabilities.kll index 319b81d..8221ec8 100644 --- a/Scan/MatrixARM/capabilities.kll +++ b/Scan/MatrixARM/capabilities.kll @@ -18,3 +18,17 @@ DebounceDivThreshold => DebounceDivThreshold_define; DebounceDivThreshold = 0xFFFF; # Default debounce #DebounceDivThreshold = 0xFFFFFFFF; # Max debounce +# This defines how often the matrix is scanned +# By, default the key matrix is scanned once per macro processing loop +# For fast uCs and bouncy switches, this can be non-ideal +# 0 - Bit-shift of 0 +# 1 - Bit-shift of 1 (i.e. divide by 2) +# 2 - Bit-shift of 2 (i.e. divide by 4) +# 3 - Bit-shift of 3 (i.e. divide by 8) +# etc. +# Depending on the architecture, this is either a maximum of 16 or 32 +# Increasing this value will increase switch latency +DebounceThrottleDiv => DebounceThrottleDiv_define; +DebounceThrottleDiv = 0; # Default +#DebounceThrottleDiv = 2; # /4 divider + diff --git a/Scan/MatrixARM/matrix_scan.c b/Scan/MatrixARM/matrix_scan.c index eaea368..85f8205 100644 --- a/Scan/MatrixARM/matrix_scan.c +++ b/Scan/MatrixARM/matrix_scan.c @@ -26,6 +26,7 @@ // Project Includes #include +#include #include #include #include @@ -38,6 +39,14 @@ +// ----- Defines ----- + +#if ( DebounceThrottleDiv_define > 0 ) +nat_ptr_t Matrix_divCounter = 0; +#endif + + + // ----- Function Declarations ----- // CLI Functions @@ -232,6 +241,15 @@ void Matrix_keyPositionDebug( KeyPosition pos ) // NOTE: scanNum should be reset to 0 after a USB send (to reset all the counters) void Matrix_scan( uint16_t scanNum ) { +#if ( DebounceThrottleDiv_define > 0 ) + // Scan-rate throttling + // By scanning using a divider, the scan rate slowed down + // DebounceThrottleDiv_define == 1 means -> /2 or half scan rate + // This helps with bouncy switches on fast uCs + if ( !( Matrix_divCounter++ & (1 << ( DebounceThrottleDiv_define - 1 )) ) ) + return; +#endif + // Increment stats counters if ( scanNum > matrixMaxScans ) matrixMaxScans = scanNum; if ( scanNum == 0 )