]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - keyboards/ergodox_ez/matrix.c
Merge pull request #534 from willwm/teckinesis
[qmk_firmware.git] / keyboards / ergodox_ez / matrix.c
index e0de06c3492dbc2bf25ef1a36488a625ae634d2a..dc29cf5cd03c748433878b79ab3567acdd1ffedd 100644 (file)
@@ -27,7 +27,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include <stdint.h>
 #include <stdbool.h>
 #include <avr/io.h>
-#include <util/delay.h>
+#include "wait.h"
 #include "action_layer.h"
 #include "print.h"
 #include "debug.h"
@@ -39,6 +39,17 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #include  "timer.h"
 #endif
 
+/*
+ * This constant define not debouncing time in msecs, but amount of matrix
+ * scan loops which should be made to get stable debounced results.
+ *
+ * On Ergodox matrix scan rate is relatively low, because of slow I2C.
+ * Now it's only 317 scans/second, or about 3.15 msec/scan.
+ * According to Cherry specs, debouncing time is 5 msec.
+ *
+ * And so, there is no sense to have DEBOUNCE higher than 2.
+ */
+
 #ifndef DEBOUNCE
 #   define DEBOUNCE    5
 #endif
@@ -166,6 +177,7 @@ uint8_t matrix_scan(void)
 
     for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
         select_row(i);
+        wait_us(30);  // without this wait read unstable value.
         matrix_row_t cols = read_cols(i);
         if (matrix_debouncing[i] != cols) {
             matrix_debouncing[i] = cols;
@@ -179,7 +191,8 @@ uint8_t matrix_scan(void)
 
     if (debouncing) {
         if (--debouncing) {
-            _delay_ms(1);
+            wait_us(1);
+            // this should be wait_ms(1) but has been left as-is at EZ's request
         } else {
             for (uint8_t i = 0; i < MATRIX_ROWS; i++) {
                 matrix[i] = matrix_debouncing[i];
@@ -187,8 +200,7 @@ uint8_t matrix_scan(void)
         }
     }
 
-
-    matrix_scan_kb();
+    matrix_scan_quantum();
 
     return 1;
 }
@@ -268,7 +280,6 @@ static matrix_row_t read_cols(uint8_t row)
             return data;
         }
     } else {
-        _delay_us(30);  // without this wait read unstable value.
         // read from teensy
         return
             (PINF&(1<<0) ? 0 : (1<<0)) |