nvm_test.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2026 QMK
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <stdint.h>
  4. #include "community_modules.h"
  5. #include "debug.h"
  6. #include "timer.h"
  7. #include "eeconfig.h"
  8. ASSERT_COMMUNITY_MODULES_MIN_API_VERSION(1, 1, 3);
  9. typedef struct my_config_t {
  10. uint32_t data;
  11. } my_config_t;
  12. static my_config_t config;
  13. // Helpers required to bind to debounce helper
  14. void eeconfig_read_my_config(my_config_t *value) {
  15. eeconfig_read_nvm_test_datablock(value, 0, sizeof(my_config_t));
  16. }
  17. void eeconfig_update_my_config(my_config_t *value) {
  18. eeconfig_update_nvm_test_datablock(value, 0, sizeof(my_config_t));
  19. }
  20. EECONFIG_DEBOUNCE_HELPER(my_config, config);
  21. void eeconfig_init_nvm_test_datablock(void) {
  22. my_config_t default_config = {
  23. .data = 42,
  24. };
  25. eeconfig_update_nvm_test_datablock(&default_config, 0, sizeof(my_config_t));
  26. }
  27. void keyboard_post_init_nvm_test(void) {
  28. eeconfig_init_my_config();
  29. }
  30. bool process_record_nvm_test(uint16_t keycode, keyrecord_t *record) {
  31. if (!record->event.pressed) {
  32. config.data += 1;
  33. eeconfig_flag_my_config(true);
  34. }
  35. return true;
  36. }
  37. void housekeeping_task_nvm_test(void) {
  38. eeconfig_flush_my_config(false);
  39. static uint32_t last_sync = 0;
  40. if (timer_elapsed32(last_sync) > 1000) {
  41. last_sync = timer_read32();
  42. dprintf("Config: %ld\n", config.data);
  43. }
  44. }