aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-04-07 15:36:50 +0900
committertmk <nobody@nowhere>2013-04-07 15:36:50 +0900
commit4e93b3fa67d3b8170de2f05322738e08ac17948e (patch)
tree46b5191bd9e6c591bc13e05aa97a0454f30b1897
parent78fd5a715464e72df08bcf683ca45b63c2df490f (diff)
downloadqmk_firmware-4e93b3fa67d3b8170de2f05322738e08ac17948e.tar.gz
qmk_firmware-4e93b3fa67d3b8170de2f05322738e08ac17948e.zip
Fix bootmagic and eeconfig for virtual DIP SW
-rw-r--r--README.md23
-rw-r--r--common.mk1
-rw-r--r--common/bootmagic.c71
-rw-r--r--common/bootmagic.h78
-rw-r--r--common/command.c48
-rw-r--r--common/debug.c8
-rw-r--r--common/debug.h24
-rw-r--r--common/eeconfig.c9
-rw-r--r--common/eeconfig.h58
-rw-r--r--common/keyboard.c12
-rw-r--r--common/keymap.c64
-rw-r--r--common/keymap.h19
12 files changed, 246 insertions, 169 deletions
diff --git a/README.md b/README.md
index 998d99a00..eccb1bd77 100644
--- a/README.md
+++ b/README.md
@@ -106,6 +106,8 @@ Following commands can be also executed with `Magic` + key. In console mode `Mag
106 v: print device version & info 106 v: print device version & info
107 t: print timer count 107 t: print timer count
108 s: print status 108 s: print status
109 e: print eeprom config
110 n: toggle NKRO
109 0/F10: switch to Layer0 111 0/F10: switch to Layer0
110 1/F1: switch to Layer1 112 1/F1: switch to Layer1
111 2/F2: switch to Layer2 113 2/F2: switch to Layer2
@@ -117,13 +119,24 @@ Following commands can be also executed with `Magic` + key. In console mode `Mag
117 119
118**TBD** 120**TBD**
119 121
120### Conguration with Boot Magic 122### Boot Magic Configuration - Virtual DIP Switch
121Boot Magic are executed during boot up time. Press Magic key below then pulgin keyboard cable. 123Boot Magic are executed during boot up time. Press Magic key below then pulgin keyboard cable.
122These settings are stored in EEPROM. 124Note that you must use keys of **Layer 0** as Magic keys. These settings are stored in EEPROM so that retain your configure over power cycles.
123 125
126#### EEPROM
127- Skip reading EEPROM(`ESC`)
124- Clear configuration stored in EEPROM(`Backspace`) 128- Clear configuration stored in EEPROM(`Backspace`)
129
130#### Bootloader
125- Kick up Bootloader(`B`) 131- Kick up Bootloader(`B`)
132
133#### Debug
126- Debug enable(`D`) 134- Debug enable(`D`)
135- Debug matrix enable(`D`+`X`)
136- Debug keyboard enable(`D`+`K`)
137- Debug mouse enable(`D`+`M`)
138
139#### Keymap
127- Swap Control and CapsLock(`Left Control`) 140- Swap Control and CapsLock(`Left Control`)
128- Change CapsLock to Control(`Casp Lock`) 141- Change CapsLock to Control(`Casp Lock`)
129- Swap LeftAlt and Gui(`Left Alt`) 142- Swap LeftAlt and Gui(`Left Alt`)
@@ -132,6 +145,12 @@ These settings are stored in EEPROM.
132- Swap Grave and Escape(`Grave`) 145- Swap Grave and Escape(`Grave`)
133- Swap BackSlash and BackSpace(`Back Slash`) 146- Swap BackSlash and BackSpace(`Back Slash`)
134 147
148#### Default Layer
149- Set Default Layer to 0(`0`)
150- Set Default Layer to 0(`1`)
151- Set Default Layer to 0(`2`)
152- Set Default Layer to 0(`3`)
153
135**TBD** 154**TBD**
136 155
137 156
diff --git a/common.mk b/common.mk
index 6759e6ef9..810f802c6 100644
--- a/common.mk
+++ b/common.mk
@@ -9,7 +9,6 @@ SRC += $(COMMON_DIR)/host.c \
9 $(COMMON_DIR)/keymap.c \ 9 $(COMMON_DIR)/keymap.c \
10 $(COMMON_DIR)/timer.c \ 10 $(COMMON_DIR)/timer.c \
11 $(COMMON_DIR)/print.c \ 11 $(COMMON_DIR)/print.c \
12 $(COMMON_DIR)/debug.c \
13 $(COMMON_DIR)/bootloader.c \ 12 $(COMMON_DIR)/bootloader.c \
14 $(COMMON_DIR)/suspend.c \ 13 $(COMMON_DIR)/suspend.c \
15 $(COMMON_DIR)/util.c 14 $(COMMON_DIR)/util.c
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)
diff --git a/common/bootmagic.h b/common/bootmagic.h
index 5791b221f..2e7496ebc 100644
--- a/common/bootmagic.h
+++ b/common/bootmagic.h
@@ -2,71 +2,45 @@
2#define BOOTMAGIC_H 2#define BOOTMAGIC_H
3 3
4 4
5#ifndef BOOTMAGIC_IS_ENABLED 5#ifndef BOOTMAGIC_KEY_SKIP
6#define BOOTMAGIC_IS_ENABLED() true 6#define BOOTMAGIC_KEY_SKIP KC_ESC
7#endif
8
9/* eeprom clear */
10#ifndef BOOTMAGIC_KEY_EEPROM_CLEAR
11#define BOOTMAGIC_KEY_EEPROM_CLEAR KC_BSPACE
7#endif 12#endif
8 13
9/* kick up bootloader */ 14/* kick up bootloader */
10#ifndef BOOTMAGIC_BOOTLOADER_KEY 15#ifndef BOOTMAGIC_KEY_BOOTLOADER
11#define BOOTMAGIC_BOOTLOADER_KEY KC_B 16#define BOOTMAGIC_KEY_BOOTLOADER KC_B
12#endif 17#endif
18
13/* debug enable */ 19/* debug enable */
14#ifndef BOOTMAGIC_DEBUG_ENABLE_KEY 20#define BOOTMAGIC_KEY_DEBUG_ENABLE KC_D
15#define BOOTMAGIC_DEBUG_ENABLE_KEY KC_D 21#define BOOTMAGIC_KEY_DEBUG_MATRIX KC_X
16#endif 22#define BOOTMAGIC_KEY_DEBUG_KEYBOARD KC_K
17/* eeprom clear */ 23#define BOOTMAGIC_KEY_DEBUG_MOUSE KC_M
18#ifndef BOOTMAGIC_EEPROM_CLEAR_KEY
19#define BOOTMAGIC_EEPROM_CLEAR_KEY KC_BSPACE
20#endif
21 24
22/* 25/*
23 * key configure 26 * keymap config
24 */ 27 */
25/* swap control and capslock */ 28#define BOOTMAGIC_KEY_SWAP_CONTROL_CPASLOCK KC_LCTRL
26#ifndef BOOTMAGIC_SWAP_CONTROL_CPASLOCK 29#define BOOTMAGIC_KEY_CAPSLOCK_TO_CONTROL KC_CAPSLOCK
27#define BOOTMAGIC_SWAP_CONTROL_CPASLOCK KC_LCTRL 30#define BOOTMAGIC_KEY_SWAP_LALT_LGUI KC_LALT
28#endif 31#define BOOTMAGIC_KEY_SWAP_RALT_RGUI KC_RALT
29/* capslock to control */ 32#define BOOTMAGIC_KEY_NO_GUI KC_LGUI
30#ifndef BOOTMAGIC_CAPSLOCK_TO_CONTROL 33#define BOOTMAGIC_KEY_SWAP_GRAVE_ESC KC_GRAVE
31#define BOOTMAGIC_CAPSLOCK_TO_CONTROL KC_CAPSLOCK 34#define BOOTMAGIC_KEY_SWAP_BACKSLASH_BACKSPACE KC_BSLASH
32#endif
33/* swap alt and gui */
34#ifndef BOOTMAGIC_SWAP_LALT_LGUI
35#define BOOTMAGIC_SWAP_LALT_LGUI KC_LALT
36#endif
37/* swap alt and gui */
38#ifndef BOOTMAGIC_SWAP_RALT_RGUI
39#define BOOTMAGIC_SWAP_RALT_RGUI KC_RALT
40#endif
41/* no gui */
42#ifndef BOOTMAGIC_NO_GUI
43#define BOOTMAGIC_NO_GUI KC_LGUI
44#endif
45/* swap esc and grave */
46#ifndef BOOTMAGIC_SWAP_GRAVE_ESC
47#define BOOTMAGIC_SWAP_GRAVE_ESC KC_GRAVE
48#endif
49/* swap backslash and backspace */
50#ifndef BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE
51#define BOOTMAGIC_SWAP_BACKSLASH_BACKSPACE KC_BSLASH
52#endif
53 35
54 36
55/* 37/*
56 * change default layer 38 * change default layer
57 */ 39 */
58#ifndef BOOTMAGIC_DEFAULT_LAYER_0_KEY 40#define BOOTMAGIC_KEY_DEFAULT_LAYER_0 KC_0
59#define BOOTMAGIC_DEFAULT_LAYER_0_KEY KC_0 41#define BOOTMAGIC_KEY_DEFAULT_LAYER_1 KC_1
60#endif 42#define BOOTMAGIC_KEY_DEFAULT_LAYER_2 KC_2
61#ifndef BOOTMAGIC_DEFAULT_LAYER_1_KEY 43#define BOOTMAGIC_KEY_DEFAULT_LAYER_3 KC_3
62#define BOOTMAGIC_DEFAULT_LAYER_1_KEY KC_1
63#endif
64#ifndef BOOTMAGIC_DEFAULT_LAYER_2_KEY
65#define BOOTMAGIC_DEFAULT_LAYER_2_KEY KC_2
66#endif
67#ifndef BOOTMAGIC_DEFAULT_LAYER_3_KEY
68#define BOOTMAGIC_DEFAULT_LAYER_3_KEY KC_3
69#endif
70 44
71 45
72void bootmagic(void); 46void bootmagic(void);
diff --git a/common/command.c b/common/command.c
index 3a1fcb186..216ad0612 100644
--- a/common/command.c
+++ b/common/command.c
@@ -110,7 +110,7 @@ static void command_common_help(void)
110 print("v: print device version & info\n"); 110 print("v: print device version & info\n");
111 print("t: print timer count\n"); 111 print("t: print timer count\n");
112 print("s: print status\n"); 112 print("s: print status\n");
113 print("e: print eeprom boot config\n"); 113 print("e: print eeprom config\n");
114#ifdef NKRO_ENABLE 114#ifdef NKRO_ENABLE
115 print("n: toggle NKRO\n"); 115 print("n: toggle NKRO\n");
116#endif 116#endif
@@ -125,28 +125,28 @@ static void command_common_help(void)
125} 125}
126 126
127#ifdef BOOTMAGIC_ENABLE 127#ifdef BOOTMAGIC_ENABLE
128static void print_eeprom_config(void) 128static void print_eeconfig(void)
129{ 129{
130 uint8_t eebyte; 130 print("default_layer: "); print_dec(eeconfig_read_defalt_layer()); print("\n");
131 131
132 eebyte = eeconfig_read_debug(); 132 debug_config_t dc;
133 print("debug: "); print_hex8(eebyte); print("\n"); 133 dc.raw = eeconfig_read_debug();
134 134 print("debug_config.raw: "); print_hex8(dc.raw); print("\n");
135 eebyte = eeconfig_read_defalt_layer(); 135 print(".enable: "); print_dec(dc.enable); print("\n");
136 print("defalt_layer: "); print_hex8(eebyte); print("\n"); 136 print(".matrix: "); print_dec(dc.matrix); print("\n");
137 137 print(".keyboard: "); print_dec(dc.keyboard); print("\n");
138 eebyte = eeconfig_read_keyconf(); 138 print(".mouse: "); print_dec(dc.mouse); print("\n");
139 print("keyconf: "); print_hex8(eebyte); print("\n"); 139
140 140 keymap_config_t kc;
141 keyconf kc; 141 kc.raw = eeconfig_read_keymap();
142 kc = (keyconf){ .raw = eebyte }; 142 print("keymap_config.raw: "); print_hex8(kc.raw); print("\n");
143 print("keyconf.swap_control_capslock: "); print_hex8(kc.swap_control_capslock); print("\n"); 143 print(".swap_control_capslock: "); print_dec(kc.swap_control_capslock); print("\n");
144 print("keyconf.capslock_to_control: "); print_hex8(kc.capslock_to_control); print("\n"); 144 print(".capslock_to_control: "); print_dec(kc.capslock_to_control); print("\n");
145 print("keyconf.swap_lalt_lgui: "); print_hex8(kc.swap_lalt_lgui); print("\n"); 145 print(".swap_lalt_lgui: "); print_dec(kc.swap_lalt_lgui); print("\n");
146 print("keyconf.swap_ralt_rgui: "); print_hex8(kc.swap_ralt_rgui); print("\n"); 146 print(".swap_ralt_rgui: "); print_dec(kc.swap_ralt_rgui); print("\n");
147 print("keyconf.no_gui: "); print_hex8(kc.no_gui); print("\n"); 147 print(".no_gui: "); print_dec(kc.no_gui); print("\n");
148 print("keyconf.swap_grave_esc: "); print_hex8(kc.swap_grave_esc); print("\n"); 148 print(".swap_grave_esc: "); print_dec(kc.swap_grave_esc); print("\n");
149 print("keyconf.swap_backslash_backspace: "); print_hex8(kc.swap_backslash_backspace); print("\n"); 149 print(".swap_backslash_backspace: "); print_dec(kc.swap_backslash_backspace); print("\n");
150} 150}
151#endif 151#endif
152 152
@@ -162,8 +162,8 @@ static bool command_common(uint8_t code)
162 break; 162 break;
163#ifdef BOOTMAGIC_ENABLE 163#ifdef BOOTMAGIC_ENABLE
164 case KC_E: 164 case KC_E:
165 print("eeprom config\n"); 165 print("eeconfig:\n");
166 print_eeprom_config(); 166 print_eeconfig();
167 break; 167 break;
168#endif 168#endif
169 case KC_CAPSLOCK: 169 case KC_CAPSLOCK:
diff --git a/common/debug.c b/common/debug.c
deleted file mode 100644
index e406d39b0..000000000
--- a/common/debug.c
+++ /dev/null
@@ -1,8 +0,0 @@
1#include <stdbool.h>
2#include "debug.h"
3
4
5bool debug_enable = false;
6bool debug_matrix = false;
7bool debug_keyboard = false;
8bool debug_mouse = false;
diff --git a/common/debug.h b/common/debug.h
index e16ea14af..cac682703 100644
--- a/common/debug.h
+++ b/common/debug.h
@@ -79,10 +79,26 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
79extern "C" { 79extern "C" {
80#endif 80#endif
81 81
82extern bool debug_enable; 82
83extern bool debug_matrix; 83/* NOTE: Not portable. Bit field order depends on implementation */
84extern bool debug_keyboard; 84typedef union {
85extern bool debug_mouse; 85 uint8_t raw;
86 struct {
87 bool enable:1;
88 bool matrix:1;
89 bool keyboard:1;
90 bool mouse:1;
91 uint8_t reserved:4;
92 };
93} debug_config_t;
94debug_config_t debug_config;
95
96/* for backward compatibility */
97#define debug_enable (debug_config.enable)
98#define debug_matrix (debug_config.matrix)
99#define debug_keyboard (debug_config.keyboard)
100#define debug_mouse (debug_config.mouse)
101
86 102
87#ifdef __cplusplus 103#ifdef __cplusplus
88} 104}
diff --git a/common/eeconfig.c b/common/eeconfig.c
index cea3810ee..0481d4b9c 100644
--- a/common/eeconfig.c
+++ b/common/eeconfig.c
@@ -3,13 +3,12 @@
3#include <avr/eeprom.h> 3#include <avr/eeprom.h>
4#include "eeconfig.h" 4#include "eeconfig.h"
5 5
6
7void eeconfig_init(void) 6void eeconfig_init(void)
8{ 7{
9 eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); 8 eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
10 eeprom_write_byte(EECONFIG_DEBUG, 0); 9 eeprom_write_byte(EECONFIG_DEBUG, 0);
11 eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0); 10 eeprom_write_byte(EECONFIG_DEFAULT_LAYER, 0);
12 eeprom_write_byte(EECONFIG_KEYCONF, 0); 11 eeprom_write_byte(EECONFIG_KEYMAP, 0);
13 eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); 12 eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
14} 13}
15 14
@@ -25,7 +24,7 @@ void eeconfig_disable(void)
25 24
26bool eeconfig_is_enabled(void) 25bool eeconfig_is_enabled(void)
27{ 26{
28 return EECONFIG_IS_ENABLED() && (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); 27 return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
29} 28}
30 29
31uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } 30uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
@@ -34,5 +33,5 @@ void eeconfig_write_debug(uint8_t val) { eeprom_write_byte(EECONFIG_DEBUG, val);
34uint8_t eeconfig_read_defalt_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); } 33uint8_t eeconfig_read_defalt_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
35void eeconfig_write_defalt_layer(uint8_t val) { eeprom_write_byte(EECONFIG_DEFAULT_LAYER, val); } 34void eeconfig_write_defalt_layer(uint8_t val) { eeprom_write_byte(EECONFIG_DEFAULT_LAYER, val); }
36 35
37uint8_t eeconfig_read_keyconf(void) { return eeprom_read_byte(EECONFIG_KEYCONF); } 36uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); }
38void eeconfig_write_keyconf(uint8_t val) { eeprom_write_byte(EECONFIG_KEYCONF, val); } 37void eeconfig_write_keymap(uint8_t val) { eeprom_write_byte(EECONFIG_KEYMAP, val); }
diff --git a/common/eeconfig.h b/common/eeconfig.h
index 3e195478b..526cee783 100644
--- a/common/eeconfig.h
+++ b/common/eeconfig.h
@@ -20,50 +20,32 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
20 20
21#include <stdint.h> 21#include <stdint.h>
22 22
23#ifndef EECONFIG_IS_ENABLED
24#define EECONFIG_IS_ENABLED() true
25#endif
26 23
27#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED 24#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED
28 25
29/* eeprom parameteter address */ 26/* eeprom parameteter address */
30#define EECONFIG_MAGIC (uint16_t *)0 27#define EECONFIG_MAGIC (uint16_t *)0
31#define EECONFIG_DEBUG (uint8_t *)2 28#define EECONFIG_DEBUG (uint8_t *)2
32#define EECONFIG_DEFAULT_LAYER (uint8_t *)3 29#define EECONFIG_DEFAULT_LAYER (uint8_t *)3
33#define EECONFIG_KEYCONF (uint8_t *)4 30#define EECONFIG_KEYMAP (uint8_t *)4
34#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5 31#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5
35 32
36 33
37/* debug bit */ 34/* debug bit */
38#define EECONFIG_DEBUG_ENABLE (1<<0) 35#define EECONFIG_DEBUG_ENABLE (1<<0)
39#define EECONFIG_DEBUG_MATRIX (1<<1) 36#define EECONFIG_DEBUG_MATRIX (1<<1)
40#define EECONFIG_DEBUG_KEYBOARD (1<<2) 37#define EECONFIG_DEBUG_KEYBOARD (1<<2)
41#define EECONFIG_DEBUG_MOUSE (1<<3) 38#define EECONFIG_DEBUG_MOUSE (1<<3)
42 39
43/* keyconf bit */ 40/* keyconf bit */
44#define EECONFIG_KEYCONF_SWAP_CONTROL_CAPSLOCK (1<<0) 41#define EECONFIG_KEYMAP_SWAP_CONTROL_CAPSLOCK (1<<0)
45#define EECONFIG_KEYCONF_CAPSLOCK_TO_CONTROL (1<<1) 42#define EECONFIG_KEYMAP_CAPSLOCK_TO_CONTROL (1<<1)
46#define EECONFIG_KEYCONF_SWAP_LALT_LGUI (1<<2) 43#define EECONFIG_KEYMAP_SWAP_LALT_LGUI (1<<2)
47#define EECONFIG_KEYCONF_SWAP_RALT_RGUI (1<<3) 44#define EECONFIG_KEYMAP_SWAP_RALT_RGUI (1<<3)
48#define EECONFIG_KEYCONF_NO_GUI (1<<4) 45#define EECONFIG_KEYMAP_NO_GUI (1<<4)
49#define EECONFIG_KEYCONF_SWAP_GRAVE_ESC (1<<5) 46#define EECONFIG_KEYMAP_SWAP_GRAVE_ESC (1<<5)
50#define EECONFIG_KEYCONF_SWAP_BACKSLASH_BACKSPACE (1<<6) 47#define EECONFIG_KEYMAP_SWAP_BACKSLASH_BACKSPACE (1<<6)
51 48
52
53/* XXX: Not portable. Bit field order depends on implementation */
54typedef union {
55 uint8_t raw;
56 struct {
57 bool swap_control_capslock:1;
58 bool capslock_to_control:1;
59 bool swap_lalt_lgui:1;
60 bool swap_ralt_rgui:1;
61 bool no_gui:1;
62 bool swap_grave_esc:1;
63 bool swap_backslash_backspace:1;
64 bool reserved:1;
65 };
66} keyconf;
67 49
68bool eeconfig_is_enabled(void); 50bool eeconfig_is_enabled(void);
69 51
@@ -79,7 +61,7 @@ void eeconfig_write_debug(uint8_t val);
79uint8_t eeconfig_read_defalt_layer(void); 61uint8_t eeconfig_read_defalt_layer(void);
80void eeconfig_write_defalt_layer(uint8_t val); 62void eeconfig_write_defalt_layer(uint8_t val);
81 63
82uint8_t eeconfig_read_keyconf(void); 64uint8_t eeconfig_read_keymap(void);
83void eeconfig_write_keyconf(uint8_t val); 65void eeconfig_write_keymap(uint8_t val);
84 66
85#endif 67#endif
diff --git a/common/keyboard.c b/common/keyboard.c
index cb0dc06e6..6bc6fae6e 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -64,18 +64,6 @@ void keyboard_init(void)
64 64
65#ifdef BOOTMAGIC_ENABLE 65#ifdef BOOTMAGIC_ENABLE
66 bootmagic(); 66 bootmagic();
67
68 if (eeconfig_is_enabled()) {
69 uint8_t config;
70 config = eeconfig_read_debug();
71 // ignored if debug is enabled by program before.
72 if (!debug_enable) debug_enable = (config & EECONFIG_DEBUG_ENABLE);
73 if (!debug_matrix) debug_matrix = (config & EECONFIG_DEBUG_MATRIX);
74 if (!debug_keyboard) debug_keyboard = (config & EECONFIG_DEBUG_KEYBOARD);
75 if (!debug_mouse) debug_mouse = (config & EECONFIG_DEBUG_MOUSE);
76 } else {
77 eeconfig_init();
78 }
79#endif 67#endif
80} 68}
81 69
diff --git a/common/keymap.c b/common/keymap.c
index 572d922c6..8e2b8607c 100644
--- a/common/keymap.c
+++ b/common/keymap.c
@@ -34,6 +34,70 @@ action_t action_for_key(uint8_t layer, key_t key)
34 switch (keycode) { 34 switch (keycode) {
35 case KC_FN0 ... KC_FN31: 35 case KC_FN0 ... KC_FN31:
36 return keymap_fn_to_action(keycode); 36 return keymap_fn_to_action(keycode);
37#ifdef BOOTMAGIC_ENABLE
38 case KC_CAPSLOCK:
39 if (keymap_config.swap_control_capslock || keymap_config.capslock_to_control) {
40 return keycode_to_action(KC_LCTL);
41 }
42 return keycode_to_action(KC_CAPS);
43 case KC_LCTL:
44 if (keymap_config.swap_control_capslock) {
45 return keycode_to_action(KC_CAPSLOCK);
46 }
47 return keycode_to_action(KC_LCTL);
48 case KC_LALT:
49 if (keymap_config.swap_lalt_lgui) {
50 if (keymap_config.no_gui) {
51 return keycode_to_action(ACTION_NO);
52 }
53 return keycode_to_action(KC_LGUI);
54 }
55 return keycode_to_action(KC_LALT);
56 case KC_LGUI:
57 if (keymap_config.swap_lalt_lgui) {
58 return keycode_to_action(KC_LALT);
59 }
60 if (keymap_config.no_gui) {
61 return keycode_to_action(ACTION_NO);
62 }
63 return keycode_to_action(KC_LGUI);
64 case KC_RALT:
65 if (keymap_config.swap_ralt_rgui) {
66 if (keymap_config.no_gui) {
67 return keycode_to_action(ACTION_NO);
68 }
69 return keycode_to_action(KC_RGUI);
70 }
71 return keycode_to_action(KC_RALT);
72 case KC_RGUI:
73 if (keymap_config.swap_ralt_rgui) {
74 return keycode_to_action(KC_RALT);
75 }
76 if (keymap_config.no_gui) {
77 return keycode_to_action(ACTION_NO);
78 }
79 return keycode_to_action(KC_RGUI);
80 case KC_GRAVE:
81 if (keymap_config.swap_grave_esc) {
82 return keycode_to_action(KC_ESC);
83 }
84 return keycode_to_action(KC_GRAVE);
85 case KC_ESC:
86 if (keymap_config.swap_grave_esc) {
87 return keycode_to_action(KC_GRAVE);
88 }
89 return keycode_to_action(KC_ESC);
90 case KC_BSLASH:
91 if (keymap_config.swap_backslash_backspace) {
92 return keycode_to_action(KC_BSPACE);
93 }
94 return keycode_to_action(KC_BSLASH);
95 case KC_BSPACE:
96 if (keymap_config.swap_backslash_backspace) {
97 return keycode_to_action(KC_BSLASH);
98 }
99 return keycode_to_action(KC_BSPACE);
100#endif
37 default: 101 default:
38 return keycode_to_action(keycode); 102 return keycode_to_action(keycode);
39 } 103 }
diff --git a/common/keymap.h b/common/keymap.h
index 7efd91f70..bf32aceda 100644
--- a/common/keymap.h
+++ b/common/keymap.h
@@ -23,6 +23,25 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
23#include "action.h" 23#include "action.h"
24 24
25 25
26#ifdef BOOTMAGIC_ENABLE
27/* NOTE: Not portable. Bit field order depends on implementation */
28typedef union {
29 uint8_t raw;
30 struct {
31 bool swap_control_capslock:1;
32 bool capslock_to_control:1;
33 bool swap_lalt_lgui:1;
34 bool swap_ralt_rgui:1;
35 bool no_gui:1;
36 bool swap_grave_esc:1;
37 bool swap_backslash_backspace:1;
38 bool reserved:1;
39 };
40} keymap_config_t;
41keymap_config_t keymap_config;
42#endif
43
44
26/* translates key to keycode */ 45/* translates key to keycode */
27uint8_t keymap_key_to_keycode(uint8_t layer, key_t key); 46uint8_t keymap_key_to_keycode(uint8_t layer, key_t key);
28 47