Browse Source

Unify AVR90USB: pinsDebug changes

Scott Lahteine 8 years ago
parent
commit
748bf32388
4 changed files with 235 additions and 132 deletions
  1. 45
    23
      Marlin/Marlin_main.cpp
  2. 151
    88
      Marlin/pinsDebug.h
  3. 11
    15
      Marlin/pinsDebug_Teensyduino.h
  4. 28
    6
      Marlin/pinsDebug_list.h

+ 45
- 23
Marlin/Marlin_main.cpp View File

732
     SERIAL_ECHOPAIR(", ", y);
732
     SERIAL_ECHOPAIR(", ", y);
733
     SERIAL_ECHOPAIR(", ", z);
733
     SERIAL_ECHOPAIR(", ", z);
734
     SERIAL_CHAR(')');
734
     SERIAL_CHAR(')');
735
-
736
-    if (suffix) {serialprintPGM(suffix);}  //won't compile for Teensy with the previous construction
737
-    else SERIAL_EOL();
735
+    if (suffix) serialprintPGM(suffix); else SERIAL_EOL();
738
   }
736
   }
739
 
737
 
740
   void print_xyz(const char* prefix, const char* suffix, const float xyz[]) {
738
   void print_xyz(const char* prefix, const char* suffix, const float xyz[]) {
6366
               wait = parser.seen('W') ? parser.value_int() : 500;
6364
               wait = parser.seen('W') ? parser.value_int() : 500;
6367
 
6365
 
6368
     for (uint8_t pin = start; pin <= end; pin++) {
6366
     for (uint8_t pin = start; pin <= end; pin++) {
6367
+      //report_pin_state_extended(pin, I_flag, false);
6368
+
6369
       if (!I_flag && pin_is_protected(pin)) {
6369
       if (!I_flag && pin_is_protected(pin)) {
6370
-        SERIAL_ECHOPAIR("Sensitive Pin: ", pin);
6371
-        SERIAL_ECHOLNPGM(" untouched.");
6370
+        report_pin_state_extended(pin, I_flag, true, "Untouched ");
6371
+        SERIAL_EOL();
6372
       }
6372
       }
6373
       else {
6373
       else {
6374
-        SERIAL_ECHOPAIR("Pulsing Pin: ", pin);
6375
-        pinMode(pin, OUTPUT);
6376
-        for (int16_t j = 0; j < repeat; j++) {
6377
-          digitalWrite(pin, 0);
6378
-          safe_delay(wait);
6379
-          digitalWrite(pin, 1);
6380
-          safe_delay(wait);
6381
-          digitalWrite(pin, 0);
6382
-          safe_delay(wait);
6374
+        report_pin_state_extended(pin, I_flag, true, "Pulsing   ");
6375
+        #ifdef AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
6376
+          if (pin == 46) {
6377
+            SET_OUTPUT(46);
6378
+            for (int16_t j = 0; j < repeat; j++) {
6379
+              WRITE(46, 0); safe_delay(wait);
6380
+              WRITE(46, 1); safe_delay(wait);
6381
+              WRITE(46, 0); safe_delay(wait);
6382
+            }
6383
+          }
6384
+          else if (pin == 47) {
6385
+            SET_OUTPUT(47);
6386
+            for (int16_t j = 0; j < repeat; j++) {
6387
+              WRITE(47, 0); safe_delay(wait);
6388
+              WRITE(47, 1); safe_delay(wait);
6389
+              WRITE(47, 0); safe_delay(wait);
6390
+            }
6391
+          }
6392
+          else
6393
+        #endif
6394
+        {
6395
+          pinMode(pin, OUTPUT);
6396
+          for (int16_t j = 0; j < repeat; j++) {
6397
+            digitalWrite(pin, 0); safe_delay(wait);
6398
+            digitalWrite(pin, 1); safe_delay(wait);
6399
+            digitalWrite(pin, 0); safe_delay(wait);
6400
+          }
6383
         }
6401
         }
6402
+
6384
       }
6403
       }
6385
-      SERIAL_CHAR('\n');
6404
+      SERIAL_EOL();
6386
     }
6405
     }
6387
     SERIAL_ECHOLNPGM("Done.");
6406
     SERIAL_ECHOLNPGM("Done.");
6388
 
6407
 
6527
    *  M43 E<bool> - Enable / disable background endstop monitoring
6546
    *  M43 E<bool> - Enable / disable background endstop monitoring
6528
    *                  - Machine continues to operate
6547
    *                  - Machine continues to operate
6529
    *                  - Reports changes to endstops
6548
    *                  - Reports changes to endstops
6530
-   *                  - Toggles LED when an endstop changes
6549
+   *                  - Toggles LED_PIN when an endstop changes
6531
    *                  - Can not reliably catch the 5mS pulse from BLTouch type probes
6550
    *                  - Can not reliably catch the 5mS pulse from BLTouch type probes
6532
    *
6551
    *
6533
    *  M43 T       - Toggle pin(s) and report which pin is being toggled
6552
    *  M43 T       - Toggle pin(s) and report which pin is being toggled
6534
    *                  S<pin>  - Start Pin number.   If not given, will default to 0
6553
    *                  S<pin>  - Start Pin number.   If not given, will default to 0
6535
    *                  L<pin>  - End Pin number.   If not given, will default to last pin defined for this board
6554
    *                  L<pin>  - End Pin number.   If not given, will default to last pin defined for this board
6536
-   *                  I       - Flag to ignore Marlin's pin protection.   Use with caution!!!!
6555
+   *                  I<bool> - Flag to ignore Marlin's pin protection.   Use with caution!!!!
6537
    *                  R       - Repeat pulses on each pin this number of times before continueing to next pin
6556
    *                  R       - Repeat pulses on each pin this number of times before continueing to next pin
6538
    *                  W       - Wait time (in miliseconds) between pulses.  If not given will default to 500
6557
    *                  W       - Wait time (in miliseconds) between pulses.  If not given will default to 500
6539
    *
6558
    *
6542
    */
6561
    */
6543
   inline void gcode_M43() {
6562
   inline void gcode_M43() {
6544
 
6563
 
6545
-    if (parser.seen('T')) {   // must be first ot else it's "S" and "E" parameters will execute endstop or servo test
6564
+    if (parser.seen('T')) {   // must be first or else it's "S" and "E" parameters will execute endstop or servo test
6546
       toggle_pins();
6565
       toggle_pins();
6547
       return;
6566
       return;
6548
     }
6567
     }
6576
       for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6595
       for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6577
         if (pin_is_protected(pin) && !ignore_protection) continue;
6596
         if (pin_is_protected(pin) && !ignore_protection) continue;
6578
         pinMode(pin, INPUT_PULLUP);
6597
         pinMode(pin, INPUT_PULLUP);
6598
+        delay(1);
6579
         /*
6599
         /*
6580
           if (IS_ANALOG(pin))
6600
           if (IS_ANALOG(pin))
6581
             pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
6601
             pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
6591
 
6611
 
6592
       for (;;) {
6612
       for (;;) {
6593
         for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6613
         for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6594
-          if (pin_is_protected(pin)) continue;
6614
+          if (pin_is_protected(pin) && !ignore_protection) continue;
6595
           const byte val =
6615
           const byte val =
6596
             /*
6616
             /*
6597
               IS_ANALOG(pin)
6617
               IS_ANALOG(pin)
6600
             //*/
6620
             //*/
6601
               digitalRead(pin);
6621
               digitalRead(pin);
6602
           if (val != pin_state[pin - first_pin]) {
6622
           if (val != pin_state[pin - first_pin]) {
6603
-            report_pin_state(pin);
6623
+            report_pin_state_extended(pin, ignore_protection, false);
6604
             pin_state[pin - first_pin] = val;
6624
             pin_state[pin - first_pin] = val;
6605
           }
6625
           }
6606
         }
6626
         }
6612
           }
6632
           }
