]> git.donarmstrong.com Git - kiibohd-controller.git/blobdiff - Scan/MatrixARM/matrix_scan.c
Adding DebounceThrottleDiv define to slow down the debounce rate.
[kiibohd-controller.git] / Scan / MatrixARM / matrix_scan.c
index eaea368f4b01e6a8635879e4f9ba1b25e92ca3dc..85f82050f33cb4ef83ce08086af369d85db0ccc0 100644 (file)
@@ -26,6 +26,7 @@
 
 // Project Includes
 #include <cli.h>
+#include <kll.h>
 #include <led.h>
 #include <print.h>
 #include <macro.h>
 
 
 
+// ----- 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 )