eeconfig.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include "eeprom.h"
  4. #include "eeconfig.h"
  5. #ifdef STM32F303xC
  6. #include "hal.h"
  7. #include "eeprom_stm32.h"
  8. #endif
  9. /** \brief eeconfig initialization
  10. *
  11. * FIXME: needs doc
  12. */
  13. void eeconfig_init(void)
  14. {
  15. #ifdef STM32F303xC
  16. EEPROM_format();
  17. #endif
  18. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
  19. eeprom_update_byte(EECONFIG_DEBUG, 0);
  20. eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
  21. eeprom_update_byte(EECONFIG_KEYMAP, 0);
  22. eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
  23. #ifdef BACKLIGHT_ENABLE
  24. eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
  25. #endif
  26. #ifdef AUDIO_ENABLE
  27. eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default
  28. #endif
  29. #if defined(RGBLIGHT_ENABLE) || defined(RGB_MATRIX_ENABLE)
  30. eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
  31. #endif
  32. #ifdef STENO_ENABLE
  33. eeprom_update_byte(EECONFIG_STENOMODE, 0);
  34. #endif
  35. }
  36. /** \brief eeconfig enable
  37. *
  38. * FIXME: needs doc
  39. */
  40. void eeconfig_enable(void)
  41. {
  42. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
  43. }
  44. /** \brief eeconfig disable
  45. *
  46. * FIXME: needs doc
  47. */
  48. void eeconfig_disable(void)
  49. {
  50. #ifdef STM32F303xC
  51. EEPROM_format();
  52. #endif
  53. eeprom_update_word(EECONFIG_MAGIC, 0xFFFF);
  54. }
  55. /** \brief eeconfig is enabled
  56. *
  57. * FIXME: needs doc
  58. */
  59. bool eeconfig_is_enabled(void)
  60. {
  61. return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
  62. }
  63. /** \brief eeconfig read debug
  64. *
  65. * FIXME: needs doc
  66. */
  67. uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
  68. /** \brief eeconfig update debug
  69. *
  70. * FIXME: needs doc
  71. */
  72. void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val); }
  73. /** \brief eeconfig read default layer
  74. *
  75. * FIXME: needs doc
  76. */
  77. uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
  78. /** \brief eeconfig update default layer
  79. *
  80. * FIXME: needs doc
  81. */
  82. void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); }
  83. /** \brief eeconfig read keymap
  84. *
  85. * FIXME: needs doc
  86. */
  87. uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); }
  88. /** \brief eeconfig update keymap
  89. *
  90. * FIXME: needs doc
  91. */
  92. void eeconfig_update_keymap(uint8_t val) { eeprom_update_byte(EECONFIG_KEYMAP, val); }
  93. #ifdef BACKLIGHT_ENABLE
  94. /** \brief eeconfig read backlight
  95. *
  96. * FIXME: needs doc
  97. */
  98. uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
  99. /** \brief eeconfig update backlight
  100. *
  101. * FIXME: needs doc
  102. */
  103. void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
  104. #endif
  105. #ifdef AUDIO_ENABLE
  106. /** \brief eeconfig read audio
  107. *
  108. * FIXME: needs doc
  109. */
  110. uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); }
  111. /** \brief eeconfig update audio
  112. *
  113. * FIXME: needs doc
  114. */
  115. void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
  116. #endif