You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

340 lines
8.0 KiB

Add ChibiOS support for QMK (#465) * Modularity and gcc warnings fixes. * Add ChibiOS support (USB stack + support files). * Make usb_main more USB_DRIVER #define independent. * Move chibios to tool. * Implement jump-to-bootloader. * Small updates. * Fix bootloader-jump compiling. * Move AVR specific sleep_led.c into avr. * Add basic sleep_led for chibios. * Update chibios README. * NKRO fixes. * Rename some Makefile defines. * Move STM32 bootloader address config to separate .h file. * Add ARM Teensies bootloader code. * Fix chibios/usb_main GET_REPORT handing. * Add missing #include to keymap.c. * Make bootmagic.c code portable (_delay_ms -> wait_ms). * Move declaration of keymap_config. Should really not declare variables in .h files - since it's included in different .c files, a proper linker then complains that the same variable is declared more than once (once for each .c file that the offending .h is included in). * Add eeprom support for chibios/kinetis. * Rename chibios example keyboard. * Move chibios/cortex selection to local Makefiles. * Chibios: use WFI in idle. WIP suspend stuff. * ChibiOS/kinetis: sending remote wakeup. * ChibiOS/STM32: send remote wakeup. * Fix report size of boot protocol. * Fix drop key stroke Keyboard report should be checked if its transfer finishs successfully. Otherwise key stroke can be missing when other key event occurs before the last report transfer is done. Boot protocol 10ms interval probably causes this problem in case it receives key events in a row within the period. NKRO protocol suffers less or nothing due to its interval 1ms. * Chibios/usb_main: rename a variable for clarity. * Add correct chibios/bootloader_jump for infinity KB. * ChibiOS: make reset request more CMSISy. * Chibios: Add breathing sleep LED on Kinetis MCUs. * ChibiOS: Update infinity bootloader code to match updated ChibiOS. * ChibiOS: prettify/document sleep_led code. * Chibios: Remove the wait in the main loop. * Add maple mini code. * Do timeout when writing to CONSOLE EP queue. Fixes TMK bug #266. * Chibios: add 'core/protocol' to the makefiles' search path. * Chibios: Update to new USB API. * Chibios: add more guards for transmitting (fix a deadlock bug). * Add update for chibios in README * Chibios: Fix a HardFault bug (wait after start). * Chibios: cleanup usb_main code. * Chibios: Revert common.mk change (fix AVR linking problem). * core: Fix chibios user compile options Compile options can be defined in project Makefile such as UDEFS, UADEFS, UINCDIR, ULIBDIR and ULIBS. * Sysv format for ChibiOS arm-none-eabi-size Some new patches to ChibiOS puts heap as it's own section. So the berkeley format is now useless, as the heap will be included in the BSS report. The sysv format displays the bss size correctly. * Fix hard-coded path of CHIBIOS * Add support for new version of ChibiOS and Contrib The Kinetis support has moved to a separate Contrib repository in the newest version of Chibios. There has also been some structure changes. So this adds support for those, while maintaining back- wards compability. * Update ChibiOS instructions * Chibios: implement sleep LED for STM32. * Chibios: Update the main chibios README. * Chibios: fix STM32_BOOTLOADER_ADDRESS name. * Chibios: make the default bootloader_jump redefinable (weak). * Chibios: disable LTO (link-time optimisation). With LTO enabled, sometimes things fail for mysterious reasons (e.g. bootloader jump on WF with LEDs enabled), just because the linker optimisation is too aggressive. * Chibios: add default location for chibios-contrib. * ChibiOS: update mk to match chibios/master. * ChibiOS: update instructions.md. * Add chibi_onekey example. * Add comments to chibi_onekey Makefile. * Rename some Makefile defines. * Move STM32 bootloader address config to separate .h file. * Rename chibios example keyboard. * Move chibios/cortex selection to local Makefiles. * Add Teensy LC onekey example. * Chibios: use WFI in idle. WIP suspend stuff. * Update chibi/teensy instructions. * Update chibios/Teensy instructions. * Add infinity_chibios * Add keymap_hasu.c * Infinity_chibios: select correct bootloader_jump. * Infinity_chibios: improve comments. * Add generic STM32F103C8T6 example. * Add maple mini code. * STM32F103x fixes. * Add maple mini pinout pic. * Chibios: updates for 3.0.4 git. * Chibios: rename example stm32_onekey -> stm32_f072_onekey. * Chibios: add makefiles for Teensy 3.x examples. * Chibios: update Teensy 3.x instructions. * Chibios: Tsy LC is cortex-m0plus. * Chibios: add more guards for transmitting (fix a deadlock bug). * Change README for chibios * Chibios: update examples to current chibios git. Match the changes in mainline chibios: - update chconf.h - update supplied ld scripts structure - update Teensy instructions (switch to official chibios and introduce contrib) * Add ChibiOS and ChibiOS-Contrib submodules Also fix the makefile path for them. * Moves chibios keyboards to keyboards folder * First version of ChibiOS compilation Only the stm32_f072_onkey keyboard is ported at the moment. It compiles, but still doesn't link. * More chibios fixes It now compiles without warnings and links * Move the teensy_lc_onekey to the keyboards folder * Clean up the make file rule structure * Remove keymap_fn_to_action * Update more ChibiOS keyboards to QMK Most of them does not compile at the moment though. * Use older version of Chibios libraries The newest ones have problems with compilation * Remove USB_UNCONFIGURED event It isn't present in the older version of ChibiOS * Fix the infinity_chibios compilation * Fix potentially uninitialized variable * Add missing include * Fix the ChibiOS makefile * Fix some Chibios keyboard compilation * Revert the rules.mk file back to master version * Combine the chibios and AVR makefiles With just the required overrides in the respective platform specific one. * Slight makefile restrucuring Platform specific compiler options * Move avr specific targets out of the main rules * Fix ChibiOS objcopy The ChibiOS objcopy needs different parameters, so the parameters are moved to the corresponding platform rule file * Fix the objcopy for real this time The comands were moved around, so chibios used avr and the ohter way around. Also change the objsize output format * Fix the thumb flags * Fix the infinity hasu keymap * Per platform cpp flags * Add gcc-arm-none-eabi package to travis * Add arm-none-eabi-newlib to travis * Fix the name of the libnewlib-arm-none-eabi lib * Fix the ChibiOS paths So that they are properly relative, and builds don't generate extra folders * Fix the board path of stm32_f103_onekey * Only consider folders with Makefiles as subproject
7 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
2020 November 28 Breaking Changes Update (#11053) * Branch point for 2020 November 28 Breaking Change * Remove matrix_col_t to allow MATRIX_ROWS > 32 (#10183) * Add support for soft serial to ATmega32U2 (#10204) * Change MIDI velocity implementation to allow direct control of velocity value (#9940) * Add ability to build a subset of all keyboards based on platform. * Actually use eeprom_driver_init(). * Make bootloader_jump weak for ChibiOS. (#10417) * Joystick 16-bit support (#10439) * Per-encoder resolutions (#10259) * Share button state from mousekey to pointing_device (#10179) * Add hotfix for chibios keyboards not wake (#10088) * Add advanced/efficient RGB Matrix Indicators (#8564) * Naming change. * Support for STM32 GPIOF,G,H,I,J,K (#10206) * Add milc as a dependency and remove the installed milc (#10563) * ChibiOS upgrade: early init conversions (#10214) * ChibiOS upgrade: configuration file migrator (#9952) * Haptic and solenoid cleanup (#9700) * XD75 cleanup (#10524) * OLED display update interval support (#10388) * Add definition based on currently-selected serial driver. (#10716) * New feature: Retro Tapping per key (#10622) * Allow for modification of output RGB values when using rgblight/rgb_matrix. (#10638) * Add housekeeping task callbacks so that keyboards/keymaps are capable of executing code for each main loop iteration. (#10530) * Rescale both ChibiOS and AVR backlighting. * Reduce Helix keyboard build variation (#8669) * Minor change to behavior allowing display updates to continue between task ticks (#10750) * Some GPIO manipulations in matrix.c change to atomic. (#10491) * qmk cformat (#10767) * [Keyboard] Update the Speedo firmware for v3.0 (#10657) * Maartenwut/Maarten namechange to evyd13/Evy (#10274) * [quantum] combine repeated lines of code (#10837) * Add step sequencer feature (#9703) * aeboards/ext65 refactor (#10820) * Refactor xelus/dawn60 for Rev2 later (#10584) * add DEBUG_MATRIX_SCAN_RATE_ENABLE to common_features.mk (#10824) * [Core] Added `add_oneshot_mods` & `del_oneshot_mods` (#10549) * update chibios os usb for the otg driver (#8893) * Remove HD44780 References, Part 4 (#10735) * [Keyboard] Add Valor FRL TKL (+refactor) (#10512) * Fix cursor position bug in oled_write_raw functions (#10800) * Fixup version.h writing when using SKIP_VERSION=yes (#10972) * Allow for certain code in the codebase assuming length of string. (#10974) * Add AT90USB support for serial.c (#10706) * Auto shift: support repeats and early registration (#9826) * Rename ledmatrix.h to match .c file (#7949) * Split RGB_MATRIX_ENABLE into _ENABLE and _DRIVER (#10231) * Split LED_MATRIX_ENABLE into _ENABLE and _DRIVER (#10840) * Merge point for 2020 Nov 28 Breaking Change
3 years ago
  1. #include <string.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include "eeprom.h"
  5. #include "eeconfig.h"
  6. #include "action_layer.h"
  7. #if defined(EEPROM_DRIVER)
  8. # include "eeprom_driver.h"
  9. #endif
  10. #if defined(HAPTIC_ENABLE)
  11. # include "haptic.h"
  12. #endif
  13. #if defined(VIA_ENABLE)
  14. bool via_eeprom_is_valid(void);
  15. void via_eeprom_set_valid(bool valid);
  16. void eeconfig_init_via(void);
  17. #endif
  18. /** \brief eeconfig enable
  19. *
  20. * FIXME: needs doc
  21. */
  22. __attribute__((weak)) void eeconfig_init_user(void) {
  23. #if (EECONFIG_USER_DATA_SIZE) == 0
  24. // Reset user EEPROM value to blank, rather than to a set value
  25. eeconfig_update_user(0);
  26. #endif
  27. }
  28. __attribute__((weak)) void eeconfig_init_kb(void) {
  29. #if (EECONFIG_KB_DATA_SIZE) == 0
  30. // Reset Keyboard EEPROM value to blank, rather than to a set value
  31. eeconfig_update_kb(0);
  32. #endif
  33. eeconfig_init_user();
  34. }
  35. /*
  36. * FIXME: needs doc
  37. */
  38. void eeconfig_init_quantum(void) {
  39. #if defined(EEPROM_DRIVER)
  40. eeprom_driver_erase();
  41. #endif
  42. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
  43. eeprom_update_byte(EECONFIG_DEBUG, 0);
  44. default_layer_state = (layer_state_t)1 << 0;
  45. eeprom_update_byte(EECONFIG_DEFAULT_LAYER, default_layer_state);
  46. // Enable oneshot and autocorrect by default: 0b0001 0100 0000 0000
  47. eeprom_update_word(EECONFIG_KEYMAP, 0x1400);
  48. eeprom_update_byte(EECONFIG_BACKLIGHT, 0);
  49. eeprom_update_byte(EECONFIG_AUDIO, 0);
  50. eeprom_update_dword(EECONFIG_RGBLIGHT, 0);
  51. eeprom_update_byte(EECONFIG_RGBLIGHT_EXTENDED, 0);
  52. eeprom_update_byte(EECONFIG_UNUSED, 0);
  53. eeprom_update_byte(EECONFIG_UNICODEMODE, 0);
  54. eeprom_update_byte(EECONFIG_STENOMODE, 0);
  55. uint64_t dummy = 0;
  56. eeprom_update_block(&dummy, EECONFIG_RGB_MATRIX, sizeof(uint64_t));
  57. eeprom_update_dword(EECONFIG_HAPTIC, 0);
  58. #if defined(HAPTIC_ENABLE)
  59. haptic_reset();
  60. #endif
  61. #if (EECONFIG_KB_DATA_SIZE) > 0
  62. eeconfig_init_kb_datablock();
  63. #endif
  64. #if (EECONFIG_USER_DATA_SIZE) > 0
  65. eeconfig_init_user_datablock();
  66. #endif
  67. #if defined(VIA_ENABLE)
  68. // Invalidate VIA eeprom config, and then reset.
  69. // Just in case if power is lost mid init, this makes sure that it pets
  70. // properly re-initialized.
  71. via_eeprom_set_valid(false);
  72. eeconfig_init_via();
  73. #endif
  74. eeconfig_init_kb();
  75. }
  76. /** \brief eeconfig initialization
  77. *
  78. * FIXME: needs doc
  79. */
  80. void eeconfig_init(void) {
  81. eeconfig_init_quantum();
  82. }
  83. /** \brief eeconfig enable
  84. *
  85. * FIXME: needs doc
  86. */
  87. void eeconfig_enable(void) {
  88. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
  89. }
  90. /** \brief eeconfig disable
  91. *
  92. * FIXME: needs doc
  93. */
  94. void eeconfig_disable(void) {
  95. #if defined(EEPROM_DRIVER)
  96. eeprom_driver_erase();
  97. #endif
  98. eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
  99. }
  100. /** \brief eeconfig is enabled
  101. *
  102. * FIXME: needs doc
  103. */
  104. bool eeconfig_is_enabled(void) {
  105. bool is_eeprom_enabled = (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER);
  106. #ifdef VIA_ENABLE
  107. if (is_eeprom_enabled) {
  108. is_eeprom_enabled = via_eeprom_is_valid();
  109. }
  110. #endif
  111. return is_eeprom_enabled;
  112. }
  113. /** \brief eeconfig is disabled
  114. *
  115. * FIXME: needs doc
  116. */
  117. bool eeconfig_is_disabled(void) {
  118. bool is_eeprom_disabled = (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF);
  119. #ifdef VIA_ENABLE
  120. if (!is_eeprom_disabled) {
  121. is_eeprom_disabled = !via_eeprom_is_valid();
  122. }
  123. #endif
  124. return is_eeprom_disabled;
  125. }
  126. /** \brief eeconfig read debug
  127. *
  128. * FIXME: needs doc
  129. */
  130. uint8_t eeconfig_read_debug(void) {
  131. return eeprom_read_byte(EECONFIG_DEBUG);
  132. }
  133. /** \brief eeconfig update debug
  134. *
  135. * FIXME: needs doc
  136. */
  137. void eeconfig_update_debug(uint8_t val) {
  138. eeprom_update_byte(EECONFIG_DEBUG, val);
  139. }
  140. /** \brief eeconfig read default layer
  141. *
  142. * FIXME: needs doc
  143. */
  144. uint8_t eeconfig_read_default_layer(void) {
  145. return eeprom_read_byte(EECONFIG_DEFAULT_LAYER);
  146. }
  147. /** \brief eeconfig update default layer
  148. *
  149. * FIXME: needs doc
  150. */
  151. void eeconfig_update_default_layer(uint8_t val) {
  152. eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val);
  153. }
  154. /** \brief eeconfig read keymap
  155. *
  156. * FIXME: needs doc
  157. */
  158. uint16_t eeconfig_read_keymap(void) {
  159. return eeprom_read_word(EECONFIG_KEYMAP);
  160. }
  161. /** \brief eeconfig update keymap
  162. *
  163. * FIXME: needs doc
  164. */
  165. void eeconfig_update_keymap(uint16_t val) {
  166. eeprom_update_word(EECONFIG_KEYMAP, val);
  167. }
  168. /** \brief eeconfig read audio
  169. *
  170. * FIXME: needs doc
  171. */
  172. uint8_t eeconfig_read_audio(void) {
  173. return eeprom_read_byte(EECONFIG_AUDIO);
  174. }
  175. /** \brief eeconfig update audio
  176. *
  177. * FIXME: needs doc
  178. */
  179. void eeconfig_update_audio(uint8_t val) {
  180. eeprom_update_byte(EECONFIG_AUDIO, val);
  181. }
  182. #if (EECONFIG_KB_DATA_SIZE) == 0
  183. /** \brief eeconfig read kb
  184. *
  185. * FIXME: needs doc
  186. */
  187. uint32_t eeconfig_read_kb(void) {
  188. return eeprom_read_dword(EECONFIG_KEYBOARD);
  189. }
  190. /** \brief eeconfig update kb
  191. *
  192. * FIXME: needs doc
  193. */
  194. void eeconfig_update_kb(uint32_t val) {
  195. eeprom_update_dword(EECONFIG_KEYBOARD, val);
  196. }
  197. #endif // (EECONFIG_KB_DATA_SIZE) == 0
  198. #if (EECONFIG_USER_DATA_SIZE) == 0
  199. /** \brief eeconfig read user
  200. *
  201. * FIXME: needs doc
  202. */
  203. uint32_t eeconfig_read_user(void) {
  204. return eeprom_read_dword(EECONFIG_USER);
  205. }
  206. /** \brief eeconfig update user
  207. *
  208. * FIXME: needs doc
  209. */
  210. void eeconfig_update_user(uint32_t val) {
  211. eeprom_update_dword(EECONFIG_USER, val);
  212. }
  213. #endif // (EECONFIG_USER_DATA_SIZE) == 0
  214. /** \brief eeconfig read haptic
  215. *
  216. * FIXME: needs doc
  217. */
  218. uint32_t eeconfig_read_haptic(void) {
  219. return eeprom_read_dword(EECONFIG_HAPTIC);
  220. }
  221. /** \brief eeconfig update haptic
  222. *
  223. * FIXME: needs doc
  224. */
  225. void eeconfig_update_haptic(uint32_t val) {
  226. eeprom_update_dword(EECONFIG_HAPTIC, val);
  227. }
  228. /** \brief eeconfig read split handedness
  229. *
  230. * FIXME: needs doc
  231. */
  232. bool eeconfig_read_handedness(void) {
  233. return !!eeprom_read_byte(EECONFIG_HANDEDNESS);
  234. }
  235. /** \brief eeconfig update split handedness
  236. *
  237. * FIXME: needs doc
  238. */
  239. void eeconfig_update_handedness(bool val) {
  240. eeprom_update_byte(EECONFIG_HANDEDNESS, !!val);
  241. }
  242. #if (EECONFIG_KB_DATA_SIZE) > 0
  243. /** \brief eeconfig assert keyboard data block version
  244. *
  245. * FIXME: needs doc
  246. */
  247. bool eeconfig_is_kb_datablock_valid(void) {
  248. return eeprom_read_dword(EECONFIG_KEYBOARD) == (EECONFIG_KB_DATA_VERSION);
  249. }
  250. /** \brief eeconfig read keyboard data block
  251. *
  252. * FIXME: needs doc
  253. */
  254. void eeconfig_read_kb_datablock(void *data) {
  255. if (eeconfig_is_kb_datablock_valid()) {
  256. eeprom_read_block(data, EECONFIG_KB_DATABLOCK, (EECONFIG_KB_DATA_SIZE));
  257. } else {
  258. memset(data, 0, (EECONFIG_KB_DATA_SIZE));
  259. }
  260. }
  261. /** \brief eeconfig update keyboard data block
  262. *
  263. * FIXME: needs doc
  264. */
  265. void eeconfig_update_kb_datablock(const void *data) {
  266. eeprom_update_dword(EECONFIG_KEYBOARD, (EECONFIG_KB_DATA_VERSION));
  267. eeprom_update_block(data, EECONFIG_KB_DATABLOCK, (EECONFIG_KB_DATA_SIZE));
  268. }
  269. /** \brief eeconfig init keyboard data block
  270. *
  271. * FIXME: needs doc
  272. */
  273. __attribute__((weak)) void eeconfig_init_kb_datablock(void) {
  274. uint8_t dummy_kb[(EECONFIG_KB_DATA_SIZE)] = {0};
  275. eeconfig_update_kb_datablock(dummy_kb);
  276. }
  277. #endif // (EECONFIG_KB_DATA_SIZE) > 0
  278. #if (EECONFIG_USER_DATA_SIZE) > 0
  279. /** \brief eeconfig assert user data block version
  280. *
  281. * FIXME: needs doc
  282. */
  283. bool eeconfig_is_user_datablock_valid(void) {
  284. return eeprom_read_dword(EECONFIG_USER) == (EECONFIG_USER_DATA_VERSION);
  285. }
  286. /** \brief eeconfig read user data block
  287. *
  288. * FIXME: needs doc
  289. */
  290. void eeconfig_read_user_datablock(void *data) {
  291. if (eeconfig_is_user_datablock_valid()) {
  292. eeprom_read_block(data, EECONFIG_USER_DATABLOCK, (EECONFIG_USER_DATA_SIZE));
  293. } else {
  294. memset(data, 0, (EECONFIG_USER_DATA_SIZE));
  295. }
  296. }
  297. /** \brief eeconfig update user data block
  298. *
  299. * FIXME: needs doc
  300. */
  301. void eeconfig_update_user_datablock(const void *data) {
  302. eeprom_update_dword(EECONFIG_USER, (EECONFIG_USER_DATA_VERSION));
  303. eeprom_update_block(data, EECONFIG_USER_DATABLOCK, (EECONFIG_USER_DATA_SIZE));
  304. }
  305. /** \brief eeconfig init user data block
  306. *
  307. * FIXME: needs doc
  308. */
  309. __attribute__((weak)) void eeconfig_init_user_datablock(void) {
  310. uint8_t dummy_user[(EECONFIG_USER_DATA_SIZE)] = {0};
  311. eeconfig_update_user_datablock(dummy_user);
  312. }
  313. #endif // (EECONFIG_USER_DATA_SIZE) > 0