aboutsummaryrefslogtreecommitdiff
path: root/tmk_core/common/bootmagic.c
diff options
context:
space:
mode:
Diffstat (limited to 'tmk_core/common/bootmagic.c')
-rw-r--r--tmk_core/common/bootmagic.c163
1 files changed, 0 insertions, 163 deletions
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
deleted file mode 100644
index c1b3adf94..000000000
--- a/tmk_core/common/bootmagic.c
+++ /dev/null
@@ -1,163 +0,0 @@
1#include <stdint.h>
2#include <stdbool.h>
3#include "wait.h"
4#include "matrix.h"
5#include "bootloader.h"
6#include "debug.h"
7#include "keymap.h"
8#include "host.h"
9#include "action_layer.h"
10#include "eeconfig.h"
11#include "bootmagic.h"
12
13keymap_config_t keymap_config;
14
15/** \brief Bootmagic
16 *
17 * FIXME: needs doc
18 */
19void bootmagic(void) {
20 /* check signature */
21 if (!eeconfig_is_enabled()) {
22 eeconfig_init();
23 }
24
25 /* do scans in case of bounce */
26 print("bootmagic scan: ... ");
27 uint8_t scan = 100;
28 while (scan--) {
29 matrix_scan();
30 wait_ms(10);
31 }
32 print("done.\n");
33
34 /* bootmagic skip */
35 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SKIP)) {
36 return;
37 }
38
39 /* eeconfig clear */
40 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) {
41 eeconfig_init();
42 }
43
44 /* bootloader */
45 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_BOOTLOADER)) {
46 bootloader_jump();
47 }
48
49 /* debug enable */
50 debug_config.raw = eeconfig_read_debug();
51 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_ENABLE)) {
52 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MATRIX)) {
53 debug_config.matrix = !debug_config.matrix;
54 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_KEYBOARD)) {
55 debug_config.keyboard = !debug_config.keyboard;
56 } else if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEBUG_MOUSE)) {
57 debug_config.mouse = !debug_config.mouse;
58 } else {
59 debug_config.enable = !debug_config.enable;
60 }
61 }
62 eeconfig_update_debug(debug_config.raw);
63
64 /* keymap config */
65 keymap_config.raw = eeconfig_read_keymap();
66 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_CONTROL_CAPSLOCK)) {
67 keymap_config.swap_control_capslock = !keymap_config.swap_control_capslock;
68 }
69 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL)) {
70 keymap_config.capslock_to_control = !keymap_config.capslock_to_control;
71 }
72 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_LALT_LGUI)) {
73 keymap_config.swap_lalt_lgui = !keymap_config.swap_lalt_lgui;
74 }
75 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_RALT_RGUI)) {
76 keymap_config.swap_ralt_rgui = !keymap_config.swap_ralt_rgui;
77 }
78 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_NO_GUI)) {
79 keymap_config.no_gui = !keymap_config.no_gui;
80 }
81 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_GRAVE_ESC)) {
82 keymap_config.swap_grave_esc = !keymap_config.swap_grave_esc;
83 }
84 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE)) {
85 keymap_config.swap_backslash_backspace = !keymap_config.swap_backslash_backspace;
86 }
87 if (bootmagic_scan_keycode(BOOTMAGIC_HOST_NKRO)) {
88 keymap_config.nkro = !keymap_config.nkro;
89 }
90 eeconfig_update_keymap(keymap_config.raw);
91
92 /* default layer */
93 uint8_t default_layer = 0;
94 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) {
95 default_layer |= (1 << 0);
96 }
97 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) {
98 default_layer |= (1 << 1);
99 }
100 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) {
101 default_layer |= (1 << 2);
102 }
103 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) {
104 default_layer |= (1 << 3);
105 }
106 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) {
107 default_layer |= (1 << 4);
108 }
109 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) {
110 default_layer |= (1 << 5);
111 }
112 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) {
113 default_layer |= (1 << 6);
114 }
115 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) {
116 default_layer |= (1 << 7);
117 }
118 if (default_layer) {
119 eeconfig_update_default_layer(default_layer);
120 default_layer_set((layer_state_t)default_layer);
121 } else {
122 default_layer = eeconfig_read_default_layer();
123 default_layer_set((layer_state_t)default_layer);
124 }
125 /* Also initialize layer state to trigger callback functions for layer_state */
126 layer_state_set_kb((layer_state_t)layer_state);
127
128 /* EE_HANDS handedness */
129 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_LEFT)) {
130 eeconfig_update_handedness(true);
131 }
132 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EE_HANDS_RIGHT)) {
133 eeconfig_update_handedness(false);
134 }
135}
136
137/** \brief Scan Keycode
138 *
139 * FIXME: needs doc
140 */
141static bool scan_keycode(uint8_t keycode) {
142 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
143 matrix_row_t matrix_row = matrix_get_row(r);
144 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
145 if (matrix_row & ((matrix_row_t)1 << c)) {
146 if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) {
147 return true;
148 }
149 }
150 }
151 }
152 return false;
153}
154
155/** \brief Bootmagic Scan Keycode
156 *
157 * FIXME: needs doc
158 */
159bool bootmagic_scan_keycode(uint8_t keycode) {
160 if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
161
162 return scan_keycode(keycode);
163}