Skip to content

Commit

Permalink
Provide method to save a single default layer in the full range of 0-…
Browse files Browse the repository at this point in the history
…31 (#24639)
  • Loading branch information
zvecr authored Nov 24, 2024
1 parent f3bae56 commit 36f306b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
25 changes: 20 additions & 5 deletions quantum/eeconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <stdbool.h>
#include "eeprom.h"
#include "eeconfig.h"
#include "action_layer.h"

#if defined(EEPROM_DRIVER)
# include "eeprom_driver.h"
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions quantum/eeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stddef.h> // 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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 36f306b

Please sign in to comment.