From a80d7891472335ec297082daecc6fbf90042c38c Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Fri, 20 Aug 2021 21:02:53 -0700 Subject: Fix issues with VIA EEPROM init and bring in line with eeconfig functionality (#13243) Co-authored-by: Ryan --- quantum/eeconfig.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) (limited to 'quantum/eeconfig.c') diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index ffa56ab56d..92f0ac4439 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -17,6 +17,12 @@ # include "haptic.h" #endif +#if defined(VIA_ENABLE) +bool via_eeprom_is_valid(void); +void via_eeprom_set_valid(bool valid); +void eeconfig_init_via(void); +#endif + /** \brief eeconfig enable * * FIXME: needs doc @@ -77,6 +83,13 @@ void eeconfig_init_quantum(void) { // when a haptic-enabled firmware is loaded onto the keyboard. eeprom_update_dword(EECONFIG_HAPTIC, 0); #endif +#if defined(VIA_ENABLE) + // Invalidate VIA eeprom config, and then reset. + // Just in case if power is lost mid init, this makes sure that it pets + // properly re-initialized. + via_eeprom_set_valid(false); + eeconfig_init_via(); +#endif eeconfig_init_kb(); } @@ -111,13 +124,29 @@ void eeconfig_disable(void) { * * FIXME: needs doc */ -bool eeconfig_is_enabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); } +bool eeconfig_is_enabled(void) { + bool is_eeprom_enabled = (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); +#ifdef VIA_ENABLE + if (is_eeprom_enabled) { + is_eeprom_enabled = via_eeprom_is_valid(); + } +#endif + return is_eeprom_enabled; +} /** \brief eeconfig is disabled * * FIXME: needs doc */ -bool eeconfig_is_disabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); } +bool eeconfig_is_disabled(void) { + bool is_eeprom_disabled = (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); +#ifdef VIA_ENABLE + if (!is_eeprom_disabled) { + is_eeprom_disabled = !via_eeprom_is_valid(); + } +#endif + return is_eeprom_disabled; +} /** \brief eeconfig read debug * -- cgit v1.2.3