From 36f306b4a5973568997691b6b820a863bbb6b043 Mon Sep 17 00:00:00 2001 From: Joel Challis Date: Sun, 24 Nov 2024 20:35:21 +0000 Subject: [PATCH] Provide method to save a single default layer in the full range of 0-31 (#24639) --- quantum/eeconfig.c | 25 ++++++++++++++++++++----- quantum/eeconfig.h | 5 +++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index ffbbf43a95c..e27f604f124 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -3,7 +3,6 @@ #include #include "eeprom.h" #include "eeconfig.h" -#include "action_layer.h" #if defined(EEPROM_DRIVER) # include "eeprom_driver.h" @@ -52,7 +51,7 @@ void eeconfig_init_quantum(void) { eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); eeprom_update_byte(EECONFIG_DEBUG, 0); default_layer_state = (layer_state_t)1 << 0; - eeprom_update_byte(EECONFIG_DEFAULT_LAYER, default_layer_state); + eeconfig_update_default_layer(default_layer_state); // Enable oneshot and autocorrect by default: 0b0001 0100 0000 0000 eeprom_update_word(EECONFIG_KEYMAP, 0x1400); eeprom_update_byte(EECONFIG_BACKLIGHT, 0); @@ -160,14 +159,30 @@ void eeconfig_update_debug(uint8_t val) { * * FIXME: needs doc */ -uint8_t eeconfig_read_default_layer(void) { - return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); +layer_state_t eeconfig_read_default_layer(void) { + uint8_t val = eeprom_read_byte(EECONFIG_DEFAULT_LAYER); + +#ifdef DEFAULT_LAYER_STATE_IS_VALUE_NOT_BITMASK + // stored as a layer number, so convert back to bitmask + return 1 << val; +#else + // stored as 8-bit-wide bitmask, so read the value directly - handling padding to 16/32 bit layer_state_t + return val; +#endif } /** \brief eeconfig update default layer * * FIXME: needs doc */ -void eeconfig_update_default_layer(uint8_t val) { +void eeconfig_update_default_layer(layer_state_t state) { +#ifdef DEFAULT_LAYER_STATE_IS_VALUE_NOT_BITMASK + // stored as a layer number, so only store the highest layer + uint8_t val = get_highest_layer(state); +#else + // stored as 8-bit-wide bitmask, so write the value directly - handling truncation from 16/32 bit layer_state_t + uint8_t val = state; +#endif + eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); } diff --git a/quantum/eeconfig.h b/quantum/eeconfig.h index fa0dd799d19..11cf1ccbca8 100644 --- a/quantum/eeconfig.h +++ b/quantum/eeconfig.h @@ -22,6 +22,7 @@ along with this program. If not, see . #include // offsetof #include "eeprom.h" #include "util.h" +#include "action_layer.h" // layer_state_t #ifndef EECONFIG_MAGIC_NUMBER # define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE5 // When changing, decrement this value to avoid future re-init issues @@ -122,8 +123,8 @@ void eeconfig_disable(void); uint8_t eeconfig_read_debug(void); void eeconfig_update_debug(uint8_t val); -uint8_t eeconfig_read_default_layer(void); -void eeconfig_update_default_layer(uint8_t val); +layer_state_t eeconfig_read_default_layer(void); +void eeconfig_update_default_layer(layer_state_t val); uint16_t eeconfig_read_keymap(void); void eeconfig_update_keymap(uint16_t val);