From 753f5646d0744ea4c97525adb3ebe4009198488e Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Fri, 12 Sep 2014 10:23:07 +0900 Subject: [PATCH] New features for AKB96 - USB 6KRO - SoftPWM LED - Breathing LED - Fading LED - Typing LED - Ledmap - Ledmap in EEPROM --- common/action_layer.c | 3 - keyboard/akb96/Makefile | 12 +++- keyboard/akb96/backlight.c | 98 +++++++++++++++++++++++++++++++ keyboard/akb96/config.h | 8 +++ keyboard/akb96/keymap_common.c | 6 +- keyboard/akb96/keymap_common.h | 2 +- keyboard/akb96/keymap_default.c | 2 +- keyboard/akb96/led.c | 31 +++++----- keyboard/akb96/ledmap.c | 100 ++++++++++++++++++++++++++++++++ 9 files changed, 233 insertions(+), 29 deletions(-) create mode 100644 keyboard/akb96/ledmap.c diff --git a/common/action_layer.c b/common/action_layer.c index 2b626d30..579950ac 100644 --- a/common/action_layer.c +++ b/common/action_layer.c @@ -70,9 +70,6 @@ static void layer_state_set(uint32_t state) layer_state_change(state); #endif clear_keyboard_but_mods(); // To avoid stuck keys -#ifdef ON_LAYER_CHANGE - layer_change(layer_state); -#endif } void layer_clear(void) diff --git a/keyboard/akb96/Makefile b/keyboard/akb96/Makefile index fdb99046..1354a1a8 100644 --- a/keyboard/akb96/Makefile +++ b/keyboard/akb96/Makefile @@ -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) @@ -134,12 +135,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_EX_ENABLE = yes # External keymap in eeprom -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 # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/keyboard/akb96/backlight.c b/keyboard/akb96/backlight.c index 1133149a..d884a605 100644 --- a/keyboard/akb96/backlight.c +++ b/keyboard/akb96/backlight.c @@ -19,10 +19,19 @@ along with this program. If not, see . #include #include #include "backlight.h" +#ifdef SOFTPWM_LED_ENABLE +#include "softpwm_led.h" +#else #include "breathing_led.h" +#endif +#include "action.h" #ifdef BACKLIGHT_ENABLE +static uint8_t backlight_mode; + +void backlight_enable(void); +void backlight_disable(void); inline void backlight_set_raw(uint8_t raw); static const uint8_t backlight_table[] PROGMEM = { @@ -34,16 +43,23 @@ static const uint8_t backlight_table[] PROGMEM = { */ void backlight_enable(void) { +#ifdef SOFTPWM_LED_ENABLE + softpwm_led_enable(); +#else // Turn on PWM DDRB |= (1<. /* number of backlight levels */ #ifdef BREATHING_LED_ENABLE +#ifdef FADING_LED_ENABLE +#define BACKLIGHT_LEVELS 8 +#else #define BACKLIGHT_LEVELS 6 +#endif #else #define BACKLIGHT_LEVELS 3 #endif +#ifdef SOFTPWM_LED_ENABLE +#define LED_COUNT 3 +#endif + /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */ #define LOCKING_SUPPORT_ENABLE diff --git a/keyboard/akb96/keymap_common.c b/keyboard/akb96/keymap_common.c index ae934eea..6ab88064 100644 --- a/keyboard/akb96/keymap_common.c +++ b/keyboard/akb96/keymap_common.c @@ -19,7 +19,7 @@ along with this program. If not, see . /* translates key to keycode */ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) { -#ifndef KEYMAP_EX_ENABLE +#ifndef KEYMAP_IN_EEPROM_ENABLE return pgm_read_byte(&keymaps[(layer)][(key.row)][(key.col)]); #else return eeconfig_read_keymap_key(layer, key.row, key.col); @@ -30,7 +30,7 @@ uint8_t keymap_key_to_keycode(uint8_t layer, key_t key) action_t keymap_fn_to_action(uint8_t keycode) { return (action_t) { -#ifndef KEYMAP_EX_ENABLE +#ifndef KEYMAP_IN_EEPROM_ENABLE .code = pgm_read_word(&fn_actions[FN_INDEX(keycode)]) #else .code = eeconfig_read_keymap_fn_action(FN_INDEX(keycode)) @@ -38,7 +38,7 @@ action_t keymap_fn_to_action(uint8_t keycode) }; } -#ifdef KEYMAP_EX_ENABLE +#ifdef KEYMAP_IN_EEPROM_ENABLE const uint8_t* keymaps_pointer(void) { return (const uint8_t*)keymaps; } diff --git a/keyboard/akb96/keymap_common.h b/keyboard/akb96/keymap_common.h index 28312d7f..e05e1cef 100644 --- a/keyboard/akb96/keymap_common.h +++ b/keyboard/akb96/keymap_common.h @@ -28,7 +28,7 @@ along with this program. If not, see . #include "print.h" #include "debug.h" #include "keymap.h" -#include "keymap_ex.h" +#include "keymap_in_eeprom.h" extern const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS]; diff --git a/keyboard/akb96/keymap_default.c b/keyboard/akb96/keymap_default.c index 753f5acd..de46da2f 100644 --- a/keyboard/akb96/keymap_default.c +++ b/keyboard/akb96/keymap_default.c @@ -90,7 +90,7 @@ const uint16_t fn_actions[] PROGMEM = { [4] = ACTION_LAYER_TOGGLE(2) }; -#ifdef KEYMAP_EX_ENABLE +#ifdef KEYMAP_IN_EEPROM_ENABLE uint16_t keys_count(void) { return sizeof(keymaps) / sizeof(keymaps[0]) * MATRIX_ROWS * MATRIX_COLS; } diff --git a/keyboard/akb96/led.c b/keyboard/akb96/led.c index 7a0b79d3..a84a23e6 100644 --- a/keyboard/akb96/led.c +++ b/keyboard/akb96/led.c @@ -21,6 +21,8 @@ along with this program. If not, see . #include "action_layer.h" +#ifndef LEDMAP_ENABLE + /* LED pin configration * REV_V2 * CapsLock PB5 (D9) @@ -41,6 +43,15 @@ void led_set(uint8_t usb_led) DDRB &= ~(1< +#include "ledmap.h" +#include "debug.h" + + +#ifdef LEDMAP_ENABLE + +static const uint8_t ledmaps[LED_COUNT] PROGMEM = { + [0] = LEDMAP_CAPS_LOCK | LEDMAP_BACKLIGHT, // CapsLock + [1] = LEDMAP_LAYER(2) | LEDMAP_BACKLIGHT, // NumLock + [2] = LEDMAP_BACKLIGHT, // Backlight +}; + +uint8_t ledmap_get_code(uint8_t index) +{ + return pgm_read_byte(&ledmaps[index]); +} + +/* LED pin configration + * REV_V2 + * CapsLock PB5 (D9) + * NumLock PB2 (D16) + * Backlight PB6 (D10) + * REV_V3 + * CapsLock PC7 + * NumLock PC6 + * Backlight PB6 + */ +void ledmap_led_init(void) +{ +#if defined(REV_V2) + DDRB |= (1<