]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - tmk_core/common/bootmagic.c
Add ChibiOS support for QMK (#465)
[qmk_firmware.git] / tmk_core / common / bootmagic.c
index 2c1b1adfc5d6f86050f039139a81622c4c195ec7..90275a18ba7b3330b4bab770cf03a79f1c616300 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdint.h>
 #include <stdbool.h>
-#include <util/delay.h>
+#include "wait.h"
 #include "matrix.h"
 #include "bootloader.h"
 #include "debug.h"
@@ -10,6 +10,7 @@
 #include "eeconfig.h"
 #include "bootmagic.h"
 
+keymap_config_t keymap_config;
 
 void bootmagic(void)
 {
@@ -19,9 +20,9 @@ void bootmagic(void)
     }
 
     /* do scans in case of bounce */
-    print("boogmagic scan: ... ");
+    print("bootmagic scan: ... ");
     uint8_t scan = 100;
-    while (scan--) { matrix_scan(); _delay_ms(10); }
+    while (scan--) { matrix_scan(); wait_ms(10); }
     print("done.\n");
 
     /* bootmagic skip */
@@ -105,15 +106,13 @@ void bootmagic(void)
     }
 }
 
-static bool scan_keycode(uint8_t keycode)
-{
-    for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
+static bool scan_keycode(uint8_t keycode) {
+    for (int8_t r = MATRIX_ROWS - 1; r >= 0; --r) {
         matrix_row_t matrix_row = matrix_get_row(r);
-        for (uint8_t c = 0; c < MATRIX_COLS; c++) {
-            if (matrix_row & ((matrix_row_t)1<<c)) {
-                if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) {
-                    return true;
-                }
+        for (int8_t c = MATRIX_COLS - 1; c >= 0; --c) {
+            if (matrix_row & (matrix_row_t)1 << c) {
+                keypos_t key = (keypos_t){ .row = r, .col = c };
+                if (keycode == keymap_key_to_keycode(0, key)) return true;
             }
         }
     }