diff options
Diffstat (limited to 'quantum/eeconfig.c')
-rw-r--r-- | quantum/eeconfig.c | 86 |
1 files changed, 70 insertions, 16 deletions
diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c index 0ff9996ca4..3b4d690e42 100644 --- a/quantum/eeconfig.c +++ b/quantum/eeconfig.c @@ -1,3 +1,4 @@ +#include <string.h> #include <stdint.h> #include <stdbool.h> #include "eeprom.h" @@ -23,13 +24,17 @@ void eeconfig_init_via(void); * FIXME: needs doc */ __attribute__((weak)) void eeconfig_init_user(void) { +#if (EECONFIG_USER_DATA_SIZE) == 0 // Reset user EEPROM value to blank, rather than to a set value eeconfig_update_user(0); +#endif } __attribute__((weak)) void eeconfig_init_kb(void) { +#if (EECONFIG_KB_DATA_SIZE) == 0 // Reset Keyboard EEPROM value to blank, rather than to a set value eeconfig_update_kb(0); +#endif eeconfig_init_user(); } @@ -45,9 +50,8 @@ void eeconfig_init_quantum(void) { eeprom_update_byte(EECONFIG_DEBUG, 0); eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0); default_layer_state = 0; - eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0); - eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0x4); - eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0); + // Enable oneshot and autocorrect by default: 0b0001 0100 0000 0000 + eeprom_update_word(EECONFIG_KEYMAP, 0x1400); eeprom_update_byte(EECONFIG_BACKLIGHT, 0); eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default eeprom_update_dword(EECONFIG_RGBLIGHT, 0); @@ -57,16 +61,6 @@ void eeconfig_init_quantum(void) { eeprom_update_dword(EECONFIG_RGB_MATRIX, 0); eeprom_update_word(EECONFIG_RGB_MATRIX_EXTENDED, 0); - // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS - // within the emulated eeprom via dfu-util or another tool -#if defined INIT_EE_HANDS_LEFT -# pragma message "Faking EE_HANDS for left hand" - eeprom_update_byte(EECONFIG_HANDEDNESS, 1); -#elif defined INIT_EE_HANDS_RIGHT -# pragma message "Faking EE_HANDS for right hand" - eeprom_update_byte(EECONFIG_HANDEDNESS, 0); -#endif - #if defined(HAPTIC_ENABLE) haptic_reset(); #else @@ -75,6 +69,19 @@ void eeconfig_init_quantum(void) { // when a haptic-enabled firmware is loaded onto the keyboard. eeprom_update_dword(EECONFIG_HAPTIC, 0); #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)); +#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)); +#endif + #if defined(VIA_ENABLE) // Invalidate VIA eeprom config, and then reset. // Just in case if power is lost mid init, this makes sure that it pets @@ -176,15 +183,14 @@ void eeconfig_update_default_layer(uint8_t val) { * FIXME: needs doc */ uint16_t eeconfig_read_keymap(void) { - return (eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8)); + return eeprom_read_word(EECONFIG_KEYMAP); } /** \brief eeconfig update keymap * * FIXME: needs doc */ void eeconfig_update_keymap(uint16_t val) { - eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, val & 0xFF); - eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, (val >> 8) & 0xFF); + eeprom_update_word(EECONFIG_KEYMAP, val); } /** \brief eeconfig read audio @@ -202,6 +208,7 @@ void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); } +#if (EECONFIG_KB_DATA_SIZE) == 0 /** \brief eeconfig read kb * * FIXME: needs doc @@ -216,7 +223,9 @@ uint32_t eeconfig_read_kb(void) { void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); } +#endif // (EECONFIG_KB_DATA_SIZE) == 0 +#if (EECONFIG_USER_DATA_SIZE) == 0 /** \brief eeconfig read user * * FIXME: needs doc @@ -231,6 +240,7 @@ uint32_t eeconfig_read_user(void) { void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); } +#endif // (EECONFIG_USER_DATA_SIZE) == 0 /** \brief eeconfig read haptic * @@ -261,3 +271,47 @@ bool eeconfig_read_handedness(void) { void eeconfig_update_handedness(bool val) { eeprom_update_byte(EECONFIG_HANDEDNESS, !!val); } + +#if (EECONFIG_KB_DATA_SIZE) > 0 +/** \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)) { + eeprom_read_block(data, EECONFIG_KB_DATABLOCK, (EECONFIG_KB_DATA_SIZE)); + } else { + memset(data, 0, (EECONFIG_KB_DATA_SIZE)); + } +} +/** \brief eeconfig update keyboard data block + * + * FIXME: needs doc + */ +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)); +} +#endif // (EECONFIG_KB_DATA_SIZE) > 0 + +#if (EECONFIG_USER_DATA_SIZE) > 0 +/** \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)) { + eeprom_read_block(data, EECONFIG_USER_DATABLOCK, (EECONFIG_USER_DATA_SIZE)); + } else { + memset(data, 0, (EECONFIG_USER_DATA_SIZE)); + } +} +/** \brief eeconfig update user data block + * + * FIXME: needs doc + */ +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)); +} +#endif // (EECONFIG_USER_DATA_SIZE) > 0 |