Browse Source

Merge pull request #5132 from thinkyhead/rc_fix_M43

Followup to #5118 - pins debugging cleanup
Scott Lahteine 8 years ago
parent
commit
9c108aea18
1 changed files with 34 additions and 36 deletions
  1. 34
    36
      Marlin/pinsDebug.h

+ 34
- 36
Marlin/pinsDebug.h View File

34
 #define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(5)))
34
 #define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(5)))
35
 
35
 
36
 int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
36
 int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
37
-	uint8_t port = digitalPinToPort(pin);
38
-	return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
37
+  uint8_t port = digitalPinToPort(pin);
38
+  return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
39
 }
39
 }
40
 
40
 
41
 /**
41
 /**
60
     if (pin == 1) { sprintf(buffer, NAME_FORMAT, "TXD"); SERIAL_ECHO(buffer); return true; }
60
     if (pin == 1) { sprintf(buffer, NAME_FORMAT, "TXD"); SERIAL_ECHO(buffer); return true; }
61
   #endif
61
   #endif
62
 
62
 
63
-  // Pin list updated from 7 OCT RCBugfix branch
63
+  // Pin list updated from 7 OCT RCBugfix branch   - max length of pin name is 24
64
   #if defined(__FD) && __FD >= 0
64
   #if defined(__FD) && __FD >= 0
65
     PIN_SAY(__FD)
65
     PIN_SAY(__FD)
66
   #endif
66
   #endif
656
 } // report_pin_name
656
 } // report_pin_name
657
 
657
 
658
 #define PWM_PRINT(V) do{ sprintf(buffer, "PWM:  %4d", V); SERIAL_ECHO(buffer); }while(0)
658
 #define PWM_PRINT(V) do{ sprintf(buffer, "PWM:  %4d", V); SERIAL_ECHO(buffer); }while(0)
659
-#define PWM_CASE(N) \
660
-  case TIMER##N: \
661
-    if (TCCR##N & (_BV(COM## N ##1) | _BV(COM## N ##0))) { \
662
-      PWM_PRINT(OCR##N); \
659
+#define PWM_CASE(N,Z) \
660
+  case TIMER##N##Z: \
661
+    if (TCCR##N##A & (_BV(COM##N##Z##1) | _BV(COM##N##Z##0))) { \
662
+      PWM_PRINT(OCR##N##Z); \
663
       return true; \
663
       return true; \
664
     } else return false
664
     } else return false
665
 
665
 
667
  * Print a pin's PWM status.
667
  * Print a pin's PWM status.
668
  * Return true if it's currently a PWM pin.
668
  * Return true if it's currently a PWM pin.
669
  */
669
  */
670
-static bool PWM_status(uint8_t pin) {
670
+static bool pwm_status(uint8_t pin) {
671
   char buffer[20];   // for the sprintf statements
671
   char buffer[20];   // for the sprintf statements
672
 
672
 
673
   switch(digitalPinToTimer(pin)) {
673
   switch(digitalPinToTimer(pin)) {
674
 
674
 
675
     #if defined(TCCR0A) && defined(COM0A1)
675
     #if defined(TCCR0A) && defined(COM0A1)
676
-      PWM_CASE(0A);
677
-      PWM_CASE(0B);
676
+      PWM_CASE(0,A);
677
+      PWM_CASE(0,B);
678
     #endif
678
     #endif
679
 
679
 
680
     #if defined(TCCR1A) && defined(COM1A1)
680
     #if defined(TCCR1A) && defined(COM1A1)
681
-      PWM_CASE(1A);
682
-      PWM_CASE(1B);
683
-      PWM_CASE(1C);
681
+      PWM_CASE(1,A);
682
+      PWM_CASE(1,B);
683
+      PWM_CASE(1,C);
684
     #endif
684
     #endif
685
 
685
 
686
     #if defined(TCCR2A) && defined(COM2A1)
686
     #if defined(TCCR2A) && defined(COM2A1)
687
-      PWM_CASE(2A);
688
-      PWM_CASE(2B);
687
+      PWM_CASE(2,A);
688
+      PWM_CASE(2,B);
689
     #endif
689
     #endif
690
 
690
 
691
     #if defined(TCCR3A) && defined(COM3A1)
691
     #if defined(TCCR3A) && defined(COM3A1)
692
-      PWM_CASE(3A);
693
-      PWM_CASE(3B);
694
-      PWM_CASE(3C);
692
+      PWM_CASE(3,A);
693
+      PWM_CASE(3,B);
694
+      PWM_CASE(3,C);
695
     #endif
695
     #endif
696
 
696
 
697
     #ifdef TCCR4A
697
     #ifdef TCCR4A
698
-      PWM_CASE(4A);
699
-      PWM_CASE(4B);
700
-      PWM_CASE(4C);
698
+      PWM_CASE(4,A);
699
+      PWM_CASE(4,B);
700
+      PWM_CASE(4,C);
701
     #endif
701
     #endif
702
 
702
 
703
     #if defined(TCCR5A) && defined(COM5A1)
703
     #if defined(TCCR5A) && defined(COM5A1)
704
-      PWM_CASE(5A);
705
-      PWM_CASE(5B);
706
-      PWM_CASE(5C);
704
+      PWM_CASE(5,A);
705
+      PWM_CASE(5,B);
706
+      PWM_CASE(5,C);
707
     #endif
707
     #endif
708
 
708
 
709
     case NOT_ON_TIMER:
709
     case NOT_ON_TIMER:
711
       return false;
711
       return false;
712
   }
712
   }
713
   SERIAL_PROTOCOLPGM("  ");
713
   SERIAL_PROTOCOLPGM("  ");
714
-}  //PWM_status
714
+} // pwm_status
715
 
