Browse Source

Clean up pins debugging

Scott Lahteine 4 years ago
parent
commit
ca4423ed2a
3 changed files with 71 additions and 40 deletions
  1. 2
    2
      Marlin/src/gcode/config/M43.cpp
  2. 40
    0
      Marlin/src/pins/pins.h
  3. 29
    38
      Marlin/src/pins/pinsDebug.h

+ 2
- 2
Marlin/src/gcode/config/M43.cpp View File

@@ -61,12 +61,12 @@ inline void toggle_pins() {
61 61
     pin_t pin = GET_PIN_MAP_PIN_M43(i);
62 62
     if (!VALID_PIN(pin)) continue;
63 63
     if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) {
64
-      report_pin_state_extended(pin, ignore_protection, true, "Untouched ");
64
+      report_pin_state_extended(pin, ignore_protection, true, PSTR("Untouched "));
65 65
       SERIAL_EOL();
66 66
     }
67 67
     else {
68 68
       watchdog_refresh();
69
-      report_pin_state_extended(pin, ignore_protection, true, "Pulsing   ");
69
+      report_pin_state_extended(pin, ignore_protection, true, PSTR("Pulsing   "));
70 70
       #if AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
71 71
         if (pin == TEENSY_E2) {
72 72
           SET_OUTPUT(TEENSY_E2);

+ 40
- 0
Marlin/src/pins/pins.h View File

@@ -862,6 +862,43 @@
862 862
   #define E7_ENABLE_PIN -1
863 863
 #endif
864 864
 
865
+//
866
+// Destroy unused CS pins
867
+//
868
+#if !AXIS_HAS_SPI(X)
869
+  #undef X_CS_PIN
870
+#endif
871
+#if !AXIS_HAS_SPI(Y)
872
+  #undef Y_CS_PIN
873
+#endif
874
+#if !AXIS_HAS_SPI(Z)
875
+  #undef Z_CS_PIN
876
+#endif
877
+#if !AXIS_HAS_SPI(E0)
878
+  #undef E0_CS_PIN
879
+#endif
880
+#if !AXIS_HAS_SPI(E1)
881
+  #undef E1_CS_PIN
882
+#endif
883
+#if !AXIS_HAS_SPI(E2)
884
+  #undef E2_CS_PIN
885
+#endif
886
+#if !AXIS_HAS_SPI(E3)
887
+  #undef E3_CS_PIN
888
+#endif
889
+#if !AXIS_HAS_SPI(E4)
890
+  #undef E4_CS_PIN
891
+#endif
892
+#if !AXIS_HAS_SPI(E5)
893
+  #undef E5_CS_PIN
894
+#endif
895
+#if !AXIS_HAS_SPI(E6)
896
+  #undef E6_CS_PIN
897
+#endif
898
+#if !AXIS_HAS_SPI(E7)
899
+  #undef E7_CS_PIN
900
+#endif
901
+
865 902
 #ifndef X_CS_PIN
866 903
   #define X_CS_PIN -1
867 904
 #endif
@@ -1170,6 +1207,9 @@
1170 1207
 
1171 1208
 #if HAS_FILAMENT_SENSOR
1172 1209
   #define FIL_RUNOUT1_PIN FIL_RUNOUT_PIN
1210
+#else
1211
+  #undef FIL_RUNOUT_PIN
1212
+  #undef FIL_RUNOUT1_PIN
1173 1213
 #endif
1174 1214
 
1175 1215
 #ifndef LCD_PINS_D4

+ 29
- 38
Marlin/src/pins/pinsDebug.h View File

@@ -207,17 +207,32 @@ static void print_input_or_output(const bool isout) {
207 207
 }
208 208
 
209 209
 // pretty report with PWM info
210
-inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = false, const char *start_string = "") {
210
+inline void report_pin_state_extended(const pin_t pin, const bool ignore, const bool extended=false, PGM_P const start_string=nullptr) {
211 211
   char buffer[MAX_NAME_LENGTH + 1];   // for the sprintf statements
212 212
   bool found = false, multi_name_pin = false;
213 213
 
214
+  auto alt_pin_echo = [](const pin_t &pin) {
215
+    #if AVR_AT90USB1286_FAMILY
216
+      // Use FastIO for pins Teensy doesn't expose
217
+      if (pin == 46) {
218
+        print_input_or_output(IS_OUTPUT(46));
219
+        SERIAL_CHAR('0' + READ(46));
220
+        return false;
221
+      }
222
+      else if (pin == 47) {
223
+        print_input_or_output(IS_OUTPUT(47));
224
+        SERIAL_CHAR('0' + READ(47));
225
+        return false;
226
+      }
227
+    #endif
228
+    return true;
229
+  };
230
+
214 231
   for (uint8_t x = 0; x < COUNT(pin_array); x++)  {    // scan entire array and report all instances of this pin
215 232
     if (GET_ARRAY_PIN(x) == pin) {
216
-      if (found) multi_name_pin = true;
217
-      found = true;
218
-      if (!multi_name_pin) {    // report digital and analog pin number only on the first time through
219
-        sprintf_P(buffer, PSTR("%sPIN: "), start_string);     // digital pin number
220
-        SERIAL_ECHO(buffer);
233
+      if (!found) {    // report digital and analog pin number only on the first time through
234
+        if (start_string) serialprintPGM(start_string);
235
+        serialprintPGM(PSTR("PIN: "));
221 236
         PRINT_PIN(pin);
222 237
         PRINT_PORT(pin);
223 238
         if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
@@ -228,27 +243,14 @@ inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = fa
228 243
       }
229 244
       else {
230 245
         SERIAL_CHAR('.');
231
-        SERIAL_ECHO_SP(MULTI_NAME_PAD + strlen(start_string));  // add padding if not the first instance found
246
+        SERIAL_ECHO_SP(MULTI_NAME_PAD + (start_string ? strlen_P(start_string) : 0));  // add padding if not the first instance found
232 247
       }
233 248
       PRINT_ARRAY_NAME(x);
234 249
       if (extended) {
235 250
         if (pin_is_protected(pin) && !ignore)
236 251
           SERIAL_ECHOPGM("protected ");
237 252
         else {
238
-          #if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO
239
-            if (pin == 46 || pin == 47) {
240
-              if (pin == 46) {
241
-                print_input_or_output(IS_OUTPUT(46));
242
-                SERIAL_CHAR('0' + READ(46));
243
-              }
244
-              else if (pin == 47) {
245
-                print_input_or_output(IS_OUTPUT(47));
246
-                SERIAL_CHAR('0' + READ(47));
247
-              }
248
-            }
249
-            else
250
-          #endif
251
-          {
253
+          if (alt_pin_echo(pin)) {
252 254
             if (!GET_ARRAY_IS_DIGITAL(x)) {
253 255
               sprintf_P(buffer, PSTR("Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
254 256
               SERIAL_ECHO(buffer);
@@ -274,12 +276,14 @@ inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = fa
274 276
         }
275 277
       }
276 278
       SERIAL_EOL();
279
+      multi_name_pin = found;
280
+      found = true;
277 281
     }  // end of IF
278 282
   } // end of for loop
279 283
 
280 284
   if (!found) {
281
-    sprintf_P(buffer, PSTR("%sPIN: "), start_string);
282
-    SERIAL_ECHO(buffer);
285
+    if (start_string) serialprintPGM(start_string);
286
+    serialprintPGM(PSTR("PIN: "));
283 287
     PRINT_PIN(pin);
284 288
     PRINT_PORT(pin);
285 289
     if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
@@ -290,21 +294,8 @@ inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = fa
290 294
       SERIAL_ECHO_SP(8);   // add padding if not an analog pin
291 295
     SERIAL_ECHOPGM("<unused/unknown>");
292 296
     if (extended) {
293
-      #if AVR_AT90USB1286_FAMILY  //Teensy IDEs don't know about these pins so must use FASTIO
294
-        if (pin == 46 || pin == 47) {
295
-          SERIAL_ECHO_SP(12);
296
-          if (pin == 46) {
297
-            print_input_or_output(IS_OUTPUT(46));
298
-            SERIAL_CHAR('0' + READ(46));
299
-          }
300
-          else {
301
-            print_input_or_output(IS_OUTPUT(47));
302
-            SERIAL_CHAR('0' + READ(47));
303
-          }
304
-        }
305
-        else
306
-      #endif
307
-      {
297
+
298
+      if (alt_pin_echo(pin)) {
308 299
         if (pwm_status(pin)) {
309 300
           // do nothing
310 301
         }

Loading…
Cancel
Save