logo

qmk_firmware

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

eeconfig.h (10442B)


  1. /*
  2. Copyright 2013 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #pragma once
  15. #include <stdint.h>
  16. #include <stdbool.h>
  17. #include <stddef.h> // offsetof
  18. #include "action_layer.h" // layer_state_t
  19. // Size of EEPROM dedicated to keyboard- and user-specific data
  20. #ifndef EECONFIG_KB_DATA_SIZE
  21. # define EECONFIG_KB_DATA_SIZE 0
  22. #endif
  23. #ifndef EECONFIG_KB_DATA_VERSION
  24. # define EECONFIG_KB_DATA_VERSION (EECONFIG_KB_DATA_SIZE)
  25. #endif
  26. #ifndef EECONFIG_USER_DATA_SIZE
  27. # define EECONFIG_USER_DATA_SIZE 0
  28. #endif
  29. #ifndef EECONFIG_USER_DATA_VERSION
  30. # define EECONFIG_USER_DATA_VERSION (EECONFIG_USER_DATA_SIZE)
  31. #endif
  32. /* debug bit */
  33. #define EECONFIG_DEBUG_ENABLE (1 << 0)
  34. #define EECONFIG_DEBUG_MATRIX (1 << 1)
  35. #define EECONFIG_DEBUG_KEYBOARD (1 << 2)
  36. #define EECONFIG_DEBUG_MOUSE (1 << 3)
  37. /* keyconf bit */
  38. #define EECONFIG_KEYMAP_SWAP_CONTROL_CAPSLOCK (1 << 0)
  39. #define EECONFIG_KEYMAP_CAPSLOCK_TO_CONTROL (1 << 1)
  40. #define EECONFIG_KEYMAP_SWAP_LALT_LGUI (1 << 2)
  41. #define EECONFIG_KEYMAP_SWAP_RALT_RGUI (1 << 3)
  42. #define EECONFIG_KEYMAP_NO_GUI (1 << 4)
  43. #define EECONFIG_KEYMAP_SWAP_GRAVE_ESC (1 << 5)
  44. #define EECONFIG_KEYMAP_SWAP_BACKSLASH_BACKSPACE (1 << 6)
  45. #define EECONFIG_KEYMAP_NKRO (1 << 7)
  46. bool eeconfig_is_enabled(void);
  47. bool eeconfig_is_disabled(void);
  48. void eeconfig_init(void);
  49. void eeconfig_init_quantum(void);
  50. void eeconfig_init_kb(void);
  51. void eeconfig_init_user(void);
  52. void eeconfig_enable(void);
  53. void eeconfig_disable(void);
  54. typedef union debug_config_t debug_config_t;
  55. void eeconfig_read_debug(debug_config_t *debug_config) __attribute__((nonnull));
  56. void eeconfig_update_debug(const debug_config_t *debug_config) __attribute__((nonnull));
  57. layer_state_t eeconfig_read_default_layer(void);
  58. void eeconfig_update_default_layer(layer_state_t state);
  59. typedef union keymap_config_t keymap_config_t;
  60. void eeconfig_read_keymap(keymap_config_t *keymap_config) __attribute__((nonnull));
  61. void eeconfig_update_keymap(const keymap_config_t *keymap_config) __attribute__((nonnull));
  62. #ifdef AUDIO_ENABLE
  63. typedef union audio_config_t audio_config_t;
  64. void eeconfig_read_audio(audio_config_t *audio_config) __attribute__((nonnull));
  65. void eeconfig_update_audio(const audio_config_t *audio_config) __attribute__((nonnull));
  66. #endif // AUDIO_ENABLE
  67. #ifdef UNICODE_COMMON_ENABLE
  68. typedef union unicode_config_t unicode_config_t;
  69. void eeconfig_read_unicode_mode(unicode_config_t *unicode_config) __attribute__((nonnull));
  70. void eeconfig_update_unicode_mode(const unicode_config_t *unicode_config) __attribute__((nonnull));
  71. #endif // UNICODE_COMMON_ENABLE
  72. #ifdef BACKLIGHT_ENABLE
  73. typedef union backlight_config_t backlight_config_t;
  74. void eeconfig_read_backlight(backlight_config_t *backlight_config) __attribute__((nonnull));
  75. void eeconfig_update_backlight(const backlight_config_t *backlight_config) __attribute__((nonnull));
  76. #endif // BACKLIGHT_ENABLE
  77. #ifdef STENO_ENABLE
  78. uint8_t eeconfig_read_steno_mode(void);
  79. void eeconfig_update_steno_mode(uint8_t val);
  80. #endif // STENO_ENABLE
  81. #ifdef RGB_MATRIX_ENABLE
  82. typedef union rgb_config_t rgb_config_t;
  83. void eeconfig_read_rgb_matrix(rgb_config_t *rgb_matrix_config) __attribute__((nonnull));
  84. void eeconfig_update_rgb_matrix(const rgb_config_t *rgb_matrix_config) __attribute__((nonnull));
  85. #endif // RGB_MATRIX_ENABLE
  86. #ifdef LED_MATRIX_ENABLE
  87. typedef union led_eeconfig_t led_eeconfig_t;
  88. void eeconfig_read_led_matrix(led_eeconfig_t *led_matrix_config) __attribute__((nonnull));
  89. void eeconfig_update_led_matrix(const led_eeconfig_t *led_matrix_config) __attribute__((nonnull));
  90. #endif // LED_MATRIX_ENABLE
  91. #ifdef RGBLIGHT_ENABLE
  92. typedef union rgblight_config_t rgblight_config_t;
  93. void eeconfig_read_rgblight(rgblight_config_t *rgblight_config) __attribute__((nonnull));
  94. void eeconfig_update_rgblight(const rgblight_config_t *rgblight_config) __attribute__((nonnull));
  95. #endif // RGBLIGHT_ENABLE
  96. #if (EECONFIG_KB_DATA_SIZE) == 0
  97. uint32_t eeconfig_read_kb(void);
  98. void eeconfig_update_kb(uint32_t val);
  99. #endif // (EECONFIG_KB_DATA_SIZE) == 0
  100. #if (EECONFIG_USER_DATA_SIZE) == 0
  101. uint32_t eeconfig_read_user(void);
  102. void eeconfig_update_user(uint32_t val);
  103. #endif // (EECONFIG_USER_DATA_SIZE) == 0
  104. #ifdef HAPTIC_ENABLE
  105. typedef union haptic_config_t haptic_config_t;
  106. void eeconfig_read_haptic(haptic_config_t *haptic_config) __attribute__((nonnull));
  107. void eeconfig_update_haptic(const haptic_config_t *haptic_config) __attribute__((nonnull));
  108. #endif
  109. #ifdef CONNECTION_ENABLE
  110. typedef union connection_config_t connection_config_t;
  111. void eeconfig_read_connection(connection_config_t *config);
  112. void eeconfig_update_connection(const connection_config_t *config);
  113. #endif
  114. bool eeconfig_read_handedness(void);
  115. void eeconfig_update_handedness(bool val);
  116. #if (EECONFIG_KB_DATA_SIZE) > 0
  117. bool eeconfig_is_kb_datablock_valid(void);
  118. uint32_t eeconfig_read_kb_datablock(void *data, uint32_t offset, uint32_t length) __attribute__((nonnull));
  119. uint32_t eeconfig_update_kb_datablock(const void *data, uint32_t offset, uint32_t length) __attribute__((nonnull));
  120. void eeconfig_init_kb_datablock(void);
  121. # define eeconfig_read_kb_datablock_field(__object, __field) eeconfig_read_kb_datablock(&(__object.__field), offsetof(typeof(__object), __field), sizeof(__object.__field))
  122. # define eeconfig_update_kb_datablock_field(__object, __field) eeconfig_update_kb_datablock(&(__object.__field), offsetof(typeof(__object), __field), sizeof(__object.__field))
  123. #endif // (EECONFIG_KB_DATA_SIZE) > 0
  124. #if (EECONFIG_USER_DATA_SIZE) > 0
  125. bool eeconfig_is_user_datablock_valid(void);
  126. uint32_t eeconfig_read_user_datablock(void *data, uint32_t offset, uint32_t length) __attribute__((nonnull));
  127. uint32_t eeconfig_update_user_datablock(const void *data, uint32_t offset, uint32_t length) __attribute__((nonnull));
  128. void eeconfig_init_user_datablock(void);
  129. # define eeconfig_read_user_datablock_field(__object, __field) eeconfig_read_user_datablock(&(__object.__field), offsetof(typeof(__object), __field), sizeof(__object.__field))
  130. # define eeconfig_update_user_datablock_field(__object, __field) eeconfig_update_user_datablock(&(__object.__field), offsetof(typeof(__object), __field), sizeof(__object.__field))
  131. #endif // (EECONFIG_USER_DATA_SIZE) > 0
  132. // Any "checked" debounce variant used requires implementation of:
  133. // -- bool eeconfig_check_valid_##name(void)
  134. // -- void eeconfig_post_flush_##name(void)
  135. #define EECONFIG_DEBOUNCE_HELPER_CHECKED(name, config) \
  136. static uint8_t dirty_##name = false; \
  137. \
  138. bool eeconfig_check_valid_##name(void); \
  139. void eeconfig_post_flush_##name(void); \
  140. \
  141. static inline void eeconfig_init_##name(void) { \
  142. dirty_##name = true; \
  143. if (eeconfig_check_valid_##name()) { \
  144. eeconfig_read_##name(&config); \
  145. dirty_##name = false; \
  146. } \
  147. } \
  148. static inline void eeconfig_flush_##name(bool force) { \
  149. if (force || dirty_##name) { \
  150. eeconfig_update_##name(&config); \
  151. eeconfig_post_flush_##name(); \
  152. dirty_##name = false; \
  153. } \
  154. } \
  155. static inline void eeconfig_flush_##name##_task(uint16_t timeout) { \
  156. static uint16_t flush_timer = 0; \
  157. if (timer_elapsed(flush_timer) > timeout) { \
  158. eeconfig_flush_##name(false); \
  159. flush_timer = timer_read(); \
  160. } \
  161. } \
  162. static inline void eeconfig_flag_##name(bool v) { \
  163. dirty_##name |= v; \
  164. } \
  165. static inline void eeconfig_write_##name(typeof(config) *conf) { \
  166. if (memcmp(&config, conf, sizeof(config)) != 0) { \
  167. memcpy(&config, conf, sizeof(config)); \
  168. eeconfig_flag_##name(true); \
  169. } \
  170. }
  171. #define EECONFIG_DEBOUNCE_HELPER(name, config) \
  172. EECONFIG_DEBOUNCE_HELPER_CHECKED(name, config) \
  173. \
  174. bool eeconfig_check_valid_##name(void) { \
  175. return true; \
  176. } \
  177. void eeconfig_post_flush_##name(void) {}