715
 
716
-#define WGM_MAKE3(N) ((TEST(TCCR##N##B, WGM##N##2) >> 1) | (TCCR##N##A & (_BV(WGM##N##0) | _BV(WGM##N##1))))
717
-#define WGM_MAKE4(N) (WGM_MAKE3(N) | (TEST(TCCR##N##B, WGM##N##3) >> 1))
716
+#define WGM_MAKE3(N) (((TCCR##N##B & _BV(WGM##N##2)) >> 1) | (TCCR##N##A & (_BV(WGM##N##0) | _BV(WGM##N##1))))
717
+#define WGM_MAKE4(N) (WGM_MAKE3(N) | (TCCR##N##B & _BV(WGM##N##3)) >> 1)
718
 #define TIMER_PREFIX(T,L,N) do{ \
718
 #define TIMER_PREFIX(T,L,N) do{ \
719
     WGM = WGM_MAKE##N(T); \
719
     WGM = WGM_MAKE##N(T); \
720
     SERIAL_PROTOCOLPGM("    TIMER"); \
720
     SERIAL_PROTOCOLPGM("    TIMER"); \
745
 }
745
 }
746
 static void can_be_used() { SERIAL_PROTOCOLPGM("   can be used as PWM   "); }
746
 static void can_be_used() { SERIAL_PROTOCOLPGM("   can be used as PWM   "); }
747
 
747
 
748
-static void PWM_details(uint8_t pin) {
748
+static void pwm_details(uint8_t pin) {
749
 
749
 
750
   uint8_t WGM;
750
   uint8_t WGM;
751
 
751
 
752
   switch(digitalPinToTimer(pin)) {
752
   switch(digitalPinToTimer(pin)) {
753
 
753
 
754
-  	#if defined(TCCR0A) && defined(COM0A1)
754
+    #if defined(TCCR0A) && defined(COM0A1)
755
       case TIMER0A:
755
       case TIMER0A:
756
         TIMER_PREFIX(0,A,3);
756
         TIMER_PREFIX(0,A,3);
757
         if (WGM_TEST1) err_is_counter();
757
         if (WGM_TEST1) err_is_counter();
881
         break;
881
         break;
882
     #endif
882
     #endif
883
 
883
 
884
-  	case NOT_ON_TIMER: break;
884
+    case NOT_ON_TIMER: break;
885
 
885
 
886
-	}
886
+  }
887
   SERIAL_PROTOCOLPGM("  ");
887
   SERIAL_PROTOCOLPGM("  ");
888
-}  // PWM_details
889
-
890
-
888
+} // pwm_details
891
 
889
 
892
 inline void report_pin_state(int8_t pin) {
890
 inline void report_pin_state(int8_t pin) {
893
   SERIAL_ECHO((int)pin);
891
   SERIAL_ECHO((int)pin);
938
         pinMode(pin, INPUT_PULLUP);  // make sure input isn't floating
936
         pinMode(pin, INPUT_PULLUP);  // make sure input isn't floating
939
         SERIAL_PROTOCOLPAIR("Input  = ", digitalRead_mod(pin));
937
         SERIAL_PROTOCOLPAIR("Input  = ", digitalRead_mod(pin));
940
       }
938
       }
941
-      else if (PWM_status(pin)) {
939
+      else if (pwm_status(pin)) {
942
         // do nothing
940
         // do nothing
943
       }
941
       }
944
       else SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
942
       else SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
946
   }
944
   }
947
 
945
 
948
   // report PWM capabilities
946
   // report PWM capabilities
949
-  PWM_details(pin);
947
+  pwm_details(pin);
950
   SERIAL_EOL;
948
   SERIAL_EOL;
951
 }
949
 }
952
 
950
 

Loading…
Cancel
Save