Consistently handle datablock init (#26282)

This commit is contained in:
Joel Challis
2026-06-24 20:36:51 +01:00
committed by GitHub
parent ee9354d36e
commit 0ec0cdde81
6 changed files with 64 additions and 13 deletions
+20 -5
View File
@@ -191,7 +191,9 @@ void eeconfig_init_user_datablock(void);
:::::
### Example
### Examples
#### Basic
This is an example of how to add settings, and read and write it. We're using the user keymap for the example here.
@@ -215,10 +217,6 @@ typedef struct my_config_t {
static my_config_t config;
void keyboard_post_init_user(void) {
if (!eeconfig_is_user_datablock_valid()) {
eeconfig_init_user_datablock();
}
eeconfig_read_user_datablock(&config, 0, sizeof(my_config_t));
}
@@ -240,3 +238,20 @@ void housekeeping_task_user(void) {
}
}
```
#### Default Values
Extending the above example, a default value for the datablock can be configured as follows:
```c
void eeconfig_init_user_datablock(void) {
my_config_t default_config = {
.data = 42,
};
eeconfig_update_user_datablock(&default_config, 0, sizeof(my_config_t));
}
```
::: tip
For large datablocks, you might need to manually update in chunks to avoid memory issues.
:::