mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-04-09 07:15:40 +00:00
nvm_xxxxx_erase
This commit is contained in:
parent
3456f0b6a6
commit
7847adcdf3
@ -56,6 +56,9 @@ void dynamic_keymap_set_encoder(uint8_t layer, uint8_t encoder_id, bool clockwis
|
||||
#endif // ENCODER_MAP_ENABLE
|
||||
|
||||
void dynamic_keymap_reset(void) {
|
||||
// Erase the keymaps, if necessary.
|
||||
nvm_dynamic_keymap_erase();
|
||||
|
||||
// Reset the keymaps in EEPROM to what is in flash.
|
||||
for (int layer = 0; layer < DYNAMIC_KEYMAP_LAYER_COUNT; layer++) {
|
||||
for (int row = 0; row < MATRIX_ROWS; row++) {
|
||||
@ -113,6 +116,8 @@ void dynamic_keymap_macro_set_buffer(uint16_t offset, uint16_t size, uint8_t *da
|
||||
}
|
||||
|
||||
void dynamic_keymap_macro_reset(void) {
|
||||
// Erase the macros, if necessary.
|
||||
nvm_dynamic_keymap_macro_erase();
|
||||
nvm_dynamic_keymap_macro_reset();
|
||||
}
|
||||
|
||||
|
@ -63,9 +63,7 @@ __attribute__((weak)) void eeconfig_init_kb(void) {
|
||||
}
|
||||
|
||||
void eeconfig_init_quantum(void) {
|
||||
#ifdef EEPROM_DRIVER
|
||||
eeprom_driver_format(false);
|
||||
#endif // EEPROM_DRIVER
|
||||
nvm_eeconfig_erase();
|
||||
|
||||
eeconfig_enable();
|
||||
|
||||
@ -144,8 +142,9 @@ void eeconfig_init_quantum(void) {
|
||||
// Invalidate VIA eeprom config, and then reset.
|
||||
// Just in case if power is lost mid init, this makes sure that it gets
|
||||
// properly re-initialized.
|
||||
via_eeprom_set_valid(false);
|
||||
eeconfig_init_via();
|
||||
#elif defined(DYNAMIC_KEYMAP_ENABLE)
|
||||
dynamic_keymap_reset();
|
||||
#endif
|
||||
|
||||
eeconfig_init_kb();
|
||||
|
@ -71,6 +71,14 @@ _Static_assert((DYNAMIC_KEYMAP_EEPROM_MAX_ADDR) - (DYNAMIC_KEYMAP_MACRO_EEPROM_A
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void nvm_dynamic_keymap_erase(void) {
|
||||
// No-op, nvm_eeconfig_erase() will have already erased EEPROM if necessary.
|
||||
}
|
||||
|
||||
void nvm_dynamic_keymap_macro_erase(void) {
|
||||
// No-op, nvm_eeconfig_erase() will have already erased EEPROM if necessary.
|
||||
}
|
||||
|
||||
static inline void *dynamic_keymap_key_to_eeprom_address(uint8_t layer, uint8_t row, uint8_t column) {
|
||||
return ((void *)DYNAMIC_KEYMAP_EEPROM_ADDR) + (layer * MATRIX_ROWS * MATRIX_COLS * 2) + (row * MATRIX_COLS * 2) + (column * 2);
|
||||
}
|
||||
@ -174,10 +182,14 @@ void nvm_dynamic_keymap_macro_update_buffer(uint32_t offset, uint32_t size, uint
|
||||
}
|
||||
|
||||
void nvm_dynamic_keymap_macro_reset(void) {
|
||||
void *p = (void *)(uintptr_t)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
|
||||
void *end = (void *)(uintptr_t)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
|
||||
while (p != end) {
|
||||
eeprom_update_byte(p, 0);
|
||||
++p;
|
||||
void * start = (void *)(uintptr_t)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR);
|
||||
void * end = (void *)(uintptr_t)(DYNAMIC_KEYMAP_MACRO_EEPROM_ADDR + DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE);
|
||||
long remaining = end - start;
|
||||
uint8_t dummy[16] = {0};
|
||||
for (int i = 0; i < DYNAMIC_KEYMAP_MACRO_EEPROM_SIZE; i += sizeof(dummy)) {
|
||||
int this_loop = remaining < sizeof(dummy) ? remaining : sizeof(dummy);
|
||||
eeprom_update_block(dummy, start, this_loop);
|
||||
start += this_loop;
|
||||
remaining -= this_loop;
|
||||
}
|
||||
}
|
||||
|
@ -41,6 +41,12 @@
|
||||
# include "haptic.h"
|
||||
#endif
|
||||
|
||||
void nvm_eeconfig_erase(void) {
|
||||
#ifdef EEPROM_DRIVER
|
||||
eeprom_driver_format(false);
|
||||
#endif // EEPROM_DRIVER
|
||||
}
|
||||
|
||||
bool nvm_eeconfig_is_enabled(void) {
|
||||
return eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER;
|
||||
}
|
||||
@ -211,8 +217,18 @@ uint32_t nvm_eeconfig_update_kb_datablock(const void *data, uint32_t offset, uin
|
||||
}
|
||||
|
||||
void nvm_eeconfig_init_kb_datablock(void) {
|
||||
uint8_t dummy_kb[(EECONFIG_KB_DATA_SIZE)] = {0};
|
||||
eeconfig_update_kb_datablock(dummy_kb, 0, (EECONFIG_KB_DATA_SIZE));
|
||||
eeprom_update_dword(EECONFIG_KEYBOARD, (EECONFIG_KB_DATA_VERSION));
|
||||
|
||||
void * start = (void *)(uintptr_t)(EECONFIG_KB_DATABLOCK);
|
||||
void * end = (void *)(uintptr_t)(EECONFIG_KB_DATABLOCK + EECONFIG_KB_DATA_SIZE);
|
||||
long remaining = end - start;
|
||||
uint8_t dummy[16] = {0};
|
||||
for (int i = 0; i < EECONFIG_KB_DATA_SIZE; i += sizeof(dummy)) {
|
||||
int this_loop = remaining < sizeof(dummy) ? remaining : sizeof(dummy);
|
||||
eeprom_update_block(dummy, start, this_loop);
|
||||
start += this_loop;
|
||||
remaining -= this_loop;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // (EECONFIG_KB_DATA_SIZE) > 0
|
||||
@ -245,8 +261,18 @@ uint32_t nvm_eeconfig_update_user_datablock(const void *data, uint32_t offset, u
|
||||
}
|
||||
|
||||
void nvm_eeconfig_init_user_datablock(void) {
|
||||
uint8_t dummy_user[(EECONFIG_USER_DATA_SIZE)] = {0};
|
||||
eeconfig_update_user_datablock(dummy_user, 0, (EECONFIG_USER_DATA_SIZE));
|
||||
eeprom_update_dword(EECONFIG_USER, (EECONFIG_USER_DATA_VERSION));
|
||||
|
||||
void * start = (void *)(uintptr_t)(EECONFIG_USER_DATABLOCK);
|
||||
void * end = (void *)(uintptr_t)(EECONFIG_USER_DATABLOCK + EECONFIG_USER_DATA_SIZE);
|
||||
long remaining = end - start;
|
||||
uint8_t dummy[16] = {0};
|
||||
for (int i = 0; i < EECONFIG_USER_DATA_SIZE; i += sizeof(dummy)) {
|
||||
int this_loop = remaining < sizeof(dummy) ? remaining : sizeof(dummy);
|
||||
eeprom_update_block(dummy, start, this_loop);
|
||||
start += this_loop;
|
||||
remaining -= this_loop;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // (EECONFIG_USER_DATA_SIZE) > 0
|
||||
|
@ -8,6 +8,10 @@
|
||||
#include "nvm_eeprom_eeconfig_internal.h"
|
||||
#include "nvm_eeprom_via_internal.h"
|
||||
|
||||
void nvm_via_erase(void) {
|
||||
// No-op, nvm_eeconfig_erase() will have already erased EEPROM if necessary.
|
||||
}
|
||||
|
||||
void nvm_via_read_magic(uint8_t *magic0, uint8_t *magic1, uint8_t *magic2) {
|
||||
if (magic0) {
|
||||
*magic0 = eeprom_read_byte((void *)VIA_EEPROM_MAGIC_ADDR + 0);
|
||||
@ -70,4 +74,4 @@ uint32_t nvm_via_update_custom_config(const void *buf, uint32_t offset, uint32_t
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void nvm_dynamic_keymap_erase(void);
|
||||
void nvm_dynamic_keymap_macro_erase(void);
|
||||
|
||||
uint16_t nvm_dynamic_keymap_read_keycode(uint8_t layer, uint8_t row, uint8_t column);
|
||||
void nvm_dynamic_keymap_update_keycode(uint8_t layer, uint8_t row, uint8_t column, uint16_t keycode);
|
||||
|
||||
@ -21,4 +24,4 @@ uint32_t nvm_dynamic_keymap_macro_size(void);
|
||||
void nvm_dynamic_keymap_macro_read_buffer(uint32_t offset, uint32_t size, uint8_t *data);
|
||||
void nvm_dynamic_keymap_macro_update_buffer(uint32_t offset, uint32_t size, uint8_t *data);
|
||||
|
||||
void nvm_dynamic_keymap_macro_reset(void);
|
||||
void nvm_dynamic_keymap_macro_reset(void);
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void nvm_eeconfig_erase(void);
|
||||
|
||||
bool nvm_eeconfig_is_enabled(void);
|
||||
bool nvm_eeconfig_is_disabled(void);
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void nvm_via_erase(void);
|
||||
|
||||
void nvm_via_read_magic(uint8_t *magic0, uint8_t *magic1, uint8_t *magic2);
|
||||
void nvm_via_update_magic(uint8_t magic0, uint8_t magic1, uint8_t magic2);
|
||||
|
||||
@ -12,4 +14,4 @@ uint32_t nvm_via_read_layout_options(void);
|
||||
void nvm_via_update_layout_options(uint32_t val);
|
||||
|
||||
uint32_t nvm_via_read_custom_config(void *buf, uint32_t offset, uint32_t length);
|
||||
uint32_t nvm_via_update_custom_config(const void *buf, uint32_t offset, uint32_t length);
|
||||
uint32_t nvm_via_update_custom_config(const void *buf, uint32_t offset, uint32_t length);
|
||||
|
@ -111,6 +111,8 @@ void via_init(void) {
|
||||
}
|
||||
|
||||
void eeconfig_init_via(void) {
|
||||
// Erase any NVM storage if necessary
|
||||
nvm_via_erase();
|
||||
// set the magic number to false, in case this gets interrupted
|
||||
via_eeprom_set_valid(false);
|
||||
// This resets the layout options
|
||||
|
Loading…
Reference in New Issue
Block a user