1
0
Fork 0

[MERGE] Non-Volatile memory data repository pattern (24356)
Some checks failed
Unit Tests / test (push) Has been cancelled

This commit is contained in:
Drashna Jael're 2025-01-26 23:21:16 -08:00
parent 4a138dd93c
commit 20033594ef
Signed by: drashna
GPG key ID: DBA1FD3A860D1B11
82 changed files with 1478 additions and 838 deletions

View file

@ -24,9 +24,7 @@
#include "util.h"
#include "led_tables.h"
#include <lib/lib8tion/lib8tion.h>
#ifdef EEPROM_ENABLE
# include "eeprom.h"
#endif
#include "eeconfig.h"
#ifdef RGBLIGHT_SPLIT
/* for split keyboard */
@ -176,24 +174,9 @@ void rgblight_check_config(void) {
}
}
uint64_t eeconfig_read_rgblight(void) {
#ifdef EEPROM_ENABLE
return (uint64_t)((eeprom_read_dword(EECONFIG_RGBLIGHT)) | ((uint64_t)eeprom_read_byte(EECONFIG_RGBLIGHT_EXTENDED) << 32));
#else
return 0;
#endif
}
void eeconfig_update_rgblight(uint64_t val) {
#ifdef EEPROM_ENABLE
rgblight_check_config();
eeprom_update_dword(EECONFIG_RGBLIGHT, val & 0xFFFFFFFF);
eeprom_update_byte(EECONFIG_RGBLIGHT_EXTENDED, (val >> 32) & 0xFF);
#endif
}
void eeconfig_update_rgblight_current(void) {
eeconfig_update_rgblight(rgblight_config.raw);
rgblight_check_config();
eeconfig_update_rgblight(&rgblight_config);
}
void eeconfig_update_rgblight_default(void) {
@ -205,7 +188,7 @@ void eeconfig_update_rgblight_default(void) {
rgblight_config.val = RGBLIGHT_DEFAULT_VAL;
rgblight_config.speed = RGBLIGHT_DEFAULT_SPD;
RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
eeconfig_update_rgblight(rgblight_config.raw);
eeconfig_update_rgblight(&rgblight_config);
}
void eeconfig_debug_rgblight(void) {
@ -228,12 +211,12 @@ void rgblight_init(void) {
}
dprintf("rgblight_init start!\n");
rgblight_config.raw = eeconfig_read_rgblight();
eeconfig_read_rgblight(&rgblight_config);
RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
if (!rgblight_config.mode) {
dprintf("rgblight_init rgblight_config.mode = 0. Write default values to EEPROM.\n");
eeconfig_update_rgblight_default();
rgblight_config.raw = eeconfig_read_rgblight();
eeconfig_read_rgblight(&rgblight_config);
}
rgblight_check_config();
@ -252,7 +235,7 @@ void rgblight_init(void) {
void rgblight_reload_from_eeprom(void) {
/* Reset back to what we have in eeprom */
rgblight_config.raw = eeconfig_read_rgblight();
eeconfig_read_rgblight(&rgblight_config);
RGBLIGHT_SPLIT_SET_CHANGE_MODEHSVS;
rgblight_check_config();
eeconfig_debug_rgblight(); // display current eeprom values
@ -341,7 +324,7 @@ void rgblight_mode_eeprom_helper(uint8_t mode, bool write_to_eeprom) {
}
RGBLIGHT_SPLIT_SET_CHANGE_MODE;
if (write_to_eeprom) {
eeconfig_update_rgblight(rgblight_config.raw);
eeconfig_update_rgblight(&rgblight_config);
dprintf("rgblight mode [EEPROM]: %u\n", rgblight_config.mode);
} else {
dprintf("rgblight mode [NOEEPROM]: %u\n", rgblight_config.mode);
@ -386,7 +369,7 @@ void rgblight_toggle_noeeprom(void) {
void rgblight_enable(void) {
rgblight_config.enable = 1;
// No need to update EEPROM here. rgblight_mode() will do that, actually
// eeconfig_update_rgblight(rgblight_config.raw);
// eeconfig_update_rgblight(&rgblight_config);
dprintf("rgblight enable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
rgblight_mode(rgblight_config.mode);
}
@ -399,7 +382,7 @@ void rgblight_enable_noeeprom(void) {
void rgblight_disable(void) {
rgblight_config.enable = 0;
eeconfig_update_rgblight(rgblight_config.raw);
eeconfig_update_rgblight(&rgblight_config);
dprintf("rgblight disable [EEPROM]: rgblight_config.enable = %u\n", rgblight_config.enable);
rgblight_timer_disable();
RGBLIGHT_SPLIT_SET_CHANGE_MODE;
@ -487,7 +470,7 @@ void rgblight_increase_speed_helper(bool write_to_eeprom) {
if (rgblight_config.speed < 3) rgblight_config.speed++;
// RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED?
if (write_to_eeprom) {
eeconfig_update_rgblight(rgblight_config.raw);
eeconfig_update_rgblight(&rgblight_config);
}
}
void rgblight_increase_speed(void) {
@ -501,7 +484,7 @@ void rgblight_decrease_speed_helper(bool write_to_eeprom) {
if (rgblight_config.speed > 0) rgblight_config.speed--;
// RGBLIGHT_SPLIT_SET_CHANGE_HSVS; // NEED??
if (write_to_eeprom) {
eeconfig_update_rgblight(rgblight_config.raw);
eeconfig_update_rgblight(&rgblight_config);
}
}
void rgblight_decrease_speed(void) {
@ -585,7 +568,7 @@ void rgblight_sethsv_eeprom_helper(uint8_t hue, uint8_t sat, uint8_t val, bool w
rgblight_config.sat = sat;
rgblight_config.val = val;
if (write_to_eeprom) {
eeconfig_update_rgblight(rgblight_config.raw);
eeconfig_update_rgblight(&rgblight_config);
dprintf("rgblight set hsv [EEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
} else {
dprintf("rgblight set hsv [NOEEPROM]: %u,%u,%u\n", rgblight_config.hue, rgblight_config.sat, rgblight_config.val);
@ -608,7 +591,7 @@ uint8_t rgblight_get_speed(void) {
void rgblight_set_speed_eeprom_helper(uint8_t speed, bool write_to_eeprom) {
rgblight_config.speed = speed;
if (write_to_eeprom) {
eeconfig_update_rgblight(rgblight_config.raw);
eeconfig_update_rgblight(&rgblight_config);
dprintf("rgblight set speed [EEPROM]: %u\n", rgblight_config.speed);
} else {
dprintf("rgblight set speed [NOEEPROM]: %u\n", rgblight_config.speed);

View file

@ -168,7 +168,6 @@ enum RGBLIGHT_EFFECT_MODE {
#include <stdbool.h>
#include "rgblight_drivers.h"
#include "progmem.h"
#include "eeconfig.h"
#include "color.h"
#ifdef RGBLIGHT_LAYERS
@ -248,7 +247,7 @@ extern const uint16_t RGBLED_RGBTEST_INTERVALS[1] PROGMEM;
extern const uint8_t RGBLED_TWINKLE_INTERVALS[3] PROGMEM;
extern bool is_rgblight_initialized;
typedef union {
typedef union rgblight_config_t {
uint64_t raw;
struct {
bool enable : 1;
@ -370,8 +369,6 @@ void rgblight_suspend(void);
void rgblight_wakeup(void);
uint64_t rgblight_read_qword(void);
void rgblight_update_qword(uint64_t qword);
uint64_t eeconfig_read_rgblight(void);
void eeconfig_update_rgblight(uint64_t val);
void eeconfig_update_rgblight_current(void);
void eeconfig_update_rgblight_default(void);
void eeconfig_debug_rgblight(void);