eeconfig.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #include <stdint.h>
  2. #include <stdbool.h>
  3. #include "eeprom.h"
  4. #include "eeconfig.h"
  5. #include "action_layer.h"
  6. #ifdef STM32_EEPROM_ENABLE
  7. # include "hal.h"
  8. # include "eeprom_stm32.h"
  9. #endif
  10. #if defined(EEPROM_DRIVER)
  11. # include "eeprom_driver.h"
  12. #endif
  13. /** \brief eeconfig enable
  14. *
  15. * FIXME: needs doc
  16. */
  17. __attribute__((weak)) void eeconfig_init_user(void) {
  18. // Reset user EEPROM value to blank, rather than to a set value
  19. eeconfig_update_user(0);
  20. }
  21. __attribute__((weak)) void eeconfig_init_kb(void) {
  22. // Reset Keyboard EEPROM value to blank, rather than to a set value
  23. eeconfig_update_kb(0);
  24. eeconfig_init_user();
  25. }
  26. /*
  27. * FIXME: needs doc
  28. */
  29. void eeconfig_init_quantum(void) {
  30. #ifdef STM32_EEPROM_ENABLE
  31. EEPROM_Erase();
  32. #endif
  33. #if defined(EEPROM_DRIVER)
  34. eeprom_driver_erase();
  35. #endif
  36. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
  37. eeprom_update_byte(EECONFIG_DEBUG, 0);
  38. eeprom_update_byte(EECONFIG_DEFAULT_LAYER, 0);
  39. default_layer_state = 0;
  40. eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, 0);
  41. eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, 0);
  42. eeprom_update_byte(EECONFIG_MOUSEKEY_ACCEL, 0);
  43. eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
  44. eeprom_update_byte(EECONFIG_AUDIO, 0xFF); // On by default
  45. eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
  46. eeprom_update_byte(EECONFIG_STENOMODE, 0);
  47. eeprom_update_dword(EECONFIG_HAPTIC, 0);
  48. eeprom_update_byte(EECONFIG_VELOCIKEY, 0);
  49. eeprom_update_dword(EECONFIG_RGB_MATRIX, 0);
  50. eeprom_update_byte(EECONFIG_RGB_MATRIX_SPEED, 0);
  51. // TODO: Remove once ARM has a way to configure EECONFIG_HANDEDNESS
  52. // within the emulated eeprom via dfu-util or another tool
  53. #if defined INIT_EE_HANDS_LEFT
  54. # pragma message "Faking EE_HANDS for left hand"
  55. eeprom_update_byte(EECONFIG_HANDEDNESS, 1);
  56. #elif defined INIT_EE_HANDS_RIGHT
  57. # pragma message "Faking EE_HANDS for right hand"
  58. eeprom_update_byte(EECONFIG_HANDEDNESS, 0);
  59. #endif
  60. eeconfig_init_kb();
  61. }
  62. /** \brief eeconfig initialization
  63. *
  64. * FIXME: needs doc
  65. */
  66. void eeconfig_init(void) { eeconfig_init_quantum(); }
  67. /** \brief eeconfig enable
  68. *
  69. * FIXME: needs doc
  70. */
  71. void eeconfig_enable(void) { eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); }
  72. /** \brief eeconfig disable
  73. *
  74. * FIXME: needs doc
  75. */
  76. void eeconfig_disable(void) {
  77. #ifdef STM32_EEPROM_ENABLE
  78. EEPROM_Erase();
  79. #endif
  80. #if defined(EEPROM_DRIVER)
  81. eeprom_driver_erase();
  82. #endif
  83. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
  84. }
  85. /** \brief eeconfig is enabled
  86. *
  87. * FIXME: needs doc
  88. */
  89. bool eeconfig_is_enabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); }
  90. /** \brief eeconfig is disabled
  91. *
  92. * FIXME: needs doc
  93. */
  94. bool eeconfig_is_disabled(void) { return (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); }
  95. /** \brief eeconfig read debug
  96. *
  97. * FIXME: needs doc
  98. */
  99. uint8_t eeconfig_read_debug(void) { return eeprom_read_byte(EECONFIG_DEBUG); }
  100. /** \brief eeconfig update debug
  101. *
  102. * FIXME: needs doc
  103. */
  104. void eeconfig_update_debug(uint8_t val) { eeprom_update_byte(EECONFIG_DEBUG, val); }
  105. /** \brief eeconfig read default layer
  106. *
  107. * FIXME: needs doc
  108. */
  109. uint8_t eeconfig_read_default_layer(void) { return eeprom_read_byte(EECONFIG_DEFAULT_LAYER); }
  110. /** \brief eeconfig update default layer
  111. *
  112. * FIXME: needs doc
  113. */
  114. void eeconfig_update_default_layer(uint8_t val) { eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); }
  115. /** \brief eeconfig read keymap
  116. *
  117. * FIXME: needs doc
  118. */
  119. uint16_t eeconfig_read_keymap(void) { return (eeprom_read_byte(EECONFIG_KEYMAP_LOWER_BYTE) | (eeprom_read_byte(EECONFIG_KEYMAP_UPPER_BYTE) << 8)); }
  120. /** \brief eeconfig update keymap
  121. *
  122. * FIXME: needs doc
  123. */
  124. void eeconfig_update_keymap(uint16_t val) {
  125. eeprom_update_byte(EECONFIG_KEYMAP_LOWER_BYTE, val & 0xFF);
  126. eeprom_update_byte(EECONFIG_KEYMAP_UPPER_BYTE, (val >> 8) & 0xFF);
  127. }
  128. /** \brief eeconfig read backlight
  129. *
  130. * FIXME: needs doc
  131. */
  132. uint8_t eeconfig_read_backlight(void) { return eeprom_read_byte(EECONFIG_BACKLIGHT); }
  133. /** \brief eeconfig update backlight
  134. *
  135. * FIXME: needs doc
  136. */
  137. void eeconfig_update_backlight(uint8_t val) { eeprom_update_byte(EECONFIG_BACKLIGHT, val); }
  138. /** \brief eeconfig read audio
  139. *
  140. * FIXME: needs doc
  141. */
  142. uint8_t eeconfig_read_audio(void) { return eeprom_read_byte(EECONFIG_AUDIO); }
  143. /** \brief eeconfig update audio
  144. *
  145. * FIXME: needs doc
  146. */
  147. void eeconfig_update_audio(uint8_t val) { eeprom_update_byte(EECONFIG_AUDIO, val); }
  148. /** \brief eeconfig read kb
  149. *
  150. * FIXME: needs doc
  151. */
  152. uint32_t eeconfig_read_kb(void) { return eeprom_read_dword(EECONFIG_KEYBOARD); }
  153. /** \brief eeconfig update kb
  154. *
  155. * FIXME: needs doc
  156. */
  157. void eeconfig_update_kb(uint32_t val) { eeprom_update_dword(EECONFIG_KEYBOARD, val); }
  158. /** \brief eeconfig read user
  159. *
  160. * FIXME: needs doc
  161. */
  162. uint32_t eeconfig_read_user(void) { return eeprom_read_dword(EECONFIG_USER); }
  163. /** \brief eeconfig update user
  164. *
  165. * FIXME: needs doc
  166. */
  167. void eeconfig_update_user(uint32_t val) { eeprom_update_dword(EECONFIG_USER, val); }
  168. /** \brief eeconfig read haptic
  169. *
  170. * FIXME: needs doc
  171. */
  172. uint32_t eeconfig_read_haptic(void) { return eeprom_read_dword(EECONFIG_HAPTIC); }
  173. /** \brief eeconfig update haptic
  174. *
  175. * FIXME: needs doc
  176. */
  177. void eeconfig_update_haptic(uint32_t val) { eeprom_update_dword(EECONFIG_HAPTIC, val); }
  178. /** \brief eeconfig read split handedness
  179. *
  180. * FIXME: needs doc
  181. */
  182. bool eeconfig_read_handedness(void) { return !!eeprom_read_byte(EECONFIG_HANDEDNESS); }
  183. /** \brief eeconfig update split handedness
  184. *
  185. * FIXME: needs doc
  186. */
  187. void eeconfig_update_handedness(bool val) { eeprom_update_byte(EECONFIG_HANDEDNESS, !!val); }