1
0
Fork 0

Reuse of EEPROM debounce logic (#14699)

* reuse rgb debounce logic

* Refactor led matrix

* Remove log line

* timeout should not be hard coded
This commit is contained in:
Joel Challis 2021-10-07 01:47:14 +01:00 committed by GitHub
parent 951331cd8d
commit 60297a1099
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 44 deletions

View file

@ -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); \
}