Merge pull request #1073 from qmk/backlight_changes

Open backlight functionality to all ports
This commit is contained in:
Jack Humbert 2017-02-09 20:14:35 -05:00 committed by GitHub
commit 6c462e0c01

View file

@ -594,19 +594,29 @@ static const uint8_t backlight_pin = BACKLIGHT_PIN;
# define COM1x1 COM1A1 # define COM1x1 COM1A1
# define OCR1x OCR1A # define OCR1x OCR1A
#else #else
# error "Backlight pin not supported - use B5, B6, or B7" # define NO_BACKLIGHT_CLOCK
#endif
#ifndef BACKLIGHT_ON_STATE
#define BACKLIGHT_ON_STATE 0
#endif #endif
__attribute__ ((weak)) __attribute__ ((weak))
void backlight_init_ports(void) void backlight_init_ports(void)
{ {
// Setup backlight pin as output and output low. // Setup backlight pin as output and output to on state.
// DDRx |= n // DDRx |= n
_SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF); _SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
#if BACKLIGHT_ON_STATE == 0
// PORTx &= ~n // PORTx &= ~n
_SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
#else
// PORTx |= n
_SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
#endif
#ifndef NO_BACKLIGHT_CLOCK
// Use full 16-bit resolution. // Use full 16-bit resolution.
ICR1 = 0xFFFF; ICR1 = 0xFFFF;
@ -622,6 +632,7 @@ void backlight_init_ports(void)
TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010; TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
#endif
backlight_init(); backlight_init();
#ifdef BACKLIGHT_BREATHING #ifdef BACKLIGHT_BREATHING
@ -633,24 +644,43 @@ __attribute__ ((weak))
void backlight_set(uint8_t level) void backlight_set(uint8_t level)
{ {
// Prevent backlight blink on lowest level // Prevent backlight blink on lowest level
#if BACKLIGHT_ON_STATE == 0
// PORTx &= ~n // PORTx &= ~n
_SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF); _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
#else
// PORTx |= n
_SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
#endif
if ( level == 0 ) { if ( level == 0 ) {
#ifndef NO_BACKLIGHT_CLOCK
// Turn off PWM control on backlight pin, revert to output low. // Turn off PWM control on backlight pin, revert to output low.
TCCR1A &= ~(_BV(COM1x1)); TCCR1A &= ~(_BV(COM1x1));
OCR1x = 0x0; OCR1x = 0x0;
} else if ( level == BACKLIGHT_LEVELS ) { #else
#if BACKLIGHT_ON_STATE == 0
// PORTx |= n
_SFR_IO8((backlight_pin >> 4) + 2) |= _BV(backlight_pin & 0xF);
#else
// PORTx &= ~n
_SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
#endif
#endif
}
#ifndef NO_BACKLIGHT_CLOCK
else if ( level == BACKLIGHT_LEVELS ) {
// Turn on PWM control of backlight pin // Turn on PWM control of backlight pin
TCCR1A |= _BV(COM1x1); TCCR1A |= _BV(COM1x1);
// Set the brightness // Set the brightness
OCR1x = 0xFFFF; OCR1x = 0xFFFF;
} else { }
else {
// Turn on PWM control of backlight pin // Turn on PWM control of backlight pin
TCCR1A |= _BV(COM1x1); TCCR1A |= _BV(COM1x1);
// Set the brightness // Set the brightness
OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2)); OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
} }
#endif
#ifdef BACKLIGHT_BREATHING #ifdef BACKLIGHT_BREATHING
breathing_intensity_default(); breathing_intensity_default();