5 #include "bootloader.h"
9 #include "action_layer.h"
11 #include "bootmagic.h"
13 keymap_config_t keymap_config;
22 if (!eeconfig_is_enabled()) {
26 /* do scans in case of bounce */
27 print("bootmagic scan: ... ");
29 while (scan--) { matrix_scan(); wait_ms(10); }
33 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
38 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
43 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) {
48 debug_config.raw = eeconfig_read_debug();
49 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
50 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
51 debug_config.matrix = !debug_config.matrix;
52 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
53 debug_config.keyboard = !debug_config.keyboard;
54 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
55 debug_config.mouse = !debug_config.mouse;
57 debug_config.enable = !debug_config.enable;
60 eeconfig_update_debug(debug_config.raw);
63 keymap_config.raw = eeconfig_read_keymap();
64 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
65 keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
67 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
68 keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
70 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
71 keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
73 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
74 keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
76 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
77 keymap_config.no_gui = !keymap_config.no_gui;
79 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
80 keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
82 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
83 keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
85 if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) {
86 keymap_config.nkro = !keymap_config.nkro;
88 eeconfig_update_keymap(keymap_config.raw);
91 uint8_t default_layer = 0;
92 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); }
93 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); }
94 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); }
95 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); }
96 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); }
97 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); }
98 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); }
99 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); }
101 eeconfig_update_default_layer(default_layer);
102 default_layer_set((uint32_t)default_layer);
104 default_layer = eeconfig_read_default_layer();
105 default_layer_set((uint32_t)default_layer);
109 /** \brief Scan Keycode
113 static bool scan_keycode(uint8_t keycode)
115 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
116 matrix_row_t matrix_row = matrix_get_row(r);
117 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
118 if (matrix_row & ((matrix_row_t)1<<c)) {
119 if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) {
128 /** \brief Bootmagic Scan Keycode
132 bool bootmagic_scan_keycode(uint8_t keycode)
134 if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
136 return scan_keycode(keycode);