aboutsummaryrefslogtreecommitdiff
path: root/quantum/via.c
diff options
context:
space:
mode:
authorDrashna Jaelre <drashna@live.com>2021-08-20 21:02:53 -0700
committerGitHub <noreply@github.com>2021-08-20 21:02:53 -0700
commita80d7891472335ec297082daecc6fbf90042c38c (patch)
tree04d34e9dd3658bf471ca9b11db3fa1095b4aa2c0 /quantum/via.c
parentafd3bcbf45a9b7de097d7666ced2c674192949e5 (diff)
downloadqmk_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/via.c')
-rw-r--r--quantum/via.c42
1 files changed, 22 insertions, 20 deletions
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.
89void 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
107void 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.
127uint32_t via_get_layout_options(void) { 122uint32_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;