Browse Source

Cleanup following Pins Debug update

Scott Lahteine 7 years ago
parent
commit
d4ce839351
2 changed files with 66 additions and 88 deletions
  1. 14
    27
      Marlin/Marlin_main.cpp
  2. 52
    61
      Marlin/pinsDebug.h

+ 14
- 27
Marlin/Marlin_main.cpp View File

5317
   #include "pinsDebug.h"
5317
   #include "pinsDebug.h"
5318
 
5318
 
5319
   inline void toggle_pins() {
5319
   inline void toggle_pins() {
5320
-    int pin, j, start = 0, I_flag = 0, end = NUM_DIGITAL_PINS - 1, wait = 500, repeat = 1;
5320
+    int pin, j;
5321
 
5321
 
5322
-    if (code_seen('R'))
5323
-      repeat = code_value_int();
5322
+    bool I_flag = code_seen('I') ? code_value_bool() : false;
5324
 
5323
 
5325
-    if (code_seen('S'))
5326
-      start = code_value_int();
5324
+    int repeat = code_seen('R') ? code_value_int() : 1,
5325
+        start = code_seen('S') ? code_value_int() : 0,
5326
+        end = code_seen('E') ? code_value_int() : NUM_DIGITAL_PINS - 1,
5327
+        wait = code_seen('W') ? code_value_int() : 500;
5327
 
5328
 
5328
-    if (code_seen('E'))
5329
-      end = code_value_int();
5330
-
5331
-    if (code_seen('I') )
5332
-      I_flag++;
5333
-
5334
-    if (code_seen('W'))
5335
-      wait = code_value_int();
5336
-
5337
-    for(pin = start; pin <= end; pin++) {
5338
-        if ( I_flag == 0 && pin_is_protected(pin)) {
5329
+    for (pin = start; pin <= end; pin++) {
5330
+        if (!I_flag && pin_is_protected(pin)) {
5339
           SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
5331
           SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
5340
           SERIAL_ECHOPGM(" untouched.\n");
5332
           SERIAL_ECHOPGM(" untouched.\n");
5341
         }
5333
         }
5344
           pinMode(pin, OUTPUT);
5336
           pinMode(pin, OUTPUT);
5345
           for(j = 0; j < repeat; j++) {
5337
           for(j = 0; j < repeat; j++) {
5346
             digitalWrite(pin, 0);
5338
             digitalWrite(pin, 0);
5347
-            idle();
5348
-            delay(wait);
5339
+            safe_delay(wait);
5349
             digitalWrite(pin, 1);
5340
             digitalWrite(pin, 1);
5350
-            idle();
5351
-            delay(wait);
5341
+            safe_delay(wait);
5352
             digitalWrite(pin, 0);
5342
             digitalWrite(pin, 0);
5353
-            idle();
5354
-            delay(wait);
5343
+            safe_delay(wait);
5355
           }
5344
           }
5356
         }
5345
         }
5357
       SERIAL_ECHOPGM("\n");
5346
       SERIAL_ECHOPGM("\n");
5358
     }
5347
     }
5359
     SERIAL_ECHOPGM("Done\n");
5348
     SERIAL_ECHOPGM("Done\n");
5360
-    return;
5361
-  }  // toggle pin(s)
5362
-
5349
+  } // toggle_pins
5363
 
5350
 
5364
   inline void servo_probe_test(){
5351
   inline void servo_probe_test(){
5365
     #if !(NUM_SERVOS >= 1 && HAS_SERVO_0)
5352
     #if !(NUM_SERVOS >= 1 && HAS_SERVO_0)
5505
       if (first_pin > NUM_DIGITAL_PINS - 1) return;
5492
       if (first_pin > NUM_DIGITAL_PINS - 1) return;
5506
     }
5493
     }
5507
 
5494
 
5508
-    bool ignore_protection = code_seen('I');
5495
+    bool ignore_protection = code_seen('I') ? code_value_bool() : false;
5509
 
5496
 
5510
     // Watch until click, M108, or reset
5497
     // Watch until click, M108, or reset
