summaryrefslogtreecommitdiff
path: root/quantum/eeconfig.c
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2025-03-21 23:38:34 +1100
committerGitHub <noreply@github.com>2025-03-21 23:38:34 +1100
commit2b00b846dce1d1267dfdb2a3c2972a367cc0dd44 (patch)
tree6d801a8d83c58ee646b789bfa9ab912857ee7d8c /quantum/eeconfig.c
parentc9d62ddc78e879053241202b288d0129073b07dc (diff)
Non-volatile memory data repository pattern (#24356)
* First batch of eeconfig conversions. * Offset and length for datablocks. * `via`, `dynamic_keymap`. * Fix filename. * Commentary. * wilba leds * satisfaction75 * satisfaction75 * more keyboard whack-a-mole * satisfaction75 * omnikeyish * more whack-a-mole * `generic_features.mk` to automatically pick up nvm repositories * thievery * deferred variable resolve * whitespace * convert api to structs/unions * convert api to structs/unions * convert api to structs/unions * fixups * code-side docs * code size fix * rollback * nvm_xxxxx_erase * Updated location of eeconfig magic numbers so non-EEPROM nvm drivers can use them too. * Fixup build. * Fixup compilation error with encoders. * Build fixes. * Add `via_ci` keymap to onekey to exercise VIA bindings (and thus dynamic keymap et.al.), fixup compilation errors based on preprocessor+sizeof. * Build failure rectification.
Diffstat (limited to 'quantum/eeconfig.c')
-rw-r--r--quantum/eeconfig.c444
1 files changed, 211 insertions, 233 deletions
diff --git a/quantum/eeconfig.c b/quantum/eeconfig.c
index e27f604f12..9aa60fc968 100644
--- a/quantum/eeconfig.c
+++ b/quantum/eeconfig.c
@@ -1,355 +1,333 @@
1#include <string.h> 1#include <string.h>
2#include <stdint.h> 2#include <stdint.h>
3#include <stdbool.h> 3#include <stdbool.h>
4#include "debug.h"
4#include "eeprom.h" 5#include "eeprom.h"
5#include "eeconfig.h" 6#include "eeconfig.h"
7#include "action_layer.h"
8#include "nvm_eeconfig.h"
9#include "keycode_config.h"
6 10
7#if defined(EEPROM_DRIVER) 11#ifdef EEPROM_DRIVER
8# include "eeprom_driver.h" 12# include "eeprom_driver.h"
9#endif 13#endif // EEPROM_DRIVER
14
15#ifdef BACKLIGHT_ENABLE
16# include "backlight.h"
17#endif // BACKLIGHT_ENABLE
18
19#ifdef AUDIO_ENABLE
20# include "audio.h"
21#endif // AUDIO_ENABLE
22
23#ifdef RGBLIGHT_ENABLE
24# include "rgblight.h"
25#endif // RGBLIGHT_ENABLE
26
27#ifdef RGB_MATRIX_ENABLE
28# include "rgb_matrix_types.h"
29#endif // RGB_MATRIX_ENABLE
10 30
11#if defined(HAPTIC_ENABLE) 31#ifdef LED_MATRIX_ENABLE
32# include "led_matrix_types.h"
33#endif // LED_MATRIX_ENABLE
34
35#ifdef UNICODE_COMMON_ENABLE
36# include "unicode.h"
37#endif // UNICODE_COMMON_ENABLE
38
39#ifdef HAPTIC_ENABLE
12# include "haptic.h" 40# include "haptic.h"
13#endif 41#endif // HAPTIC_ENABLE
14 42
15#if defined(VIA_ENABLE) 43#ifdef VIA_ENABLE
16bool via_eeprom_is_valid(void); 44bool via_eeprom_is_valid(void);
17void via_eeprom_set_valid(bool valid); 45void via_eeprom_set_valid(bool valid);
18void eeconfig_init_via(void); 46void eeconfig_init_via(void);
19#endif 47#else
20 48void dynamic_keymap_reset(void);
21_Static_assert((intptr_t)EECONFIG_HANDEDNESS == 14, "EEPROM handedness offset is incorrect"); 49#endif // VIA_ENABLE
22 50
23/** \brief eeconfig enable
24 *
25 * FIXME: needs doc
26 */
27__attribute__((weak)) void eeconfig_init_user(void) { 51__attribute__((weak)) void eeconfig_init_user(void) {
28#if (EECONFIG_USER_DATA_SIZE) == 0 52#if (EECONFIG_USER_DATA_SIZE) == 0
29 // Reset user EEPROM value to blank, rather than to a set value 53 // Reset user EEPROM value to blank, rather than to a set value
30 eeconfig_update_user(0); 54 eeconfig_update_user(0);
31#endif 55#endif // (EECONFIG_USER_DATA_SIZE) == 0
32} 56}
33 57
34__attribute__((weak)) void eeconfig_init_kb(void) { 58__attribute__((weak)) void eeconfig_init_kb(void) {
35#if (EECONFIG_KB_DATA_SIZE) == 0 59#if (EECONFIG_KB_DATA_SIZE) == 0
36 // Reset Keyboard EEPROM value to blank, rather than to a set value 60 // Reset Keyboard EEPROM value to blank, rather than to a set value
37 eeconfig_update_kb(0); 61 eeconfig_update_kb(0);
38#endif 62#endif // (EECONFIG_KB_DATA_SIZE) == 0
39 63
40 eeconfig_init_user(); 64 eeconfig_init_user();
41} 65}
42 66
43/*
44 * FIXME: needs doc
45 */
46void eeconfig_init_quantum(void) { 67void eeconfig_init_quantum(void) {
47#if defined(EEPROM_DRIVER) 68 nvm_eeconfig_erase();
48 eeprom_driver_format(false); 69
49#endif 70 eeconfig_enable();
71
72 debug_config_t debug_config = {0};
73 eeconfig_update_debug(&debug_config);
50 74
51 eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER);
52 eeprom_update_byte(EECONFIG_DEBUG, 0);
53 default_layer_state = (layer_state_t)1 << 0; 75 default_layer_state = (layer_state_t)1 << 0;
54 eeconfig_update_default_layer(default_layer_state); 76 eeconfig_update_default_layer(default_layer_state);
55 // Enable oneshot and autocorrect by default: 0b0001 0100 0000 0000 77
56 eeprom_update_word(EECONFIG_KEYMAP, 0x1400); 78 keymap_config_t keymap_config = {
57 eeprom_update_byte(EECONFIG_BACKLIGHT, 0); 79 .swap_control_capslock = false,
58 eeprom_update_byte(EECONFIG_AUDIO, 0); 80 .capslock_to_control = false,
59 eeprom_update_dword(EECONFIG_RGBLIGHT, 0); 81 .swap_lalt_lgui = false,
60 eeprom_update_byte(EECONFIG_RGBLIGHT_EXTENDED, 0); 82 .swap_ralt_rgui = false,
61 eeprom_update_byte(EECONFIG_UNICODEMODE, 0); 83 .no_gui = false,
62 eeprom_update_byte(EECONFIG_STENOMODE, 0); 84 .swap_grave_esc = false,
63 eeprom_write_qword(EECONFIG_RGB_MATRIX, 0); 85 .swap_backslash_backspace = false,
64 eeprom_update_dword(EECONFIG_HAPTIC, 0); 86 .nkro = false,
65#if defined(HAPTIC_ENABLE) 87 .swap_lctl_lgui = false,
66 haptic_reset(); 88 .swap_rctl_rgui = false,
89 .oneshot_enable = true, // Enable oneshot by default
90 .swap_escape_capslock = false,
91 .autocorrect_enable = true, // Enable autocorrect by default
92 };
93 eeconfig_update_keymap(&keymap_config);
94
95#ifdef BACKLIGHT_ENABLE
96 backlight_config_t backlight_config = {0};
97 eeconfig_update_backlight(&backlight_config);
98#endif // BACKLIGHT_ENABLE
99
100#ifdef AUDIO_ENABLE
101 audio_config_t audio_config = {0};
102 eeconfig_update_audio(&audio_config);
103#endif // AUDIO_ENABLE
104
105#ifdef RGBLIGHT_ENABLE
106 rgblight_config_t rgblight_config = {0};
107 eeconfig_update_rgblight(&rgblight_config);
108#endif // RGBLIGHT_ENABLE
109
110#ifdef UNICODE_COMMON_ENABLE
111 unicode_config_t unicode_config = {0};
112 eeconfig_update_unicode_mode(&unicode_config);
113#endif // UNICODE_COMMON_ENABLE
114
115#ifdef STENO_ENABLE
116 eeconfig_update_steno_mode(0);
117#endif // STENO_ENABLE
118
119#ifdef RGB_MATRIX_ENABLE
120 rgb_config_t rgb_matrix_config = {0};
121 eeconfig_update_rgb_matrix(&rgb_matrix_config);
67#endif 122#endif
68 123
124#ifdef LED_MATRIX_ENABLE
125 led_eeconfig_t led_matrix_config = {0};
126 eeconfig_update_led_matrix(&led_matrix_config);
127#endif // LED_MATRIX_ENABLE
128
129#ifdef HAPTIC_ENABLE
130 haptic_config_t haptic_config = {0};
131 eeconfig_update_haptic(&haptic_config);
132 haptic_reset();
133#endif // HAPTIC_ENABLE
134
69#if (EECONFIG_KB_DATA_SIZE) > 0 135#if (EECONFIG_KB_DATA_SIZE) > 0
70 eeconfig_init_kb_datablock(); 136 eeconfig_init_kb_datablock();
71#endif 137#endif // (EECONFIG_KB_DATA_SIZE) > 0
72 138
73#if (EECONFIG_USER_DATA_SIZE) > 0 139#if (EECONFIG_USER_DATA_SIZE) > 0
74 eeconfig_init_user_datablock(); 140 eeconfig_init_user_datablock();
75#endif 141#endif // (EECONFIG_USER_DATA_SIZE) > 0
76 142
77#if defined(VIA_ENABLE) 143#if defined(VIA_ENABLE)
78 // Invalidate VIA eeprom config, and then reset. 144 // Invalidate VIA eeprom config, and then reset.
79 // Just in case if power is lost mid init, this makes sure that it pets 145 // Just in case if power is lost mid init, this makes sure that it gets
80 // properly re-initialized. 146 // properly re-initialized.
81 via_eeprom_set_valid(false);
82 eeconfig_init_via(); 147 eeconfig_init_via();
148#elif defined(DYNAMIC_KEYMAP_ENABLE)
149 dynamic_keymap_reset();
83#endif 150#endif
84 151
85 eeconfig_init_kb(); 152 eeconfig_init_kb();
86} 153}
87 154
88/** \brief eeconfig initialization
89 *
90 * FIXME: needs doc
91 */
92void eeconfig_init(void) { 155void eeconfig_init(void) {
93 eeconfig_init_quantum(); 156 eeconfig_init_quantum();
94} 157}
95 158
96/** \brief eeconfig enable
97 *
98 * FIXME: needs doc
99 */
100void eeconfig_enable(void) { 159void eeconfig_enable(void) {
101 eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER); 160 nvm_eeconfig_enable();
102} 161}
103 162
104/** \brief eeconfig disable
105 *
106 * FIXME: needs doc
107 */
108void eeconfig_disable(void) { 163void eeconfig_disable(void) {
109#if defined(EEPROM_DRIVER) 164 nvm_eeconfig_disable();
110 eeprom_driver_format(false);
111#endif
112 eeprom_update_word(EECONFIG_MAGIC, EECONFIG_MAGIC_NUMBER_OFF);
113} 165}
114 166
115/** \brief eeconfig is enabled
116 *
117 * FIXME: needs doc
118 */
119bool eeconfig_is_enabled(void) { 167bool eeconfig_is_enabled(void) {
120 bool is_eeprom_enabled = (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER); 168 bool is_eeprom_enabled = nvm_eeconfig_is_enabled();
121#ifdef VIA_ENABLE 169#ifdef VIA_ENABLE
122 if (is_eeprom_enabled) { 170 if (is_eeprom_enabled) {
123 is_eeprom_enabled = via_eeprom_is_valid(); 171 is_eeprom_enabled = via_eeprom_is_valid();
124 } 172 }
125#endif 173#endif // VIA_ENABLE
126 return is_eeprom_enabled; 174 return is_eeprom_enabled;
127} 175}
128 176
129/** \brief eeconfig is disabled
130 *
131 * FIXME: needs doc
132 */
133bool eeconfig_is_disabled(void) { 177bool eeconfig_is_disabled(void) {
134 bool is_eeprom_disabled = (eeprom_read_word(EECONFIG_MAGIC) == EECONFIG_MAGIC_NUMBER_OFF); 178 bool is_eeprom_disabled = nvm_eeconfig_is_disabled();
135#ifdef VIA_ENABLE 179#ifdef VIA_ENABLE
136 if (!is_eeprom_disabled) { 180 if (!is_eeprom_disabled) {
137 is_eeprom_disabled = !via_eeprom_is_valid(); 181 is_eeprom_disabled = !via_eeprom_is_valid();
138 } 182 }
139#endif 183#endif // VIA_ENABLE
140 return is_eeprom_disabled; 184 return is_eeprom_disabled;
141} 185}
142 186
143/** \brief eeconfig read debug 187void eeconfig_read_debug(debug_config_t *debug_config) {
144 * 188 nvm_eeconfig_read_debug(debug_config);
145 * FIXME: needs doc
146 */
147uint8_t eeconfig_read_debug(void) {
148 return eeprom_read_byte(EECONFIG_DEBUG);
149} 189}
150/** \brief eeconfig update debug 190void eeconfig_update_debug(const debug_config_t *debug_config) {
151 * 191 nvm_eeconfig_update_debug(debug_config);
152 * FIXME: needs doc
153 */
154void eeconfig_update_debug(uint8_t val) {
155 eeprom_update_byte(EECONFIG_DEBUG, val);
156} 192}
157 193
158/** \brief eeconfig read default layer
159 *
160 * FIXME: needs doc
161 */
162layer_state_t eeconfig_read_default_layer(void) { 194layer_state_t eeconfig_read_default_layer(void) {
163 uint8_t val = eeprom_read_byte(EECONFIG_DEFAULT_LAYER); 195 return nvm_eeconfig_read_default_layer();
164
165#ifdef DEFAULT_LAYER_STATE_IS_VALUE_NOT_BITMASK
166 // stored as a layer number, so convert back to bitmask
167 return 1 << val;
168#else
169 // stored as 8-bit-wide bitmask, so read the value directly - handling padding to 16/32 bit layer_state_t
170 return val;
171#endif
172} 196}
173/** \brief eeconfig update default layer
174 *
175 * FIXME: needs doc
176 */
177void eeconfig_update_default_layer(layer_state_t state) { 197void eeconfig_update_default_layer(layer_state_t state) {
178#ifdef DEFAULT_LAYER_STATE_IS_VALUE_NOT_BITMASK 198 nvm_eeconfig_update_default_layer(state);
179 // stored as a layer number, so only store the highest layer 199}
180 uint8_t val = get_highest_layer(state); 200
181#else 201void eeconfig_read_keymap(keymap_config_t *keymap_config) {
182 // stored as 8-bit-wide bitmask, so write the value directly - handling truncation from 16/32 bit layer_state_t 202 nvm_eeconfig_read_keymap(keymap_config);
183 uint8_t val = state; 203}
184#endif 204void eeconfig_update_keymap(const keymap_config_t *keymap_config) {
205 nvm_eeconfig_update_keymap(keymap_config);
206}
207
208#ifdef AUDIO_ENABLE
209void eeconfig_read_audio(audio_config_t *audio_config) {
210 nvm_eeconfig_read_audio(audio_config);
211}
212void eeconfig_update_audio(const audio_config_t *audio_config) {
213 nvm_eeconfig_update_audio(audio_config);
214}
215#endif // AUDIO_ENABLE
216
217#ifdef UNICODE_COMMON_ENABLE
218void eeconfig_read_unicode_mode(unicode_config_t *unicode_config) {
219 return nvm_eeconfig_read_unicode_mode(unicode_config);
220}
221void eeconfig_update_unicode_mode(const unicode_config_t *unicode_config) {
222 nvm_eeconfig_update_unicode_mode(unicode_config);
223}
224#endif // UNICODE_COMMON_ENABLE
185 225
186 eeprom_update_byte(EECONFIG_DEFAULT_LAYER, val); 226#ifdef BACKLIGHT_ENABLE
227void eeconfig_read_backlight(backlight_config_t *backlight_config) {
228 nvm_eeconfig_read_backlight(backlight_config);
229}
230void eeconfig_update_backlight(const backlight_config_t *backlight_config) {
231 nvm_eeconfig_update_backlight(backlight_config);
232}
233#endif // BACKLIGHT_ENABLE
234
235#ifdef STENO_ENABLE
236uint8_t eeconfig_read_steno_mode(void) {
237 return nvm_eeconfig_read_steno_mode();
238}
239void eeconfig_update_steno_mode(uint8_t val) {
240 nvm_eeconfig_update_steno_mode(val);
187} 241}
242#endif // STENO_ENABLE
188 243
189/** \brief eeconfig read keymap 244#ifdef RGB_MATRIX_ENABLE
190 * 245void eeconfig_read_rgb_matrix(rgb_config_t *rgb_matrix_config) {
191 * FIXME: needs doc 246 nvm_eeconfig_read_rgb_matrix(rgb_matrix_config);
192 */
193uint16_t eeconfig_read_keymap(void) {
194 return eeprom_read_word(EECONFIG_KEYMAP);
195} 247}
196/** \brief eeconfig update keymap 248void eeconfig_update_rgb_matrix(const rgb_config_t *rgb_matrix_config) {
197 * 249 nvm_eeconfig_update_rgb_matrix(rgb_matrix_config);
198 * FIXME: needs doc
199 */
200void eeconfig_update_keymap(uint16_t val) {
201 eeprom_update_word(EECONFIG_KEYMAP, val);
202} 250}
251#endif // RGB_MATRIX_ENABLE
203 252
204/** \brief eeconfig read audio 253#ifdef LED_MATRIX_ENABLE
205 * 254void eeconfig_read_led_matrix(led_eeconfig_t *led_matrix_config) {
206 * FIXME: needs doc 255 nvm_eeconfig_read_led_matrix(led_matrix_config);
207 */
208uint8_t eeconfig_read_audio(void) {
209 return eeprom_read_byte(EECONFIG_AUDIO);
210} 256}
211/** \brief eeconfig update audio 257void eeconfig_update_led_matrix(const led_eeconfig_t *led_matrix_config) {
212 * 258 nvm_eeconfig_update_led_matrix(led_matrix_config);
213 * FIXME: needs doc
214 */
215void eeconfig_update_audio(uint8_t val) {
216 eeprom_update_byte(EECONFIG_AUDIO, val);
217} 259}
260#endif // LED_MATRIX_ENABLE
261
262#ifdef RGBLIGHT_ENABLE
263void eeconfig_read_rgblight(rgblight_config_t *rgblight_config) {
264 nvm_eeconfig_read_rgblight(rgblight_config);
265}
266void eeconfig_update_rgblight(const rgblight_config_t *rgblight_config) {
267 nvm_eeconfig_update_rgblight(rgblight_config);
268}
269#endif // RGBLIGHT_ENABLE
218 270
219#if (EECONFIG_KB_DATA_SIZE) == 0 271#if (EECONFIG_KB_DATA_SIZE) == 0
220/** \brief eeconfig read kb
221 *
222 * FIXME: needs doc
223 */
224uint32_t eeconfig_read_kb(void) { 272uint32_t eeconfig_read_kb(void) {
225 return eeprom_read_dword(EECONFIG_KEYBOARD); 273 return nvm_eeconfig_read_kb();
226} 274}
227/** \brief eeconfig update kb
228 *
229 * FIXME: needs doc
230 */
231void eeconfig_update_kb(uint32_t val) { 275void eeconfig_update_kb(uint32_t val) {
232 eeprom_update_dword(EECONFIG_KEYBOARD, val); 276 nvm_eeconfig_update_kb(val);
233} 277}
234#endif // (EECONFIG_KB_DATA_SIZE) == 0 278#endif // (EECONFIG_KB_DATA_SIZE) == 0
235 279
236#if (EECONFIG_USER_DATA_SIZE) == 0 280#if (EECONFIG_USER_DATA_SIZE) == 0
237/** \brief eeconfig read user
238 *
239 * FIXME: needs doc
240 */
241uint32_t eeconfig_read_user(void) { 281uint32_t eeconfig_read_user(void) {
242 return eeprom_read_dword(EECONFIG_USER); 282 return nvm_eeconfig_read_user();
243} 283}
244/** \brief eeconfig update user
245 *
246 * FIXME: needs doc
247 */
248void eeconfig_update_user(uint32_t val) { 284void eeconfig_update_user(uint32_t val) {
249 eeprom_update_dword(EECONFIG_USER, val); 285 nvm_eeconfig_update_user(val);
250} 286}
251#endif // (EECONFIG_USER_DATA_SIZE) == 0 287#endif // (EECONFIG_USER_DATA_SIZE) == 0
252 288
253/** \brief eeconfig read haptic 289#ifdef HAPTIC_ENABLE
254 * 290void eeconfig_read_haptic(haptic_config_t *haptic_config) {
255 * FIXME: needs doc 291 nvm_eeconfig_read_haptic(haptic_config);
256 */ 292}
257uint32_t eeconfig_read_haptic(void) { 293void eeconfig_update_haptic(const haptic_config_t *haptic_config) {
258 return eeprom_read_dword(EECONFIG_HAPTIC); 294 nvm_eeconfig_update_haptic(haptic_config);
259} 295}
260/** \brief eeconfig update haptic 296#endif // HAPTIC_ENABLE
261 * 297
262 * FIXME: needs doc
263 */
264void eeconfig_update_haptic(uint32_t val) {
265 eeprom_update_dword(EECONFIG_HAPTIC, val);
266}
267
268/** \brief eeconfig read split handedness
269 *
270 * FIXME: needs doc
271 */
272bool eeconfig_read_handedness(void) { 298bool eeconfig_read_handedness(void) {
273 return !!eeprom_read_byte(EECONFIG_HANDEDNESS); 299 return nvm_eeconfig_read_handedness();
274} 300}
275/** \brief eeconfig update split handedness
276 *
277 * FIXME: needs doc
278 */
279void eeconfig_update_handedness(bool val) { 301void eeconfig_update_handedness(bool val) {
280 eeprom_update_byte(EECONFIG_HANDEDNESS, !!val); 302 nvm_eeconfig_update_handedness(val);
281} 303}
282 304
283#if (EECONFIG_KB_DATA_SIZE) > 0 305#if (EECONFIG_KB_DATA_SIZE) > 0
284/** \brief eeconfig assert keyboard data block version
285 *
286 * FIXME: needs doc
287 */
288bool eeconfig_is_kb_datablock_valid(void) { 306bool eeconfig_is_kb_datablock_valid(void) {
289 return eeprom_read_dword(EECONFIG_KEYBOARD) == (EECONFIG_KB_DATA_VERSION); 307 return nvm_eeconfig_is_kb_datablock_valid();
290} 308}
291/** \brief eeconfig read keyboard data block 309uint32_t eeconfig_read_kb_datablock(void *data, uint32_t offset, uint32_t length) {
292 * 310 return nvm_eeconfig_read_kb_datablock(data, offset, length);
293 * FIXME: needs doc 311}
294 */ 312uint32_t eeconfig_update_kb_datablock(const void *data, uint32_t offset, uint32_t length) {
295void eeconfig_read_kb_datablock(void *data) { 313 return nvm_eeconfig_update_kb_datablock(data, offset, length);
296 if (eeconfig_is_kb_datablock_valid()) {
297 eeprom_read_block(data, EECONFIG_KB_DATABLOCK, (EECONFIG_KB_DATA_SIZE));
298 } else {
299 memset(data, 0, (EECONFIG_KB_DATA_SIZE));
300 }
301} 314}
302/** \brief eeconfig update keyboard data block
303 *
304 * FIXME: needs doc
305 */
306void eeconfig_update_kb_datablock(const void *data) {
307 eeprom_update_dword(EECONFIG_KEYBOARD, (EECONFIG_KB_DATA_VERSION));
308 eeprom_update_block(data, EECONFIG_KB_DATABLOCK, (EECONFIG_KB_DATA_SIZE));
309}
310/** \brief eeconfig init keyboard data block
311 *
312 * FIXME: needs doc
313 */
314__attribute__((weak)) void eeconfig_init_kb_datablock(void) { 315__attribute__((weak)) void eeconfig_init_kb_datablock(void) {
315 uint8_t dummy_kb[(EECONFIG_KB_DATA_SIZE)] = {0}; 316 nvm_eeconfig_init_kb_datablock();
316 eeconfig_update_kb_datablock(dummy_kb);
317} 317}
318#endif // (EECONFIG_KB_DATA_SIZE) > 0 318#endif // (EECONFIG_KB_DATA_SIZE) > 0
319 319
320#if (EECONFIG_USER_DATA_SIZE) > 0 320#if (EECONFIG_USER_DATA_SIZE) > 0
321/** \brief eeconfig assert user data block version
322 *
323 * FIXME: needs doc
324 */
325bool eeconfig_is_user_datablock_valid(void) { 321bool eeconfig_is_user_datablock_valid(void) {
326 return eeprom_read_dword(EECONFIG_USER) == (EECONFIG_USER_DATA_VERSION); 322 return nvm_eeconfig_is_user_datablock_valid();
327} 323}
328/** \brief eeconfig read user data block 324uint32_t eeconfig_read_user_datablock(void *data, uint32_t offset, uint32_t length) {
329 * 325 return nvm_eeconfig_read_user_datablock(data, offset, length);
330 * FIXME: needs doc 326}
331 */ 327uint32_t eeconfig_update_user_datablock(const void *data, uint32_t offset, uint32_t length) {
332void eeconfig_read_user_datablock(void *data) { 328 return nvm_eeconfig_update_user_datablock(data, offset, length);
333 if (eeconfig_is_user_datablock_valid()) {
334 eeprom_read_block(data, EECONFIG_USER_DATABLOCK, (EECONFIG_USER_DATA_SIZE));
335 } else {
336 memset(data, 0, (EECONFIG_USER_DATA_SIZE));
337 }
338} 329}
339/** \brief eeconfig update user data block
340 *
341 * FIXME: needs doc
342 */
343void eeconfig_update_user_datablock(const void *data) {
344 eeprom_update_dword(EECONFIG_USER, (EECONFIG_USER_DATA_VERSION));
345 eeprom_update_block(data, EECONFIG_USER_DATABLOCK, (EECONFIG_USER_DATA_SIZE));
346}
347/** \brief eeconfig init user data block
348 *
349 * FIXME: needs doc
350 */
351__attribute__((weak)) void eeconfig_init_user_datablock(void) { 330__attribute__((weak)) void eeconfig_init_user_datablock(void) {
352 uint8_t dummy_user[(EECONFIG_USER_DATA_SIZE)] = {0}; 331 nvm_eeconfig_init_user_datablock();
353 eeconfig_update_user_datablock(dummy_user);
354} 332}
355#endif // (EECONFIG_USER_DATA_SIZE) > 0 333#endif // (EECONFIG_USER_DATA_SIZE) > 0