forked from mfulz_github/qmk_firmware
		
	Fix issues with VIA EEPROM init and bring in line with eeconfig functionality (#13243)
Co-authored-by: Ryan <fauxpark@gmail.com>
This commit is contained in:
		
							parent
							
								
									afd3bcbf45
								
							
						
					
					
						commit
						a80d789147
					
				@ -19,13 +19,7 @@
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * ...just incase someone wants to only change the eeprom behaviour
 | 
					 * ...just incase someone wants to only change the eeprom behaviour
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
__attribute__((weak)) void bootmagic_lite_reset_eeprom(void) {
 | 
					__attribute__((weak)) void bootmagic_lite_reset_eeprom(void) { eeconfig_disable(); }
 | 
				
			||||||
#if defined(VIA_ENABLE)
 | 
					 | 
				
			||||||
    via_eeprom_reset();
 | 
					 | 
				
			||||||
#else
 | 
					 | 
				
			||||||
    eeconfig_disable();
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** \brief The lite version of TMK's bootmagic based on Wilba.
 | 
					/** \brief The lite version of TMK's bootmagic based on Wilba.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,12 @@
 | 
				
			|||||||
#    include "haptic.h"
 | 
					#    include "haptic.h"
 | 
				
			||||||
#endif
 | 
					#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
 | 
					/** \brief eeconfig enable
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * FIXME: needs doc
 | 
					 * FIXME: needs doc
 | 
				
			||||||
@ -77,6 +83,13 @@ void eeconfig_init_quantum(void) {
 | 
				
			|||||||
    // when a haptic-enabled firmware is loaded onto the keyboard.
 | 
					    // when a haptic-enabled firmware is loaded onto the keyboard.
 | 
				
			||||||
    eeprom_update_dword(EECONFIG_HAPTIC, 0);
 | 
					    eeprom_update_dword(EECONFIG_HAPTIC, 0);
 | 
				
			||||||
#endif
 | 
					#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();
 | 
					    eeconfig_init_kb();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@ -111,13 +124,29 @@ void eeconfig_disable(void) {
 | 
				
			|||||||
 *
 | 
					 *
 | 
				
			||||||
 * FIXME: needs doc
 | 
					 * 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
 | 
					/** \brief eeconfig is disabled
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * FIXME: needs doc
 | 
					 * 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
 | 
					/** \brief eeconfig read debug
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 | 
				
			|||||||
@ -309,13 +309,13 @@ void housekeeping_task(void) {
 | 
				
			|||||||
void keyboard_init(void) {
 | 
					void keyboard_init(void) {
 | 
				
			||||||
    timer_init();
 | 
					    timer_init();
 | 
				
			||||||
    sync_timer_init();
 | 
					    sync_timer_init();
 | 
				
			||||||
 | 
					#ifdef VIA_ENABLE
 | 
				
			||||||
 | 
					    via_init();
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
    matrix_init();
 | 
					    matrix_init();
 | 
				
			||||||
#if defined(CRC_ENABLE)
 | 
					#if defined(CRC_ENABLE)
 | 
				
			||||||
    crc_init();
 | 
					    crc_init();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#ifdef VIA_ENABLE
 | 
					 | 
				
			||||||
    via_init();
 | 
					 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
#ifdef QWIIC_ENABLE
 | 
					#ifdef QWIIC_ENABLE
 | 
				
			||||||
    qwiic_init();
 | 
					    qwiic_init();
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
@ -83,16 +83,6 @@ void via_eeprom_set_valid(bool valid) {
 | 
				
			|||||||
    eeprom_update_byte((void *)VIA_EEPROM_MAGIC_ADDR + 2, valid ? magic2 : 0xFF);
 | 
					    eeprom_update_byte((void *)VIA_EEPROM_MAGIC_ADDR + 2, valid ? magic2 : 0xFF);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Flag QMK and VIA/keyboard level EEPROM as invalid.
 | 
					 | 
				
			||||||
// Used in bootmagic_lite() and VIA command handler.
 | 
					 | 
				
			||||||
// Keyboard level code should not need to call this.
 | 
					 | 
				
			||||||
void via_eeprom_reset(void) {
 | 
					 | 
				
			||||||
    // Set the VIA specific EEPROM state as invalid.
 | 
					 | 
				
			||||||
    via_eeprom_set_valid(false);
 | 
					 | 
				
			||||||
    // Set the TMK/QMK EEPROM state as invalid.
 | 
					 | 
				
			||||||
    eeconfig_disable();
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Override this at the keyboard code level to check
 | 
					// Override this at the keyboard code level to check
 | 
				
			||||||
// VIA's EEPROM valid state and reset to defaults as needed.
 | 
					// VIA's EEPROM valid state and reset to defaults as needed.
 | 
				
			||||||
// Used by keyboards that store their own state in EEPROM,
 | 
					// Used by keyboards that store their own state in EEPROM,
 | 
				
			||||||
@ -109,8 +99,14 @@ void via_init(void) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    // If the EEPROM has the magic, the data is good.
 | 
					    // If the EEPROM has the magic, the data is good.
 | 
				
			||||||
    // OK to load from EEPROM.
 | 
					    // OK to load from EEPROM.
 | 
				
			||||||
    if (via_eeprom_is_valid()) {
 | 
					    if (!via_eeprom_is_valid()) {
 | 
				
			||||||
    } else {
 | 
					        eeconfig_init_via();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void eeconfig_init_via(void) {
 | 
				
			||||||
 | 
					    // set the magic number to false, in case this gets interrupted
 | 
				
			||||||
 | 
					    via_eeprom_set_valid(false);
 | 
				
			||||||
    // This resets the layout options
 | 
					    // This resets the layout options
 | 
				
			||||||
    via_set_layout_options(VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT);
 | 
					    via_set_layout_options(VIA_EEPROM_LAYOUT_OPTIONS_DEFAULT);
 | 
				
			||||||
    // This resets the keymaps in EEPROM to what is in flash.
 | 
					    // This resets the keymaps in EEPROM to what is in flash.
 | 
				
			||||||
@ -120,7 +116,6 @@ void via_init(void) {
 | 
				
			|||||||
    // Save the magic number last, in case saving was interrupted
 | 
					    // Save the magic number last, in case saving was interrupted
 | 
				
			||||||
    via_eeprom_set_valid(true);
 | 
					    via_eeprom_set_valid(true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// This is generalized so the layout options EEPROM usage can be
 | 
					// This is generalized so the layout options EEPROM usage can be
 | 
				
			||||||
// variable, between 1 and 4 bytes.
 | 
					// variable, between 1 and 4 bytes.
 | 
				
			||||||
@ -329,6 +324,13 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					#ifdef VIA_EEPROM_ALLOW_RESET
 | 
				
			||||||
 | 
					        case id_eeprom_reset: {
 | 
				
			||||||
 | 
					            via_eeprom_set_valid(false);
 | 
				
			||||||
 | 
					            eeconfig_init_via();
 | 
				
			||||||
 | 
					            break;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
        case id_dynamic_keymap_macro_get_count: {
 | 
					        case id_dynamic_keymap_macro_get_count: {
 | 
				
			||||||
            command_data[0] = dynamic_keymap_macro_get_count();
 | 
					            command_data[0] = dynamic_keymap_macro_get_count();
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
 | 
				
			|||||||
@ -152,12 +152,8 @@ bool via_eeprom_is_valid(void);
 | 
				
			|||||||
// Keyboard level code (eg. via_init_kb()) should not call this
 | 
					// Keyboard level code (eg. via_init_kb()) should not call this
 | 
				
			||||||
void via_eeprom_set_valid(bool valid);
 | 
					void via_eeprom_set_valid(bool valid);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Flag QMK and VIA/keyboard level EEPROM as invalid.
 | 
					 | 
				
			||||||
// Used in bootmagic_lite() and VIA command handler.
 | 
					 | 
				
			||||||
// Keyboard level code should not need to call this.
 | 
					 | 
				
			||||||
void via_eeprom_reset(void);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// Called by QMK core to initialize dynamic keymaps etc.
 | 
					// Called by QMK core to initialize dynamic keymaps etc.
 | 
				
			||||||
 | 
					void eeconfig_init_via(void);
 | 
				
			||||||
void via_init(void);
 | 
					void via_init(void);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Used by VIA to store and retrieve the layout options.
 | 
					// Used by VIA to store and retrieve the layout options.
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user