diff options
author | Joel Challis <git@zvecr.com> | 2022-11-16 07:06:49 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-16 18:06:49 +1100 |
commit | 57ac917b4366cbd25044ed59496e6b4f3bb9a17a (patch) | |
tree | 1fd2e06959f3f2c473db07355f75e625f5f57a3a /quantum/eeconfig.c | |
parent | 81a6407dcaf32e4b2115daccc7c0658add4de7d4 (diff) |
Extend eeconfig kb/user datablock API (#19094)
Diffstat (limited to 'quantum/eeconfig.c')
-rw-r--r-- | quantum/eeconfig.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index 3b4d690e42..21bcce2654 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -71,15 +71,11 @@ void eeconfig_init_quantum(void) { #endif #if (EECONFIG_KB_DATA_SIZE) > 0 - eeprom_update_dword(EECONFIG_KEYBOARD, (EECONFIG_KB_DATA_VERSION)); - uint8_t dummy_kb[(EECONFIG_KB_DATA_SIZE)] = {0}; - eeprom_update_block(EECONFIG_KB_DATABLOCK, dummy_kb, (EECONFIG_KB_DATA_SIZE)); + eeconfig_init_kb_datablock(); #endif #if (EECONFIG_USER_DATA_SIZE) > 0 - eeprom_update_dword(EECONFIG_USER, (EECONFIG_USER_DATA_VERSION)); - uint8_t dummy_user[(EECONFIG_USER_DATA_SIZE)] = {0}; - eeprom_update_block(EECONFIG_USER_DATABLOCK, dummy_user, (EECONFIG_USER_DATA_SIZE)); + eeconfig_init_user_datablock(); #endif #if defined(VIA_ENABLE) @@ -273,12 +269,19 @@ void eeconfig_update_handedness(bool val) { } #if (EECONFIG_KB_DATA_SIZE) > 0 +/** \brief eeconfig assert keyboard data block version + * + * FIXME: needs doc + */ +bool eeconfig_is_kb_datablock_valid(void) { + return eeprom_read_dword(EECONFIG_KEYBOARD) == (EECONFIG_KB_DATA_VERSION); +} /** \brief eeconfig read keyboard data block * * FIXME: needs doc */ void eeconfig_read_kb_datablock(void *data) { - if (eeprom_read_dword(EECONFIG_KEYBOARD) == (EECONFIG_KB_DATA_VERSION)) { + if (eeconfig_is_kb_datablock_valid()) { eeprom_read_block(data, EECONFIG_KB_DATABLOCK, (EECONFIG_KB_DATA_SIZE)); } else { memset(data, 0, (EECONFIG_KB_DATA_SIZE)); @@ -292,15 +295,30 @@ void eeconfig_update_kb_datablock(const void *data) { eeprom_update_dword(EECONFIG_KEYBOARD, (EECONFIG_KB_DATA_VERSION)); eeprom_update_block(data, EECONFIG_KB_DATABLOCK, (EECONFIG_KB_DATA_SIZE)); } +/** \brief eeconfig init keyboard data block + * + * FIXME: needs doc + */ +__attribute__((weak)) void eeconfig_init_kb_datablock(void) { + uint8_t dummy_kb[(EECONFIG_KB_DATA_SIZE)] = {0}; + eeconfig_update_kb_datablock(dummy_kb); +} #endif // (EECONFIG_KB_DATA_SIZE) > 0 #if (EECONFIG_USER_DATA_SIZE) > 0 +/** \brief eeconfig assert user data block version + * + * FIXME: needs doc + */ +bool eeconfig_is_user_datablock_valid(void) { + return eeprom_read_dword(EECONFIG_USER) == (EECONFIG_USER_DATA_VERSION); +} /** \brief eeconfig read user data block * * FIXME: needs doc */ void eeconfig_read_user_datablock(void *data) { - if (eeprom_read_dword(EECONFIG_USER) == (EECONFIG_USER_DATA_VERSION)) { + if (eeconfig_is_user_datablock_valid()) { eeprom_read_block(data, EECONFIG_USER_DATABLOCK, (EECONFIG_USER_DATA_SIZE)); } else { memset(data, 0, (EECONFIG_USER_DATA_SIZE)); @@ -314,4 +332,12 @@ void eeconfig_update_user_datablock(const void *data) { eeprom_update_dword(EECONFIG_USER, (EECONFIG_USER_DATA_VERSION)); eeprom_update_block(data, EECONFIG_USER_DATABLOCK, (EECONFIG_USER_DATA_SIZE)); } +/** \brief eeconfig init user data block + * + * FIXME: needs doc + */ +__attribute__((weak)) void eeconfig_init_user_datablock(void) { + uint8_t dummy_user[(EECONFIG_USER_DATA_SIZE)] = {0}; + eeconfig_update_user_datablock(dummy_user); +} #endif // (EECONFIG_USER_DATA_SIZE) > 0 |