aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/bootmagic.c4
-rw-r--r--common/bootmagic.h4
-rw-r--r--common/eeconfig.c14
-rw-r--r--common/eeconfig.h10
-rw-r--r--common/keyboard.c11
5 files changed, 31 insertions, 12 deletions
diff --git a/common/bootmagic.c b/common/bootmagic.c
index 46fbc180a..388099e2e 100644
--- a/common/bootmagic.c
+++ b/common/bootmagic.c
@@ -10,12 +10,12 @@
10 10
11void bootmagic(void) 11void bootmagic(void)
12{ 12{
13 if (!BOOTMAGIC_IS_ENABLED()) { return; }
14
13 /* do scans in case of bounce */ 15 /* do scans in case of bounce */
14 uint8_t scan = 100; 16 uint8_t scan = 100;
15 while (scan--) { matrix_scan(); _delay_ms(1); } 17 while (scan--) { matrix_scan(); _delay_ms(1); }
16 18
17 if (!BOOTMAGIC_IS_ENABLE()) { return; }
18
19 if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) { 19 if (bootmagic_scan_keycode(BOOTMAGIC_BOOTLOADER_KEY)) {
20 bootloader_jump(); 20 bootloader_jump();
21 } 21 }
diff --git a/common/bootmagic.h b/common/bootmagic.h
index d32a5bef8..5791b221f 100644
--- a/common/bootmagic.h
+++ b/common/bootmagic.h
@@ -2,8 +2,8 @@
2#define BOOTMAGIC_H 2#define BOOTMAGIC_H
3 3
4 4
5#ifndef BOOTMAGIC_IS_ENABLE 5#ifndef BOOTMAGIC_IS_ENABLED
6#define BOOTMAGIC_IS_ENABLE() true 6#define BOOTMAGIC_IS_ENABLED() true
7#endif 7#endif
8 8
9/* kick up bootloader */ 9/* kick up bootloader */
diff --git a/common/eeconfig.c b/common/eeconfig.c
index f536dc06c..cea3810ee 100644
--- a/common/eeconfig.c
+++ b/common/eeconfig.c
@@ -13,9 +13,19 @@ void eeconfig_init(void)
13 eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0); 13 eeprom_write_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
14} 14}
15 15
16bool eeconfig_initialized(void) 16void eeconfig_enable(void)
17{ 17{
18 return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); 18 eeprom_write_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
19}
20
21void eeconfig_disable(void)
22{
23 eeprom_write_word(EECONFIG_MAGIC, 0xFFFF);
24}
25
26bool eeconfig_is_enabled(void)
27{
28 return EECONFIG_IS_ENABLED() && (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
19} 29}
20 30
21uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); } 31uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
diff --git a/common/eeconfig.h b/common/eeconfig.h
index 2786995a2..3e195478b 100644
--- a/common/eeconfig.h
+++ b/common/eeconfig.h
@@ -20,6 +20,10 @@ 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#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED 27#define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEED
24 28
25/* eeprom parameteter address */ 29/* eeprom parameteter address */
@@ -61,10 +65,14 @@ typedef union {
61 }; 65 };
62} keyconf; 66} keyconf;
63 67
64bool eeconfig_initialized(void); 68bool eeconfig_is_enabled(void);
65 69
66void eeconfig_init(void); 70void eeconfig_init(void);
67 71
72void eeconfig_enable(void);
73
74void eeconfig_disable(void);
75
68uint8_t eeconfig_read_debug(void); 76uint8_t eeconfig_read_debug(void);
69void eeconfig_write_debug(uint8_t val); 77void eeconfig_write_debug(uint8_t val);
70 78
diff --git a/common/keyboard.c b/common/keyboard.c
index 0a0bacd43..1acb79861 100644
--- a/common/keyboard.c
+++ b/common/keyboard.c
@@ -66,13 +66,14 @@ void keyboard_init(void)
66 66
67 bootmagic(); 67 bootmagic();
68 68
69 if (eeconfig_initialized()) { 69 if (eeconfig_is_enabled()) {
70 uint8_t config; 70 uint8_t config;
71 config = eeconfig_read_debug(); 71 config = eeconfig_read_debug();
72 debug_enable = (config & EECONFIG_DEBUG_ENABLE); 72 // ignored if debug is enabled by program before.
73 debug_matrix = (config & EECONFIG_DEBUG_MATRIX); 73 if (!debug_enable) debug_enable = (config & EECONFIG_DEBUG_ENABLE);
74 debug_keyboard = (config & EECONFIG_DEBUG_KEYBOARD); 74 if (!debug_matrix) debug_matrix = (config & EECONFIG_DEBUG_MATRIX);
75 debug_mouse = (config & EECONFIG_DEBUG_MOUSE); 75 if (!debug_keyboard) debug_keyboard = (config & EECONFIG_DEBUG_KEYBOARD);
76 if (!debug_mouse) debug_mouse = (config & EECONFIG_DEBUG_MOUSE);
76 } else { 77 } else {
77 eeconfig_init(); 78 eeconfig_init();
78 } 79 }