From 8b75dd43ba1478904a75a10ce2db0f6195ceb828 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Tue, 8 Apr 2014 17:59:31 +0900 Subject: [PATCH] Extend reset eeconfig of bootmagic to reset keymap too --- common/bootmagic.c | 1 + common/eeconfig.c | 7 +++++++ common/keymap_ex.c | 6 +++++- common/keymap_ex.h | 3 ++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common/bootmagic.c b/common/bootmagic.c index 036d4904..311a02f2 100644 --- a/common/bootmagic.c +++ b/common/bootmagic.c @@ -30,6 +30,7 @@ void bootmagic(void) /* eeconfig clear */ if (bootmagic_scan_keycode(BOOTMAGIC_KEY_EEPROM_CLEAR)) { + eeconfig_disable(); eeconfig_init(); } diff --git a/common/eeconfig.c b/common/eeconfig.c index 5bd47dc6..5aadf1c5 100644 --- a/common/eeconfig.c +++ b/common/eeconfig.c @@ -2,6 +2,7 @@ #include #include #include "eeconfig.h" +#include "keymap_ex.h" void eeconfig_init(void) { @@ -13,6 +14,9 @@ void eeconfig_init(void) #ifdef BACKLIGHT_ENABLE eeprom_write_byte(EECONFIG_BACKLIGHT, 0); #endif +#ifdef KEYMAP_EX_ENABLE + keymap_ex_init(); +#endif } void eeconfig_enable(void) @@ -22,6 +26,9 @@ void eeconfig_enable(void) void eeconfig_disable(void) { +#ifdef KEYMAP_EX_ENABLE + keymap_ex_disable(); +#endif eeprom_write_word(EECONFIG_MAGIC, 0xFFFF); } diff --git a/common/keymap_ex.c b/common/keymap_ex.c index 0c01f707..99859c06 100644 --- a/common/keymap_ex.c +++ b/common/keymap_ex.c @@ -23,12 +23,16 @@ along with this program. If not, see . #ifdef KEYMAP_EX_ENABLE -void keymap_init(void) { +void keymap_ex_init(void) { if (!check_keymap_in_eeprom()) { write_keymap_to_eeprom(); } } +void keymap_ex_disable(void) { + eeprom_write_word((void*)EECONFIG_KEYMAP_CHECKSUM, eeprom_read_word((void*)EECONFIG_KEYMAP_CHECKSUM) + 1); +} + bool check_keymap_in_eeprom(void) { uint16_t checksum_in_eeprom = eeprom_read_word(&((keymap_ex_t*)EECONFIG_KEYMAP_EX)->checksum); uint16_t checksum = EECONFIG_MAGIC_NUMBER; diff --git a/common/keymap_ex.h b/common/keymap_ex.h index e64bace6..ee6ff8c6 100644 --- a/common/keymap_ex.h +++ b/common/keymap_ex.h @@ -47,7 +47,8 @@ typedef struct { #define FN_ACTION_OFFSET(index) (sizeof(uint16_t) * index) #define KEY_OFFSET(layer, row, col) (sizeof(uint8_t) * (layer * MATRIX_ROWS * MATRIX_COLS + row * MATRIX_COLS + col)) -void keymap_init(void); +void keymap_ex_init(void); +void keymap_ex_disable(void); bool check_keymap_in_eeprom(void); void write_keymap_to_eeprom(void); uint8_t eeconfig_read_keymap_key(uint8_t layer, uint8_t row, uint8_t col);