diff options
Diffstat (limited to 'quantum/eeconfig.h')
| -rw-r--r-- | quantum/eeconfig.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/quantum/eeconfig.h b/quantum/eeconfig.h index bd39971b2..22d874273 100644 --- a/quantum/eeconfig.h +++ b/quantum/eeconfig.h | |||
| @@ -111,3 +111,29 @@ void eeconfig_update_haptic(uint32_t val); | |||
| 111 | 111 | ||
| 112 | bool eeconfig_read_handedness(void); | 112 | bool eeconfig_read_handedness(void); |
| 113 | void eeconfig_update_handedness(bool val); | 113 | void eeconfig_update_handedness(bool val); |
| 114 | |||
| 115 | #define EECONFIG_DEBOUNCE_HELPER(name, offset, config) \ | ||
| 116 | static uint8_t dirty_##name = false; \ | ||
| 117 | \ | ||
| 118 | static inline void eeconfig_init_##name(void) { \ | ||
| 119 | eeprom_read_block(&config, offset, sizeof(config)); \ | ||
| 120 | dirty_##name = false; \ | ||
| 121 | } \ | ||
| 122 | static inline void eeconfig_flush_##name(bool force) { \ | ||
| 123 | if (force || dirty_##name) { \ | ||
| 124 | eeprom_update_block(&config, offset, sizeof(config)); \ | ||
| 125 | dirty_##name = false; \ | ||
| 126 | } \ | ||
| 127 | } \ | ||
| 128 | static inline void eeconfig_flush_##name##_task(uint16_t timeout) { \ | ||
| 129 | static uint16_t flush_timer = 0; \ | ||
| 130 | if (timer_elapsed(flush_timer) > timeout) { \ | ||
| 131 | eeconfig_flush_##name(false); \ | ||
| 132 | flush_timer = timer_read(); \ | ||
| 133 | } \ | ||
| 134 | } \ | ||
| 135 | static inline void eeconfig_flag_##name(bool v) { dirty_##name |= v; } \ | ||
| 136 | static inline void eeconfig_write_##name(typeof(config) conf) { \ | ||
| 137 | memcpy(&config, &conf, sizeof(config)); \ | ||
| 138 | eeconfig_flag_##name(true); \ | ||
| 139 | } | ||
