eeconfig.c 4.6 KB

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