eeconfig.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. eeprom_update_dword(EECONFIG_HAPTIC, 0);
  43. eeconfig_init_kb();
  44. }
  45. /** \brief eeconfig initialization
  46. *
  47. * FIXME: needs doc
  48. */
  49. void eeconfig_init(void) {
  50. eeconfig_init_quantum();
  51. }
  52. /** \brief eeconfig enable
  53. *
  54. * FIXME: needs doc
  55. */
  56. void eeconfig_enable(void)
  57. {
  58. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
  59. }
  60. /** \brief eeconfig disable
  61. *
  62. * FIXME: needs doc
  63. */
  64. void eeconfig_disable(void)
  65. {
  66. #ifdef STM32_EEPROM_ENABLE
  67. EEPROM_Erase();
  68. #endif
  69. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
  70. }
  71. /** \brief eeconfig is enabled
  72. *
  73. * FIXME: needs doc
  74. */
  75. bool eeconfig_is_enabled(void)
  76. {
  77. return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
  78. }
  79. /** \brief eeconfig is disabled
  80. *
  81. * FIXME: needs doc
  82. */
  83. bool eeconfig_is_disabled(void)
  84. {
  85. return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF);
  86. }
  87. /** \brief eeconfig read debug
  88. *
  89. * FIXME: needs doc
  90. */
  91. uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
  92. /** \brief eeconfig update debug
  93. *
  94. * FIXME: needs doc
  95. */
  96. void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val); }
  97. /** \brief eeconfig read default layer
  98. *
  99. * FIXME: needs doc
  100. */
  101. uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
  102. /** \brief eeconfig update default layer
  103. *
  104. * FIXME: needs doc
  105. */
  106. void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); }
  107. /** \brief eeconfig read keymap
  108. *
  109. * FIXME: needs doc
  110. */
  111. uint8_t eeconfig_read_keymap(void) { return eeprom_read_byte(EECONFIG_KEYMAP); }
  112. /** \brief eeconfig update keymap
  113. *
  114. * FIXME: needs doc
  115. */
  116. void eeconfig_update_keymap(uint8_t val) { eeprom_update_byte(EECONFIG_KEYMAP, val); }
  117. /** \brief eeconfig read backlight
  118. *
  119. * FIXME: needs doc
  120. */
  121. uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
  122. /** \brief eeconfig update backlight
  123. *
  124. * FIXME: needs doc
  125. */
  126. void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
  127. /** \brief eeconfig read audio
  128. *
  129. * FIXME: needs doc
  130. */
  131. uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); }
  132. /** \brief eeconfig update audio
  133. *
  134. * FIXME: needs doc
  135. */
  136. void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
  137. /** \brief eeconfig read kb
  138. *
  139. * FIXME: needs doc
  140. */
  141. uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); }
  142. /** \brief eeconfig update kb
  143. *
  144. * FIXME: needs doc
  145. */
  146. void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); }
  147. /** \brief eeconfig read user
  148. *
  149. * FIXME: needs doc
  150. */
  151. uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); }
  152. /** \brief eeconfig update user
  153. *
  154. * FIXME: needs doc
  155. */
  156. void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); }
  157. uint32_t eeconfig_read_haptic(void) { return eeprom_read_dword(EECONFIG_HAPTIC); }
  158. /** \brief eeconfig update user
  159. *
  160. * FIXME: needs doc
  161. */
  162. void eeconfig_update_haptic(uint32_t val) { eeprom_update_dword(EECONFIG_HAPTIC, val); }