aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--quantum/quantum.c94
1 files changed, 62 insertions, 32 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c
index d3905decf..45ea8cb73 100644
--- a/quantum/quantum.c
+++ b/quantum/quantum.c
@@ -594,34 +594,45 @@ static const uint8_t backlight_pin = BACKLIGHT_PIN;
# define COM1x1 COM1A1
# define OCR1x OCR1A
#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
__attribute__ ((weak))
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
_SFR_IO8((backlight_pin >> 4) + 1) |= _BV(backlight_pin & 0xF);
- // PORTx &= ~n
- _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
+ #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
- // Use full 16-bit resolution.
- ICR1 = 0xFFFF;
+ #ifndef NO_BACKLIGHT_CLOCK
+ // Use full 16-bit resolution.
+ ICR1 = 0xFFFF;
- // I could write a wall of text here to explain... but TL;DW
- // Go read the ATmega32u4 datasheet.
- // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
+ // I could write a wall of text here to explain... but TL;DW
+ // Go read the ATmega32u4 datasheet.
+ // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
- // Pin PB7 = OCR1C (Timer 1, Channel C)
- // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
- // (i.e. start high, go low when counter matches.)
- // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
- // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
+ // Pin PB7 = OCR1C (Timer 1, Channel C)
+ // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
+ // (i.e. start high, go low when counter matches.)
+ // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
+ // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
- TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
- TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
+ TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
+ TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
+ #endif
backlight_init();
#ifdef BACKLIGHT_BREATHING
@@ -633,24 +644,43 @@ __attribute__ ((weak))
void backlight_set(uint8_t level)
{
// Prevent backlight blink on lowest level
- // PORTx &= ~n
- _SFR_IO8((backlight_pin >> 4) + 2) &= ~_BV(backlight_pin & 0xF);
+ #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
if ( level == 0 ) {
- // Turn off PWM control on backlight pin, revert to output low.
- TCCR1A &= ~(_BV(COM1x1));
- OCR1x = 0x0;
- } else if ( level == BACKLIGHT_LEVELS ) {
- // Turn on PWM control of backlight pin
- TCCR1A |= _BV(COM1x1);
- // Set the brightness
- OCR1x = 0xFFFF;
- } else {
- // Turn on PWM control of backlight pin
- TCCR1A |= _BV(COM1x1);
- // Set the brightness
- OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
- }
+ #ifndef NO_BACKLIGHT_CLOCK
+ // Turn off PWM control on backlight pin, revert to output low.
+ TCCR1A &= ~(_BV(COM1x1));
+ OCR1x = 0x0;
+ #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
+ TCCR1A |= _BV(COM1x1);
+ // Set the brightness
+ OCR1x = 0xFFFF;
+ }
+ else {
+ // Turn on PWM control of backlight pin
+ TCCR1A |= _BV(COM1x1);
+ // Set the brightness
+ OCR1x = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
+ }
+ #endif
#ifdef BACKLIGHT_BREATHING
breathing_intensity_default();