aboutsummaryrefslogtreecommitdiff
path: root/common/bootmagic.c
diff options
context:
space:
mode:
Diffstat (limited to 'common/bootmagic.c')
-rw-r--r--common/bootmagic.c71
1 files changed, 48 insertions, 23 deletions
diff --git a/common/bootmagic.c b/common/bootmagic.c
index 388099e2e..716f5d956 100644
--- a/common/bootmagic.c
+++ b/common/bootmagic.c
@@ -2,53 +2,78 @@
2#include <stdbool.h> 2#include <stdbool.h>
3#include <util/delay.h> 3#include <util/delay.h>
4#include "matrix.h" 4#include "matrix.h"
5#include "bootloader.h"
6#include "debug.h"
5#include "keymap.h" 7#include "keymap.h"
6#include "eeconfig.h" 8#include "eeconfig.h"
7#include "bootloader.h"
8#include "bootmagic.h" 9#include "bootmagic.h"
9 10
10 11
11void bootmagic(void) 12void bootmagic(void)
12{ 13{
13 if (!BOOTMAGIC_IS_ENABLED()) { return; } 14 /* check signature */
15 if (!eeconfig_is_enabled()) {
16 eeconfig_init();
17 }
14 18
15 /* do scans in case of bounce */ 19 /* do scans in case of bounce */
16 uint8_t scan = 100; 20 uint8_t scan = 100;
17 while (scan--) { matrix_scan(); _delay_ms(1); } 21 while (scan--) { matrix_scan(); _delay_ms(10); }
18 22
19 if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) { 23 /* bootmagic skip */
20 bootloader_jump(); 24 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
25 return;
21 } 26 }
22 27
23 if (bootmagic_scan_keycode(BOOTMAGIC_DEBUG_ENABLE_KEY)) { 28 /* eeconfig clear */
24 eeconfig_write_debug(eeconfig_read_debug() ^ EECONFIG_DEBUG_ENABLE); 29 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
30 eeconfig_init();
25 } 31 }
26 32
27 if (bootmagic_scan_keycode(BOOTMAGIC_EEPROM_CLEAR_KEY)) { 33 /* bootloader */
28 eeconfig_init(); 34 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) {
35 bootloader_jump();
36 }
37
38 /* debug enable */
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;
47 } else {
48 debug_config.enable = !debug_config.enable;
49 }
29 } 50 }
51 eeconfig_write_debug(debug_config.raw);
30 52
31 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_CONTROL_CPASLOCK)) { 53 /* keymap config */
32 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_CONTROL_CAPSLOCK); 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;
33 } 57 }
34 if (bootmagic_scan_keycode(BOOTMAGIC_CAPSLOCK_TO_CONTROL)) { 58 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
35 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_CAPSLOCK_TO_CONTROL); 59 keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
36 } 60 }
37 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_LALT_LGUI)) { 61 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
38 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_LALT_LGUI); 62 keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
39 } 63 }
40 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_RALT_RGUI)) { 64 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
41 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_RALT_RGUI); 65 keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
42 } 66 }
43 if (bootmagic_scan_keycode(BOOTMAGIC_NO_GUI)) { 67 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
44 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_NO_GUI); 68 keymap_config.no_gui = !keymap_config.no_gui;
45 } 69 }
46 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_GRAVE_ESC)) { 70 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
47 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_GRAVE_ESC); 71 keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
48 } 72 }
49 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE)) { 73 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
50 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE); 74 keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
51 } 75 }
76 eeconfig_write_keymap(keymap_config.raw);
52} 77}
53 78
54bool bootmagic_scan_keycode(uint8_t keycode) 79bool bootmagic_scan_keycode(uint8_t keycode)