3 #include <util/delay.h>
5 #include "bootloader.h"
15 if (!eeconfig_is_enabled()) {
19 /* do scans in case of bounce */
21 while (scan--) { matrix_scan(); _delay_ms(10); }
24 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
29 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
34 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) {
39 debug_config.raw = eeconfig_read_debug();
40 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
41 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
42 debug_config.matrix = !debug_config.matrix;
43 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
44 debug_config.keyboard = !debug_config.keyboard;
45 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
46 debug_config.mouse = !debug_config.mouse;
48 debug_config.enable = !debug_config.enable;
51 eeconfig_write_debug(debug_config.raw);
54 keymap_config.raw = eeconfig_read_keymap();
55 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CPASLOCK)) {
56 keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
58 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
59 keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
61 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
62 keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
64 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
65 keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
67 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
68 keymap_config.no_gui = !keymap_config.no_gui;
70 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
71 keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
73 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
74 keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
76 eeconfig_write_keymap(keymap_config.raw);
79 uint8_t default_layer = 0;
80 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
81 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); }
82 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); }
83 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); }
84 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); }
85 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); }
86 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); }
87 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
89 eeconfig_write_default_layer(default_layer);
90 default_layer_set((uint32_t)default_layer);
92 default_layer = eeconfig_read_default_layer();
93 default_layer_set((uint32_t)default_layer);
97 bool bootmagic_scan_keycode(uint8_t keycode)
99 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
100 matrix_row_t matrix_row = matrix_get_row(r);
101 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
102 if (matrix_row & ((matrix_row_t)1<<c)) {
103 if (keycode == keymap_key_to_keycode(0, (key_t){ .row = r, .col = c })) {