mirror of
https://github.com/qmk/qmk_firmware.git
synced 2026-09-28 21:08:57 +02:00
Enable modules to persist data (#26201)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
// Copyright 2026 QMK
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#pragma once
|
||||
|
||||
#define EECONFIG_MODULE_NVM_TEST_DATA_SIZE 4
|
||||
@@ -0,0 +1,53 @@
|
||||
// Copyright 2026 QMK
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
#include <stdint.h>
|
||||
#include "community_modules.h"
|
||||
#include "debug.h"
|
||||
#include "timer.h"
|
||||
#include "eeconfig.h"
|
||||
|
||||
ASSERT_COMMUNITY_MODULES_MIN_API_VERSION(1, 1, 3);
|
||||
|
||||
typedef struct my_config_t {
|
||||
uint32_t data;
|
||||
} my_config_t;
|
||||
|
||||
static my_config_t config;
|
||||
|
||||
// Helpers required to bind to debounce helper
|
||||
void eeconfig_read_my_config(my_config_t *value) {
|
||||
eeconfig_read_nvm_test_datablock(value, 0, sizeof(my_config_t));
|
||||
}
|
||||
void eeconfig_update_my_config(my_config_t *value) {
|
||||
eeconfig_update_nvm_test_datablock(value, 0, sizeof(my_config_t));
|
||||
}
|
||||
|
||||
EECONFIG_DEBOUNCE_HELPER(my_config, config);
|
||||
|
||||
void keyboard_post_init_nvm_test(void) {
|
||||
if (!eeconfig_is_nvm_test_datablock_valid()) {
|
||||
eeconfig_init_nvm_test_datablock();
|
||||
}
|
||||
|
||||
eeconfig_init_my_config();
|
||||
}
|
||||
|
||||
bool process_record_nvm_test(uint16_t keycode, keyrecord_t *record) {
|
||||
if (!record->event.pressed) {
|
||||
config.data += 1;
|
||||
eeconfig_flag_my_config(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void housekeeping_task_nvm_test(void) {
|
||||
eeconfig_flush_my_config(false);
|
||||
|
||||
static uint32_t last_sync = 0;
|
||||
if (timer_elapsed32(last_sync) > 1000) {
|
||||
last_sync = timer_read32();
|
||||
|
||||
dprintf("Config: %ld\n", config.data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"module_name": "Example nvm persistence",
|
||||
"maintainer": "QMK Maintainers",
|
||||
"license": "GPL-2.0-or-later"
|
||||
}
|
||||
Reference in New Issue
Block a user