diff --git a/common.mk b/common.mk index bef00a3c..09561cba 100644 --- a/common.mk +++ b/common.mk @@ -54,6 +54,11 @@ ifdef SLEEP_LED_ENABLE OPT_DEFS += -DNO_SUSPEND_POWER_DOWN endif +ifdef BREATHING_LED_ENABLE + SRC += $(COMMON_DIR)/breathing_led.c + OPT_DEFS += -DBREATHING_LED_ENABLE +endif + ifdef BACKLIGHT_ENABLE SRC += $(COMMON_DIR)/backlight.c OPT_DEFS += -DBACKLIGHT_ENABLE diff --git a/common/breathing_led.c b/common/breathing_led.c new file mode 100644 index 00000000..4e4822f8 --- /dev/null +++ b/common/breathing_led.c @@ -0,0 +1,73 @@ +#include +#include +#include "led.h" +#include "breathing_led.h" +#include "debug.h" + +#define BREATHING_LED_TIMER_TOP F_CPU/256 + +static uint8_t breathing_led_duration = 0; + +void breathing_led_init(void) +{ + /* Timer3 setup */ + /* CTC mode */ + TCCR3B |= (1<>8)&0xff; + OCR3AL = BREATHING_LED_TIMER_TOP&0xff; + SREG = sreg; +} + +void breathing_led_enable(void) +{ + /* Enable Compare Match Interrupt */ + TIMSK3 |= (1< breathing_led_duration) { + step = 0; + breathing_led_set_raw(pgm_read_byte(&breathing_table[index])); + index++; + } +} diff --git a/common/breathing_led.h b/common/breathing_led.h new file mode 100644 index 00000000..b3a9e775 --- /dev/null +++ b/common/breathing_led.h @@ -0,0 +1,25 @@ +#ifndef BREATHING_LED_H +#define BREATHING_LED_H + + +#ifdef BREATHING_LED_ENABLE + +void breathing_led_init(void); +void breathing_led_enable(void); +void breathing_led_disable(void); +void breathing_led_toggle(void); +void breathing_led_set_duration(uint8_t dur); +void breathing_led_set_raw(uint8_t raw); + +#else + +#define breathing_led_init() +#define breathing_led_enable() +#define breathing_led_disable() +#define breathing_led_toggle() +#define breathing_led_set_duration() +#define breathing_led_set_raw() + +#endif + +#endif diff --git a/common/keyboard.c b/common/keyboard.c index 933eb780..29155cfe 100644 --- a/common/keyboard.c +++ b/common/keyboard.c @@ -81,6 +81,10 @@ void keyboard_init(void) backlight_init(); #endif +#ifdef BREATHING_LED_ENABLE + breathing_led_init(); +#endif + #ifdef KEYMAP_EX_ENABLE keymap_ex_init(); #endif diff --git a/keyboard/gh60/Makefile b/keyboard/gh60/Makefile index 5bdd7e46..56da7779 100644 --- a/keyboard/gh60/Makefile +++ b/keyboard/gh60/Makefile @@ -138,7 +138,7 @@ NKRO_ENABLE = yes # USB Nkey Rollover - not yet supported in LUFA 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 -#LED_MATRIX_ENABLE = yes +BREATHING_LED_ENABLE = yes # Enable breathing backlight # Optimize size but this may cause error "relocation truncated to fit" #EXTRALDFLAGS = -Wl,--relax diff --git a/keyboard/gh60/backlight.c b/keyboard/gh60/backlight.c index bc524f6d..4c96d041 100644 --- a/keyboard/gh60/backlight.c +++ b/keyboard/gh60/backlight.c @@ -19,98 +19,133 @@ along with this program. If not, see . #include #include #include "backlight.h" +#include "breathing_led.h" + +#ifdef GH60_REV_CHN +#else +#define SOFTPWM_TIMER_TOP F_CPU/(256*64) +uint8_t softpwm_ocr = 0; +uint8_t softpwm_ocr_buff = 0; +#endif -#if defined(GH60_REV_CHN) static const uint8_t backlight_table[] PROGMEM = { 0, 16, 128, 255 }; /* Backlight pin configuration - * PWM: PB7 + * PWM: PB6 (Rev.CHN) + * GPIO: PF7 PF6 PF5 PF4 (Rev.B) */ -void backlight_set(uint8_t level) +void backlight_enable(void) { - if (level > 0) { - // Turn on PWM - cli(); - DDRB |= (1<>8)&0xff; + OCR1AL = SOFTPWM_TIMER_TOP&0xff; + TIMSK1 |= (1< 0) { - led_matrix_disable(); - for (uint8_t row = 0; row < LED_MATRIX_ROWS; row++) { - for (uint8_t col = 0; col < LED_MATRIX_COLS; col++) { - led_matrix_set_value(row, col, pgm_read_byte(&backlight_table[level])); - } - } - led_matrix_enable(); + backlight_enable(); + backlight_set_raw(pgm_read_byte(&backlight_table[level])); } else { - led_matrix_disable(); + backlight_disable(); } #endif } -#else -static const uint8_t backlight_table[] PROGMEM = { - 0, 16, 128, 255 -}; -void backlight_set(uint8_t level) +#ifdef BREATHING_LED_ENABLE +void breathing_led_set_raw(uint8_t raw) { - if (level > 0) { - DDRF |= (1<. #define DEBOUNCE 5 /* number of backlight levels */ +#ifdef BREATHING_LED_ENABLE +#define BACKLIGHT_LEVELS 6 +#else #define BACKLIGHT_LEVELS 3 +#endif #ifdef GH60_REV_CNY -# define LED_MATRIX_ROWS 6 -# define LED_MATRIX_COLS 14 +#define LED_MATRIX_ROWS 6 +#define LED_MATRIX_COLS 14 #endif /* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */