diff options
| author | Drashna Jaelre <drashna@live.com> | 2021-08-20 21:02:53 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-08-20 21:02:53 -0700 |
| commit | a80d7891472335ec297082daecc6fbf90042c38c (patch) | |
| tree | 04d34e9dd3658bf471ca9b11db3fa1095b4aa2c0 /quantum | |
| parent | afd3bcbf45a9b7de097d7666ced2c674192949e5 (diff) | |
| download | qmk_firmware-a80d7891472335ec297082daecc6fbf90042c38c.tar.gz qmk_firmware-a80d7891472335ec297082daecc6fbf90042c38c.zip | |
Fix issues with VIA EEPROM init and bring in line with eeconfig functionality (#13243)
Co-authored-by: Ryan <fauxpark@gmail.com>
Diffstat (limited to 'quantum')
| -rw-r--r-- | quantum/bootmagic/bootmagic_lite.c | 8 | ||||
| -rw-r--r-- | quantum/eeconfig.c | 33 | ||||
| -rw-r--r-- | quantum/keyboard.c | 6 | ||||
| -rw-r--r-- | quantum/via.c | 42 | ||||
| -rw-r--r-- | quantum/via.h | 6 |
5 files changed, 58 insertions, 37 deletions
diff --git a/quantum/bootmagic/bootmagic_lite.c b/quantum/bootmagic/bootmagic_lite.c index 9cbdcb0bb..54bbf5a2e 100644 --- a/quantum/bootmagic/bootmagic_lite.c +++ b/quantum/bootmagic/bootmagic_lite.c | |||
| @@ -19,13 +19,7 @@ | |||
| 19 | * | 19 | * |
| 20 | * ...just incase someone wants to only change the eeprom behaviour | 20 | * ...just incase someone wants to only change the eeprom behaviour |
| 21 | */ | 21 | */ |
| 22 | __attribute__((weak)) void bootmagic_lite_reset_eeprom(void) { | 22 | __attribute__((weak)) void bootmagic_lite_reset_eeprom(void) { eeconfig_disable(); } |
| 23 | #if defined(VIA_ENABLE) | ||
| 24 | via_eeprom_reset(); | ||
| 25 | #else | ||
| 26 | eeconfig_disable(); | ||
| 27 | #endif | ||
| 28 | } | ||
| 29 | 23 | ||
| 30 | /** \brief The lite version of TMK's bootmagic based on Wilba. | 24 | /** \brief The lite version of TMK's bootmagic based on Wilba. |
| 31 | * | 25 | * |
diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index ffa56ab56..92f0ac443 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c | |||
| @@ -17,6 +17,12 @@ | |||
| 17 | # include "haptic.h" | 17 | # include "haptic.h" |
| 18 | #endif | 18 | #endif |
| 19 | 19 | ||
| 20 | #if defined(VIA_ENABLE) | ||
| 21 | bool via_eeprom_is_valid(void); | ||
| 22 | void via_eeprom_set_valid(bool valid); | ||
| 23 | void eeconfig_init_via(void); | ||
| 24 | #endif | ||
| 25 | |||
| 20 | /** \brief eeconfig enable | 26 | /** \brief eeconfig enable |
| 21 | * | 27 | * |
| 22 | * FIXME: needs doc | 28 | * FIXME: needs doc |
| @@ -77,6 +83,13 @@ void eeconfig_init_quantum(void) { | |||
| 77 | // when a haptic-enabled firmware is loaded onto the keyboard. | 83 | // when a haptic-enabled firmware is loaded onto the keyboard. |
| 78 | eeprom_update_dword(EECONFIG_HAPTIC, 0); | 84 | eeprom_update_dword(EECONFIG_HAPTIC, 0); |
| 79 | #endif | 85 | #endif |
| 86 | #if defined(VIA_ENABLE) | ||
| 87 | // Invalidate VIA eeprom config, and then reset. | ||
| 88 | // Just in case if power is lost mid init, this makes sure that it pets | ||
| 89 | // properly re-initialized. | ||
| 90 | via_eeprom_set_valid(false); | ||
| 91 | eeconfig_init_via(); | ||
| 92 | #endif | ||
| 80 | 93 | ||
| 81 | eeconfig_init_kb(); | 94 | eeconfig_init_kb(); |
| 82 | } | 95 | } |
| @@ -111,13 +124,29 @@ void eeconfig_disable(void) { | |||
| 111 | * | 124 | * |
| 112 | * FIXME: needs doc | 125 | * FIXME: needs doc |
| 113 | */ | 126 | */ |
| 114 | bool eeconfig_is_enabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); } | 127 | bool eeconfig_is_enabled(void) { |
| 128 | bool is_eeprom_enabled = (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); | ||
| 129 | #ifdef VIA_ENABLE | ||
| 130 | if (is_eeprom_enabled) { | ||
| 131 | is_eeprom_enabled = via_eeprom_is_valid(); | ||
| 132 | } | ||
| 133 | #endif | ||
| 134 | return is_eeprom_enabled; | ||
| 135 | } | ||
| 115 | 136 | ||
| 116 | /** \brief eeconfig is disabled | 137 | /** \brief eeconfig is disabled |
| 117 | * | 138 | * |
| 118 | * FIXME: needs doc | 139 | * FIXME: needs doc |
| 119 | */ | 140 | */ |
| 120 | bool eeconfig_is_disabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); } | 141 | bool eeconfig_is_disabled(void) { |
| 142 | bool is_eeprom_disabled = (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); | ||
| 143 | #ifdef VIA_ENABLE | ||
| 144 | if (!is_eeprom_disabled) { | ||
| 145 | is_eeprom_disabled = !via_eeprom_is_valid(); | ||
| 146 | } | ||
| 147 | #endif | ||
| 148 | return is_eeprom_disabled; | ||
| 149 | } | ||
| 121 | 150 | ||
| 122 | /** \brief eeconfig read debug | 151 | /** \brief eeconfig read debug |
| 123 | * | 152 | * |
diff --git a/quantum/keyboard.c b/quantum/keyboard.c index 0eb41e7d3..644d8650d 100644 --- a/quantum/keyboard.c +++ b/quantum/keyboard.c | |||
| @@ -309,13 +309,13 @@ void housekeeping_task(void) { | |||
| 309 | void keyboard_init(void) { | 309 | void keyboard_init(void) { |
| 310 | timer_init(); | 310 | timer_init(); |
| 311 | sync_timer_init(); | 311 | sync_timer_init(); |
| 312 | #ifdef VIA_ENABLE | ||
| 313 | via_init(); | ||
| 314 | #endif | ||
| 312 | matrix_init(); | 315 | matrix_init(); |
| 313 | #if defined(CRC_ENABLE) | 316 | #if defined(CRC_ENABLE) |
| 314 | crc_init(); | 317 | crc_init(); |
| 315 | #endif | 318 | #endif |
| 316 | #ifdef VIA_ENABLE | ||
| 317 | via_init(); | ||
| 318 | #endif | ||
| 319 | #ifdef QWIIC_ENABLE | 319 | #ifdef QWIIC_ENABLE |
| 320 | qwiic_init(); | 320 | qwiic_init(); |
| 321 | #endif | 321 | #endif |
diff --git a/quantum/via.c b/quantum/via.c index c89b663b9..1b2dbcf08 100644 --- a/quantum/via.c +++ b/quantum/via.c | |||
| @@ -83,16 +83,6 @@ void via_eeprom_set_valid(bool valid) { | |||
| 83 | eeprom_update_byte((void *)VIA_EEPROM_MAGIC_ADDR + 2, valid ? magic2 : 0xFF); | 83 | eeprom_update_byte((void *)VIA_EEPROM_MAGIC_ADDR + 2, valid ? magic2 : 0xFF); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | // Flag QMK and VIA/keyboard level EEPROM as invalid. | ||
| 87 | // Used in bootmagic_lite() and VIA command handler. | ||
| 88 | // Keyboard level code should not need to call this. | ||
| 89 | void via_eeprom_reset(void) { | ||
| 90 | // Set the VIA specific EEPROM state as invalid. | ||
| 91 | via_eeprom_set_valid(false); | ||
| 92 | // Set the TMK/QMK EEPROM state as invalid. | ||
| 93 | eeconfig_disable(); | ||
| 94 | } | ||
| 95 | |||
| 96 | // Override this at the keyboard code level to check | 86 | // Override this at the keyboard code level to check |
| 97 | // VIA's EEPROM valid state and reset to defaults as needed. | 87 | // VIA's EEPROM valid state and reset to defaults as needed. |
| 98 | // Used by keyboards that store their own state in EEPROM, | 88 | // Used by keyboards that store their own state in EEPROM, |
| @@ -109,19 +99,24 @@ void via_init(void) { | |||
| 109 | 99 | ||
| 110 | // If the EEPROM has the magic, the data is good. | 100 | // If the EEPROM has the magic, the data is good. |
| 111 | // OK to load from EEPROM. | 101 | // OK to load from EEPROM. |
| 112 | if (via_eeprom_is_valid()) { | 102 | if (!via_eeprom_is_valid()) { |
| 113 | } else { | 103 | eeconfig_init_via(); |
| 114 | // This resets the layout options | ||
| 115 | via_set_layout_options(VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT); | ||
| 116 | // This resets the keymaps in EEPROM to what is in flash. | ||
| 117 | dynamic_keymap_reset(); | ||
| 118 | // This resets the macros in EEPROM to nothing. | ||
| 119 | dynamic_keymap_macro_reset(); | ||
| 120 | // Save the magic number last, in case saving was interrupted | ||
| 121 | via_eeprom_set_valid(true); | ||
| 122 | } | 104 | } |
| 123 | } | 105 | } |
| 124 | 106 | ||
| 107 | void eeconfig_init_via(void) { | ||
| 108 | // set the magic number to false, in case this gets interrupted | ||
| 109 | via_eeprom_set_valid(false); | ||
| 110 | // This resets the layout options | ||
| 111 | via_set_layout_options(VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT); | ||
| 112 | // This resets the keymaps in EEPROM to what is in flash. | ||
| 113 | dynamic_keymap_reset(); | ||
| 114 | // This resets the macros in EEPROM to nothing. | ||
| 115 | dynamic_keymap_macro_reset(); | ||
| 116 | // Save the magic number last, in case saving was interrupted | ||
| 117 | via_eeprom_set_valid(true); | ||
| 118 | } | ||
| 119 | |||
| 125 | // This is generalized so the layout options EEPROM usage can be | 120 | // This is generalized so the layout options EEPROM usage can be |
| 126 | // variable, between 1 and 4 bytes. | 121 | // variable, between 1 and 4 bytes. |
| 127 | uint32_t via_get_layout_options(void) { | 122 | uint32_t via_get_layout_options(void) { |
| @@ -329,6 +324,13 @@ void raw_hid_receive(uint8_t *data, uint8_t length) { | |||
| 329 | #endif | 324 | #endif |
| 330 | break; | 325 | break; |
| 331 | } | 326 | } |
| 327 | #ifdef VIA_EEPROM_ALLOW_RESET | ||
| 328 | case id_eeprom_reset: { | ||
| 329 | via_eeprom_set_valid(false); | ||
| 330 | eeconfig_init_via(); | ||
| 331 | break; | ||
| 332 | } | ||
| 333 | #endif | ||
| 332 | case id_dynamic_keymap_macro_get_count: { | 334 | case id_dynamic_keymap_macro_get_count: { |
| 333 | command_data[0] = dynamic_keymap_macro_get_count(); | 335 | command_data[0] = dynamic_keymap_macro_get_count(); |
| 334 | break; | 336 | break; |
diff --git a/quantum/via.h b/quantum/via.h index de0a21da2..3db318a45 100644 --- a/quantum/via.h +++ b/quantum/via.h | |||
| @@ -152,12 +152,8 @@ bool via_eeprom_is_valid(void); | |||
| 152 | // Keyboard level code (eg. via_init_kb()) should not call this | 152 | // Keyboard level code (eg. via_init_kb()) should not call this |
| 153 | void via_eeprom_set_valid(bool valid); | 153 | void via_eeprom_set_valid(bool valid); |
| 154 | 154 | ||
| 155 | // Flag QMK and VIA/keyboard level EEPROM as invalid. | ||
| 156 | // Used in bootmagic_lite() and VIA command handler. | ||
| 157 | // Keyboard level code should not need to call this. | ||
| 158 | void via_eeprom_reset(void); | ||
| 159 | |||
| 160 | // Called by QMK core to initialize dynamic keymaps etc. | 155 | // Called by QMK core to initialize dynamic keymaps etc. |
| 156 | void eeconfig_init_via(void); | ||
| 161 | void via_init(void); | 157 | void via_init(void); |
| 162 | 158 | ||
| 163 | // Used by VIA to store and retrieve the layout options. | 159 | // Used by VIA to store and retrieve the layout options. |
