Squash redundant code in PWM_status

master
Scott Lahteine 8 years ago
parent af26d22741
commit dbe414ef03

@ -675,167 +675,61 @@ static bool report_pin_name(int8_t pin, bool &pin_is_analog) {
return false; return false;
} // report_pin_name } // report_pin_name
// True - currently a PWM pin #define PWM_PRINT(V) do{ sprintf(buffer, "PWM: %4d", V); SERIAL_ECHO(buffer); }while(0)
#define PWM_CASE(N) \
case TIMER##N: \
if (TCCR##N & (_BV(COM## N ##1) | _BV(COM## N ##0))) { \
PWM_PRINT(OCR##N); \
return true; \
} else return false
/**
* Print a pin's PWM status.
* Return true if it's currently a PWM pin.
*/
static bool PWM_status(uint8_t pin) { static bool PWM_status(uint8_t pin) {
char buffer[20]; // for the sprintf statements char buffer[20]; // for the sprintf statements
switch(digitalPinToTimer(pin)) { switch(digitalPinToTimer(pin)) {
#if defined(TCCR0A) && defined(COM0A1) #if defined(TCCR0A) && defined(COM0A1)
case TIMER0A: PWM_CASE(0A);
if (TCCR0A & (_BV(COM0A1) | _BV(COM0A0))){ PWM_CASE(0B);
sprintf(buffer, "PWM: %4d", OCR0A);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER0B:
if (TCCR0A & (_BV(COM0B1) | _BV(COM0B0))){
sprintf(buffer, "PWM: %4d",OCR0B);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
#endif #endif
#if defined(TCCR1A) && defined(COM1A1) #if defined(TCCR1A) && defined(COM1A1)
case TIMER1A: PWM_CASE(1A);
if (TCCR1A & (_BV(COM1A1) | _BV(COM1A0))){ PWM_CASE(1B);
sprintf(buffer, "PWM: %4d",OCR1A); PWM_CASE(1C);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER1B:
if (TCCR1A & (_BV(COM1B1) | _BV(COM1B0))){
sprintf(buffer, "PWM: %4d",OCR1B);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER1C:
if (TCCR1A & (_BV(COM1C1) | _BV(COM1C0))){
sprintf(buffer, "PWM: %4d",OCR1C);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
#endif #endif
#if defined(TCCR2A) && defined(COM2A1) #if defined(TCCR2A) && defined(COM2A1)
case TIMER2A: PWM_CASE(2A);
if (TCCR2A & (_BV(COM2A1) | _BV(COM2A0))){ PWM_CASE(2B);
sprintf(buffer, "PWM: %4d",OCR2A);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER2B:
if (TCCR2A & (_BV(COM2B1) | _BV(COM2B0))){
sprintf(buffer, "PWM: %4d",OCR2B);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
#endif #endif
#if defined(TCCR3A) && defined(COM3A1) #if defined(TCCR3A) && defined(COM3A1)
case TIMER3A: PWM_CASE(3A);
if (TCCR3A & (_BV(COM3A1) | _BV(COM3A0))){ PWM_CASE(3B);
sprintf(buffer, "PWM: %4d",OCR3A); PWM_CASE(3C);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER3B:
if (TCCR3A & (_BV(COM3B1) | _BV(COM3B0))){
sprintf(buffer, "PWM: %4d",OCR3B);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER3C:
if (TCCR3A & (_BV(COM3C1) | _BV(COM3C0))){
sprintf(buffer, "PWM: %4d",OCR3C);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
#endif #endif
#ifdef TCCR4A #ifdef TCCR4A
case TIMER4A: PWM_CASE(4A);
if (TCCR4A & (_BV(COM4A1) | _BV(COM4A0))){ PWM_CASE(4B);
sprintf(buffer, "PWM: %4d",OCR4A); PWM_CASE(4C);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER4B:
if (TCCR4A & (_BV(COM4B1) | _BV(COM4B0))){
sprintf(buffer, "PWM: %4d",OCR4B);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER4C:
if (TCCR4A & (_BV(COM4C1) | _BV(COM4C0))){
sprintf(buffer, "PWM: %4d",OCR4C);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
#endif #endif
#if defined(TCCR5A) && defined(COM5A1) #if defined(TCCR5A) && defined(COM5A1)
case TIMER5A: PWM_CASE(5A);
if (TCCR5A & (_BV(COM5A1) | _BV(COM5A0))){ PWM_CASE(5B);
sprintf(buffer, "PWM: %4d",OCR5A); PWM_CASE(5C);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER5B:
if (TCCR5A & (_BV(COM5B1) | _BV(COM5B0))){
sprintf(buffer, "PWM: %4d",OCR5B);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
case TIMER5C:
if (TCCR5A & (_BV(COM5C1) | _BV(COM5C0))){
sprintf(buffer, "PWM: %4d",OCR5C);
SERIAL_ECHO(buffer);
return true;
}
else return false;
break;
#endif #endif
case NOT_ON_TIMER: case NOT_ON_TIMER:
return false;
break;
default: default:
return false; return false;
} }
SERIAL_PROTOCOLPGM(" "); SERIAL_PROTOCOLPGM(" ");
} //PWM_status } //PWM_status

Loading…
Cancel
Save