3 #include <util/delay.h>
5 #include "bootloader.h"
9 #include "action_layer.h"
11 #include "bootmagic.h"
17 if (!eeconfig_is_enabled()) {
21 /* do scans in case of bounce */
22 print("bootmagic scan: ... ");
24 while (scan--) { matrix_scan(); _delay_ms(10); }
28 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
33 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
38 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) {
43 debug_config.raw = eeconfig_read_debug();
44 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
45 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
46 debug_config.matrix = !debug_config.matrix;
47 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
48 debug_config.keyboard = !debug_config.keyboard;
49 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
50 debug_config.mouse = !debug_config.mouse;
52 debug_config.enable = !debug_config.enable;
55 eeconfig_write_debug(debug_config.raw);
58 keymap_config.raw = eeconfig_read_keymap();
59 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
60 keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
62 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
63 keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
65 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
66 keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
68 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
69 keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
71 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
72 keymap_config.no_gui = !keymap_config.no_gui;
74 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
75 keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
77 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
78 keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
80 if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) {
81 keymap_config.nkro = !keymap_config.nkro;
83 eeconfig_write_keymap(keymap_config.raw);
86 keyboard_nkro = keymap_config.nkro;
90 uint8_t default_layer = 0;
91 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
92 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); }
93 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); }
94 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); }
95 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); }
96 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); }
97 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); }
98 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
100 eeconfig_write_default_layer(default_layer);
101 default_layer_set((uint32_t)default_layer);
103 default_layer = eeconfig_read_default_layer();
104 default_layer_set((uint32_t)default_layer);
108 static bool scan_keycode(uint8_t keycode)
110 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
111 matrix_row_t matrix_row = matrix_get_row(r);
112 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
113 if (matrix_row & ((matrix_row_t)1<<c)) {
114 if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) {
123 bool bootmagic_scan_keycode(uint8_t keycode)
125 if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
127 return scan_keycode(keycode);