Mercurial > louis > kiibohd-controller
comparison Scan/MatrixARM/matrix_scan.c @ 299:c856f826bd49
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.
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Fri, 06 Mar 2015 22:18:15 -0800 |
parents | 57f40871c726 |
children | e464aaa4730f |
comparison
equal
deleted
inserted
replaced
298:39f84a603350 | 299:c856f826bd49 |
---|---|
24 // Compiler Includes | 24 // Compiler Includes |
25 #include <Lib/ScanLib.h> | 25 #include <Lib/ScanLib.h> |
26 | 26 |
27 // Project Includes | 27 // Project Includes |
28 #include <cli.h> | 28 #include <cli.h> |
29 #include <kll.h> | |
29 #include <led.h> | 30 #include <led.h> |
30 #include <print.h> | 31 #include <print.h> |
31 #include <macro.h> | 32 #include <macro.h> |
32 | 33 |
33 // Local Includes | 34 // Local Includes |
34 #include "matrix_scan.h" | 35 #include "matrix_scan.h" |
35 | 36 |
36 // Matrix Configuration | 37 // Matrix Configuration |
37 #include <matrix.h> | 38 #include <matrix.h> |
39 | |
40 | |
41 | |
42 // ----- Defines ----- | |
43 | |
44 #if ( DebounceThrottleDiv_define > 0 ) | |
45 nat_ptr_t Matrix_divCounter = 0; | |
46 #endif | |
38 | 47 |
39 | 48 |
40 | 49 |
41 // ----- Function Declarations ----- | 50 // ----- Function Declarations ----- |
42 | 51 |
230 | 239 |
231 // Scan the matrix for keypresses | 240 // Scan the matrix for keypresses |
232 // NOTE: scanNum should be reset to 0 after a USB send (to reset all the counters) | 241 // NOTE: scanNum should be reset to 0 after a USB send (to reset all the counters) |
233 void Matrix_scan( uint16_t scanNum ) | 242 void Matrix_scan( uint16_t scanNum ) |
234 { | 243 { |
244 #if ( DebounceThrottleDiv_define > 0 ) | |
245 // Scan-rate throttling | |
246 // By scanning using a divider, the scan rate slowed down | |
247 // DebounceThrottleDiv_define == 1 means -> /2 or half scan rate | |
248 // This helps with bouncy switches on fast uCs | |
249 if ( !( Matrix_divCounter++ & (1 << ( DebounceThrottleDiv_define - 1 )) ) ) | |
250 return; | |
251 #endif | |
252 | |
235 // Increment stats counters | 253 // Increment stats counters |
236 if ( scanNum > matrixMaxScans ) matrixMaxScans = scanNum; | 254 if ( scanNum > matrixMaxScans ) matrixMaxScans = scanNum; |
237 if ( scanNum == 0 ) | 255 if ( scanNum == 0 ) |
238 { | 256 { |
239 matrixPrevScans = matrixCurScans; | 257 matrixPrevScans = matrixCurScans; |