eeconfig.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include "eeprom.h"
  4. #include "eeconfig.h"
  5. #ifdef STM32_EEPROM_ENABLE
  6. #include "hal.h"
  7. #include "eeprom_stm32.h"
  8. #endif
  9. extern uint32_t default_layer_state;
  10. /** \brief eeconfig enable
  11. *
  12. * FIXME: needs doc
  13. */
  14. __attribute__ ((weak))
  15. void eeconfig_init_user(void) {
  16. // Reset user EEPROM value to blank, rather than to a set value
  17. eeconfig_update_user(0);
  18. }
  19. __attribute__ ((weak))
  20. void eeconfig_init_kb(void) {
  21. // Reset Keyboard EEPROM value to blank, rather than to a set value
  22. eeconfig_update_kb(0);
  23. eeconfig_init_user();
  24. }
  25. /*
  26. * FIXME: needs doc
  27. */
  28. void eeconfig_init_quantum(void) {
  29. #ifdef STM32_EEPROM_ENABLE
  30. EEPROM_Erase();
  31. #endif
  32. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
  33. eeprom_update_byte(EECONFIG_DEBUG, 0);
  34. eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
  35. default_layer_state = 0;
  36. eeprom_update_byte(EECONFIG_KEYMAP, 0);
  37. eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
  38. eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
  39. eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default
  40. eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
  41. eeprom_update_byte(EECONFIG_STENOMODE, 0);
  42. eeconfig_init_kb();
  43. }
  44. /** \brief eeconfig initialization
  45. *
  46. * FIXME: needs doc
  47. */
  48. void eeconfig_init(void) {
  49. eeconfig_init_quantum();
  50. }
  51. /** \brief eeconfig enable
  52. *
  53. * FIXME: needs doc
  54. */
  55. void eeconfig_enable(void)
  56. {
  57. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
  58. }
  59. /** \brief eeconfig disable
  60. *
  61. * FIXME: needs doc
  62. */
  63. void eeconfig_disable(void)
  64. {
  65. #ifdef STM32_EEPROM_ENABLE
  66. EEPROM_Erase();
  67. #endif
  68. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
  69. }
  70. /** \brief eeconfig is enabled
  71. *
  72. * FIXME: needs doc
  73. */
  74. bool eeconfig_is_enabled(void)
  75. {
  76. return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
  77. }
  78. /** \brief eeconfig is disabled
  79. *
  80. * FIXME: needs doc
  81. */
  82. bool eeconfig_is_disabled(void)
  83. {
  84. return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF);
  85. }
  86. /** \brief eeconfig read debug
  87. *
  88. * FIXME: needs doc
  89. */
  90. uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
  91. /** \brief eeconfig update debug
  92. *
  93. * FIXME: needs doc
  94. */
  95. void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val); }
  96. /** \brief eeconfig read default layer
  97. *
  98. * FIXME: needs doc
  99. */
  100. uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
  101. /** \brief eeconfig update default layer
  102. *
  103. * FIXME: needs doc
  104. */
  105. void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); }
  106. /** \brief eeconfig read keymap
  107. *
  108. * FIXME: needs doc
  109. */
  110. uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); }
  111. /** \brief eeconfig update keymap
  112. *
  113. * FIXME: needs doc
  114. */
  115. void eeconfig_update_keymap(uint8_t val) { eeprom_update_byte(EECONFIG_KEYMAP, val); }
  116. /** \brief eeconfig read backlight
  117. *
  118. * FIXME: needs doc
  119. */
  120. uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
  121. /** \brief eeconfig update backlight
  122. *
  123. * FIXME: needs doc
  124. */
  125. void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
  126. /** \brief eeconfig read audio
  127. *
  128. * FIXME: needs doc
  129. */
  130. uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); }
  131. /** \brief eeconfig update audio
  132. *
  133. * FIXME: needs doc
  134. */
  135. void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
  136. /** \brief eeconfig read kb
  137. *
  138. * FIXME: needs doc
  139. */
  140. uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); }
  141. /** \brief eeconfig update kb
  142. *
  143. * FIXME: needs doc
  144. */
  145. void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); }
  146. /** \brief eeconfig read user
  147. *
  148. * FIXME: needs doc
  149. */
  150. uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); }
  151. /** \brief eeconfig update user
  152. *
  153. * FIXME: needs doc
  154. */
  155. void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); }