Add breathing backlight support for smart68
This commit is contained in:
parent
d8f4801f34
commit
58d598d5ee
@ -131,6 +131,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
|
||||
BREATHING_LED_ENABLE = yes # Enable breathing backlight
|
||||
|
||||
|
||||
# Optimize size but this may cause error "relocation truncated to fit"
|
||||
|
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#include "backlight.h"
|
||||
#include "breathing_led.h"
|
||||
|
||||
static const uint8_t backlight_table[] PROGMEM = {
|
||||
0, 16, 128, 255
|
||||
@ -27,26 +28,68 @@ static const uint8_t backlight_table[] PROGMEM = {
|
||||
/* Backlight pin configuration
|
||||
* PWM: PB7
|
||||
*/
|
||||
void backlight_set(uint8_t level)
|
||||
void backlight_enable(void)
|
||||
{
|
||||
if (level > 0) {
|
||||
// Turn on PWM
|
||||
cli();
|
||||
DDRB |= (1<<PB7);
|
||||
TCCR1A |= ( (1<<WGM10) | (1<<COM1C1) );
|
||||
TCCR1B |= ( (1<<CS11) | (1<<CS10) );
|
||||
sei();
|
||||
// Set PWM
|
||||
OCR1C = pgm_read_byte(&backlight_table[level]);
|
||||
}
|
||||
else {
|
||||
}
|
||||
void backlight_disable(void)
|
||||
{
|
||||
// Turn off PWM
|
||||
cli();
|
||||
DDRB &= ~(1<<PB7);
|
||||
TCCR1A &= ~( (1<<WGM10) | (1<<COM1C1) );
|
||||
TCCR1B &= ~( (1<<CS11) | (1<<CS10) );
|
||||
sei();
|
||||
// Set PWM
|
||||
OCR1C = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void backlight_set(uint8_t level)
|
||||
{
|
||||
#ifdef BREATHING_LED_ENABLE
|
||||
switch (level) {
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
backlight_enable();
|
||||
breathing_led_disable();
|
||||
backlight_set_raw(pgm_read_byte(&backlight_table[level]));
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
backlight_enable();
|
||||
breathing_led_enable();
|
||||
breathing_led_set_duration(6 - level);
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
breathing_led_disable();
|
||||
backlight_disable();
|
||||
break;
|
||||
}
|
||||
#else
|
||||
if (level > 0) {
|
||||
backlight_enable();
|
||||
backlight_set_raw(pgm_read_byte(&backlight_table[level]));
|
||||
}
|
||||
else {
|
||||
backlight_disable();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef BREATHING_LED_ENABLE
|
||||
void breathing_led_set_raw(uint8_t raw)
|
||||
{
|
||||
backlight_set_raw(raw);
|
||||
}
|
||||
#endif
|
||||
|
||||
inline void backlight_set_raw(uint8_t raw)
|
||||
{
|
||||
OCR1C = raw;
|
||||
}
|
||||
|
@ -42,7 +42,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define DEBOUNCE 5
|
||||
|
||||
/* number of backlight levels */
|
||||
#ifdef BREATHING_LED_ENABLE
|
||||
#define BACKLIGHT_LEVELS 6
|
||||
#else
|
||||
#define BACKLIGHT_LEVELS 3
|
||||
#endif
|
||||
|
||||
/* Mechanical locking support. Use KC_LCAP, KC_LNUM or KC_LSCR instead in keymap */
|
||||
#define LOCKING_SUPPORT_ENABLE
|
||||
|
Reference in New Issue
Block a user