]> git.gir.st - tmk_keyboard.git/blob - common/bootmagic.c
Fix debug parameter setting in eeconfig
[tmk_keyboard.git] / common / bootmagic.c
1 #include <stdint.h>
2 #include <stdbool.h>
3 #include <util/delay.h>
4 #include "matrix.h"
5 #include "keymap.h"
6 #include "eeconfig.h"
7 #include "bootloader.h"
8 #include "bootmagic.h"
9
10
11 void bootmagic(void)
12 {
13 if (!BOOTMAGIC_IS_ENABLED()) { return; }
14
15 /* do scans in case of bounce */
16 uint8_t scan = 100;
17 while (scan--) { matrix_scan(); _delay_ms(1); }
18
19 if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) {
20 bootloader_jump();
21 }
22
23 if (bootmagic_scan_keycode(BOOTMAGIC_DEBUG_ENABLE_KEY)) {
24 eeconfig_write_debug(eeconfig_read_debug() ^ EECONFIG_DEBUG_ENABLE);
25 }
26
27 if (bootmagic_scan_keycode(BOOTMAGIC_EEPROM_CLEAR_KEY)) {
28 eeconfig_init();
29 }
30
31 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_CONTROL_CPASLOCK)) {
32 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_CONTROL_CAPSLOCK);
33 }
34 if (bootmagic_scan_keycode(BOOTMAGIC_CAPSLOCK_TO_CONTROL)) {
35 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_CAPSLOCK_TO_CONTROL);
36 }
37 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_LALT_LGUI)) {
38 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_LALT_LGUI);
39 }
40 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_RALT_RGUI)) {
41 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_RALT_RGUI);
42 }
43 if (bootmagic_scan_keycode(BOOTMAGIC_NO_GUI)) {
44 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_NO_GUI);
45 }
46 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_GRAVE_ESC)) {
47 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_GRAVE_ESC);
48 }
49 if (bootmagic_scan_keycode(BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE)) {
50 eeconfig_write_keyconf(eeconfig_read_keyconf() ^ EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE);
51 }
52 }
53
54 bool bootmagic_scan_keycode(uint8_t keycode)
55 {
56 for (uint8_t r = 0; r < MATRIX_ROWS; r++) {
57 matrix_row_t matrix_row = matrix_get_row(r);
58 for (uint8_t c = 0; c < MATRIX_COLS; c++) {
59 if (matrix_row & ((matrix_row_t)1<<c)) {
60 if (keycode == keymap_key_to_keycode(0, (key_t){ .row = r, .col = c })) {
61 return true;
62 }
63 }
64 }
65 }
66 return false;
67 }
Imprint / Impressum