From e3fab7cf4072aa7792b1bb371377bc2fd208ede0 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 15 Dec 2014 12:43:09 +0100 Subject: pwm: Add method to switch all LEDs off This is used quite often and we can implement it more efficiently. --- pwm.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'pwm.c') diff --git a/pwm.c b/pwm.c index 49045b4..250e489 100644 --- a/pwm.c +++ b/pwm.c @@ -14,9 +14,9 @@ static uint8_t count = 0; static uint8_t speakerCount = 0; static uint8_t pwmvalue[PWM_MAX_BRIGHTNESS][2]; -/* led bitfield, indicating which ones are pwm-controlled */ -static const uint8_t offbits[2] = {(uint8_t) ~((1 << PB6) | (1 << PB7)), - (uint8_t) ~((1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5) | (1 << PD6))}; +/* inversed(!) bitfield, indicating which LEDs are pwm-controlled */ +static const uint8_t notledbits[2] = {(uint8_t) ~((1 << PB6) | (1 << PB7)), + (uint8_t) ~((1 << PD2) | (1 << PD3) | (1 << PD4) | (1 << PD5))}; ISR(TIMER0_COMPA_vect) { if (speakerCount > 0) { @@ -83,15 +83,11 @@ void pwmStart () { TCCR0B = (1 << CS02) | (0 << CS01) | (1 << CS00); } -static void allLedsOff () { - PORTB &= offbits[0]; - PORTD &= offbits[1]; -} - void pwmStop () { /* zero clock source */ TCCR0B = 0; - allLedsOff (); + PORTB &= notledbits[0]; + PORTD &= notledbits[1]; } /* Set LED brightness @@ -113,6 +109,15 @@ void pwmSet (const uint8_t i, const uint8_t value) { } } +/* Switch all LEDs off + */ +void pwmSetOff () { + for (uint8_t i = 0; i < PWM_MAX_BRIGHTNESS; i++) { + pwmvalue[i][0] &= notledbits[0]; + pwmvalue[i][1] &= notledbits[1]; + } +} + void speakerStart (const speakerMode mode __unused__) { /* 12.8ms */ speakerCount = 100; -- cgit v1.2.3