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.c50
1 files changed, 33 insertions, 17 deletions
diff --git a/tmk_core/common/bootmagic.c b/tmk_core/common/bootmagic.c
index cc780d17a..09b1664c9 100644
--- a/tmk_core/common/bootmagic.c
+++ b/tmk_core/common/bootmagic.c
@@ -16,8 +16,7 @@ keymap_config_t keymap_config;
16 * 16 *
17 * FIXME: needs doc 17 * FIXME: needs doc
18 */ 18 */
19void bootmagic(void) 19void bootmagic(void) {
20{
21 /* check signature */ 20 /* check signature */
22 if (!eeconfig_is_enabled()) { 21 if (!eeconfig_is_enabled()) {
23 eeconfig_init(); 22 eeconfig_init();
@@ -26,7 +25,10 @@ void bootmagic(void)
26 /* do scans in case of bounce */ 25 /* do scans in case of bounce */
27 print("bootmagic scan: ... "); 26 print("bootmagic scan: ... ");
28 uint8_t scan = 100; 27 uint8_t scan = 100;
29 while (scan--) { matrix_scan(); wait_ms(10); } 28 while (scan--) {
29 matrix_scan();
30 wait_ms(10);
31 }
30 print("done.\n"); 32 print("done.\n");
31 33
32 /* bootmagic skip */ 34 /* bootmagic skip */
@@ -89,14 +91,30 @@ void bootmagic(void)
89 91
90 /* default layer */ 92 /* default layer */
91 uint8_t default_layer = 0; 93 uint8_t default_layer = 0;
92 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) { default_layer |= (1<<0); } 94 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_0)) {
93 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) { default_layer |= (1<<1); } 95 default_layer |= (1 << 0);
94 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) { default_layer |= (1<<2); } 96 }
95 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_3)) { default_layer |= (1<<3); } 97 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_1)) {
96 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_4)) { default_layer |= (1<<4); } 98 default_layer |= (1 << 1);
97 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_5)) { default_layer |= (1<<5); } 99 }
98 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_6)) { default_layer |= (1<<6); } 100 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_2)) {
99 if (bootmagic_scan_keycode(BOOTMAGIC_KEY_DEFAULT_LAYER_7)) { default_layer |= (1<<7); } 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 }
100 if (default_layer) { 118 if (default_layer) {
101 eeconfig_update_default_layer(default_layer); 119 eeconfig_update_default_layer(default_layer);
102 default_layer_set((layer_state_t)default_layer); 120 default_layer_set((layer_state_t)default_layer);
@@ -110,13 +128,12 @@ void bootmagic(void)
110 * 128 *
111 * FIXME: needs doc 129 * FIXME: needs doc
112 */ 130 */
113static bool scan_keycode(uint8_t keycode) 131static bool scan_keycode(uint8_t keycode) {
114{
115 for (uint8_t r = 0; r < MATRIX_ROWS; r++) { 132 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
116 matrix_row_t matrix_row = matrix_get_row(r); 133 matrix_row_t matrix_row = matrix_get_row(r);
117 for (uint8_t c = 0; c < MATRIX_COLS; c++) { 134 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
118 if (matrix_row & ((matrix_row_t)1<<c)) { 135 if (matrix_row & ((matrix_row_t)1 << c)) {
119 if (keycode == keymap_key_to_keycode(0, (keypos_t){ .row = r, .col = c })) { 136 if (keycode == keymap_key_to_keycode(0, (keypos_t){.row = r, .col = c})) {
120 return true; 137 return true;
121 } 138 }
122 } 139 }
@@ -129,8 +146,7 @@ static bool scan_keycode(uint8_t keycode)
129 * 146 *
130 * FIXME: needs doc 147 * FIXME: needs doc
131 */ 148 */
132bool bootmagic_scan_keycode(uint8_t keycode) 149bool bootmagic_scan_keycode(uint8_t keycode) {
133{
134 if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false; 150 if (!scan_keycode(BOOTMAGIC_KEY_SALT)) return false;
135 151
136 return scan_keycode(keycode); 152 return scan_keycode(keycode);