logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

eeconfig.c (10293B)


  1. #include <string.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include "debug.h"
  5. #include "eeconfig.h"
  6. #include "action_layer.h"
  7. #include "nvm_eeconfig.h"
  8. #include "keycode_config.h"
  9. #ifdef BACKLIGHT_ENABLE
  10. # include "backlight.h"
  11. #endif // BACKLIGHT_ENABLE
  12. #ifdef AUDIO_ENABLE
  13. # include "audio.h"
  14. #endif // AUDIO_ENABLE
  15. #ifdef RGBLIGHT_ENABLE
  16. # include "rgblight.h"
  17. #endif // RGBLIGHT_ENABLE
  18. #ifdef RGB_MATRIX_ENABLE
  19. # include "rgb_matrix_types.h"
  20. #endif // RGB_MATRIX_ENABLE
  21. #ifdef LED_MATRIX_ENABLE
  22. # include "led_matrix_types.h"
  23. #endif // LED_MATRIX_ENABLE
  24. #ifdef UNICODE_COMMON_ENABLE
  25. # include "unicode.h"
  26. #endif // UNICODE_COMMON_ENABLE
  27. #ifdef HAPTIC_ENABLE
  28. # include "haptic.h"
  29. #endif // HAPTIC_ENABLE
  30. #ifdef CONNECTION_ENABLE
  31. # include "connection.h"
  32. #endif // CONNECTION_ENABLE
  33. #ifdef VIA_ENABLE
  34. bool via_eeprom_is_valid(void);
  35. void via_eeprom_set_valid(bool valid);
  36. void eeconfig_init_via(void);
  37. #else
  38. void dynamic_keymap_reset(void);
  39. #endif // VIA_ENABLE
  40. #ifndef NKRO_DEFAULT_ON
  41. # define NKRO_DEFAULT_ON false
  42. #endif
  43. __attribute__((weak)) void eeconfig_init_user(void) {
  44. #if (EECONFIG_USER_DATA_SIZE) == 0
  45. // Reset user EEPROM value to blank, rather than to a set value
  46. eeconfig_update_user(0);
  47. #endif // (EECONFIG_USER_DATA_SIZE) == 0
  48. }
  49. __attribute__((weak)) void eeconfig_init_kb(void) {
  50. #if (EECONFIG_KB_DATA_SIZE) == 0
  51. // Reset Keyboard EEPROM value to blank, rather than to a set value
  52. eeconfig_update_kb(0);
  53. #endif // (EECONFIG_KB_DATA_SIZE) == 0
  54. eeconfig_init_user();
  55. }
  56. void eeconfig_init_quantum(void) {
  57. nvm_eeconfig_erase();
  58. eeconfig_enable();
  59. debug_config_t debug_config = {0};
  60. eeconfig_update_debug(&debug_config);
  61. default_layer_state = (layer_state_t)1 << 0;
  62. eeconfig_update_default_layer(default_layer_state);
  63. keymap_config_t keymap_config = {
  64. .swap_control_capslock = false,
  65. .capslock_to_control = false,
  66. .swap_lalt_lgui = false,
  67. .swap_ralt_rgui = false,
  68. .no_gui = false,
  69. .swap_grave_esc = false,
  70. .swap_backslash_backspace = false,
  71. .nkro = NKRO_DEFAULT_ON,
  72. .swap_lctl_lgui = false,
  73. .swap_rctl_rgui = false,
  74. .oneshot_enable = true, // Enable oneshot by default
  75. .swap_escape_capslock = false,
  76. .autocorrect_enable = true, // Enable autocorrect by default
  77. };
  78. eeconfig_update_keymap(&keymap_config);
  79. #ifdef BACKLIGHT_ENABLE
  80. backlight_config_t backlight_config = {0};
  81. eeconfig_update_backlight(&backlight_config);
  82. #endif // BACKLIGHT_ENABLE
  83. #ifdef AUDIO_ENABLE
  84. audio_config_t audio_config = {0};
  85. eeconfig_update_audio(&audio_config);
  86. #endif // AUDIO_ENABLE
  87. #ifdef RGBLIGHT_ENABLE
  88. extern void eeconfig_update_rgblight_default(void);
  89. eeconfig_update_rgblight_default();
  90. #endif // RGBLIGHT_ENABLE
  91. #ifdef UNICODE_COMMON_ENABLE
  92. unicode_config_t unicode_config = {0};
  93. eeconfig_update_unicode_mode(&unicode_config);
  94. #endif // UNICODE_COMMON_ENABLE
  95. #ifdef STENO_ENABLE
  96. eeconfig_update_steno_mode(0);
  97. #endif // STENO_ENABLE
  98. #ifdef RGB_MATRIX_ENABLE
  99. extern void eeconfig_update_rgb_matrix_default(void);
  100. eeconfig_update_rgb_matrix_default();
  101. #endif
  102. #ifdef LED_MATRIX_ENABLE
  103. extern void eeconfig_update_led_matrix_default(void);
  104. eeconfig_update_led_matrix_default();
  105. #endif // LED_MATRIX_ENABLE
  106. #ifdef HAPTIC_ENABLE
  107. haptic_config_t haptic_config = {0};
  108. eeconfig_update_haptic(&haptic_config);
  109. haptic_reset();
  110. #endif // HAPTIC_ENABLE
  111. #ifdef CONNECTION_ENABLE
  112. extern void eeconfig_update_connection_default(void);
  113. eeconfig_update_connection_default();
  114. #endif // CONNECTION_ENABLE
  115. #if (EECONFIG_KB_DATA_SIZE) > 0
  116. eeconfig_init_kb_datablock();
  117. #endif // (EECONFIG_KB_DATA_SIZE) > 0
  118. #if (EECONFIG_USER_DATA_SIZE) > 0
  119. eeconfig_init_user_datablock();
  120. #endif // (EECONFIG_USER_DATA_SIZE) > 0
  121. #if defined(VIA_ENABLE)
  122. // Invalidate VIA eeprom config, and then reset.
  123. // Just in case if power is lost mid init, this makes sure that it gets
  124. // properly re-initialized.
  125. eeconfig_init_via();
  126. #elif defined(DYNAMIC_KEYMAP_ENABLE)
  127. dynamic_keymap_reset();
  128. #endif
  129. eeconfig_init_kb();
  130. #ifdef RGB_MATRIX_ENABLE
  131. extern void eeconfig_force_flush_rgb_matrix(void);
  132. eeconfig_force_flush_rgb_matrix();
  133. #endif // RGB_MATRIX_ENABLE
  134. #ifdef LED_MATRIX_ENABLE
  135. extern void eeconfig_force_flush_led_matrix(void);
  136. eeconfig_force_flush_led_matrix();
  137. #endif // LED_MATRIX_ENABLE
  138. }
  139. void eeconfig_init(void) {
  140. eeconfig_init_quantum();
  141. }
  142. void eeconfig_enable(void) {
  143. nvm_eeconfig_enable();
  144. }
  145. void eeconfig_disable(void) {
  146. nvm_eeconfig_disable();
  147. }
  148. bool eeconfig_is_enabled(void) {
  149. bool is_eeprom_enabled = nvm_eeconfig_is_enabled();
  150. #ifdef VIA_ENABLE
  151. if (is_eeprom_enabled) {
  152. is_eeprom_enabled = via_eeprom_is_valid();
  153. }
  154. #endif // VIA_ENABLE
  155. return is_eeprom_enabled;
  156. }
  157. bool eeconfig_is_disabled(void) {
  158. bool is_eeprom_disabled = nvm_eeconfig_is_disabled();
  159. #ifdef VIA_ENABLE
  160. if (!is_eeprom_disabled) {
  161. is_eeprom_disabled = !via_eeprom_is_valid();
  162. }
  163. #endif // VIA_ENABLE
  164. return is_eeprom_disabled;
  165. }
  166. void eeconfig_read_debug(debug_config_t *debug_config) {
  167. nvm_eeconfig_read_debug(debug_config);
  168. }
  169. void eeconfig_update_debug(const debug_config_t *debug_config) {
  170. nvm_eeconfig_update_debug(debug_config);
  171. }
  172. layer_state_t eeconfig_read_default_layer(void) {
  173. return nvm_eeconfig_read_default_layer();
  174. }
  175. void eeconfig_update_default_layer(layer_state_t state) {
  176. nvm_eeconfig_update_default_layer(state);
  177. }
  178. void eeconfig_read_keymap(keymap_config_t *keymap_config) {
  179. nvm_eeconfig_read_keymap(keymap_config);
  180. }
  181. void eeconfig_update_keymap(const keymap_config_t *keymap_config) {
  182. nvm_eeconfig_update_keymap(keymap_config);
  183. }
  184. #ifdef AUDIO_ENABLE
  185. void eeconfig_read_audio(audio_config_t *audio_config) {
  186. nvm_eeconfig_read_audio(audio_config);
  187. }
  188. void eeconfig_update_audio(const audio_config_t *audio_config) {
  189. nvm_eeconfig_update_audio(audio_config);
  190. }
  191. #endif // AUDIO_ENABLE
  192. #ifdef UNICODE_COMMON_ENABLE
  193. void eeconfig_read_unicode_mode(unicode_config_t *unicode_config) {
  194. return nvm_eeconfig_read_unicode_mode(unicode_config);
  195. }
  196. void eeconfig_update_unicode_mode(const unicode_config_t *unicode_config) {
  197. nvm_eeconfig_update_unicode_mode(unicode_config);
  198. }
  199. #endif // UNICODE_COMMON_ENABLE
  200. #ifdef BACKLIGHT_ENABLE
  201. void eeconfig_read_backlight(backlight_config_t *backlight_config) {
  202. nvm_eeconfig_read_backlight(backlight_config);
  203. }
  204. void eeconfig_update_backlight(const backlight_config_t *backlight_config) {
  205. nvm_eeconfig_update_backlight(backlight_config);
  206. }
  207. #endif // BACKLIGHT_ENABLE
  208. #ifdef STENO_ENABLE
  209. uint8_t eeconfig_read_steno_mode(void) {
  210. return nvm_eeconfig_read_steno_mode();
  211. }
  212. void eeconfig_update_steno_mode(uint8_t val) {
  213. nvm_eeconfig_update_steno_mode(val);
  214. }
  215. #endif // STENO_ENABLE
  216. #ifdef RGB_MATRIX_ENABLE
  217. void eeconfig_read_rgb_matrix(rgb_config_t *rgb_matrix_config) {
  218. nvm_eeconfig_read_rgb_matrix(rgb_matrix_config);
  219. }
  220. void eeconfig_update_rgb_matrix(const rgb_config_t *rgb_matrix_config) {
  221. nvm_eeconfig_update_rgb_matrix(rgb_matrix_config);
  222. }
  223. #endif // RGB_MATRIX_ENABLE
  224. #ifdef LED_MATRIX_ENABLE
  225. void eeconfig_read_led_matrix(led_eeconfig_t *led_matrix_config) {
  226. nvm_eeconfig_read_led_matrix(led_matrix_config);
  227. }
  228. void eeconfig_update_led_matrix(const led_eeconfig_t *led_matrix_config) {
  229. nvm_eeconfig_update_led_matrix(led_matrix_config);
  230. }
  231. #endif // LED_MATRIX_ENABLE
  232. #ifdef RGBLIGHT_ENABLE
  233. void eeconfig_read_rgblight(rgblight_config_t *rgblight_config) {
  234. nvm_eeconfig_read_rgblight(rgblight_config);
  235. }
  236. void eeconfig_update_rgblight(const rgblight_config_t *rgblight_config) {
  237. nvm_eeconfig_update_rgblight(rgblight_config);
  238. }
  239. #endif // RGBLIGHT_ENABLE
  240. #if (EECONFIG_KB_DATA_SIZE) == 0
  241. uint32_t eeconfig_read_kb(void) {
  242. return nvm_eeconfig_read_kb();
  243. }
  244. void eeconfig_update_kb(uint32_t val) {
  245. nvm_eeconfig_update_kb(val);
  246. }
  247. #endif // (EECONFIG_KB_DATA_SIZE) == 0
  248. #if (EECONFIG_USER_DATA_SIZE) == 0
  249. uint32_t eeconfig_read_user(void) {
  250. return nvm_eeconfig_read_user();
  251. }
  252. void eeconfig_update_user(uint32_t val) {
  253. nvm_eeconfig_update_user(val);
  254. }
  255. #endif // (EECONFIG_USER_DATA_SIZE) == 0
  256. #ifdef HAPTIC_ENABLE
  257. void eeconfig_read_haptic(haptic_config_t *haptic_config) {
  258. nvm_eeconfig_read_haptic(haptic_config);
  259. }
  260. void eeconfig_update_haptic(const haptic_config_t *haptic_config) {
  261. nvm_eeconfig_update_haptic(haptic_config);
  262. }
  263. #endif // HAPTIC_ENABLE
  264. #ifdef CONNECTION_ENABLE
  265. void eeconfig_read_connection(connection_config_t *config) {
  266. nvm_eeconfig_read_connection(config);
  267. }
  268. void eeconfig_update_connection(const connection_config_t *config) {
  269. nvm_eeconfig_update_connection(config);
  270. }
  271. #endif // CONNECTION_ENABLE
  272. bool eeconfig_read_handedness(void) {
  273. return nvm_eeconfig_read_handedness();
  274. }
  275. void eeconfig_update_handedness(bool val) {
  276. nvm_eeconfig_update_handedness(val);
  277. }
  278. #if (EECONFIG_KB_DATA_SIZE) > 0
  279. bool eeconfig_is_kb_datablock_valid(void) {
  280. return nvm_eeconfig_is_kb_datablock_valid();
  281. }
  282. uint32_t eeconfig_read_kb_datablock(void *data, uint32_t offset, uint32_t length) {
  283. return nvm_eeconfig_read_kb_datablock(data, offset, length);
  284. }
  285. uint32_t eeconfig_update_kb_datablock(const void *data, uint32_t offset, uint32_t length) {
  286. return nvm_eeconfig_update_kb_datablock(data, offset, length);
  287. }
  288. __attribute__((weak)) void eeconfig_init_kb_datablock(void) {
  289. nvm_eeconfig_init_kb_datablock();
  290. }
  291. #endif // (EECONFIG_KB_DATA_SIZE) > 0
  292. #if (EECONFIG_USER_DATA_SIZE) > 0
  293. bool eeconfig_is_user_datablock_valid(void) {
  294. return nvm_eeconfig_is_user_datablock_valid();
  295. }
  296. uint32_t eeconfig_read_user_datablock(void *data, uint32_t offset, uint32_t length) {
  297. return nvm_eeconfig_read_user_datablock(data, offset, length);
  298. }
  299. uint32_t eeconfig_update_user_datablock(const void *data, uint32_t offset, uint32_t length) {
  300. return nvm_eeconfig_update_user_datablock(data, offset, length);
  301. }
  302. __attribute__((weak)) void eeconfig_init_user_datablock(void) {
  303. nvm_eeconfig_init_user_datablock();
  304. }
  305. #endif // (EECONFIG_USER_DATA_SIZE) > 0