diff options
| -rw-r--r-- | quantum/quantum.c | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/quantum/quantum.c b/quantum/quantum.c index 5abd222d1..b9934aee8 100644 --- a/quantum/quantum.c +++ b/quantum/quantum.c | |||
| @@ -898,14 +898,29 @@ static const uint8_t backlight_pin = BACKLIGHT_PIN; | |||
| 898 | 898 | ||
| 899 | // depending on the pin, we use a different output compare unit | 899 | // depending on the pin, we use a different output compare unit |
| 900 | #if BACKLIGHT_PIN == B7 | 900 | #if BACKLIGHT_PIN == B7 |
| 901 | # define COM1x1 COM1C1 | 901 | # define TCCRxA TCCR1A |
| 902 | # define OCR1x OCR1C | 902 | # define TCCRxB TCCR1B |
| 903 | # define COMxx1 COM1C1 | ||
| 904 | # define OCRxx OCR1C | ||
| 905 | # define ICRx ICR1 | ||
| 903 | #elif BACKLIGHT_PIN == B6 | 906 | #elif BACKLIGHT_PIN == B6 |
| 904 | # define COM1x1 COM1B1 | 907 | # define TCCRxA TCCR1A |
| 905 | # define OCR1x OCR1B | 908 | # define TCCRxB TCCR1B |
| 909 | # define COMxx1 COM1B1 | ||
| 910 | # define OCRxx OCR1B | ||
| 911 | # define ICRx ICR1 | ||
| 906 | #elif BACKLIGHT_PIN == B5 | 912 | #elif BACKLIGHT_PIN == B5 |
| 907 | # define COM1x1 COM1A1 | 913 | # define TCCRxA TCCR1A |
| 908 | # define OCR1x OCR1A | 914 | # define TCCRxB TCCR1B |
| 915 | # define COMxx1 COM1A1 | ||
| 916 | # define OCRxx OCR1A | ||
| 917 | # define ICRx ICR1 | ||
| 918 | #elif BACKLIGHT_PIN == C6 | ||
| 919 | # define TCCRxA TCCR3A | ||
| 920 | # define TCCRxB TCCR3B | ||
| 921 | # define COMxx1 COM1A1 | ||
| 922 | # define OCRxx OCR3A | ||
| 923 | # define ICRx ICR3 | ||
| 909 | #else | 924 | #else |
| 910 | # define NO_HARDWARE_PWM | 925 | # define NO_HARDWARE_PWM |
| 911 | #endif | 926 | #endif |
| @@ -987,7 +1002,7 @@ static uint16_t cie_lightness(uint16_t v) { | |||
| 987 | 1002 | ||
| 988 | // range for val is [0..TIMER_TOP]. PWM pin is high while the timer count is below val. | 1003 | // range for val is [0..TIMER_TOP]. PWM pin is high while the timer count is below val. |
| 989 | static inline void set_pwm(uint16_t val) { | 1004 | static inline void set_pwm(uint16_t val) { |
| 990 | OCR1x = val; | 1005 | OCRxx = val; |
| 991 | } | 1006 | } |
| 992 | 1007 | ||
| 993 | #ifndef BACKLIGHT_CUSTOM_DRIVER | 1008 | #ifndef BACKLIGHT_CUSTOM_DRIVER |
| @@ -998,10 +1013,10 @@ void backlight_set(uint8_t level) { | |||
| 998 | 1013 | ||
| 999 | if (level == 0) { | 1014 | if (level == 0) { |
| 1000 | // Turn off PWM control on backlight pin | 1015 | // Turn off PWM control on backlight pin |
| 1001 | TCCR1A &= ~(_BV(COM1x1)); | 1016 | TCCRxA &= ~(_BV(COMxx1)); |
| 1002 | } else { | 1017 | } else { |
| 1003 | // Turn on PWM control of backlight pin | 1018 | // Turn on PWM control of backlight pin |
| 1004 | TCCR1A |= _BV(COM1x1); | 1019 | TCCRxA |= _BV(COMxx1); |
| 1005 | } | 1020 | } |
| 1006 | // Set the brightness | 1021 | // Set the brightness |
| 1007 | set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS)); | 1022 | set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS)); |
| @@ -1149,11 +1164,10 @@ void backlight_init_ports(void) | |||
| 1149 | "In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM [..]." | 1164 | "In fast PWM mode, the compare units allow generation of PWM waveforms on the OCnx pins. Setting the COMnx1:0 bits to two will produce a non-inverted PWM [..]." |
| 1150 | "In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGMn3:0 = 5, 6, or 7), the value in ICRn (WGMn3:0 = 14), or the value in OCRnA (WGMn3:0 = 15)." | 1165 | "In fast PWM mode the counter is incremented until the counter value matches either one of the fixed values 0x00FF, 0x01FF, or 0x03FF (WGMn3:0 = 5, 6, or 7), the value in ICRn (WGMn3:0 = 14), or the value in OCRnA (WGMn3:0 = 15)." |
| 1151 | */ | 1166 | */ |
| 1152 | 1167 | TCCRxA = _BV(COMxx1) | _BV(WGM11); // = 0b00001010; | |
| 1153 | TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010; | 1168 | TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; |
| 1154 | TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001; | ||
| 1155 | // Use full 16-bit resolution. Counter counts to ICR1 before reset to 0. | 1169 | // Use full 16-bit resolution. Counter counts to ICR1 before reset to 0. |
| 1156 | ICR1 = TIMER_TOP; | 1170 | ICRx = TIMER_TOP; |
| 1157 | 1171 | ||
| 1158 | backlight_init(); | 1172 | backlight_init(); |
| 1159 | #ifdef BACKLIGHT_BREATHING | 1173 | #ifdef BACKLIGHT_BREATHING |
