5 #include "bootloader.h"
9 #include "action_layer.h"
11 #include "bootmagic.h"
13 keymap_config_t keymap_config;
18 if (!eeconfig_is_enabled()) {
22 /* do scans in case of bounce */
23 print("bootmagic scan: ... ");
25 while (scan--) { matrix_scan(); wait_ms(10); }
29 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
34 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
39 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) {
44 debug_config.raw = eeconfig_read_debug();
45 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
46 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
47 debug_config.matrix = !debug_config.matrix;
48 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
49 debug_config.keyboard = !debug_config.keyboard;
50 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
51 debug_config.mouse = !debug_config.mouse;
53 debug_config.enable = !debug_config.enable;
56 eeconfig_update_debug(debug_config.raw);
59 keymap_config.raw = eeconfig_read_keymap();
60 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
61 keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
63 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
64 keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
66 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
67 keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
69 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
70 keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
72 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
73 keymap_config.no_gui = !keymap_config.no_gui;
75 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
76 keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
78 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
79 keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
81 if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) {
82 keymap_config.nkro = !keymap_config.nkro;
84 eeconfig_update_keymap(keymap_config.raw);
87 uint8_t default_layer = 0;
88 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
89 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); }
90 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); }
91 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); }
92 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); }
93 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); }
94 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); }
95 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
97 eeconfig_update_default_layer(default_layer);
98 default_layer_set((uint32_t)default_layer);
100 default_layer = eeconfig_read_default_layer();
101 default_layer_set((uint32_t)default_layer);
105 static bool scan_keycode(uint8_t keycode)
107 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
108 matrix_row_t matrix_row = matrix_get_row(r);
109 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
110 if (matrix_row & ((matrix_row_t)1<<c)) {
111 if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) {
120 bool bootmagic_scan_keycode(uint8_t keycode)
122 if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
124 return scan_keycode(keycode);