diff --git a/common.mk b/common.mk index f4c5c420..0930406d 100644 --- a/common.mk +++ b/common.mk @@ -79,7 +79,12 @@ endif ifdef LEDMAP_ENABLE SRC += $(COMMON_DIR)/ledmap.c OPT_DEFS += -DLEDMAP_ENABLE +ifdef LEDMAP_IN_EEPROM_ENABLE + SRC += $(COMMON_DIR)/ledmap_in_eeprom.c + OPT_DEFS += -DLEDMAP_IN_EEPROM_ENABLE endif +endif + ifdef KEYMAP_SECTION_ENABLE OPT_DEFS += -DKEYMAP_SECTION_ENABLE diff --git a/common/ledmap.c b/common/ledmap.c index fccd4218..2002095e 100644 --- a/common/ledmap.c +++ b/common/ledmap.c @@ -1,4 +1,5 @@ #include "ledmap.h" +#include "ledmap_in_eeprom.h" #include "led.h" #include "softpwm_led.h" #include "action_layer.h" diff --git a/common/ledmap.h b/common/ledmap.h index 8a570081..56960edc 100644 --- a/common/ledmap.h +++ b/common/ledmap.h @@ -36,7 +36,8 @@ typedef enum { LEDMAP_SCROLL_LOCK, LEDMAP_COMPOSE, LEDMAP_KANA, - LEDMAP_BACKLIGHT + LEDMAP_BACKLIGHT = 0x80, + LEDMAP_UNCONFIGURED = 0xFF } ledmap_code_t; #define LEDMAP_LAYER(x) (x) diff --git a/common/ledmap_in_eeprom.c b/common/ledmap_in_eeprom.c new file mode 100644 index 00000000..a0c4adb0 --- /dev/null +++ b/common/ledmap_in_eeprom.c @@ -0,0 +1,28 @@ +#include +#include +#include "ledmap.h" +#include "ledmap_in_eeprom.h" + +#ifdef LEDMAP_IN_EEPROM_ENABLE + +#undef ledmap_get_code + +static uint8_t ledmap[LED_COUNT]; + +void ledmap_in_eeprom_init(void) { + // read and check ledmap in eeprom + for (uint8_t i = 0; i < LED_COUNT; i++) { + ledmap[i] = eeprom_read_byte(EECONFIG_LEDMAP + i); + if (ledmap[i] == LEDMAP_UNCONFIGURED) { + ledmap[i] = lemap_get_code(i); + eeprom_write_byte(EECONFIG_LEDMAP + i, ledmap[i]); + } + } +} + +uint8_t ledmap_in_eeprom_get_code(uint8_t i) +{ + return ledmap[i]; +} + +#endif diff --git a/common/ledmap_in_eeprom.h b/common/ledmap_in_eeprom.h new file mode 100644 index 00000000..9adf7547 --- /dev/null +++ b/common/ledmap_in_eeprom.h @@ -0,0 +1,20 @@ +#ifndef LEDMAP_IN_EEPROM_H +#define LEDMAP_IN_EEPROM_H + +#ifndef EECONFIG_LEDMAP_IN_EEPROM +#define EECONFIG_LEDMAP_IN_EEPROM 7 +#endif + +#define EECONFIG_LEDMAP (uint8_t*)EECONFIG_LEDMAP_IN_EEPROM +#define LEDMAP_SIZE (sizeof(uint8_t) * LED_COUNT) + +#ifdef LEDMAP_IN_EEPROM_ENABLE +#define ledmap_get_code ledmap_in_eeprom_get_code +void ledmap_in_eeprom_init(void); +uint8_t ledmap_in_eeprom_get_code(uint8_t index); +#else +#define ledmap_in_eeprom_init() +#define ledmap_in_eeprom_get_code() +#endif + +#endif