mirror of
https://github.com/qmk/qmk_firmware.git
synced 2024-11-21 19:09:25 +00:00
EEPROM: Don't erase if we don't have to. Adding eeprom_driver_format abstraction. (#18332)
This commit is contained in:
parent
6921c8a7dd
commit
267dffda15
@ -23,6 +23,17 @@ void eeprom_driver_init(void) {
|
|||||||
/* Any initialisation code */
|
/* Any initialisation code */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void eeprom_driver_format(bool erase) {
|
||||||
|
/* If erase=false, then only do the absolute minimum initialisation necessary
|
||||||
|
to make sure that the eeprom driver is usable. It doesn't need to guarantee
|
||||||
|
that the content of the eeprom is reset to any particular value. For many
|
||||||
|
eeprom drivers this may be a no-op.
|
||||||
|
|
||||||
|
If erase=true, then in addition to making sure the eeprom driver is in a
|
||||||
|
usable state, also make sure that it is erased.
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
void eeprom_driver_erase(void) {
|
void eeprom_driver_erase(void) {
|
||||||
/* Wipe out the EEPROM, setting values to zero */
|
/* Wipe out the EEPROM, setting values to zero */
|
||||||
}
|
}
|
||||||
|
@ -77,3 +77,9 @@ void eeprom_update_dword(uint32_t *addr, uint32_t value) {
|
|||||||
eeprom_write_dword(addr, value);
|
eeprom_write_dword(addr, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void eeprom_driver_format(bool erase) __attribute__((weak));
|
||||||
|
void eeprom_driver_format(bool erase) {
|
||||||
|
(void)erase; /* The default implementation assumes that the eeprom must be erased in order to be usable. */
|
||||||
|
eeprom_driver_erase();
|
||||||
|
}
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
|
||||||
void eeprom_driver_init(void);
|
void eeprom_driver_init(void);
|
||||||
|
void eeprom_driver_format(bool erase);
|
||||||
void eeprom_driver_erase(void);
|
void eeprom_driver_erase(void);
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#include "wait.h"
|
#include "wait.h"
|
||||||
#include "i2c_master.h"
|
#include "i2c_master.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
#include "eeprom_driver.h"
|
||||||
#include "eeprom_i2c.h"
|
#include "eeprom_i2c.h"
|
||||||
|
|
||||||
// #define DEBUG_EEPROM_OUTPUT
|
// #define DEBUG_EEPROM_OUTPUT
|
||||||
@ -62,6 +63,13 @@ void eeprom_driver_init(void) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void eeprom_driver_format(bool erase) {
|
||||||
|
/* i2c eeproms do not need to be formatted before use */
|
||||||
|
if (erase) {
|
||||||
|
eeprom_driver_erase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void eeprom_driver_erase(void) {
|
void eeprom_driver_erase(void) {
|
||||||
#if defined(CONSOLE_ENABLE) && defined(DEBUG_EEPROM_OUTPUT)
|
#if defined(CONSOLE_ENABLE) && defined(DEBUG_EEPROM_OUTPUT)
|
||||||
uint32_t start = timer_read32();
|
uint32_t start = timer_read32();
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "spi_master.h"
|
#include "spi_master.h"
|
||||||
#include "eeprom.h"
|
#include "eeprom.h"
|
||||||
|
#include "eeprom_driver.h"
|
||||||
#include "eeprom_spi.h"
|
#include "eeprom_spi.h"
|
||||||
|
|
||||||
#define CMD_WREN 6
|
#define CMD_WREN 6
|
||||||
@ -92,6 +93,13 @@ void eeprom_driver_init(void) {
|
|||||||
spi_init();
|
spi_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void eeprom_driver_format(bool erase) {
|
||||||
|
/* spi eeproms do not need to be formatted before use */
|
||||||
|
if (erase) {
|
||||||
|
eeprom_driver_erase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void eeprom_driver_erase(void) {
|
void eeprom_driver_erase(void) {
|
||||||
#if defined(CONSOLE_ENABLE) && defined(DEBUG_EEPROM_OUTPUT)
|
#if defined(CONSOLE_ENABLE) && defined(DEBUG_EEPROM_OUTPUT)
|
||||||
uint32_t start = timer_read32();
|
uint32_t start = timer_read32();
|
||||||
|
@ -30,8 +30,13 @@ size_t clamp_length(intptr_t offset, size_t len) {
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void eeprom_driver_init(void) {
|
void eeprom_driver_init(void) {}
|
||||||
eeprom_driver_erase();
|
|
||||||
|
void eeprom_driver_format(bool erase) {
|
||||||
|
/* The transient eeprom driver doesn't necessarily need to be formatted before use, and it always starts up filled with zeros, due to placement in the .bss section */
|
||||||
|
if (erase) {
|
||||||
|
eeprom_driver_erase();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void eeprom_driver_erase(void) {
|
void eeprom_driver_erase(void) {
|
||||||
|
@ -10,6 +10,12 @@ void eeprom_driver_init(void) {
|
|||||||
wear_leveling_init();
|
wear_leveling_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void eeprom_driver_format(bool erase) {
|
||||||
|
/* wear leveling requires the write log data structures to be erased before use. */
|
||||||
|
(void)erase;
|
||||||
|
eeprom_driver_erase();
|
||||||
|
}
|
||||||
|
|
||||||
void eeprom_driver_erase(void) {
|
void eeprom_driver_erase(void) {
|
||||||
wear_leveling_erase();
|
wear_leveling_erase();
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
#include "eeprom_legacy_emulated_flash.h"
|
#include "eeprom_legacy_emulated_flash.h"
|
||||||
#include "legacy_flash_ops.h"
|
#include "legacy_flash_ops.h"
|
||||||
|
#include "eeprom_driver.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We emulate eeprom by writing a snapshot compacted view of eeprom contents,
|
* We emulate eeprom by writing a snapshot compacted view of eeprom contents,
|
||||||
@ -564,6 +565,12 @@ void eeprom_driver_init(void) {
|
|||||||
EEPROM_Init();
|
EEPROM_Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void eeprom_driver_format(bool erase) {
|
||||||
|
/* emulated eepron requires the write log data structures to be erased before use. */
|
||||||
|
(void)erase;
|
||||||
|
eeprom_driver_erase();
|
||||||
|
}
|
||||||
|
|
||||||
void eeprom_driver_erase(void) {
|
void eeprom_driver_erase(void) {
|
||||||
EEPROM_Erase();
|
EEPROM_Erase();
|
||||||
}
|
}
|
||||||
|
@ -52,6 +52,12 @@ static inline void STM32_L0_L1_EEPROM_Lock(void) {
|
|||||||
|
|
||||||
void eeprom_driver_init(void) {}
|
void eeprom_driver_init(void) {}
|
||||||
|
|
||||||
|
void eeprom_driver_format(bool erase) {
|
||||||
|
if (erase) {
|
||||||
|
eeprom_driver_erase();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void eeprom_driver_erase(void) {
|
void eeprom_driver_erase(void) {
|
||||||
STM32_L0_L1_EEPROM_Unlock();
|
STM32_L0_L1_EEPROM_Unlock();
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ __attribute__((weak)) void eeconfig_init_kb(void) {
|
|||||||
*/
|
*/
|
||||||
void eeconfig_init_quantum(void) {
|
void eeconfig_init_quantum(void) {
|
||||||
#if defined(EEPROM_DRIVER)
|
#if defined(EEPROM_DRIVER)
|
||||||
eeprom_driver_erase();
|
eeprom_driver_format(false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
|
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
|
||||||
@ -108,7 +108,7 @@ void eeconfig_enable(void) {
|
|||||||
*/
|
*/
|
||||||
void eeconfig_disable(void) {
|
void eeconfig_disable(void) {
|
||||||
#if defined(EEPROM_DRIVER)
|
#if defined(EEPROM_DRIVER)
|
||||||
eeprom_driver_erase();
|
eeprom_driver_format(false);
|
||||||
#endif
|
#endif
|
||||||
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
|
eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user