Added pin C6 to hardware PWM backlight
This commit is contained in:
parent
ffa5c48430
commit
ffa119941c
@ -898,14 +898,29 @@ static const uint8_t backlight_pin = BACKLIGHT_PIN;
|
|||||||
|
|
||||||
// depending on the pin, we use a different output compare unit
|
// depending on the pin, we use a different output compare unit
|
||||||
#if BACKLIGHT_PIN == B7
|
#if BACKLIGHT_PIN == B7
|
||||||
# define COM1x1 COM1C1
|
# define TCCRxA TCCR1A
|
||||||
# define OCR1x OCR1C
|
# define TCCRxB TCCR1B
|
||||||
|
# define COMxx1 COM1C1
|
||||||
|
# define OCRxx OCR1C
|
||||||
|
# define ICRx ICR1
|
||||||
#elif BACKLIGHT_PIN == B6
|
#elif BACKLIGHT_PIN == B6
|
||||||
# define COM1x1 COM1B1
|
# define TCCRxA TCCR1A
|
||||||
# define OCR1x OCR1B
|
# define TCCRxB TCCR1B
|
||||||
|
# define COMxx1 COM1B1
|
||||||
|
# define OCRxx OCR1B
|
||||||
|
# define ICRx ICR1
|
||||||
#elif BACKLIGHT_PIN == B5
|
#elif BACKLIGHT_PIN == B5
|
||||||
# define COM1x1 COM1A1
|
# define TCCRxA TCCR1A
|
||||||
# define OCR1x OCR1A
|
# define TCCRxB TCCR1B
|
||||||
|
# define COMxx1 COM1A1
|
||||||
|
# define OCRxx OCR1A
|
||||||
|
# define ICRx ICR1
|
||||||
|
#elif BACKLIGHT_PIN == C6
|
||||||
|
# define TCCRxA TCCR3A
|
||||||
|
# define TCCRxB TCCR3B
|
||||||
|
# define COMxx1 COM1A1
|
||||||
|
# define OCRxx OCR3A
|
||||||
|
# define ICRx ICR3
|
||||||
#else
|
#else
|
||||||
# define NO_HARDWARE_PWM
|
# define NO_HARDWARE_PWM
|
||||||
#endif
|
#endif
|
||||||
@ -987,7 +1002,7 @@ static uint16_t cie_lightness(uint16_t v) {
|
|||||||
|
|
||||||
// range for val is [0..TIMER_TOP]. PWM pin is high while the timer count is below val.
|
// range for val is [0..TIMER_TOP]. PWM pin is high while the timer count is below val.
|
||||||
static inline void set_pwm(uint16_t val) {
|
static inline void set_pwm(uint16_t val) {
|
||||||
OCR1x = val;
|
OCRxx = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef BACKLIGHT_CUSTOM_DRIVER
|
#ifndef BACKLIGHT_CUSTOM_DRIVER
|
||||||
@ -998,10 +1013,10 @@ void backlight_set(uint8_t level) {
|
|||||||
|
|
||||||
if (level == 0) {
|
if (level == 0) {
|
||||||
// Turn off PWM control on backlight pin
|
// Turn off PWM control on backlight pin
|
||||||
TCCR1A &= ~(_BV(COM1x1));
|
TCCRxA &= ~(_BV(COMxx1));
|
||||||
} else {
|
} else {
|
||||||
// Turn on PWM control of backlight pin
|
// Turn on PWM control of backlight pin
|
||||||
TCCR1A |= _BV(COM1x1);
|
TCCRxA |= _BV(COMxx1);
|
||||||
}
|
}
|
||||||
// Set the brightness
|
// Set the brightness
|
||||||
set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS));
|
set_pwm(cie_lightness(TIMER_TOP * (uint32_t)level / BACKLIGHT_LEVELS));
|
||||||
@ -1149,11 +1164,10 @@ void backlight_init_ports(void)
|
|||||||
"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 [..]."
|
"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 [..]."
|
||||||
"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)."
|
"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)."
|
||||||
*/
|
*/
|
||||||
|
TCCRxA = _BV(COMxx1) | _BV(WGM11); // = 0b00001010;
|
||||||
TCCR1A = _BV(COM1x1) | _BV(WGM11); // = 0b00001010;
|
TCCRxB = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
|
||||||
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;
|
|
||||||
// Use full 16-bit resolution. Counter counts to ICR1 before reset to 0.
|
// Use full 16-bit resolution. Counter counts to ICR1 before reset to 0.
|
||||||
ICR1 = TIMER_TOP;
|
ICRx = TIMER_TOP;
|
||||||
|
|
||||||
backlight_init();
|
backlight_init();
|
||||||
#ifdef BACKLIGHT_BREATHING
|
#ifdef BACKLIGHT_BREATHING
|
||||||
|
Loading…
Reference in New Issue
Block a user