From 641490bbd25928f8248fa7840bf51a7dac8e2079 Mon Sep 17 00:00:00 2001 From: Kai Ryu Date: Thu, 28 Aug 2014 09:59:53 +0900 Subject: [PATCH] Implement backlight scheme of TentaPad --- common/softpwm_led.c | 10 +- keyboard/tentapad/backlight.c | 153 +++++++++++++++++++++++++---- keyboard/tentapad/keymap_default.c | 75 +++++++++++--- 3 files changed, 199 insertions(+), 39 deletions(-) diff --git a/common/softpwm_led.c b/common/softpwm_led.c index b8751fb5..1c072bb0 100644 --- a/common/softpwm_led.c +++ b/common/softpwm_led.c @@ -253,15 +253,13 @@ ISR(TIMER1_COMPA_vect) { static uint8_t pwm = 0; pwm++; - // LED on - if (pwm == 0) { - for (uint8_t i = 0; i < LED_COUNT; i++) { + for (uint8_t i = 0; i < LED_COUNT; i++) { + // LED on + if (pwm == 0) { softpwm_led_on(i); softpwm_led_ocr[i] = softpwm_led_ocr_buff[i]; } - } - // LED off - for (uint8_t i = 0; i < LED_COUNT; i++) { + // LED off if (pwm == softpwm_led_ocr[i]) { softpwm_led_off(i); } diff --git a/keyboard/tentapad/backlight.c b/keyboard/tentapad/backlight.c index e5c3edef..395235a1 100644 --- a/keyboard/tentapad/backlight.c +++ b/keyboard/tentapad/backlight.c @@ -20,35 +20,87 @@ along with this program. If not, see . #include #include "backlight.h" #include "softpwm_led.h" +#include "action.h" +#include "keymap_common.h" #ifdef BACKLIGHT_ENABLE -static const uint8_t backlight_table[] PROGMEM = { - 0, 16, 128, 255 +static uint8_t backlight_mode; +static const uint8_t backlight_brightness = 0xFF; + +enum { + LED_KEY_1 = 0, + LED_KEY_2, + LED_KEY_SIDE, + LED_BOARD_SIDE }; void backlight_set(uint8_t level) { + backlight_mode = level; + softpwm_led_set_all(0); + fading_led_set_duration(2); + fading_led_set_direction(FADING_LED_FADE_OUT); + breathing_led_set_duration(3); switch (level) { - case 1: - case 2: - case 3: - softpwm_led_enable(); + case 0: + softpwm_led_disable(); + fading_led_disable_all(); breathing_led_disable_all(); - softpwm_led_set_all(pgm_read_byte(&backlight_table[level])); + softpwm_led_on(LED_KEY_SIDE); + softpwm_led_on(LED_BOARD_SIDE); + break; + case 1: + softpwm_led_set(LED_BOARD_SIDE, backlight_brightness); + fading_led_disable_all(); + fading_led_enable(LED_KEY_SIDE); + breathing_led_disable_all(); + softpwm_led_enable(); + break; + case 2: + softpwm_led_set(LED_KEY_SIDE, backlight_brightness); + fading_led_disable_all(); + fading_led_enable(LED_BOARD_SIDE); + breathing_led_disable_all(); + softpwm_led_enable(); + break; + case 3: + fading_led_disable_all(); + breathing_led_disable_all(); + breathing_led_enable(LED_KEY_SIDE); + breathing_led_enable(LED_BOARD_SIDE); + softpwm_led_enable(); break; case 4: - case 5: - case 6: + softpwm_led_set(LED_KEY_SIDE, backlight_brightness); + breathing_led_disable_all(); + breathing_led_enable(LED_BOARD_SIDE); + fading_led_disable_all(); softpwm_led_enable(); - breathing_led_enable_all(); - breathing_led_set_duration_all(6 - level); break; - case 0: - default: + case 5: + softpwm_led_set(LED_BOARD_SIDE, backlight_brightness); + breathing_led_disable_all(); + breathing_led_enable(LED_KEY_SIDE); + fading_led_disable_all(); + softpwm_led_enable(); + break; + case 6: + fading_led_disable_all(); breathing_led_disable_all(); softpwm_led_disable(); break; + case 7: + fading_led_disable_all(); + breathing_led_disable_all(); + softpwm_led_disable(); + break; + case 8: + softpwm_led_set_all(16); + fading_led_disable_all(); + breathing_led_disable_all(); + softpwm_led_enable(); + break; } } @@ -67,9 +119,20 @@ void softpwm_led_init(void) void softpwm_led_on(uint8_t index) { #ifndef EXPERIMENTAL - PORTD |= (1<event.pressed) { if (config_mode) { - config_mode = 0; - layer_off(CONFIG_LAYER); + exit_config_mode(); } else { - config_mode = 1; - layer = 0; - backlight = 0; - layer_on(CONFIG_LAYER); + enter_config_mode(); } } break; case SWITCH_LAYOUT: if (record->event.pressed) { if (config_mode) { - default_layer_set(1UL<event.pressed) { if (config_mode) { - backlight_level(backlight); - backlight = (backlight + 1) % (BACKLIGHT_LEVELS + 1); + switch_backlight(); } } break; } } + +void enter_config_mode(void) +{ + config_mode = 1; + layer_modified = 0; + backlight_modified = 0; + backlight = backlight_config.level; + backlight_level(8); + layer_on(CONFIG_LAYER); +} + +void exit_config_mode(void) +{ + config_mode = 0; + backlight_level(backlight); + layer_off(CONFIG_LAYER); + if (layer_modified) { + default_layer_set(1UL<