summaryrefslogtreecommitdiff
path: root/quantum/eeconfig.h
diff options
context:
space:
mode:
authorJoel Challis <git@zvecr.com>2021-10-07 01:47:14 +0100
committerGitHub <noreply@github.com>2021-10-07 01:47:14 +0100
commit60297a1099e5a310bd10a4d59fcb80bbc7fe4be5 (patch)
treef2a6dd86ea81921ea5e6d96039880cd350630404 /quantum/eeconfig.h
parent951331cd8d24480bb95cdf2fe4527ea99b32f1c1 (diff)
downloadqmk_firmware-60297a1099e5a310bd10a4d59fcb80bbc7fe4be5.tar.gz
qmk_firmware-60297a1099e5a310bd10a4d59fcb80bbc7fe4be5.zip
Reuse of EEPROM debounce logic (#14699)
* reuse rgb debounce logic * Refactor led matrix * Remove log line * timeout should not be hard coded
Diffstat (limited to 'quantum/eeconfig.h')
-rw-r--r--quantum/eeconfig.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/quantum/eeconfig.h b/quantum/eeconfig.h
index bd39971b2c..22d874273c 100644
--- a/quantum/eeconfig.h
+++ b/quantum/eeconfig.h
@@ -111,3 +111,29 @@ 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) \
+ static uint8_t dirty_##name = false; \
+ \
+ static inline void eeconfig_init_##name(void) { \
+ 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)); \
+ dirty_##name = false; \
+ } \
+ } \
+ static inline void eeconfig_flush_##name##_task(uint16_t timeout) { \
+ static uint16_t flush_timer = 0; \
+ if (timer_elapsed(flush_timer) > timeout) { \
+ eeconfig_flush_##name(false); \
+ flush_timer = timer_read(); \
+ } \
+ } \
+ 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); \
+ }