diff --git a/common/ledmap.c b/common/ledmap.c index beb0a72c..1339cc04 100644 --- a/common/ledmap.c +++ b/common/ledmap.c @@ -10,28 +10,34 @@ static led_binding_t usb_led_binding = 0; static led_binding_t default_layer_binding = 0; static led_binding_t layer_binding = 0; static led_binding_t backlight_binding = 0; +static led_binding_t reverse_binding = 0; -static void update_led_state(led_state_t state); +static void update_led_state(led_state_t state, uint8_t force); void ledmap_init(void) { for (uint8_t i = 0; i < LED_COUNT; i++) { - uint8_t code = ledmap_get_code(i); - if (code & LEDMAP_BACKLIGHT) { + ledmap_t ledmap = ledmap_get_code(i); + if (ledmap.reverse) { + LED_BIT_SET(reverse_binding, i); + } + if (ledmap.backlight) { LED_BIT_SET(backlight_binding, i); } - code &= LEDMAP_MASK; - if (code >= LEDMAP_DEFAULT_LAYER_0 && code <= LEDMAP_DEFAULT_LAYER_31) { - LED_BIT_SET(default_layer_binding, i); - } - else if (code >= LEDMAP_LAYER_0 && code <= LEDMAP_LAYER_31) { - LED_BIT_SET(layer_binding, i); - } - else if (code >= LEDMAP_NUM_LOCK && code <= LEDMAP_KANA) { - LED_BIT_SET(usb_led_binding, i); + switch (ledmap.binding) { + case LEDMAP_BINDING_DEFAULT_LAYER: + LED_BIT_SET(default_layer_binding, i); + break; + case LEDMAP_BINDING_LAYER: + LED_BIT_SET(layer_binding, i); + break; + case LEDMAP_BINDING_USB_LED: + LED_BIT_SET(usb_led_binding, i); + break; } } ledmap_led_init(); + update_led_state(0, 1); } void led_set(uint8_t usb_led) @@ -40,15 +46,11 @@ void led_set(uint8_t usb_led) led_state_t led_state = led_state_last; for (uint8_t i = 0; i < LED_COUNT; i++) { if (usb_led_binding & LED_BIT(i)) { - uint8_t code = ledmap_get_code(i) & LEDMAP_MASK; - for (uint8_t j = USB_LED_NUM_LOCK; j <= USB_LED_KANA; j++) { - if (code - LEDMAP_NUM_LOCK == j) { - (usb_led & (1 << j)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i); - } - } + uint8_t param = ledmap_get_code(i).param; + (usb_led & (1 << param)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i); } } - update_led_state(led_state); + update_led_state(led_state, 0); } } @@ -59,11 +61,11 @@ void default_layer_state_change(uint32_t state) led_state_t led_state = led_state_last; for (uint8_t i = 0; i < LED_COUNT; i++) { if (default_layer_binding & LED_BIT(i)) { - uint8_t code = ledmap_get_code(i) & LEDMAP_MASK; - (state & (1UL << (code - LEDMAP_DEFAULT_LAYER_0))) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i); + uint8_t param = ledmap_get_code(i).param; + (state & (1UL << param)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i); } } - update_led_state(led_state); + update_led_state(led_state, 0); } } @@ -73,11 +75,11 @@ void layer_state_change(uint32_t state) led_state_t led_state = led_state_last; for (uint8_t i = 0; i < LED_COUNT; i++) { if (layer_binding & LED_BIT(i)) { - uint8_t code = ledmap_get_code(i) & LEDMAP_MASK; - (state & (1UL << (code - LEDMAP_LAYER_0))) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i); + uint8_t param = ledmap_get_code(i).param; + (state & (1UL << param)) ? LED_BIT_SET(led_state, i) : LED_BIT_CLEAR(led_state, i); } } - update_led_state(led_state); + update_led_state(led_state, 0); } } #endif @@ -106,23 +108,21 @@ void softpwm_led_state_change(uint8_t state) if (state) { } else { - led_state_t led_state = led_state_last; - led_state_last &= ~(backlight_binding); - update_led_state(led_state); + update_led_state(led_state_last, 1); } } #endif -void update_led_state(led_state_t state) +void update_led_state(led_state_t state, uint8_t force) { - uint8_t diff = led_state_last ^ state; - if (diff) { + led_state_t diff = led_state_last ^ state; + if (force || diff) { for (uint8_t i = 0; i < LED_COUNT; i++) { if (softpwm_led_get_state() && (backlight_binding & LED_BIT(i))) { continue; } - if (diff & LED_BIT(i)) { - if (state & LED_BIT(i)) { + if (force || diff & LED_BIT(i)) { + if ((state ^ reverse_binding) & LED_BIT(i)) { ledmap_led_on(i); } else { diff --git a/common/ledmap.h b/common/ledmap.h index 9a6754f3..a8492df7 100644 --- a/common/ledmap.h +++ b/common/ledmap.h @@ -8,43 +8,49 @@ typedef led_pack_t led_state_t; typedef led_pack_t led_binding_t; -typedef enum { - LEDMAP_NO = 0, - LEDMAP_DEFAULT_LAYER_0, - LEDMAP_DEFAULT_LAYER_31 = LEDMAP_DEFAULT_LAYER_0 + 31, - LEDMAP_LAYER_0, - LEDMAP_LAYER_31 = LEDMAP_LAYER_0 + 31, - LEDMAP_NUM_LOCK, - LEDMAP_CAPS_LOCK, - LEDMAP_SCROLL_LOCK, - LEDMAP_COMPOSE, - LEDMAP_KANA, - LEDMAP_BACKLIGHT = 0x80 -} ledmap_code_t; +enum ledmap_binding { + LEDMAP_BINDING_NO = 0, + LEDMAP_BINDING_DEFAULT_LAYER, + LEDMAP_BINDING_LAYER, + LEDMAP_BINDING_USB_LED +}; -#define LEDMAP_MASK 0x7F +enum ledmap_usb_led { + LEDMAP_USB_LED_NUM_LOCK = 0, + LEDMAP_USB_LED_CAPS_LOCK, + LEDMAP_USB_LED_SCROLL_LOCK, + LEDMAP_USB_LED_COMPOSE, + LEDMAP_USB_LED_KANA, +}; typedef union { - uint8_t raw; + uint16_t code; struct { - uint8_t binding : 7; - bool backlight : 1; + uint8_t param: 8; + uint8_t binding: 4; + bool reverse: 1; + bool backlight: 1; + uint8_t reserved: 2; }; } ledmap_t; -#define LEDMAP_DEFAULT_LAYER(x) (LEDMAP_DEFAULT_LAYER_0 + x) -#define LEDMAP_LAYER(x) (LEDMAP_LAYER_0 + x) +#define LEDMAP_DEFAULT_LAYER(layer) (LEDMAP_BINDING_DEFAULT_LAYER<<8 | layer) +#define LEDMAP_LAYER(layer) (LEDMAP_BINDING_LAYER<<8 | layer ) +#define LEDMAP_NUM_LOCK (LEDMAP_BINDING_USB_LED<<8 | LEDMAP_USB_LED_NUM_LOCK) +#define LEDMAP_CAPS_LOCK (LEDMAP_BINDING_USB_LED<<8 | LEDMAP_USB_LED_CAPS_LOCK) +#define LEDMAP_SCROLL_LOCK (LEDMAP_BINDING_USB_LED<<8 | LEDMAP_USB_LED_SCROLL_LOCK) +#define LEDMAP_REVERSE (1<<12) +#define LEDMAP_BACKLIGHT (1<<13) void ledmap_init(void); #ifdef LEDMAP_ENABLE -uint8_t ledmap_get_code(uint8_t index); +ledmap_t ledmap_get_code(uint8_t index); void ledmap_led_init(void); void ledmap_led_on(uint8_t index); void ledmap_led_off(uint8_t index); #else -#define ledmaps -#define ledmap_get() +#define ledmap_get_code() #define ledmap_led_init() #define ledmap_led_on() #define ledmap_led_off() diff --git a/common/ledmap_in_eeprom.c b/common/ledmap_in_eeprom.c index 9876fc72..3d6f5489 100644 --- a/common/ledmap_in_eeprom.c +++ b/common/ledmap_in_eeprom.c @@ -1,22 +1,21 @@ #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]; +static ledmap_t ledmap[LED_COUNT]; void ledmap_in_eeprom_init(void) { for (uint8_t i = 0; i < LED_COUNT; i++) { - ledmap[i] = eeprom_read_byte(EECONFIG_LEDMAP + i); - //ledmap[i] = LEDMAP_UNCONFIGURED; - if (ledmap[i] == LEDMAP_UNCONFIGURED) { + ledmap[i].code = eeprom_read_word(EECONFIG_LEDMAP + i); + /* ledmap[i].code = LEDMAP_UNCONFIGURED; */ + if (ledmap[i].code == LEDMAP_UNCONFIGURED) { ledmap[i] = ledmap_get_code(i); - eeprom_write_byte(EECONFIG_LEDMAP + i, ledmap[i]); + eeprom_write_word(EECONFIG_LEDMAP + i, ledmap[i].code); } } } @@ -24,11 +23,11 @@ void ledmap_in_eeprom_init(void) void write_ledmap_to_eeprom(void) { for (uint8_t i = 0; i < LED_COUNT; i++) { - eeprom_write_byte(EECONFIG_LEDMAP + i, ledmap_get_code(i)); + eeprom_write_word(EECONFIG_LEDMAP + i, ledmap_get_code(i).code); } } -uint8_t ledmap_in_eeprom_get_code(uint8_t i) +ledmap_t ledmap_in_eeprom_get_code(uint8_t i) { return ledmap[i]; } diff --git a/common/ledmap_in_eeprom.h b/common/ledmap_in_eeprom.h index 3e6400c3..1b6c3873 100644 --- a/common/ledmap_in_eeprom.h +++ b/common/ledmap_in_eeprom.h @@ -1,20 +1,22 @@ #ifndef LEDMAP_IN_EEPROM_H #define LEDMAP_IN_EEPROM_H +#include "ledmap.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) +#define EECONFIG_LEDMAP (uint16_t*)EECONFIG_LEDMAP_IN_EEPROM +#define LEDMAP_SIZE (sizeof(uint16_t) * LED_COUNT) -#define LEDMAP_UNCONFIGURED 0xFF +#define LEDMAP_UNCONFIGURED 0xFFFF #ifdef LEDMAP_IN_EEPROM_ENABLE #define ledmap_get_code ledmap_in_eeprom_get_code void ledmap_in_eeprom_init(void); void write_ledmap_to_eeprom(void); -uint8_t ledmap_in_eeprom_get_code(uint8_t index); +ledmap_t ledmap_in_eeprom_get_code(uint8_t index); #else #define ledmap_in_eeprom_init() #define write_ledmap_to_eeprom() diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 5d00526d..61e79720 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -50,9 +50,9 @@ TARGET_DIR = . # project specific files SRC = keymap_common.c \ matrix.c \ + led.c \ backlight.c \ - ledmap.c \ - led_matrix.c + ledmap.c ifdef KEYMAP SRC := keymap_$(KEYMAP).c $(SRC) diff --git a/keyboard/gh60/Makefile.pjrc b/keyboard/gh60/Makefile.pjrc index 7843b6bd..3882afb4 100644 --- a/keyboard/gh60/Makefile.pjrc +++ b/keyboard/gh60/Makefile.pjrc @@ -51,7 +51,8 @@ TARGET_DIR = . SRC = keymap_common.c \ matrix.c \ led.c \ - backlight.c + backlight.c \ + ledmap.c ifdef KEYMAP SRC := keymap_$(KEYMAP).c $(SRC) @@ -102,10 +103,17 @@ CONSOLE_ENABLE = yes # Console for debug(+400) COMMAND_ENABLE = yes # Commands for debug and configuration #SLEEP_LED_ENABLE = yes # Breathing sleep LED during USB suspend NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA +USB_6KRO_ENABLE = yes # USB 6key Rollover #PS2_MOUSE_ENABLE = yes # PS/2 mouse(TrackPoint) support +#PS2_USE_BUSYWAIT = yes BACKLIGHT_ENABLE = yes # Enable keyboard backlight functionality -KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor KEYMAP_IN_EEPROM_ENABLE = yes # Read keymap from eeprom +#KEYMAP_SECTION_ENABLE = yes # Fixed address keymap for keymap editor +SOFTPWM_LED_ENABLE = yes # Enable SoftPWM to drive backlight +FADING_LED_ENABLE = yes # Enable fading backlight +BREATHING_LED_ENABLE = yes # Enable breathing backlight +LEDMAP_ENABLE = yes # Enable LED mapping +LEDMAP_IN_EEPROM_ENABLE = yes # Read LED mapping from eeprom # Search Path diff --git a/keyboard/gh60/ledmap.c b/keyboard/gh60/ledmap.c index 178ebac2..2c41906c 100644 --- a/keyboard/gh60/ledmap.c +++ b/keyboard/gh60/ledmap.c @@ -5,7 +5,7 @@ #ifdef LEDMAP_ENABLE -static const uint8_t ledmaps[LED_COUNT] PROGMEM = { +static const uint16_t ledmaps[LED_COUNT] PROGMEM = { #if defined(GH60_REV_CHN) [0] = LEDMAP_CAPS_LOCK | LEDMAP_BACKLIGHT, // CapsLock - PB2 [1] = LEDMAP_BACKLIGHT, // PWM - PB6 @@ -18,9 +18,9 @@ static const uint8_t ledmaps[LED_COUNT] PROGMEM = { #endif }; -uint8_t ledmap_get_code(uint8_t index) +ledmap_t ledmap_get_code(uint8_t index) { - return pgm_read_byte(&ledmaps[index]); + return (ledmap_t) { .code = pgm_read_word(&ledmaps[index]) }; } void ledmap_led_init(void)