6613
         #endif
6633
         #endif
6614
 
6634
 
6615
-        safe_delay(500);
6635
+        safe_delay(200);
6616
       }
6636
       }
6617
       return;
6637
       return;
6618
     }
6638
     }
6619
 
6639
 
6620
     // Report current state of selected pin(s)
6640
     // Report current state of selected pin(s)
6621
     for (uint8_t pin = first_pin; pin <= last_pin; pin++)
6641
     for (uint8_t pin = first_pin; pin <= last_pin; pin++)
6622
-      report_pin_state_extended(pin, ignore_protection);
6642
+      report_pin_state_extended(pin, ignore_protection, true);
6623
   }
6643
   }
6624
 
6644
 
6625
 #endif // PINS_DEBUGGING
6645
 #endif // PINS_DEBUGGING
12164
     val &= 0x07;
12184
     val &= 0x07;
12165
     switch (digitalPinToTimer(pin)) {
12185
     switch (digitalPinToTimer(pin)) {
12166
       #ifdef TCCR0A
12186
       #ifdef TCCR0A
12167
-        case TIMER0A:
12187
+        #if !AVR_AT90USB1286_FAMILY
12188
+          case TIMER0A:
12189
+        #endif
12168
         case TIMER0B:
12190
         case TIMER0B:
12169
           //_SET_CS(0, val);
12191
           //_SET_CS(0, val);
12170
           break;
12192
           break;

+ 151
- 88
Marlin/pinsDebug.h View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-
24
 bool endstop_monitor_flag = false;
23
 bool endstop_monitor_flag = false;
25
 
24
 
26
-#define NAME_FORMAT "%-28s"   // one place to specify the format of all the sources of names
25
+#define NAME_FORMAT "%-35s"   // one place to specify the format of all the sources of names
27
                                // "-" left justify, "28" minimum width of name, pad with blanks
26
                                // "-" left justify, "28" minimum width of name, pad with blanks
28
 
27
 
29
 #define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(7)))
28
 #define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(7)))
30
 
29
 
31
-#define AVR_ATmega2560_FAMILY (defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega2561__))
32
-#define AVR_AT90USB1286_FAMILY (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__) || defined(__AVR_AT90USB1286P__) || defined(__AVR_AT90USB646__) || defined(__AVR_AT90USB646P__)  || defined(__AVR_AT90USB647__))
33
-#define AVR_ATmega1284_FAMILY (defined(__AVR_ATmega644__) || defined(__AVR_ATmega644P__) || defined(__AVR_ATmega644PA__) || defined(__AVR_ATmega1284P__))
34
-
35
 /**
30
 /**
36
  *  This routine minimizes RAM usage by creating a FLASH resident array to
31
  *  This routine minimizes RAM usage by creating a FLASH resident array to
37
  *  store the pin names, pin numbers and analog/digital flag.
32
  *  store the pin names, pin numbers and analog/digital flag.
52
 #define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
47
 #define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
53
 
48
 
54
 #include "pinsDebug_list.h"
49
 #include "pinsDebug_list.h"
55
-#line 56
50
+#line 51
56
 
51
 
57
 // manually add pins that have names that are macros which don't play well with these macros
52
 // manually add pins that have names that are macros which don't play well with these macros
58
 #if SERIAL_PORT == 0 && (AVR_ATmega2560_FAMILY || AVR_ATmega1284_FAMILY)
53
 #if SERIAL_PORT == 0 && (AVR_ATmega2560_FAMILY || AVR_ATmega1284_FAMILY)
88
   // manually add pins ...
83
   // manually add pins ...
89
   #if SERIAL_PORT == 0
84
   #if SERIAL_PORT == 0
90
     #if AVR_ATmega2560_FAMILY
85
     #if AVR_ATmega2560_FAMILY
91
-      { RXD_NAME, "0", "1" },
92
-      { TXD_NAME, "1", "1" },
86
+      { RXD_NAME, 0, 1 },
87
+      { TXD_NAME, 1, 1 },
93
     #elif AVR_ATmega1284_FAMILY
88
     #elif AVR_ATmega1284_FAMILY
94
-      { RXD_NAME, "8", "1" },
95
-      { TXD_NAME, "9", "1" },
89
+      { RXD_NAME, 8, 1 },
90
+      { TXD_NAME, 9, 1 },
96
     #endif
91
     #endif
97
   #endif
92
   #endif
98
 
93
 
99
   #include "pinsDebug_list.h"
94
   #include "pinsDebug_list.h"
100
-  #line 101
95
+  #line 96
101
 
96
 
102
 };
97
 };
103
 
98
 
104
 #define n_array (sizeof(pin_array) / sizeof(char*)) / 3
99
 #define n_array (sizeof(pin_array) / sizeof(char*)) / 3
105
 
100
 
106
-#ifndef TIMER1B
107
-  // working with Teensyduino extension so need to re-define some things
101
+#if AVR_AT90USB1286_FAMILY
102
+  // Working with Teensyduino extension so need to re-define some things
108
   #include "pinsDebug_Teensyduino.h"
103
   #include "pinsDebug_Teensyduino.h"
104
+  // Can't use the "digitalPinToPort" function from the Teensyduino type IDEs
105
+  // portModeRegister takes a different argument
106
+ #define digitalPinToPort_DEBUG(p) digitalPinToPort_Teensy(p)
107
+ #define get_pinMode(pin) (*portModeRegister(pin) & digitalPinToBitMask(pin))
108
+#else
109
+ #define digitalPinToPort_DEBUG(p) digitalPinToPort(p)
110
+ bool get_pinMode(int8_t pin) {return *portModeRegister(digitalPinToPort_DEBUG(pin)) & digitalPinToBitMask(pin); }
109
 #endif
111
 #endif
110
 
112
 
111
-#define PWM_PRINT(V) do{ sprintf(buffer, "PWM:  %4d", V); SERIAL_ECHO(buffer); }while(0)
113
+#define PWM_PRINT(V) do{ sprintf_P(buffer, PSTR("PWM:  %4d"), V); SERIAL_ECHO(buffer); }while(0)
112
 #define PWM_CASE(N,Z)                                           \
114
 #define PWM_CASE(N,Z)                                           \
113
   case TIMER##N##Z:                                             \
115
   case TIMER##N##Z:                                             \
114
     if (TCCR##N##A & (_BV(COM##N##Z##1) | _BV(COM##N##Z##0))) { \
116
     if (TCCR##N##A & (_BV(COM##N##Z##1) | _BV(COM##N##Z##0))) { \
127
 
129
 
128
     #if defined(TCCR0A) && defined(COM0A1)
130
     #if defined(TCCR0A) && defined(COM0A1)
129
       #ifdef TIMER0A
131
       #ifdef TIMER0A
130
-        PWM_CASE(0, A);
132
+        #if !AVR_AT90USB1286_FAMILY  // not available in Teensyduino type IDEs
133
+          PWM_CASE(0, A);
134
+        #endif
131
       #endif
135
       #endif
132
       PWM_CASE(0, B);
136
       PWM_CASE(0, B);
133
     #endif
137
     #endif
244
 static void err_is_counter()     { SERIAL_PROTOCOLPGM("   non-standard PWM mode"); }
248
 static void err_is_counter()     { SERIAL_PROTOCOLPGM("   non-standard PWM mode"); }
245
 static void err_is_interrupt()   { SERIAL_PROTOCOLPGM("   compare interrupt enabled"); }
249
 static void err_is_interrupt()   { SERIAL_PROTOCOLPGM("   compare interrupt enabled"); }
246
 static void err_prob_interrupt() { SERIAL_PROTOCOLPGM("   overflow interrupt enabled"); }
250
 static void err_prob_interrupt() { SERIAL_PROTOCOLPGM("   overflow interrupt enabled"); }
251
+static void print_is_also_tied() { SERIAL_PROTOCOLPGM(" is also tied to this pin"); SERIAL_PROTOCOL_SP(14); }
247
 
252
 
248
 void com_print(uint8_t N, uint8_t Z) {
253
 void com_print(uint8_t N, uint8_t Z) {
249
-  uint8_t *TCCRA = (uint8_t*)TCCR_A(N);
254
+  const uint8_t *TCCRA = (uint8_t*)TCCR_A(N);
250
   SERIAL_PROTOCOLPGM("    COM");
255
   SERIAL_PROTOCOLPGM("    COM");
251
   SERIAL_PROTOCOLCHAR(N + '0');
256
   SERIAL_PROTOCOLCHAR(N + '0');
252
   switch (Z) {
257
   switch (Z) {
264
 
269
 
265
 void timer_prefix(uint8_t T, char L, uint8_t N) {  // T - timer    L - pwm  N - WGM bit layout
270
 void timer_prefix(uint8_t T, char L, uint8_t N) {  // T - timer    L - pwm  N - WGM bit layout
266
   char buffer[20];   // for the sprintf statements
271
   char buffer[20];   // for the sprintf statements
267
-  uint8_t *TCCRB = (uint8_t*)TCCR_B(T);
268
-  uint8_t *TCCRA = (uint8_t*)TCCR_A(T);
272
+  const uint8_t *TCCRB = (uint8_t*)TCCR_B(T),
273
+                *TCCRA = (uint8_t*)TCCR_A(T);
269
   uint8_t WGM = (((*TCCRB & _BV(WGM_2)) >> 1) | (*TCCRA & (_BV(WGM_0) | _BV(WGM_1))));
274
   uint8_t WGM = (((*TCCRB & _BV(WGM_2)) >> 1) | (*TCCRA & (_BV(WGM_0) | _BV(WGM_1))));
270
   if (N == 4) WGM |= ((*TCCRB & _BV(WGM_3)) >> 1);
275
   if (N == 4) WGM |= ((*TCCRB & _BV(WGM_3)) >> 1);
271
 
276
 
275
   SERIAL_PROTOCOL_SP(3);
280
   SERIAL_PROTOCOL_SP(3);
276
 
281
 
277
   if (N == 3) {
282
   if (N == 3) {
278
-    uint8_t *OCRVAL8 = (uint8_t*)OCR_VAL(T, L - 'A');
283
+    const uint8_t *OCRVAL8 = (uint8_t*)OCR_VAL(T, L - 'A');
279
     PWM_PRINT(*OCRVAL8);
284
     PWM_PRINT(*OCRVAL8);
280
   }
285
   }
281
   else {
286
   else {
282
-    uint16_t *OCRVAL16 = (uint16_t*)OCR_VAL(T, L - 'A');
287
+    const uint16_t *OCRVAL16 = (uint16_t*)OCR_VAL(T, L - 'A');
283
     PWM_PRINT(*OCRVAL16);
288
     PWM_PRINT(*OCRVAL16);
284
   }
289
   }
285
   SERIAL_PROTOCOLPAIR("    WGM: ", WGM);
290
   SERIAL_PROTOCOLPAIR("    WGM: ", WGM);
294
   SERIAL_PROTOCOLCHAR(T + '0');
299
   SERIAL_PROTOCOLCHAR(T + '0');
295
   SERIAL_PROTOCOLPAIR("B: ", *TCCRB);
300
   SERIAL_PROTOCOLPAIR("B: ", *TCCRB);
296
 
301
 
297
-  uint8_t *TMSK = (uint8_t*)TIMSK(T);
302
+  const uint8_t *TMSK = (uint8_t*)TIMSK(T);
298
   SERIAL_PROTOCOLPGM("    TIMSK");
303
   SERIAL_PROTOCOLPGM("    TIMSK");
299
   SERIAL_PROTOCOLCHAR(T + '0');
304
   SERIAL_PROTOCOLCHAR(T + '0');
300
   SERIAL_PROTOCOLPAIR(": ", *TMSK);
305
   SERIAL_PROTOCOLPAIR(": ", *TMSK);
301
 
306
 
302
-  uint8_t OCIE = L - 'A' + 1;
307
+  const uint8_t OCIE = L - 'A' + 1;
303
   if (N == 3) { if (WGM == 0 || WGM == 2 || WGM ==  4 || WGM ==  6) err_is_counter(); }
308
   if (N == 3) { if (WGM == 0 || WGM == 2 || WGM ==  4 || WGM ==  6) err_is_counter(); }
304
   else        { if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) err_is_counter(); }
309
   else        { if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) err_is_counter(); }
305
   if (TEST(*TMSK, OCIE)) err_is_interrupt();
310
   if (TEST(*TMSK, OCIE)) err_is_interrupt();
311
 
316
 
312
     #if defined(TCCR0A) && defined(COM0A1)
317
     #if defined(TCCR0A) && defined(COM0A1)
313
       #ifdef TIMER0A
318
       #ifdef TIMER0A
314
-        case TIMER0A: timer_prefix(0, 'A', 3); break;
319
+        #if !AVR_AT90USB1286_FAMILY  // not available in Teensyduino type IDEs
320
+          case TIMER0A: timer_prefix(0, 'A', 3); break;
321
+        #endif
315
       #endif
322
       #endif
316
       case TIMER0B: timer_prefix(0, 'B', 3); break;
323
       case TIMER0B: timer_prefix(0, 'B', 3); break;
317
     #endif
324
     #endif
357
   // on pins that have two PWMs, print info on second PWM
364
   // on pins that have two PWMs, print info on second PWM
358
   #if AVR_ATmega2560_FAMILY || AVR_AT90USB1286_FAMILY
365
   #if AVR_ATmega2560_FAMILY || AVR_AT90USB1286_FAMILY
359
     // looking for port B7 - PWMs 0A and 1C
366
     // looking for port B7 - PWMs 0A and 1C
360
-    if (digitalPinToPort(pin) == 2 && digitalPinToBitMask(pin) == 0x80) {
361
-      #ifndef TEENSYDUINO_IDE
367
+    if (digitalPinToPort_DEBUG(pin) == 'B' - 64 && 0x80 == digitalPinToBitMask(pin)) {
368
+      #if !AVR_AT90USB1286_FAMILY
362
         SERIAL_PROTOCOLPGM("\n .");
369
         SERIAL_PROTOCOLPGM("\n .");
363
         SERIAL_PROTOCOL_SP(18);
370
         SERIAL_PROTOCOL_SP(18);
364
-        SERIAL_PROTOCOLPGM("TIMER1C is also tied to this pin");
365
-        SERIAL_PROTOCOL_SP(13);
371
+        SERIAL_PROTOCOLPGM("TIMER1C");
372
+        print_is_also_tied();
366
         timer_prefix(1, 'C', 4);
373
         timer_prefix(1, 'C', 4);
367
       #else
374
       #else
368
         SERIAL_PROTOCOLPGM("\n .");
375
         SERIAL_PROTOCOLPGM("\n .");
369
         SERIAL_PROTOCOL_SP(18);
376
         SERIAL_PROTOCOL_SP(18);
370
-        SERIAL_PROTOCOLPGM("TIMER0A is also tied to this pin");
371
-        SERIAL_PROTOCOL_SP(13);
377
+        SERIAL_PROTOCOLPGM("TIMER0A");
378
+        print_is_also_tied();
372
         timer_prefix(0, 'A', 3);
379
         timer_prefix(0, 'A', 3);
373
       #endif
380
       #endif
374
     }
381
     }
375
   #endif
382
   #endif
376
 } // pwm_details
383
 } // pwm_details
377
 
384
 
378
-bool get_pinMode(int8_t pin) { return *portModeRegister(digitalPinToPort(pin)) & digitalPinToBitMask(pin); }
379
-
380
-#ifndef digitalRead_mod             // use Teensyduino's version of digitalRead - it doesn't disable the PWMs
381
-  int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
382
-    uint8_t port = digitalPinToPort(pin);
385
+#ifndef digitalRead_mod                   // Use Teensyduino's version of digitalRead - it doesn't disable the PWMs
386
+  int digitalRead_mod(const int8_t pin) { // same as digitalRead except the PWM stop section has been removed
387
+    const uint8_t port = digitalPinToPort_DEBUG(pin);
383
     return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
388
     return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
384
   }
389
   }
385
 #endif
390
 #endif
386
 
391
 
387
 void print_port(int8_t pin) {   // print port number
392
 void print_port(int8_t pin) {   // print port number
388
-  #ifdef digitalPinToPort
393
+  #ifdef digitalPinToPort_DEBUG
394
+    uint8_t x;
389
     SERIAL_PROTOCOLPGM("  Port: ");
395
     SERIAL_PROTOCOLPGM("  Port: ");
390
-    uint8_t x = digitalPinToPort(pin) + 64;
396
+    #if AVR_AT90USB1286_FAMILY
397
+      x = (pin == 46 || pin == 47) ? 'E' : digitalPinToPort_DEBUG(pin) + 64;
398
+    #else
399
+      x = digitalPinToPort_DEBUG(pin) + 64;
400
+    #endif
391
     SERIAL_CHAR(x);
401
     SERIAL_CHAR(x);
392
-    uint8_t temp = digitalPinToBitMask(pin);
393
-    for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
402
+
403
+    #if AVR_AT90USB1286_FAMILY
404
+      if (pin == 46)
405
+        x = '2';
406
+      else if (pin == 47)
407
+        x = '3';
408
+      else {
409
+        uint8_t temp = digitalPinToBitMask(pin);
410
+        for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
411
+      }
412
+    #else
413
+      uint8_t temp = digitalPinToBitMask(pin);
414
+      for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
415
+    #endif
394
     SERIAL_CHAR(x);
416
     SERIAL_CHAR(x);
395
   #else
417
   #else
396
     SERIAL_PROTOCOL_SP(10);
418
     SERIAL_PROTOCOL_SP(10);
397
   #endif
419
   #endif
398
 }
420
 }
399
 
421
 
422
+static void print_input_or_output(const bool isout) {
423
+  serialprintPGM(isout ? PSTR("Output = ") : PSTR("Input  = "));
424
+}
425
+
400
 // pretty report with PWM info
426
 // pretty report with PWM info
401
-inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = true) {
427
+inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = false,const char *start_string = "") {
402
   uint8_t temp_char;
428
   uint8_t temp_char;
403
-  char *name_mem_pointer;
404
-  char buffer[30];   // for the sprintf statements
405
-  bool found = false,
406
-       multi_name_pin = false;
429
+  char *name_mem_pointer, buffer[30];   // for the sprintf statements
430
+  bool found = false, multi_name_pin = false;
407
   for (uint8_t x = 0; x < n_array; x++)  {    // scan entire array and report all instances of this pin
431
   for (uint8_t x = 0; x < n_array; x++)  {    // scan entire array and report all instances of this pin
408
     if (pgm_read_byte(&pin_array[x][1]) == pin) {
432
     if (pgm_read_byte(&pin_array[x][1]) == pin) {
409
       if (found) multi_name_pin = true;
433
       if (found) multi_name_pin = true;
410
       found = true;
434
       found = true;
411
       if (!multi_name_pin) {    // report digitial and analog pin number only on the first time through
435
       if (!multi_name_pin) {    // report digitial and analog pin number only on the first time through
412
-        sprintf(buffer, "PIN: %3d ", pin);     // digital pin number
436
+        sprintf_P(buffer, PSTR("%sPIN: %3d "), start_string, pin);     // digital pin number
413
         SERIAL_ECHO(buffer);
437
         SERIAL_ECHO(buffer);
414
         print_port(pin);
438
         print_port(pin);
415
         if (IS_ANALOG(pin)) {
439
         if (IS_ANALOG(pin)) {
416
-          sprintf(buffer, " (A%2d)  ", int(pin - analogInputToDigitalPin(0)));    // analog pin number
440
+          sprintf_P(buffer, PSTR(" (A%2d)  "), int(pin - analogInputToDigitalPin(0)));    // analog pin number
417
           SERIAL_ECHO(buffer);
441
           SERIAL_ECHO(buffer);
418
         }
442
         }
419
         else SERIAL_ECHO_SP(8);   // add padding if not an analog pin
443
         else SERIAL_ECHO_SP(8);   // add padding if not an analog pin
420
       }
444
       }
421
       else {
445
       else {
422
         SERIAL_CHAR('.');
446
         SERIAL_CHAR('.');
423
-        SERIAL_ECHO_SP(25);  // add padding if not the first instance found
447
+        SERIAL_ECHO_SP(26 + strlen(start_string));  // add padding if not the first instance found
424
       }
448
       }
425
       name_mem_pointer = (char*)pgm_read_word(&pin_array[x][0]);
449
       name_mem_pointer = (char*)pgm_read_word(&pin_array[x][0]);
426
       for (uint8_t y = 0; y < 28; y++) {                   // always print pin name
450
       for (uint8_t y = 0; y < 28; y++) {                   // always print pin name
427
         temp_char = pgm_read_byte(name_mem_pointer + y);
451
         temp_char = pgm_read_byte(name_mem_pointer + y);
428
-        if (temp_char != 0) MYSERIAL.write(temp_char);
452
+        if (temp_char != 0)
453
+          MYSERIAL.write(temp_char);
429
         else {
454
         else {
430
           for (uint8_t i = 0; i < 28 - y; i++) MYSERIAL.write(' ');
455
           for (uint8_t i = 0; i < 28 - y; i++) MYSERIAL.write(' ');
431
           break;
456
           break;
432
         }
457
         }
433
       }
458
       }
434
-      if (pin_is_protected(pin) && !ignore)
435
-        SERIAL_ECHOPGM("protected ");
436
-      else {
437
-        if (!(pgm_read_byte(&pin_array[x][2]))) {
438
-          sprintf(buffer, "Analog in = %5d", analogRead(pin - analogInputToDigitalPin(0)));
439
-          SERIAL_ECHO(buffer);
440
-        }
459
+      if (extended) {
460
+        if (pin_is_protected(pin) && !ignore)
461
+          SERIAL_ECHOPGM("protected ");
441
         else {
462
         else {
442
-          if (!get_pinMode(pin)) {
443
-            //pinMode(pin, INPUT_PULLUP);  // make sure input isn't floating - stopped doing this
444
-                                           // because this could interfere with inductive/capacitive
445
-                                           // sensors (high impedance voltage divider) and with PT100 amplifier
446
-            SERIAL_PROTOCOLPAIR("Input  = ", digitalRead_mod(pin));
447
-          }
448
-          else if (pwm_status(pin)) {
449
-            // do nothing
463
+          #ifdef AVR_AT90USB1286_FAMILY // Teensy IDEs don't know about these pins so must use FASTIO
464
+            if (pin == 46) {
465
+              print_input_or_output(GET_OUTPUT(46));
466
+              SERIAL_PROTOCOL(READ(46));
467
+            }
468
+            else if (pin == 47)
469
+              print_input_or_output(GET_OUTPUT(47));
470
+              SERIAL_PROTOCOL(READ(47));
471
+            }
472
+            else
473
+          #endif
474
+          {
475
+            if (!(pgm_read_byte(&pin_array[x][2]))) {
476
+              sprintf_P(buffer, PSTR("Analog in = %5d"), analogRead(pin - analogInputToDigitalPin(0)));
477
+              SERIAL_ECHO(buffer);
478
+            }
479
+            else {
480
+
481
+              if (!get_pinMode(pin)) {
482
+                //pinMode(pin, INPUT_PULLUP);  // make sure input isn't floating - stopped doing this
483
+                                               // because this could interfere with inductive/capacitive
484
+                                               // sensors (high impedance voltage divider) and with PT100 amplifier
485
+                print_input_or_output(false);
486
+                SERIAL_PROTOCOL(digitalRead_mod(pin));
487
+              }
488
+              else if (pwm_status(pin)) {
489
+                // do nothing
490
+              }
491
+              else {
492
+                print_input_or_output(true);
493
+                SERIAL_PROTOCOL(digitalRead_mod(pin));
494
+              }
495
+            }
496
+            if (!multi_name_pin && extended) pwm_details(pin);  // report PWM capabilities only on the first pass & only if doing an extended report
450
           }
497
           }
451
-          else SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
452
         }
498
         }
453
-        if (!multi_name_pin && extended) pwm_details(pin);  // report PWM capabilities only on the first pass & only if doing an extended report
454
       }
499
       }
455
       SERIAL_EOL();
500
       SERIAL_EOL();
456
     }  // end of IF
501
     }  // end of IF
457
   } // end of for loop
502
   } // end of for loop
458
 
503
 
459
   if (!found) {
504
   if (!found) {
460
-    sprintf(buffer, "PIN: %3d ", pin);
505
+    sprintf_P(buffer, PSTR("%sPIN: %3d "), start_string, pin);
461
     SERIAL_ECHO(buffer);
506
     SERIAL_ECHO(buffer);
462
     print_port(pin);
507
     print_port(pin);
463
     if (IS_ANALOG(pin)) {
508
     if (IS_ANALOG(pin)) {
464
-      sprintf(buffer, " (A%2d)  ", int(pin - analogInputToDigitalPin(0)));    // analog pin number
509
+      sprintf_P(buffer, PSTR(" (A%2d)  "), int(pin - analogInputToDigitalPin(0)));    // analog pin number
465
       SERIAL_ECHO(buffer);
510
       SERIAL_ECHO(buffer);
466
     }
511
     }
467
-    else
468
-      SERIAL_ECHO_SP(8);   // add padding if not an analog pin
469
-    SERIAL_ECHOPGM("<unused/unknown>");
470
-    if (get_pinMode(pin)) {
471
-      SERIAL_PROTOCOL_SP(12);
472
-      SERIAL_PROTOCOLPAIR("Output = ", digitalRead_mod(pin));
473
-    }
474
     else {
512
     else {
475
-      if (IS_ANALOG(pin)) {
476
-        sprintf(buffer, "   Analog in = %5d", analogRead(pin - analogInputToDigitalPin(0)));
477
-        SERIAL_ECHO(buffer);
513
+      SERIAL_ECHO_SP(8);   // add padding if not an analog pin
514
+      SERIAL_ECHOPGM("<unused/unknown>");
515
+      if (extended) {
516
+        #ifdef AVR_AT90USB1286_FAMILY  // Teensy IDEs don't know about these pins so must use FASTIO
517
+          if (pin == 46 || pin == 47) {
518
+            SERIAL_PROTOCOL_SP(12);
519
+            if (pin == 46) {
520
+              print_input_or_output(GET_OUTPUT(46));
521
+              SERIAL_PROTOCOL(READ(46));
522
+            }
523
+            else {
524
+              print_input_or_output(GET_OUTPUT(47));
525
+              SERIAL_PROTOCOL(READ(47));
526
+            }
527
+          }
528
+          else
529
+        #endif
530
+        {
531
+          if (get_pinMode(pin)) {
532
+            SERIAL_PROTOCOL_SP(12);
533
+            print_input_or_output(true);
534
+            SERIAL_PROTOCOL(digitalRead_mod(pin));
535
+          }
536
+          else {
537
+            if (IS_ANALOG(pin)) {
538
+              sprintf_P(buffer, PSTR("   Analog in = %5d"), analogRead(pin - analogInputToDigitalPin(0)));
539
+              SERIAL_ECHO(buffer);
540
+              SERIAL_ECHOPGM("   ");
541
+            }
542
+            else
543
+              SERIAL_ECHO_SP(12);   // add padding if not an analog pin
544
+
545
+            print_input_or_output(false);
546
+            SERIAL_PROTOCOL(digitalRead_mod(pin));
547
+          }
548
+          //if (!pwm_status(pin)) SERIAL_CHAR(' ');    // add padding if it's not a PWM pin
549
+          if (extended) pwm_details(pin);  // report PWM capabilities only if doing an extended report
550
+        }
478
       }
551
       }
479
-      else
480
-        SERIAL_ECHO_SP(9);   // add padding if not an analog pin
481
-
482
-      SERIAL_PROTOCOLPAIR("   Input  = ", digitalRead_mod(pin));
552
+      SERIAL_EOL();
483
     }
553
     }
484
-    //if (!pwm_status(pin)) SERIAL_CHAR(' ');    // add padding if it's not a PWM pin
485
-    if (extended) pwm_details(pin);  // report PWM capabilities only if doing an extended report
486
-    SERIAL_EOL();
487
   }
554
   }
488
 }
555
 }
489
-
490
-inline void report_pin_state(int8_t pin) {
491
-  report_pin_state_extended(pin, false, false);
492
-}

+ 11
- 15
Marlin/pinsDebug_Teensyduino.h View File

25
 //  do not function the same as the other Arduino extensions
25
 //  do not function the same as the other Arduino extensions
26
 //
26
 //
27
 
27
 
28
+#ifndef __PINSDEBUG_TEENSYDUINO_H__
29
+#define __PINSDEBUG_TEENSYDUINO_H__
28
 
30
 
29
-#define TEENSYDUINO_IDE
31
+#undef NUM_DIGITAL_PINS
32
+#define NUM_DIGITAL_PINS 48  // Teensy says 46 but FASTIO is 48
30
 
33
 
31
-//digitalPinToTimer(pin) function works like Arduino but Timers are not defined
32
-#define TIMER0B 1
33
-#define TIMER1A 7
34
-#define TIMER1B 8
35
-#define TIMER1C 9
36
-#define TIMER2A 6
37
-#define TIMER2B 2
38
-#define TIMER3A 5
39
-#define TIMER3B 4
40
-#define TIMER3C 3
34
+// "digitalPinToPort" function just returns the pin number so need to create our own.
35
+// Can't use the name "digitalPinToPort" for our own because it interferes with the
36
+// FAST_PWM_FAN function if we do
41
 
37
 
42
-// digitalPinToPort function just returns the pin number so need to create our own
43
 #define PA 1
38
 #define PA 1
44
 #define PB 2
39
 #define PB 2
45
 #define PC 3
40
 #define PC 3
47
 #define PE 5
42
 #define PE 5
48
 #define PF 6
43
 #define PF 6
49
 
44
 
50
-#undef digitalPinToPort
51
 
45
 
52
-const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
46
+const uint8_t PROGMEM digital_pin_to_port_PGM_Teensy[] = {
53
   PD, // 0  - PD0 - INT0 - PWM
47
   PD, // 0  - PD0 - INT0 - PWM
54
   PD, // 1  - PD1 - INT1 - PWM
48
   PD, // 1  - PD1 - INT1 - PWM
55
   PD, // 2  - PD2 - INT2 - RX
49
   PD, // 2  - PD2 - INT2 - RX
100
   PE, // 47 - PE3 (not defined in teensyduino)
94
   PE, // 47 - PE3 (not defined in teensyduino)
101
 };
95
 };
102
 
96
 
103
-#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
97
+#define digitalPinToPort_Teensy(P) ( pgm_read_byte( digital_pin_to_port_PGM_Teensy + (P) ) )
104
 
98
 
105
 // digitalPinToBitMask(pin) is OK
99
 // digitalPinToBitMask(pin) is OK
106
 
100
 
108
                                              // disable the PWMs so we can use it as is
102
                                              // disable the PWMs so we can use it as is
109
 
103
 
110
 // portModeRegister(pin) is OK
104
 // portModeRegister(pin) is OK
105
+
106
+#endif // __PINSDEBUG_TEENSYDUINO_H__

+ 28
- 6
Marlin/pinsDebug_list.h View File

353
 #if defined(LCD_CONTRAST) && LCD_CONTRAST >= 0
353
 #if defined(LCD_CONTRAST) && LCD_CONTRAST >= 0
354
   REPORT_NAME_DIGITAL(LCD_CONTRAST, __LINE__ )
354
   REPORT_NAME_DIGITAL(LCD_CONTRAST, __LINE__ )
355
 #endif
355
 #endif
356
-#if PIN_EXISTS(LCD)
356
+#if defined(LCD_PINS_D4) && LCD_PINS_D4 >= 0
357
   REPORT_NAME_DIGITAL(LCD_PINS_D4, __LINE__ )
357
   REPORT_NAME_DIGITAL(LCD_PINS_D4, __LINE__ )
358
 #endif
358
 #endif
359
-#if PIN_EXISTS(LCD)
359
+#if defined(LCD_PINS_D5) && LCD_PINS_D5 >= 0
360
   REPORT_NAME_DIGITAL(LCD_PINS_D5, __LINE__ )
360
   REPORT_NAME_DIGITAL(LCD_PINS_D5, __LINE__ )
361
 #endif
361
 #endif
362
-#if PIN_EXISTS(LCD)
362
+#if defined(LCD_PINS_D6) && LCD_PINS_D6 >= 0
363
   REPORT_NAME_DIGITAL(LCD_PINS_D6, __LINE__ )
363
   REPORT_NAME_DIGITAL(LCD_PINS_D6, __LINE__ )
364
 #endif
364
 #endif
365
-#if PIN_EXISTS(LCD)
365
+#if defined(LCD_PINS_D7) && LCD_PINS_D7 >= 0
366
   REPORT_NAME_DIGITAL(LCD_PINS_D7, __LINE__ )
366
   REPORT_NAME_DIGITAL(LCD_PINS_D7, __LINE__ )
367
 #endif
367
 #endif
368
-#if PIN_EXISTS(LCD)
368
+#if defined(LCD_PINS_ENABLE) && LCD_PINS_ENABLE >= 0
369
   REPORT_NAME_DIGITAL(LCD_PINS_ENABLE, __LINE__ )
369
   REPORT_NAME_DIGITAL(LCD_PINS_ENABLE, __LINE__ )
370
 #endif
370
 #endif
371
-#if PIN_EXISTS(LCD)
371
+#if defined(LCD_PINS_RS) && LCD_PINS_RS >= 0
372
   REPORT_NAME_DIGITAL(LCD_PINS_RS, __LINE__ )
372
   REPORT_NAME_DIGITAL(LCD_PINS_RS, __LINE__ )
373
 #endif
373
 #endif
374
 #if defined(LCD_SDSS) && LCD_SDSS >= 0
374
 #if defined(LCD_SDSS) && LCD_SDSS >= 0
446
 #if PIN_EXISTS(RAMPS_D9)
446
 #if PIN_EXISTS(RAMPS_D9)
447
   REPORT_NAME_DIGITAL(RAMPS_D9_PIN, __LINE__ )
447
   REPORT_NAME_DIGITAL(RAMPS_D9_PIN, __LINE__ )
448
 #endif
448
 #endif
449
+#if PIN_EXISTS(RGB_LED_R)
450
+  REPORT_NAME_DIGITAL(RGB_LED_R_PIN, __LINE__ )
451
+#endif
452
+#if PIN_EXISTS(RGB_LED_G)
453
+  REPORT_NAME_DIGITAL(RGB_LED_G_PIN, __LINE__ )
454
+#endif
455
+#if PIN_EXISTS(RGB_LED_B)
456
+  REPORT_NAME_DIGITAL(RGB_LED_B_PIN, __LINE__ )
457
+#endif
458
+#if PIN_EXISTS(RGB_LED_W)
459
+  REPORT_NAME_DIGITAL(RGB_LED_W_PIN, __LINE__ )
460
+#endif
449
 #if PIN_EXISTS(RX_ENABLE)
461
 #if PIN_EXISTS(RX_ENABLE)
450
   REPORT_NAME_DIGITAL(RX_ENABLE_PIN, __LINE__ )
462
   REPORT_NAME_DIGITAL(RX_ENABLE_PIN, __LINE__ )
451
 #endif
463
 #endif
500
 #if PIN_EXISTS(SLEEP_WAKE)
512
 #if PIN_EXISTS(SLEEP_WAKE)
501
   REPORT_NAME_DIGITAL(SLEEP_WAKE_PIN, __LINE__ )
513
   REPORT_NAME_DIGITAL(SLEEP_WAKE_PIN, __LINE__ )
502
 #endif
514
 #endif
515
+#if PIN_EXISTS(SOL0)
516
+  REPORT_NAME_DIGITAL(SOL0_PIN, __LINE__ )
517
+#endif
503
 #if PIN_EXISTS(SOL1)
518
 #if PIN_EXISTS(SOL1)
504
   REPORT_NAME_DIGITAL(SOL1_PIN, __LINE__ )
519
   REPORT_NAME_DIGITAL(SOL1_PIN, __LINE__ )
505
 #endif
520
 #endif
506
 #if PIN_EXISTS(SOL2)
521
 #if PIN_EXISTS(SOL2)
507
   REPORT_NAME_DIGITAL(SOL2_PIN, __LINE__ )
522
   REPORT_NAME_DIGITAL(SOL2_PIN, __LINE__ )
508
 #endif
523
 #endif
524
+#if PIN_EXISTS(SOL3)
525
+  REPORT_NAME_DIGITAL(SOL3_PIN, __LINE__ )
526
+#endif
527
+#if PIN_EXISTS(SOL4)
528
+  REPORT_NAME_DIGITAL(SOL4_PIN, __LINE__ )
529
+#endif
509
 #if defined(SPARE_IO) && SPARE_IO >= 0
530
 #if defined(SPARE_IO) && SPARE_IO >= 0
510
   REPORT_NAME_DIGITAL(SPARE_IO, __LINE__ )
531
   REPORT_NAME_DIGITAL(SPARE_IO, __LINE__ )
511
 #endif
532
 #endif
749
 #if PIN_EXISTS(Z2_STEP)
770
 #if PIN_EXISTS(Z2_STEP)
750
   REPORT_NAME_DIGITAL(Z2_STEP_PIN, __LINE__ )
771
   REPORT_NAME_DIGITAL(Z2_STEP_PIN, __LINE__ )
751
 #endif
772
 #endif
773
+

Loading…
Cancel
Save