Browse Source

Implement ledmap-in-eeprom feature

yuk86
Kai Ryu 9 years ago
parent
commit
b9c65be036
6 changed files with 57 additions and 1 deletions
  1. 5
    0
      common.mk
  2. 1
    0
      common/ledmap.c
  3. 2
    1
      common/ledmap.h
  4. 28
    0
      common/ledmap_in_eeprom.c
  5. 20
    0
      common/ledmap_in_eeprom.h
  6. 1
    0
      keyboard/gh60/Makefile

+ 5
- 0
common.mk View File

@@ -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

+ 1
- 0
common/ledmap.c View File

@@ -1,4 +1,5 @@
#include "ledmap.h"
#include "ledmap_in_eeprom.h"
#include "led.h"
#include "softpwm_led.h"
#include "action_layer.h"

+ 2
- 1
common/ledmap.h View File

@@ -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)

+ 28
- 0
common/ledmap_in_eeprom.c View File

@@ -0,0 +1,28 @@
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#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

+ 20
- 0
common/ledmap_in_eeprom.h View File

@@ -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

+ 1
- 0
keyboard/gh60/Makefile View File

@@ -143,6 +143,7 @@ KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor
SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight
BREATHING_LED_ENABLE = yes # Enable breathing backlight
LEDMAP_ENABLE = yes # Enable LED mapping
LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom


# Optimize size but this may cause error "relocation truncated to fit"