Merge pull request #1988 from kh90909/pwm-bl-fix-next-branch
Port ATmega2561 PWM_BACKLIGHT fix from master branch
This commit is contained in:
@@ -130,12 +130,19 @@ inline void boardInit()
|
|||||||
#endif
|
#endif
|
||||||
#elif defined(PWM_BACKLIGHT)
|
#elif defined(PWM_BACKLIGHT)
|
||||||
/** Smartieparts LED Backlight is connected to PORTB/pin7, which can be used as pwm output of timer2 **/
|
/** Smartieparts LED Backlight is connected to PORTB/pin7, which can be used as pwm output of timer2 **/
|
||||||
#if defined(SP22)
|
#if defined(CPUM2561)
|
||||||
TCCR2 = (0b011 << CS20)|(1<<WGM20)|(1<<COM21)|(1<<COM20); // inv. pwm mode, clk/64
|
#if defined(SP22)
|
||||||
|
TCCR0A = (1<<WGM00)|(1<<COM0A1)|(1<<COM0A0); // inv. pwm mode, clk/64
|
||||||
|
#else
|
||||||
|
TCCR0A = (1<<WGM00)|(1<<COM0A1); // pwm mode, clk/64
|
||||||
|
#endif
|
||||||
|
TCCR0B = (0b011<<CS00);
|
||||||
#else
|
#else
|
||||||
TCCR2 = (0b011 << CS20)|(1<<WGM20)|(1<<COM21); // pwm mode, clk/64
|
#if defined(SP22)
|
||||||
#endif
|
TCCR2 = (0b011<<CS20)|(1<<WGM20)|(1<<COM21)|(1<<COM20); // inv. pwm mode, clk/64
|
||||||
#if !defined(CPUM2561)
|
#else
|
||||||
|
TCCR2 = (0b011<<CS20)|(1<<WGM20)|(1<<COM21); // pwm mode, clk/64
|
||||||
|
#endif
|
||||||
TIMSK |= (1<<OCIE0) | (1<<TOIE0); // Enable Output-Compare and Overflow interrrupts
|
TIMSK |= (1<<OCIE0) | (1<<TOIE0); // Enable Output-Compare and Overflow interrrupts
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
@@ -326,13 +333,20 @@ bool getBackLightState()
|
|||||||
return (bl_target==g_eeGeneral.blOnBright);
|
return (bl_target==g_eeGeneral.blOnBright);
|
||||||
}
|
}
|
||||||
|
|
||||||
void backlightFade() //called from per10ms()
|
void backlightFade() // called from per10ms()
|
||||||
{
|
{
|
||||||
if (bl_target != bl_current) {
|
if (bl_target != bl_current) {
|
||||||
|
#if defined(CPUM2561)
|
||||||
|
if (bl_target > bl_current)
|
||||||
|
OCR0A = pgm_read_byte(&pwmtable[++bl_current]);
|
||||||
|
else
|
||||||
|
OCR0A = pgm_read_byte(&pwmtable[--bl_current]);
|
||||||
|
#else
|
||||||
if (bl_target > bl_current)
|
if (bl_target > bl_current)
|
||||||
OCR2 = pgm_read_byte(&pwmtable[++bl_current]);
|
OCR2 = pgm_read_byte(&pwmtable[++bl_current]);
|
||||||
else
|
else
|
||||||
OCR2 = pgm_read_byte(&pwmtable[--bl_current]);
|
OCR2 = pgm_read_byte(&pwmtable[--bl_current]);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user