5 #include "bootloader.h"
10 #include "action_layer.h"
12 #include "bootmagic.h"
14 keymap_config_t keymap_config;
19 if (!eeconfig_is_enabled()) {
23 /* do scans in case of bounce */
24 print("bootmagic scan: ... ");
26 while (scan--) { matrix_scan(); wait_ms(10); }
30 if (bootmagic_scan_key(BOOTMAGIC_KEY_SKIP)) {
35 if (bootmagic_scan_key(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
40 if (bootmagic_scan_key(BOOTMAGIC_KEY_BOOTLOADER)) {
45 debug_config.raw = eeconfig_read_debug();
46 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
47 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
48 debug_config.matrix = !debug_config.matrix;
49 } else if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
50 debug_config.keyboard = !debug_config.keyboard;
51 } else if (bootmagic_scan_key(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
52 debug_config.mouse = !debug_config.mouse;
54 debug_config.enable = !debug_config.enable;
57 eeconfig_write_debug(debug_config.raw);
60 keymap_config.raw = eeconfig_read_keymap();
61 if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
62 keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
64 if (bootmagic_scan_key(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
65 keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
67 if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
68 keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
70 if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
71 keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
73 if (bootmagic_scan_key(BOOTMAGIC_KEY_NO_GUI)) {
74 keymap_config.no_gui = !keymap_config.no_gui;
76 if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
77 keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
79 if (bootmagic_scan_key(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
80 keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
82 if (bootmagic_scan_key(BOOTMAGIC_HOST_NKRO)) {
83 keymap_config.nkro = !keymap_config.nkro;
85 eeconfig_write_keymap(keymap_config.raw);
88 keyboard_nkro = keymap_config.nkro;
92 uint8_t default_layer = 0;
93 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
94 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); }
95 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); }
96 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); }
97 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); }
98 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); }
99 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); }
100 if (bootmagic_scan_key(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
102 eeconfig_write_default_layer(default_layer);
103 default_layer_set((uint32_t)default_layer);
105 default_layer = eeconfig_read_default_layer();
106 default_layer_set((uint32_t)default_layer);
110 static bool scan_key(uint16_t code)
112 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
113 matrix_row_t matrix_row = matrix_get_row(r);
114 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
115 if (matrix_row & ((matrix_row_t)1<<c)) {
116 // read key from Layer 0
117 action_t action = action_for_key(0, (keypos_t){ .row = r, .col = c });
118 if (action.code == code ||
119 ((action.kind.id == ACT_LMODS ||
120 action.kind.id == ACT_RMODS ||
121 action.kind.id == ACT_LMODS_TAP ||
122 action.kind.id == ACT_RMODS_TAP ||
123 action.kind.id == ACT_LAYER_TAP ||
124 action.kind.id == ACT_LAYER_TAP_EXT) &&
125 action.key.code == code)) {
134 bool bootmagic_scan_key(uint16_t code)
136 if (!scan_key(BOOTMAGIC_KEY_SALT)) return false;
138 return scan_key(code);