You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.7 KiB

  1. // Copyright 2023 Christopher Courtney, aka Drashna Jael're (@drashna) <drashna@live.com>
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "eeconfig_users.h"
  4. #include "eeprom.h"
  5. #include "eeconfig.h"
  6. #include <string.h>
  7. #if (TOTAL_EEPROM_BYTE_COUNT - 1) < EECONFIG_SIZE && !defined(KEYBOARD_input_club_ergodox_infinity)
  8. # error "More eeprom configured than is available."
  9. #endif
  10. #if (EECONFIG_USER_DATA_SIZE) != 0 && (EECONFIG_USER_DATA_SIZE) < 4
  11. # error "Not enough EEPROM configured for user config."
  12. #endif
  13. #if (EECONFIG_USER_DATA_SIZE) == 0
  14. # define EECONFIG_USER_TEMP EECONFIG_USER
  15. #else
  16. # define EECONFIG_USER_TEMP (uint32_t *)(EECONFIG_USER_DATABLOCK)
  17. #endif
  18. void eeconfig_read_user_config(uint32_t *data) {
  19. #if (EECONFIG_USER_DATA_SIZE) > 0
  20. if (!eeconfig_is_user_datablock_valid()) {
  21. memset(data, 0, 4);
  22. } else
  23. #endif
  24. eeprom_read_block(data, EECONFIG_USER_TEMP, 4);
  25. }
  26. void eeconfig_update_user_config(const uint32_t *data) {
  27. eeprom_update_block(data, EECONFIG_USER_TEMP, 4);
  28. #if (EECONFIG_USER_DATA_SIZE) > 0
  29. eeprom_update_dword(EECONFIG_USER, (EECONFIG_USER_DATA_VERSION));
  30. #endif
  31. }
  32. void eeconfig_read_user_data(void *data) {
  33. #if (EECONFIG_USER_DATA_SIZE) > 4
  34. if (eeconfig_is_user_datablock_valid()) {
  35. eeprom_read_block(data, EECONFIG_USER_DATABLOCK + 4, (EECONFIG_USER_DATA_SIZE)-4);
  36. } else {
  37. memset(data, 0, (EECONFIG_USER_DATA_SIZE));
  38. }
  39. #endif
  40. }
  41. void eeconfig_update_user_data(const void *data) {
  42. #if (EECONFIG_USER_DATA_SIZE) > 4
  43. eeprom_update_dword(EECONFIG_USER, (EECONFIG_USER_DATA_VERSION));
  44. eeprom_update_block(data, EECONFIG_USER_DATABLOCK + 4, (EECONFIG_USER_DATA_SIZE)-4);
  45. #endif
  46. }