summaryrefslogtreecommitdiff
path: root/quantum/eeconfig.h
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/eeconfig.h')
-rw-r--r--quantum/eeconfig.h83
1 files changed, 69 insertions, 14 deletions
diff --git a/quantum/eeconfig.h b/quantum/eeconfig.h
index 565a0dbe5b..ee8e9add8b 100644
--- a/quantum/eeconfig.h
+++ b/quantum/eeconfig.h
@@ -21,7 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdbool.h>
#ifndef EECONFIG_MAGIC_NUMBER
-# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE8 // When changing, decrement this value to avoid future re-init issues
+# define EECONFIG_MAGIC_NUMBER (uint16_t)0xFEE7 // When changing, decrement this value to avoid future re-init issues
#endif
#define EECONFIG_MAGIC_NUMBER_OFF (uint16_t)0xFFFF
@@ -29,8 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define EECONFIG_MAGIC (uint16_t *)0
#define EECONFIG_DEBUG (uint8_t *)2
#define EECONFIG_DEFAULT_LAYER (uint8_t *)3
-#define EECONFIG_KEYMAP (uint8_t *)4
-#define EECONFIG_MOUSEKEY_ACCEL (uint8_t *)5
+#define EECONFIG_KEYMAP (uint16_t *)4
#define EECONFIG_BACKLIGHT (uint8_t *)6
#define EECONFIG_AUDIO (uint8_t *)7
#define EECONFIG_RGBLIGHT (uint32_t *)8
@@ -51,10 +50,29 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define EECONFIG_LED_MATRIX_EXTENDED (uint16_t *)32
#define EECONFIG_RGB_MATRIX_EXTENDED (uint16_t *)32
-// TODO: Combine these into a single word and single block of EEPROM
-#define EECONFIG_KEYMAP_UPPER_BYTE (uint8_t *)34
+// Size of EEPROM being used for core data storage
+#define EECONFIG_BASE_SIZE 34
+
+// Size of EEPROM dedicated to keyboard- and user-specific data
+#ifndef EECONFIG_KB_DATA_SIZE
+# define EECONFIG_KB_DATA_SIZE 0
+#endif
+#ifndef EECONFIG_KB_DATA_VERSION
+# define EECONFIG_KB_DATA_VERSION (EECONFIG_KB_DATA_SIZE)
+#endif
+#ifndef EECONFIG_USER_DATA_SIZE
+# define EECONFIG_USER_DATA_SIZE 0
+#endif
+#ifndef EECONFIG_USER_DATA_VERSION
+# define EECONFIG_USER_DATA_VERSION (EECONFIG_USER_DATA_SIZE)
+#endif
+
+#define EECONFIG_KB_DATABLOCK ((uint8_t *)(EECONFIG_BASE_SIZE))
+#define EECONFIG_USER_DATABLOCK ((uint8_t *)((EECONFIG_BASE_SIZE) + (EECONFIG_KB_DATA_SIZE)))
+
// Size of EEPROM being used, other code can refer to this for available EEPROM
-#define EECONFIG_SIZE 35
+#define EECONFIG_SIZE ((EECONFIG_BASE_SIZE) + (EECONFIG_KB_DATA_SIZE) + (EECONFIG_USER_DATA_SIZE))
+
/* debug bit */
#define EECONFIG_DEBUG_ENABLE (1 << 0)
#define EECONFIG_DEBUG_MATRIX (1 << 1)
@@ -71,8 +89,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define EECONFIG_KEYMAP_SWAP_BACKSLASH_BACKSPACE (1 << 6)
#define EECONFIG_KEYMAP_NKRO (1 << 7)
-#define EECONFIG_KEYMAP_LOWER_BYTE EECONFIG_KEYMAP
-
bool eeconfig_is_enabled(void);
bool eeconfig_is_disabled(void);
@@ -99,10 +115,15 @@ uint8_t eeconfig_read_audio(void);
void eeconfig_update_audio(uint8_t val);
#endif
+#if (EECONFIG_KB_DATA_SIZE) == 0
uint32_t eeconfig_read_kb(void);
void eeconfig_update_kb(uint32_t val);
+#endif // (EECONFIG_KB_DATA_SIZE) == 0
+
+#if (EECONFIG_USER_DATA_SIZE) == 0
uint32_t eeconfig_read_user(void);
void eeconfig_update_user(uint32_t val);
+#endif // (EECONFIG_USER_DATA_SIZE) == 0
#ifdef HAPTIC_ENABLE
uint32_t eeconfig_read_haptic(void);
@@ -112,16 +133,40 @@ void eeconfig_update_haptic(uint32_t val);
bool eeconfig_read_handedness(void);
void eeconfig_update_handedness(bool val);
-#define EECONFIG_DEBOUNCE_HELPER(name, offset, config) \
+#if (EECONFIG_KB_DATA_SIZE) > 0
+bool eeconfig_is_kb_datablock_valid(void);
+void eeconfig_read_kb_datablock(void *data);
+void eeconfig_update_kb_datablock(const void *data);
+void eeconfig_init_kb_datablock(void);
+#endif // (EECONFIG_KB_DATA_SIZE) > 0
+
+#if (EECONFIG_USER_DATA_SIZE) > 0
+bool eeconfig_is_user_datablock_valid(void);
+void eeconfig_read_user_datablock(void *data);
+void eeconfig_update_user_datablock(const void *data);
+void eeconfig_init_user_datablock(void);
+#endif // (EECONFIG_USER_DATA_SIZE) > 0
+
+// Any "checked" debounce variant used requires implementation of:
+// -- bool eeconfig_check_valid_##name(void)
+// -- void eeconfig_post_flush_##name(void)
+#define EECONFIG_DEBOUNCE_HELPER_CHECKED(name, offset, config) \
static uint8_t dirty_##name = false; \
\
+ bool eeconfig_check_valid_##name(void); \
+ void eeconfig_post_flush_##name(void); \
+ \
static inline void eeconfig_init_##name(void) { \
- eeprom_read_block(&config, offset, sizeof(config)); \
- dirty_##name = false; \
+ dirty_##name = true; \
+ if (eeconfig_check_valid_##name()) { \
+ eeprom_read_block(&config, offset, sizeof(config)); \
+ dirty_##name = false; \
+ } \
} \
static inline void eeconfig_flush_##name(bool force) { \
if (force || dirty_##name) { \
eeprom_update_block(&config, offset, sizeof(config)); \
+ eeconfig_post_flush_##name(); \
dirty_##name = false; \
} \
} \
@@ -135,7 +180,17 @@ void eeconfig_update_handedness(bool val);
static inline void eeconfig_flag_##name(bool v) { \
dirty_##name |= v; \
} \
- static inline void eeconfig_write_##name(typeof(config) conf) { \
- memcpy(&config, &conf, sizeof(config)); \
- eeconfig_flag_##name(true); \
+ static inline void eeconfig_write_##name(typeof(config) *conf) { \
+ if (memcmp(&config, conf, sizeof(config)) != 0) { \
+ memcpy(&config, conf, sizeof(config)); \
+ eeconfig_flag_##name(true); \
+ } \
}
+
+#define EECONFIG_DEBOUNCE_HELPER(name, offset, config) \
+ EECONFIG_DEBOUNCE_HELPER_CHECKED(name, offset, config) \
+ \
+ bool eeconfig_check_valid_##name(void) { \
+ return true; \
+ } \
+ void eeconfig_post_flush_##name(void) {}