Reduce code and build size of PWM_details

master
Scott Lahteine 8 years ago
parent dbe414ef03
commit b4444e91ae

@ -733,194 +733,176 @@ static bool PWM_status(uint8_t pin) {
SERIAL_PROTOCOLPGM(" "); SERIAL_PROTOCOLPGM(" ");
} //PWM_status } //PWM_status
static void PWM_details(uint8_t pin) #define WGM_MAKE3(N) ((TEST(TCCR##N##B, WGM##N##2) >> 1) | (TCCR##N##A & (_BV(WGM##N##0) | _BV(WGM##N##1))))
{ #define WGM_MAKE4(N) (WGM_MAKE3(N) | (TEST(TCCR##N##B, WGM##N##3) >> 1))
#define TIMER_PREFIX(T,L,N) do{ \
WGM = WGM_MAKE##N(T); \
SERIAL_PROTOCOLPGM(" TIMER"); \
SERIAL_PROTOCOLPGM(STRINGIFY(T) STRINGIFY(L)); \
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); \
SERIAL_PROTOCOLPAIR(" TIMSK" STRINGIFY(T) ": ", TIMSK##T); \
}while(0)
#define WGM_TEST1 (WGM == 0 || WGM == 2 || WGM == 4 || WGM == 6)
#define WGM_TEST2 (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13)
static void err_is_counter() {
SERIAL_PROTOCOLPGM(" Can't ");
SERIAL_PROTOCOLPGM("be used as a PWM because ");
SERIAL_PROTOCOLPGM("of counter mode");
}
static void err_is_interrupt() {
SERIAL_PROTOCOLPGM(" Can't ");
SERIAL_PROTOCOLPGM("be used as a PWM because ");
SERIAL_PROTOCOLPGM("it's ");
SERIAL_PROTOCOLPGM("being used as an interrupt");
}
static void err_prob_interrupt() {
SERIAL_PROTOCOLPGM(" Probably can't ");
SERIAL_PROTOCOLPGM("be used as a PWM because ");
SERIAL_PROTOCOLPGM("counter/timer is ");
SERIAL_PROTOCOLPGM("being used as an interrupt");
}
static void can_be_used() { SERIAL_PROTOCOLPGM(" can be used as PWM "); }
uint8_t WGM; static void PWM_details(uint8_t pin) {
uint8_t WGM;
switch(digitalPinToTimer(pin)) { switch(digitalPinToTimer(pin)) {
#if defined(TCCR0A) && defined(COM0A1) #if defined(TCCR0A) && defined(COM0A1)
case TIMER0A: case TIMER0A:
SERIAL_PROTOCOLPGM(" TIMER0A"); TIMER_PREFIX(0,A,3);
WGM = ((TCCR0B & _BV(WGM02)) >> 1 ) | (TCCR0A & (_BV(WGM00) | _BV(WGM01) )); if (WGM_TEST1) err_is_counter();
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); else if (TEST(TIMSK0, OCIE0A)) err_is_interrupt();
SERIAL_PROTOCOLPAIR(" TIMSK0: ", TIMSK0); else if (TEST(TIMSK0, TOIE0)) err_prob_interrupt();
if (WGM == 0 || WGM == 2 || WGM == 4 || WGM == 6) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); else can_be_used();
else if (TIMSK0 & _BV(OCIE0A)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); break;
else if (TIMSK0 & _BV(TOIE0) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); case TIMER0B:
else SERIAL_PROTOCOLPGM(" can be used as PWM "); TIMER_PREFIX(0,B,3);
break; if (WGM_TEST1) err_is_counter();
case TIMER0B: else if (TEST(TIMSK0, OCIE0B)) err_is_interrupt();
SERIAL_PROTOCOLPGM(" TIMER0B"); else if (TEST(TIMSK0, TOIE0)) err_prob_interrupt();
WGM = ((TCCR0B & _BV(WGM02)) >> 1 ) | (TCCR0A & (_BV(WGM00) | _BV(WGM01) )); else can_be_used();
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); break;
SERIAL_PROTOCOLPAIR(" TIMSK0: ", TIMSK0); #endif
if (WGM == 0 || WGM == 2 || WGM == 4 || WGM == 6) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode");
else if (TIMSK0 & _BV(OCIE0B)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); #if defined(TCCR1A) && defined(COM1A1)
else if (TIMSK0 & _BV(TOIE0) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); case TIMER1A:
else SERIAL_PROTOCOLPGM(" can be used as PWM "); TIMER_PREFIX(1,A,4);
break; if (WGM_TEST2) err_is_counter();
#endif else if (TEST(TIMSK1, OCIE1A)) err_is_interrupt();
else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1))) err_prob_interrupt();
#if defined(TCCR1A) && defined(COM1A1) else can_be_used();
case TIMER1A: break;
SERIAL_PROTOCOLPGM(" TIMER1A"); case TIMER1B:
WGM = ((TCCR1B & (_BV(WGM12) | _BV(WGM13) )) >> 1 ) | (TCCR1A & (_BV(WGM10) | _BV(WGM11) )); TIMER_PREFIX(1,B,4);
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); if (WGM_TEST2) err_is_counter();
SERIAL_PROTOCOLPAIR(" TIMSK1: ", TIMSK1); else if (TEST(TIMSK1, OCIE1B)) err_is_interrupt();
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1))) err_prob_interrupt();
else if (TIMSK1 & _BV(OCIE1A)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); else can_be_used();
else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); break;
else SERIAL_PROTOCOLPGM(" can be used as PWM "); case TIMER1C:
break; TIMER_PREFIX(1,C,4);
case TIMER1B: if (WGM_TEST2) err_is_counter();
SERIAL_PROTOCOLPGM(" TIMER1B"); else if (TEST(TIMSK1, OCIE1C)) err_is_interrupt();
WGM = ((TCCR1B & (_BV(WGM12) | _BV(WGM13) )) >> 1 ) | (TCCR1A & (_BV(WGM10) | _BV(WGM11) )); else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1))) err_prob_interrupt();
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); else can_be_used();
SERIAL_PROTOCOLPAIR(" TIMSK1: ", TIMSK1); break;
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); #endif
else if (TIMSK1 & _BV(OCIE1B)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt");
else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); #if defined(TCCR2A) && defined(COM2A1)
else SERIAL_PROTOCOLPGM(" can be used as PWM "); case TIMER2A:
break; TIMER_PREFIX(2,A,3);
case TIMER1C: if (WGM_TEST1) err_is_counter();
SERIAL_PROTOCOLPGM(" TIMER1C"); else if (TIMSK2 & (_BV(TOIE2) | _BV(OCIE2A))) err_is_interrupt();
WGM = ((TCCR1B & (_BV(WGM12) | _BV(WGM13) )) >> 1 ) | (TCCR1A & (_BV(WGM10) | _BV(WGM11) )); else if (TEST(TIMSK2, TOIE2)) err_prob_interrupt();
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); else can_be_used();
SERIAL_PROTOCOLPAIR(" TIMSK1: ", TIMSK1); break;
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); case TIMER2B:
else if (TIMSK1 & _BV(OCIE1C)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); TIMER_PREFIX(2,B,3);
else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); if (WGM_TEST1) err_is_counter();
else SERIAL_PROTOCOLPGM(" can be used as PWM "); else if (TEST(TIMSK2, OCIE2B)) err_is_interrupt();
break; else if (TEST(TIMSK2, TOIE2)) err_prob_interrupt();
#endif else can_be_used();
break;
#if defined(TCCR2A) && defined(COM2A1) #endif
case TIMER2A:
SERIAL_PROTOCOLPGM(" TIMER2A"); #if defined(TCCR3A) && defined(COM3A1)
WGM = ((TCCR2B & _BV(WGM22) ) >> 1 ) | (TCCR2A & (_BV(WGM20) | _BV(WGM21) )); case TIMER3A:
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); TIMER_PREFIX(3,A,3);
SERIAL_PROTOCOLPAIR(" TIMSK2: ", TIMSK2); if (WGM_TEST2) err_is_counter();
if (WGM == 0 || WGM == 2 || WGM == 4 || WGM == 6) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); else if (TEST(TIMSK3, OCIE3A)) err_is_interrupt();
else if (TIMSK2 & (_BV(TOIE2) | _BV(OCIE2A))) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3))) err_prob_interrupt();
else if (TIMSK2 & _BV(TOIE2) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); else can_be_used();
else SERIAL_PROTOCOLPGM(" can be used as PWM "); break;
break; case TIMER3B:
case TIMER2B: TIMER_PREFIX(3,B,3);
SERIAL_PROTOCOLPGM(" TIMER2B"); if (WGM_TEST2) err_is_counter();
WGM = ((TCCR2B & _BV(WGM22) ) >> 1 ) | (TCCR2A & (_BV(WGM20) | _BV(WGM21) )); else if (TEST(TIMSK3, OCIE3B)) err_is_interrupt();
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3))) err_prob_interrupt();
SERIAL_PROTOCOLPAIR(" TIMSK2: ", TIMSK2); else can_be_used();
if (WGM == 0 || WGM == 2 || WGM == 4 || WGM == 6) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); break;
else if (TIMSK2 & _BV(OCIE2B)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); case TIMER3C:
else if (TIMSK2 & _BV(TOIE2) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); TIMER_PREFIX(3,C,3);
else SERIAL_PROTOCOLPGM(" can be used as PWM "); if (WGM_TEST2) err_is_counter();
break; else if (TEST(TIMSK3, OCIE3C)) err_is_interrupt();
#endif else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3))) err_prob_interrupt();
else can_be_used();
#if defined(TCCR3A) && defined(COM3A1) break;
case TIMER3A: #endif
SERIAL_PROTOCOLPGM(" TIMER3A");
WGM = ((TCCR3B & _BV(WGM32) ) >> 1 ) | (TCCR3A & (_BV(WGM30) | _BV(WGM31) )); #ifdef TCCR4A
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); case TIMER4A:
SERIAL_PROTOCOLPAIR(" TIMSK3: ", TIMSK3); TIMER_PREFIX(4,A,4);
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); if (WGM_TEST2) err_is_counter();
else if (TIMSK3 & _BV(OCIE3A)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); else if (TEST(TIMSK4, OCIE4A)) err_is_interrupt();
else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); else if (TIMSK4 & (_BV(TOIE4) | _BV(ICIE4))) err_prob_interrupt();
else SERIAL_PROTOCOLPGM(" can be used as PWM "); else can_be_used();
break; break;
case TIMER3B: case TIMER4B:
SERIAL_PROTOCOLPGM(" TIMER3B"); TIMER_PREFIX(4,B,4);
WGM = ((TCCR3B & _BV(WGM32) ) >> 1 ) | (TCCR3A & (_BV(WGM30) | _BV(WGM31) )); if (WGM_TEST2) err_is_counter();
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); else if (TEST(TIMSK4, OCIE4B)) err_is_interrupt();
SERIAL_PROTOCOLPAIR(" TIMSK3: ", TIMSK3); else if (TIMSK4 & (_BV(TOIE4) | _BV(ICIE4))) err_prob_interrupt();
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); else can_be_used();
else if (TIMSK3 & _BV(OCIE3B)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); break;
else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); case TIMER4C:
else SERIAL_PROTOCOLPGM(" can be used as PWM "); TIMER_PREFIX(4,C,4);
break; if (WGM_TEST2) err_is_counter();
case TIMER3C: else if (TEST(TIMSK4, OCIE4C)) err_is_interrupt();
SERIAL_PROTOCOLPGM(" TIMER3C"); else if (TIMSK4 & (_BV(TOIE4) | _BV(ICIE4))) err_prob_interrupt();
WGM = ((TCCR3B & _BV(WGM32) ) >> 1 ) | (TCCR3A & (_BV(WGM30) | _BV(WGM31) )); else can_be_used();
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); break;
SERIAL_PROTOCOLPAIR(" TIMSK3: ", TIMSK3); #endif
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode");
else if (TIMSK3 & _BV(OCIE3C)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); #if defined(TCCR5A) && defined(COM5A1)
else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); case TIMER5A:
else SERIAL_PROTOCOLPGM(" can be used as PWM "); TIMER_PREFIX(5,A,4);
break; if (WGM_TEST2) err_is_counter();
#endif else if (TEST(TIMSK5, OCIE5A)) err_is_interrupt();
else if (TIMSK5 & (_BV(TOIE5) | _BV(ICIE5))) err_prob_interrupt();
#if defined(TCCR4A) else can_be_used();
case TIMER4A: break;
SERIAL_PROTOCOLPGM(" TIMER4A"); case TIMER5B:
WGM = ((TCCR4B & (_BV(WGM42) | _BV(WGM43) )) >> 1 ) | (TCCR4A & (_BV(WGM40) | _BV(WGM41) )); TIMER_PREFIX(5,B,4);
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); if (WGM_TEST2) err_is_counter();
SERIAL_PROTOCOLPAIR(" TIMSK4: ", TIMSK4); else if (TEST(TIMSK5, OCIE5B)) err_is_interrupt();
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); else if (TIMSK5 & (_BV(TOIE5) | _BV(ICIE5))) err_prob_interrupt();
else if (TIMSK4 & _BV(OCIE4A)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt"); else can_be_used();
else if (TIMSK4 & (_BV(TOIE4) | _BV(ICIE4)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); break;
else SERIAL_PROTOCOLPGM(" can be used as PWM "); case TIMER5C:
break; TIMER_PREFIX(5,C,4);
case TIMER4B: if (WGM_TEST2) err_is_counter();
SERIAL_PROTOCOLPGM(" TIMER4B"); else if (TEST(TIMSK5, OCIE5C)) err_is_interrupt();
WGM = ((TCCR4B & (_BV(WGM42) | _BV(WGM43) )) >> 1 ) | (TCCR4A & (_BV(WGM40) | _BV(WGM41) )); else if (TIMSK5 & (_BV(TOIE5) | _BV(ICIE5))) err_prob_interrupt();
SERIAL_PROTOCOLPAIR(" WGM: ", WGM); else can_be_used();
SERIAL_PROTOCOLPAIR(" TIMSK4: ", TIMSK4); break;
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode"); #endif
else if (TIMSK4 & _BV(OCIE4B)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt");
else if (TIMSK4 & (_BV(TOIE4) | _BV(ICIE4)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt"); case NOT_ON_TIMER: break;
else SERIAL_PROTOCOLPGM(" can be used as PWM ");
break;
case TIMER4C:
SERIAL_PROTOCOLPGM(" TIMER4C");
WGM = ((TCCR4B & (_BV(WGM42) | _BV(WGM43) )) >> 1 ) | (TCCR4A & (_BV(WGM40) | _BV(WGM41) ));
SERIAL_PROTOCOLPAIR(" WGM: ", WGM);
SERIAL_PROTOCOLPAIR(" TIMSK4: ", TIMSK4);
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode");
else if (TIMSK4 & _BV(OCIE4C)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt");
else if (TIMSK4 & (_BV(TOIE4) | _BV(ICIE4)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt");
else SERIAL_PROTOCOLPGM(" can be used as PWM ");
break;
#endif
#if defined(TCCR5A) && defined(COM5A1)
case TIMER5A:
SERIAL_PROTOCOLPGM(" TIMER5A");
WGM = ((TCCR5B & (_BV(WGM52) | _BV(WGM53) )) >> 1 ) | (TCCR5A & (_BV(WGM50) | _BV(WGM51) ));
SERIAL_PROTOCOLPAIR(" WGM: ", WGM);
SERIAL_PROTOCOLPAIR(" TIMSK5: ", TIMSK5);
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode");
else if (TIMSK5 & _BV(OCIE5A)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt");
else if (TIMSK5 & (_BV(TOIE5) | _BV(ICIE5)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt");
else SERIAL_PROTOCOLPGM(" can be used as PWM ");
break;
case TIMER5B:
SERIAL_PROTOCOLPGM(" TIMER5B");
WGM = ((TCCR5B & (_BV(WGM52) | _BV(WGM53) )) >> 1 ) | (TCCR5A & (_BV(WGM50) | _BV(WGM51) ));
SERIAL_PROTOCOLPAIR(" WGM: ", WGM);
SERIAL_PROTOCOLPAIR(" TIMSK5: ", TIMSK5);
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode");
else if (TIMSK5 & _BV(OCIE5B)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt");
else if (TIMSK5 & (_BV(TOIE5) | _BV(ICIE5)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt");
else SERIAL_PROTOCOLPGM(" can be used as PWM ");
break;
case TIMER5C:
SERIAL_PROTOCOLPGM(" TIMER5C");
WGM = ((TCCR5B & (_BV(WGM52) | _BV(WGM53) )) >> 1 ) | (TCCR5A & (_BV(WGM50) | _BV(WGM51) ));
SERIAL_PROTOCOLPAIR(" WGM: ", WGM);
SERIAL_PROTOCOLPAIR(" TIMSK5: ", TIMSK5);
if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because of counter mode");
else if (TIMSK5 & _BV(OCIE5C)) SERIAL_PROTOCOLPGM(" Can't be used as a PWM because being used to generate an interrupt");
else if (TIMSK5 & (_BV(TOIE5) | _BV(ICIE5)) ) SERIAL_PROTOCOLPGM(" Probably can't be used as a PWM because counter/timer being used to generate an interrupt");
else SERIAL_PROTOCOLPGM(" can be used as PWM ");
break;
#endif
case NOT_ON_TIMER:
break;
} }
SERIAL_PROTOCOLPGM(" "); SERIAL_PROTOCOLPGM(" ");
} // PWM_details } // PWM_details

Loading…
Cancel
Save