1
0

Implement backlight scheme of TentaPad

This commit is contained in:
Kai Ryu 2014-08-28 09:59:53 +09:00
parent 6d6efd10f1
commit e0ea55beeb
3 changed files with 199 additions and 39 deletions

View File

@ -253,15 +253,13 @@ ISR(TIMER1_COMPA_vect)
{ {
static uint8_t pwm = 0; static uint8_t pwm = 0;
pwm++; pwm++;
// LED on for (uint8_t i = 0; i < LED_COUNT; i++) {
if (pwm == 0) { // LED on
for (uint8_t i = 0; i < LED_COUNT; i++) { if (pwm == 0) {
softpwm_led_on(i); softpwm_led_on(i);
softpwm_led_ocr[i] = softpwm_led_ocr_buff[i]; softpwm_led_ocr[i] = softpwm_led_ocr_buff[i];
} }
} // LED off
// LED off
for (uint8_t i = 0; i < LED_COUNT; i++) {
if (pwm == softpwm_led_ocr[i]) { if (pwm == softpwm_led_ocr[i]) {
softpwm_led_off(i); softpwm_led_off(i);
} }

View File

@ -20,35 +20,87 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include "backlight.h" #include "backlight.h"
#include "softpwm_led.h" #include "softpwm_led.h"
#include "action.h"
#include "keymap_common.h"
#ifdef BACKLIGHT_ENABLE #ifdef BACKLIGHT_ENABLE
static const uint8_t backlight_table[] PROGMEM = { static uint8_t backlight_mode;
0, 16, 128, 255 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) 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) { switch (level) {
case 1: case 0:
case 2: softpwm_led_disable();
case 3: fading_led_disable_all();
softpwm_led_enable();
breathing_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; break;
case 4: case 4:
case 5: softpwm_led_set(LED_KEY_SIDE, backlight_brightness);
case 6: breathing_led_disable_all();
breathing_led_enable(LED_BOARD_SIDE);
fading_led_disable_all();
softpwm_led_enable(); softpwm_led_enable();
breathing_led_enable_all();
breathing_led_set_duration_all(6 - level);
break; break;
case 0: case 5:
default: 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(); breathing_led_disable_all();
softpwm_led_disable(); softpwm_led_disable();
break; 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) void softpwm_led_on(uint8_t index)
{ {
#ifndef EXPERIMENTAL #ifndef EXPERIMENTAL
PORTD |= (1<<PD0); switch (index) {
PORTB |= (1<<PB7); case LED_KEY_1:
PORTC |= (1<<PD5 | 1<<PD6); PORTC |= (1<<PC5);
break;
case LED_KEY_2:
PORTC |= (1<<PC6);
break;
case LED_KEY_SIDE:
PORTB |= (1<<PB7);
break;
case LED_BOARD_SIDE:
PORTD |= (1<<PD0);
break;
}
#else #else
PORTB |= (1<<PB6); PORTB |= (1<<PB6);
#endif #endif
@ -78,13 +141,65 @@ void softpwm_led_on(uint8_t index)
void softpwm_led_off(uint8_t index) void softpwm_led_off(uint8_t index)
{ {
#ifndef EXPERIMENTAL #ifndef EXPERIMENTAL
PORTD &= ~(1<<PD0); switch (index) {
PORTB &= ~(1<<PB7); case LED_KEY_1:
PORTC &= ~(1<<PD5 | 1<<PD6); PORTC &= ~(1<<PC5);
break;
case LED_KEY_2:
PORTC &= ~(1<<PC6);
break;
case LED_KEY_SIDE:
PORTB &= ~(1<<PB7);
break;
case LED_BOARD_SIDE:
PORTD &= ~(1<<PD0);
break;
}
#else #else
PORTB &= ~(1<<PB6); PORTB &= ~(1<<PB6);
#endif #endif
} }
#endif #endif
extern uint8_t config_mode;
void action_keyevent(keyevent_t event)
{
if (config_mode) return;
if (event.key.col < 2) {
if (event.pressed) {
switch (backlight_mode) {
case 0: case 6:
softpwm_led_on(event.key.col);
break;
case 1 ... 5:
softpwm_led_set(event.key.col, backlight_brightness);
break;
}
}
else {
switch (backlight_mode) {
case 0: case 6:
softpwm_led_off(event.key.col);
break;
case 1 ... 5:
softpwm_led_set(event.key.col, 0);
break;
}
}
}
switch (backlight_mode) {
case 1:
if (event.pressed) {
softpwm_led_increase(LED_KEY_SIDE, 32);
}
break;
case 2:
if (event.pressed) {
softpwm_led_increase(LED_BOARD_SIDE, 32);
}
break;
}
}
#endif #endif

View File

@ -68,42 +68,89 @@ uint16_t fn_actions_count(void) {
} }
#endif #endif
uint8_t config_mode = 0;
static uint8_t layer = 0;
static uint8_t backlight = 0;
static uint8_t layer_modified = 0;
static uint8_t backlight_modified = 0;
extern backlight_config_t backlight_config;
void enter_config_mode(void);
void exit_config_mode(void);
void switch_layout(void);
void switch_backlight(void);
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{ {
static uint8_t config_mode = 0;
static uint8_t layer = 0;
static uint8_t backlight = 0;
switch (id) { switch (id) {
case CONFIG_MODE: case CONFIG_MODE:
if (record->event.pressed) { if (record->event.pressed) {
if (config_mode) { if (config_mode) {
config_mode = 0; exit_config_mode();
layer_off(CONFIG_LAYER);
} }
else { else {
config_mode = 1; enter_config_mode();
layer = 0;
backlight = 0;
layer_on(CONFIG_LAYER);
} }
} }
break; break;
case SWITCH_LAYOUT: case SWITCH_LAYOUT:
if (record->event.pressed) { if (record->event.pressed) {
if (config_mode) { if (config_mode) {
default_layer_set(1UL<<layer); switch_layout();
eeconfig_write_default_layer(1UL<<layer);
layer = (layer + 1) % (last_layer() + 1);
} }
} }
break; break;
case SWITCH_BACKLIGHT: case SWITCH_BACKLIGHT:
if (record->event.pressed) { if (record->event.pressed) {
if (config_mode) { if (config_mode) {
backlight_level(backlight); switch_backlight();
backlight = (backlight + 1) % (BACKLIGHT_LEVELS + 1);
} }
} }
break; 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<<layer);
eeconfig_write_default_layer(1UL<<layer);
}
}
void switch_layout(void)
{
if (!layer_modified) {
layer = 0;
layer_modified = 1;
}
else {
layer = (layer + 1) % (last_layer() + 1);
}
softpwm_led_set(0, 32 * (layer + 1));
}
void switch_backlight(void)
{
if (!backlight_modified) {
backlight = 0;
backlight_modified = 1;
}
else {
backlight = (backlight + 1) % (BACKLIGHT_LEVELS);
}
softpwm_led_set(1, 32 * (backlight + 1));
}