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,8 +34,8 @@ bool endstop_monitor_flag = false;
34 34
 #define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(5)))
35 35
 
36 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,7 +60,7 @@ static bool report_pin_name(int8_t pin, bool &pin_is_analog) {
60 60
     if (pin == 1) { sprintf(buffer, NAME_FORMAT, "TXD"); SERIAL_ECHO(buffer); return true; }
61 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 64
   #if defined(__FD) && __FD >= 0
65 65
     PIN_SAY(__FD)
66 66
   #endif
@@ -656,10 +656,10 @@ static bool report_pin_name(int8_t pin, bool &pin_is_analog) {
656 656
 } // report_pin_name
657 657
 
658 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 663
       return true; \
664 664
     } else return false
665 665
 
@@ -667,43 +667,43 @@ static bool report_pin_name(int8_t pin, bool &pin_is_analog) {
667 667
  * Print a pin's PWM status.
668 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 671
   char buffer[20];   // for the sprintf statements
672 672
 
673 673
   switch(digitalPinToTimer(pin)) {
674 674
 
675 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 678
     #endif
679 679
 
680 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 684
     #endif
685 685
 
686 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 689
     #endif
690 690
 
691 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 695
     #endif
696 696
 
697 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 701
     #endif
702 702
 
703 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 707
     #endif
708 708
 
709 709
     case NOT_ON_TIMER:
@@ -711,10 +711,10 @@ static bool PWM_status(uint8_t pin) {
711 711
       return false;
712 712
   }
713 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 718
 #define TIMER_PREFIX(T,L,N) do{ \
719 719
     WGM = WGM_MAKE##N(T); \
720 720
     SERIAL_PROTOCOLPGM("    TIMER"); \
@@ -745,13 +745,13 @@ static void err_prob_interrupt() {
745 745
 }
746 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 750
   uint8_t WGM;
751 751
 
752 752
   switch(digitalPinToTimer(pin)) {
753 753
 
754
-  	#if defined(TCCR0A) && defined(COM0A1)
754
+    #if defined(TCCR0A) && defined(COM0A1)
755 755
       case TIMER0A:
756 756
         TIMER_PREFIX(0,A,3);
757 757
         if (WGM_TEST1) err_is_counter();
@@ -881,13 +881,11 @@ static void PWM_details(uint8_t pin) {
881 881
         break;
882 882
     #endif
883 883
 
884
-  	case NOT_ON_TIMER: break;
884
+    case NOT_ON_TIMER: break;
885 885
 
886
-	}
886
+  }
887 887
   SERIAL_PROTOCOLPGM("  ");
888
-}  // PWM_details
889
-
890
-
888
+} // pwm_details
891 889
 
892 890
 inline void report_pin_state(int8_t pin) {
893 891
   SERIAL_ECHO((int)pin);
@@ -938,7 +936,7 @@ inline void report_pin_state_extended(int8_t pin, bool ignore) {
938 936
         pinMode(pin, INPUT_PULLUP);  // make sure input isn't floating
939 937
         SERIAL_PROTOCOLPAIR("Input  = ", digitalRead_mod(pin));
940 938
       }
941
-      else if (PWM_status(pin)) {
939
+      else if (pwm_status(pin)) {
942 940
         // do nothing
943 941
       }
944 942
       else SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
@@ -946,7 +944,7 @@ inline void report_pin_state_extended(int8_t pin, bool ignore) {
946 944
   }
947 945
 
948 946
   // report PWM capabilities
949
-  PWM_details(pin);
947
+  pwm_details(pin);
950 948
   SERIAL_EOL;
951 949
 }
952 950
 

Loading…
Cancel
Save