5511
-    if (code_seen('W')) { // watch digital pins
5498
+    if (code_seen('W') && code_value_bool()) { // watch digital pins
5512
       SERIAL_PROTOCOLLNPGM("Watching pins");
5499
       SERIAL_PROTOCOLLNPGM("Watching pins");
5513
       byte pin_state[last_pin - first_pin + 1];
5500
       byte pin_state[last_pin - first_pin + 1];
5514
       for (int8_t pin = first_pin; pin <= last_pin; pin++) {
5501
       for (int8_t pin = first_pin; pin <= last_pin; pin++) {

+ 52
- 61
Marlin/pinsDebug.h View File

80
 
80
 
81
 const char* const pin_array[][3] PROGMEM = {
81
 const char* const pin_array[][3] PROGMEM = {
82
 
82
 
83
-/**
84
- *  [pin name]  [pin number]  [is digital or analog]  1 = digital, 0 = analog
85
- *  Each entry takes up 6 bytes in FLASH:
86
- *     2 byte pointer to location of the name string
87
- *     2 bytes containing the pin number
88
- *         analog pin numbers were convereted to digital when the array was created
89
- *     2 bytes containing the digital/analog bool flag
90
- */
91
-
92
- // manually add pins ...
83
+  /**
84
+   *  [pin name]  [pin number]  [is digital or analog]  1 = digital, 0 = analog
85
+   *  Each entry takes up 6 bytes in FLASH:
86
+   *     2 byte pointer to location of the name string
87
+   *     2 bytes containing the pin number
88
+   *         analog pin numbers were convereted to digital when the array was created
89
+   *     2 bytes containing the digital/analog bool flag
90
+   */
91
+
92
+  // manually add pins ...
93
   #if SERIAL_PORT == 0
93
   #if SERIAL_PORT == 0
94
     #if AVR_ATmega2560_FAMILY
94
     #if AVR_ATmega2560_FAMILY
95
       {RXD_NAME, 0, 1},
95
       {RXD_NAME, 0, 1},
109
 
109
 
110
 #define n_array (sizeof (pin_array) / sizeof (const char *))/3
110
 #define n_array (sizeof (pin_array) / sizeof (const char *))/3
111
 
111
 
112
-#if !defined(TIMER1B)    // working with Teensyduino extension so need to re-define some things
112
+#ifndef TIMER1B
113
+  // working with Teensyduino extension so need to re-define some things
113
   #include "pinsDebug_Teensyduino.h"
114
   #include "pinsDebug_Teensyduino.h"
114
 #endif
115
 #endif
115
 
116
 
132
   switch(digitalPinToTimer(pin)) {
133
   switch(digitalPinToTimer(pin)) {
133
 
134
 
134
     #if defined(TCCR0A) && defined(COM0A1)
135
     #if defined(TCCR0A) && defined(COM0A1)
135
-      #if defined (TIMER0A)
136
+      #ifdef TIMER0A
136
         PWM_CASE(0,A);
137
         PWM_CASE(0,A);
137
       #endif
138
       #endif
138
       PWM_CASE(0,B);
139
       PWM_CASE(0,B);
141
     #if defined(TCCR1A) && defined(COM1A1)
142
     #if defined(TCCR1A) && defined(COM1A1)
142
       PWM_CASE(1,A);
143
       PWM_CASE(1,A);
143
       PWM_CASE(1,B);
144
       PWM_CASE(1,B);
144
-     #if defined(COM1C1) && defined (TIMER1C)
145
+     #if defined(COM1C1) && defined(TIMER1C)
145
       PWM_CASE(1,C);
146
       PWM_CASE(1,C);
146
      #endif
147
      #endif
147
     #endif
148
     #endif
200
 
201
 
201
 const uint8_t* const PWM_OCR[][3] PROGMEM = {
202
 const uint8_t* const PWM_OCR[][3] PROGMEM = {
202
 
203
 
203
-  #if defined (TIMER0A)
204
+  #ifdef TIMER0A
204
     {&OCR0A,&OCR0B,0},
205
     {&OCR0A,&OCR0B,0},
205
   #else
206
   #else
206
     {0,&OCR0B,0},
207
     {0,&OCR0B,0},
207
   #endif
208
   #endif
208
 
209
 
209
-  #if defined(COM1C1) && defined (TIMER1C)
210
+  #if defined(COM1C1) && defined(TIMER1C)
210
    { (const uint8_t*) &OCR1A, (const uint8_t*) &OCR1B, (const uint8_t*) &OCR1C},
211
    { (const uint8_t*) &OCR1A, (const uint8_t*) &OCR1B, (const uint8_t*) &OCR1C},
211
   #else
212
   #else
212
    { (const uint8_t*) &OCR1A, (const uint8_t*) &OCR1B,0},
213
    { (const uint8_t*) &OCR1A, (const uint8_t*) &OCR1B,0},
217
   #endif
218
   #endif
218
 
219
 
219
   #if defined(TCCR3A) && defined(COM3A1)
220
   #if defined(TCCR3A) && defined(COM3A1)
220
-    #if defined(COM3C1)
221
+    #ifdef COM3C1
221
       { (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B, (const uint8_t*) &OCR3C},
222
       { (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B, (const uint8_t*) &OCR3C},
222
     #else
223
     #else
223
       { (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B,0},
224
       { (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B,0},
279
 }
280
 }
280
 
281
 
281
 
282
 
282
-void timer_prefix(uint8_t T, char L, uint8_t N){  // T - timer    L - pwm  n - WGM bit layout
283
+void timer_prefix(uint8_t T, char L, uint8_t N) {  // T - timer    L - pwm  n - WGM bit layout
283
   char buffer[20];   // for the sprintf statements
284
   char buffer[20];   // for the sprintf statements
284
-  uint8_t *TCCRB = (uint8_t*) TCCR_B(T);
285
-  uint8_t *TCCRA = (uint8_t*) TCCR_A(T);
285
+  uint8_t *TCCRB = (uint8_t*)TCCR_B(T);
286
+  uint8_t *TCCRA = (uint8_t*)TCCR_A(T);
286
   uint8_t WGM = (((*TCCRB & _BV(WGM_2)) >> 1) | (*TCCRA & (_BV(WGM_0) | _BV(WGM_1))));
287
   uint8_t WGM = (((*TCCRB & _BV(WGM_2)) >> 1) | (*TCCRA & (_BV(WGM_0) | _BV(WGM_1))));
287
-  if (N == 4) WGM |=  ((*TCCRB & _BV(WGM_3)) >> 1);
288
+  if (N == 4) WGM |= ((*TCCRB & _BV(WGM_3)) >> 1);
288
 
289
 
289
   SERIAL_PROTOCOLPGM("    TIMER");
290
   SERIAL_PROTOCOLPGM("    TIMER");
290
   SERIAL_PROTOCOLCHAR(T + '0');
291
   SERIAL_PROTOCOLCHAR(T + '0');
323
   if (TEST(*TMSK, TOIE)) err_prob_interrupt();
324
   if (TEST(*TMSK, TOIE)) err_prob_interrupt();
324
 }
325
 }
325
 
326
 
326
-
327
-
328
 static void pwm_details(uint8_t pin) {
327
 static void pwm_details(uint8_t pin) {
329
   char buffer[20];   // for the sprintf statements
328
   char buffer[20];   // for the sprintf statements
330
   uint8_t WGM;
329
   uint8_t WGM;
331
 
330
 
332
   switch(digitalPinToTimer(pin)) {
331
   switch(digitalPinToTimer(pin)) {
333
 
332
 
334
-
335
     #if defined(TCCR0A) && defined(COM0A1)
333
     #if defined(TCCR0A) && defined(COM0A1)
336
 
334
 
337
-      #if defined (TIMER0A)
335
+      #ifdef TIMER0A
338
         case TIMER0A:
336
         case TIMER0A:
339
           timer_prefix(0,'A',3);
337
           timer_prefix(0,'A',3);
340
           break;
338
           break;
351
       case TIMER1B:
349
       case TIMER1B:
352
         timer_prefix(1,'B',4);
350
         timer_prefix(1,'B',4);
353
         break;
351
         break;
354
-      #if defined(COM1C1) && defined (TIMER1C)
352
+      #if defined(COM1C1) && defined(TIMER1C)
355
         case TIMER1C:
353
         case TIMER1C:
356
           timer_prefix(1,'C',4);
354
           timer_prefix(1,'C',4);
357
           break;
355
           break;
374
       case TIMER3B:
372
       case TIMER3B:
375
         timer_prefix(3,'B',4);
373
         timer_prefix(3,'B',4);
376
         break;
374
         break;
377
-      #if defined(COM3C1)
375
+      #ifdef COM3C1
378
         case TIMER3C:
376
         case TIMER3C:
379
           timer_prefix(3,'C',4);
377
           timer_prefix(3,'C',4);
380
           break;
378
           break;
410
   }
408
   }
411
   SERIAL_PROTOCOLPGM("  ");
409
   SERIAL_PROTOCOLPGM("  ");
412
 
410
 
413
-// on pins that have two PWMs, print info on second PWM
411
+  // on pins that have two PWMs, print info on second PWM
414
   #if AVR_ATmega2560_FAMILY || AVR_AT90USB1286_FAMILY
412
   #if AVR_ATmega2560_FAMILY || AVR_AT90USB1286_FAMILY
415
-  // looking for port B7 - PWMs 0A and 1C
413
+    // looking for port B7 - PWMs 0A and 1C
416
     if ( ('B' == digitalPinToPort(pin) + 64) && (0x80 == digitalPinToBitMask(pin))) {
414
     if ( ('B' == digitalPinToPort(pin) + 64) && (0x80 == digitalPinToBitMask(pin))) {
417
-      #if !defined(TEENSYDUINO_IDE)
418
-        SERIAL_EOL;
419
-        SERIAL_PROTOCOLPGM (" .                  TIMER1C is also tied to this pin             ");
415
+      #ifndef TEENSYDUINO_IDE
416
+        SERIAL_PROTOCOLPGM("\n .                  TIMER1C is also tied to this pin             ");
420
         timer_prefix(1,'C',4);
417
         timer_prefix(1,'C',4);
421
       #else
418
       #else
422
-        SERIAL_EOL;
423
-        SERIAL_PROTOCOLPGM (" .                  TIMER0A is also tied to this pin             ");
419
+        SERIAL_PROTOCOLPGM("\n .                  TIMER0A is also tied to this pin             ");
424
         timer_prefix(0,'A',3);
420
         timer_prefix(0,'A',3);
425
       #endif
421
       #endif
426
     }
422
     }
429
 
425
 
430
 bool get_pinMode(int8_t pin) { return *portModeRegister(digitalPinToPort(pin)) & digitalPinToBitMask(pin); }
426
 bool get_pinMode(int8_t pin) { return *portModeRegister(digitalPinToPort(pin)) & digitalPinToBitMask(pin); }
431
 
427
 
432
-#if !defined(digitalRead_mod)    // use Teensyduino's version of digitalRead - it doesn't disable the PWMs
428
+#ifndef digitalRead_mod             // use Teensyduino's version of digitalRead - it doesn't disable the PWMs
433
   int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
429
   int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
434
     uint8_t port = digitalPinToPort(pin);
430
     uint8_t port = digitalPinToPort(pin);
435
     return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
431
     return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
437
 #endif
433
 #endif
438
 
434
 
439
 void print_port(int8_t pin) {   // print port number
435
 void print_port(int8_t pin) {   // print port number
440
-  #if defined(digitalPinToPort)
436
+  #ifdef digitalPinToPort
441
     SERIAL_PROTOCOLPGM("  Port: ");
437
     SERIAL_PROTOCOLPGM("  Port: ");
442
     uint8_t x = digitalPinToPort(pin) + 64;
438
     uint8_t x = digitalPinToPort(pin) + 64;
443
     SERIAL_CHAR(x);
439
     SERIAL_CHAR(x);
444
     uint8_t temp = digitalPinToBitMask(pin);
440
     uint8_t temp = digitalPinToBitMask(pin);
445
-    for (x = '0'; (x < '9' && !(temp == 1)); x++){
446
-      temp = temp >> 1;
447
-    }
441
+    for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
448
     SERIAL_CHAR(x);
442
     SERIAL_CHAR(x);
449
   #else
443
   #else
450
-    SERIAL_PROTOCOLPGM("          ")
444
+    SERIAL_PROTOCOLPGM("          ");
451
   #endif
445
   #endif
452
 }
446
 }
453
 
447
 
454
-
455
 // pretty report with PWM info
448
 // pretty report with PWM info
456
 inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = true) {
449
 inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = true) {
457
   uint8_t temp_char;
450
   uint8_t temp_char;
458
   char *name_mem_pointer;
451
   char *name_mem_pointer;
459
   char buffer[30];   // for the sprintf statements
452
   char buffer[30];   // for the sprintf statements
460
-  bool found = false;
461
-  bool multi_name_pin = false;
453
+  bool found = false,
454
+       multi_name_pin = false;
462
   for (uint8_t x = 0; x < n_array; x++)  {    // scan entire array and report all instances of this pin
455
   for (uint8_t x = 0; x < n_array; x++)  {    // scan entire array and report all instances of this pin
463
     if (pgm_read_byte(&pin_array[x][1]) == pin) {
456
     if (pgm_read_byte(&pin_array[x][1]) == pin) {
464
-      if (found == true) multi_name_pin = true;
457
+      if (found) multi_name_pin = true;
465
       found = true;
458
       found = true;
466
-      if (multi_name_pin == false) {    // report digitial and analog pin number only on the first time through
467
-        sprintf(buffer, "PIN:% 3d ", pin);     // digital pin number
459
+      if (!multi_name_pin) {    // report digitial and analog pin number only on the first time through
460
+        sprintf(buffer, "PIN: %3d ", pin);     // digital pin number
468
         SERIAL_ECHO(buffer);
461
         SERIAL_ECHO(buffer);
469
         print_port(pin);
462
         print_port(pin);
470
         if (IS_ANALOG(pin)) {
463
         if (IS_ANALOG(pin)) {
479
         temp_char = pgm_read_byte(name_mem_pointer + y);
472
         temp_char = pgm_read_byte(name_mem_pointer + y);
480
         if (temp_char != 0) MYSERIAL.write(temp_char);
473
         if (temp_char != 0) MYSERIAL.write(temp_char);
481
         else {
474
         else {
482
-          for (uint8_t i = 0; i < 28 - y; i++) MYSERIAL.write(" ");
475
+          for (uint8_t i = 0; i < 28 - y; i++) MYSERIAL.write(' ');
483
           break;
476
           break;
484
         }
477
         }
485
       }
478
       }
487
         SERIAL_ECHOPGM("protected ");
480
         SERIAL_ECHOPGM("protected ");
488
       else {
481
       else {
489
         if (!(pgm_read_byte(&pin_array[x][2]))) {
482
         if (!(pgm_read_byte(&pin_array[x][2]))) {
490
-          sprintf(buffer, "Analog in =% 5d", analogRead(pin - analogInputToDigitalPin(0)));
483
+          sprintf(buffer, "Analog in = %5d", analogRead(pin - analogInputToDigitalPin(0)));
491
           SERIAL_ECHO(buffer);
484
           SERIAL_ECHO(buffer);
492
         }
485
         }
493
         else {
486
         else {
494
           if (!get_pinMode(pin)) {
487
           if (!get_pinMode(pin)) {
495
-//            pinMode(pin, INPUT_PULLUP);  // make sure input isn't floating - stopped doing this 
488
+            //pinMode(pin, INPUT_PULLUP);  // make sure input isn't floating - stopped doing this
496
                                            // because this could interfere with inductive/capacitive
489
                                            // because this could interfere with inductive/capacitive
497
                                            // sensors (high impedance voltage divider) and with PT100 amplifier
490
                                            // sensors (high impedance voltage divider) and with PT100 amplifier
498
             SERIAL_PROTOCOLPAIR("Input  = ", digitalRead_mod(pin));
491
             SERIAL_PROTOCOLPAIR("Input  = ", digitalRead_mod(pin));
502
           }
495
           }
503
           else SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
496
           else SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
504
         }
497
         }
505
-        if (multi_name_pin == false && extended) pwm_details(pin);  // report PWM capabilities only on the first pass & only if doing an extended report
498
+        if (!multi_name_pin && extended) pwm_details(pin);  // report PWM capabilities only on the first pass & only if doing an extended report
506
       }
499
       }
507
       SERIAL_EOL;
500
       SERIAL_EOL;
508
     }  // end of IF
501
     }  // end of IF
509
   } // end of for loop
502
   } // end of for loop
510
 
503
 
511
-  if (found == false) {
512
-    sprintf(buffer, "PIN:% 3d ", pin);
504
+  if (!found) {
505
+    sprintf(buffer, "PIN: %3d ", pin);
513
     SERIAL_ECHO(buffer);
506
     SERIAL_ECHO(buffer);
514
     print_port(pin);
507
     print_port(pin);
515
     if (IS_ANALOG(pin)) {
508
     if (IS_ANALOG(pin)) {
516
       sprintf(buffer, " (A%2d)  ", int(pin - analogInputToDigitalPin(0)));    // analog pin number
509
       sprintf(buffer, " (A%2d)  ", int(pin - analogInputToDigitalPin(0)));    // analog pin number
517
       SERIAL_ECHO(buffer);
510
       SERIAL_ECHO(buffer);
518
     }
511
     }
519
-    else SERIAL_ECHOPGM("        ");   // add padding if not an analog pin
512
+    else
513
+      SERIAL_ECHOPGM("        ");   // add padding if not an analog pin
520
     SERIAL_ECHOPGM("<unused/unknown>");
514
     SERIAL_ECHOPGM("<unused/unknown>");
521
-    if (get_pinMode(pin)) {
515
+    if (get_pinMode(pin))
522
       SERIAL_PROTOCOLPAIR("            Output = ", digitalRead_mod(pin));
516
       SERIAL_PROTOCOLPAIR("            Output = ", digitalRead_mod(pin));
523
-    }
524
     else {
517
     else {
525
       if (IS_ANALOG(pin)) {
518
       if (IS_ANALOG(pin)) {
526
-        sprintf(buffer, "   Analog in =% 5d", analogRead(pin - analogInputToDigitalPin(0)));
519
+        sprintf(buffer, "   Analog in = %5d", analogRead(pin - analogInputToDigitalPin(0)));
527
         SERIAL_ECHO(buffer);
520
         SERIAL_ECHO(buffer);
528
       }
521
       }
529
-      else {
522
+      else
530
         SERIAL_ECHOPGM("         ");   // add padding if not an analog pin
523
         SERIAL_ECHOPGM("         ");   // add padding if not an analog pin
531
-      } 
524
+
532
       SERIAL_PROTOCOLPAIR("   Input  = ", digitalRead_mod(pin));
525
       SERIAL_PROTOCOLPAIR("   Input  = ", digitalRead_mod(pin));
533
-    }  
534
-//    if (!pwm_status(pin)) SERIAL_ECHOPGM(" ");    // add padding if it's not a PWM pin
526
+    }
527
+    //if (!pwm_status(pin)) SERIAL_ECHOCHAR(' ');    // add padding if it's not a PWM pin
535
     if (extended) pwm_details(pin);  // report PWM capabilities only if doing an extended report
528
     if (extended) pwm_details(pin);  // report PWM capabilities only if doing an extended report
536
     SERIAL_EOL;
529
     SERIAL_EOL;
537
   }
530
   }
538
 }
531
 }
539
 
532
 
540
 inline void report_pin_state(int8_t pin) {
533
 inline void report_pin_state(int8_t pin) {
541
-
542
   report_pin_state_extended(pin, false, false);
534
   report_pin_state_extended(pin, false, false);
543
-
544
 }
535
 }

Loading…
Cancel
Save