Browse Source

Debug Pins Support

Christopher Pepper 7 years ago
parent
commit
c66d1ac651

+ 9
- 6
Marlin/Marlin_main.cpp View File

@@ -6632,7 +6632,7 @@ inline void gcode_M42() {
6632 6632
 
6633 6633
 #if ENABLED(PINS_DEBUGGING)
6634 6634
 
6635
-  #include "pinsDebug.h"
6635
+  #include "src/HAL/HAL_pinsDebug.h"
6636 6636
 
6637 6637
   inline void toggle_pins() {
6638 6638
     const bool I_flag = parser.boolval('I');
@@ -6643,7 +6643,7 @@ inline void gcode_M42() {
6643 6643
 
6644 6644
     for (uint8_t pin = start; pin <= end; pin++) {
6645 6645
       //report_pin_state_extended(pin, I_flag, false);
6646
-
6646
+      if (!VALID_PIN(pin)) continue;
6647 6647
       if (!I_flag && pin_is_protected(pin)) {
6648 6648
         report_pin_state_extended(pin, I_flag, true, "Untouched ");
6649 6649
         SERIAL_EOL();
@@ -6869,14 +6869,15 @@ inline void gcode_M42() {
6869 6869
     // Watch until click, M108, or reset
6870 6870
     if (parser.boolval('W')) {
6871 6871
       SERIAL_PROTOCOLLNPGM("Watching pins");
6872
-      byte pin_state[last_pin - first_pin + 1];
6872
+      uint8_t pin_state[last_pin - first_pin + 1];
6873 6873
       for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6874
+        if (!VALID_PIN(pin)) continue;
6874 6875
         if (pin_is_protected(pin) && !ignore_protection) continue;
6875 6876
         pinMode(pin, INPUT_PULLUP);
6876 6877
         delay(1);
6877 6878
         /*
6878 6879
           if (IS_ANALOG(pin))
6879
-            pin_state[pin - first_pin] = analogRead(pin - analogInputToDigitalPin(0)); // int16_t pin_state[...]
6880
+            pin_state[pin - first_pin] = analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)); // int16_t pin_state[...]
6880 6881
           else
6881 6882
         //*/
6882 6883
             pin_state[pin - first_pin] = digitalRead(pin);
@@ -6889,11 +6890,12 @@ inline void gcode_M42() {
6889 6890
 
6890 6891
       for (;;) {
6891 6892
         for (int8_t pin = first_pin; pin <= last_pin; pin++) {
6893
+          if (!VALID_PIN(pin)) continue;
6892 6894
           if (pin_is_protected(pin) && !ignore_protection) continue;
6893 6895
           const byte val =
6894 6896
             /*
6895 6897
               IS_ANALOG(pin)
6896
-                ? analogRead(pin - analogInputToDigitalPin(0)) : // int16_t val
6898
+                ? analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)) : // int16_t val
6897 6899
                 :
6898 6900
             //*/
6899 6901
               digitalRead(pin);
@@ -6917,7 +6919,7 @@ inline void gcode_M42() {
6917 6919
 
6918 6920
     // Report current state of selected pin(s)
6919 6921
     for (uint8_t pin = first_pin; pin <= last_pin; pin++)
6920
-      report_pin_state_extended(pin, ignore_protection, true);
6922
+      if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
6921 6923
   }
6922 6924
 
6923 6925
 #endif // PINS_DEBUGGING
@@ -11086,6 +11088,7 @@ void process_next_command() {
11086 11088
         gcode_M140();
11087 11089
         break;
11088 11090
 
11091
+
11089 11092
       case 105: // M105: Report current temperature
11090 11093
         gcode_M105();
11091 11094
         KEEPALIVE_STATE(NOT_BUSY);

+ 12
- 0
Marlin/pinsDebug_list.h View File

@@ -575,6 +575,9 @@
575 575
 #if defined(TC2) && TC2 >= 0 && TC2 < NUM_ANALOG_INPUTS
576 576
   REPORT_NAME_ANALOG(TC2, __LINE__ )
577 577
 #endif
578
+#if PIN_EXISTS(FILWIDTH) && FILWIDTH_PIN < NUM_ANALOG_INPUTS
579
+  REPORT_NAME_ANALOG(FILWIDTH_PIN, __LINE__ )
580
+#endif
578 581
 #if PIN_EXISTS(TEMP_0) && TEMP_0_PIN < NUM_ANALOG_INPUTS
579 582
   REPORT_NAME_ANALOG(TEMP_0_PIN, __LINE__ )
580 583
 #endif
@@ -590,6 +593,15 @@
590 593
 #if PIN_EXISTS(TEMP_4) && TEMP_4_PIN < NUM_ANALOG_INPUTS
591 594
   REPORT_NAME_ANALOG(TEMP_4_PIN, __LINE__ )
592 595
 #endif
596
+#if PIN_EXISTS(TEMP_5) && TEMP_5_PIN < NUM_ANALOG_INPUTS
597
+  REPORT_NAME_ANALOG(TEMP_5_PIN, __LINE__ )
598
+#endif
599
+#if PIN_EXISTS(TEMP_6) && TEMP_6_PIN < NUM_ANALOG_INPUTS
600
+  REPORT_NAME_ANALOG(TEMP_6_PIN, __LINE__ )
601
+#endif
602
+#if PIN_EXISTS(TEMP_7) && TEMP_7_PIN < NUM_ANALOG_INPUTS
603
+  REPORT_NAME_ANALOG(TEMP_7_PIN, __LINE__ )
604
+#endif
593 605
 #if PIN_EXISTS(TEMP_BED) && TEMP_BED_PIN < NUM_ANALOG_INPUTS
594 606
   REPORT_NAME_ANALOG(TEMP_BED_PIN, __LINE__ )
595 607
 #endif

+ 215
- 0
Marlin/src/HAL/HAL_LPC1768/HAL_pinsDebug.h View File

@@ -0,0 +1,215 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+bool endstop_monitor_flag = false;
24
+
25
+#define MAX_NAME_LENGTH  35    // one place to specify the format of all the sources of names
26
+                               // "-" left justify, "35" minimum width of name, pad with blanks
27
+
28
+/**
29
+ *  This routine minimizes RAM usage by creating a FLASH resident array to
30
+ *  store the pin names, pin numbers and analog/digital flag.
31
+ *
32
+ *  Creating the array in FLASH is a two pass process.  The first pass puts the
33
+ *  name strings into FLASH.  The second pass actually creates the array.
34
+ *
35
+ *  Both passes use the same pin list.  The list contains two macro names. The
36
+ *  actual macro definitions are changed depending on which pass is being done.
37
+ *
38
+ */
39
+
40
+// first pass - put the name strings into FLASH
41
+
42
+#define _ADD_PIN_2(PIN_NAME, ENTRY_NAME) static const char ENTRY_NAME[] PROGMEM = { PIN_NAME };
43
+#define _ADD_PIN(PIN_NAME, COUNTER) _ADD_PIN_2(PIN_NAME, entry_NAME_##COUNTER)
44
+#define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
45
+#define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
46
+
47
+#include "../../../pinsDebug_list.h"
48
+#line 51
49
+
50
+/////////////////////////////////////////////////////////////////////////////
51
+
52
+// second pass - create the array
53
+
54
+#undef _ADD_PIN_2
55
+#undef _ADD_PIN
56
+#undef REPORT_NAME_DIGITAL
57
+#undef REPORT_NAME_ANALOG
58
+
59
+#define _ADD_PIN_2(ENTRY_NAME, NAME, IS_DIGITAL) { ENTRY_NAME, NAME, IS_DIGITAL },
60
+#define _ADD_PIN(NAME, COUNTER, IS_DIGITAL) _ADD_PIN_2(entry_NAME_##COUNTER, NAME, IS_DIGITAL)
61
+#define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(NAME, COUNTER, true)
62
+#define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(analogInputToDigitalPin(NAME), COUNTER, false)
63
+
64
+
65
+typedef struct {
66
+  const char * const name;
67
+  uint8_t pin;
68
+  bool is_digital;
69
+} PinInfo;
70
+
71
+const PinInfo pin_array[] PROGMEM = {
72
+
73
+  /**
74
+   *  [pin name]  [pin number]  [is digital or analog]  1 = digital, 0 = analog
75
+   *  Each entry takes up 6 bytes in FLASH:
76
+   *     2 byte pointer to location of the name string
77
+   *     2 bytes containing the pin number
78
+   *         analog pin numbers were convereted to digital when the array was created
79
+   *     2 bytes containing the digital/analog bool flag
80
+   */
81
+
82
+  // manually add pins ...
83
+  #if SERIAL_PORT == 0
84
+
85
+  #endif
86
+
87
+  #include "../../../pinsDebug_list.h"
88
+  #line 102
89
+
90
+};
91
+
92
+#define AVR_ATmega2560_FAMILY_PLUS_70 (MOTHERBOARD == BOARD_BQ_ZUM_MEGA_3D \
93
+|| MOTHERBOARD == BOARD_MIGHTYBOARD_REVE \
94
+|| MOTHERBOARD == BOARD_MINIRAMBO \
95
+|| MOTHERBOARD == BOARD_SCOOVO_X9H)
96
+
97
+
98
+#include "pinsDebug_Re_ARM.h"
99
+
100
+#define PWM_PRINT(V) do{ sprintf_P(buffer, PSTR("PWM:  %4d"), V); SERIAL_ECHO(buffer); }while(0)
101
+#define PWM_CASE(N,Z)                                           \
102
+  case TIMER##N##Z:                                             \
103
+    if (TCCR##N##A & (_BV(COM##N##Z##1) | _BV(COM##N##Z##0))) { \
104
+      PWM_PRINT(OCR##N##Z);                                     \
105
+      return true;                                              \
106
+    } else return false
107
+
108
+bool PWM_ok = true;
109
+
110
+static void print_input_or_output(const bool isout) {
111
+  serialprintPGM(isout ? PSTR("Output = ") : PSTR("Input  = "));
112
+}
113
+
114
+// pretty report with PWM info
115
+inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = false, const char *start_string = "") {
116
+  uint8_t temp_char;
117
+  char *name_mem_pointer, buffer[30];   // for the sprintf statements
118
+  bool found = false, multi_name_pin = false;
119
+  for (uint8_t x = 0; x < COUNT(pin_array); x++)  {    // scan entire array and report all instances of this pin
120
+    if (GET_ARRAY_PIN(x) == pin) {
121
+      GET_PIN_INFO(pin);
122
+      if (found) multi_name_pin = true;
123
+      found = true;
124
+      if (!multi_name_pin) {    // report digitial and analog pin number only on the first time through
125
+        sprintf_P(buffer, PSTR("%sPIN: %3d "), start_string, pin);     // digital pin number
126
+        SERIAL_ECHO(buffer);
127
+        PRINT_PORT(pin);
128
+        if (IS_ANALOG(pin)) {
129
+          sprintf_P(buffer, PSTR(" (A%2d)  "), DIGITAL_PIN_TO_ANALOG_PIN(pin));    // analog pin number
130
+          SERIAL_ECHO(buffer);
131
+        }
132
+        else SERIAL_ECHO_SP(8);   // add padding if not an analog pin
133
+      }
134
+      else {
135
+        SERIAL_CHAR('.');
136
+        SERIAL_ECHO_SP(26 + strlen(start_string));  // add padding if not the first instance found
137
+      }
138
+      PRINT_ARRAY_NAME(x);
139
+      if (extended) {
140
+        if (pin_is_protected(pin) && !ignore)
141
+          SERIAL_ECHOPGM("protected ");
142
+        else {
143
+//SERIAL_PROTOCOLPAIR(" GET_ARRAY_IS_DIGITAL(x) 0 = analog : ", GET_ARRAY_IS_DIGITAL(x));           
144
+
145
+          if (!GET_ARRAY_IS_DIGITAL(x)) {
146
+            sprintf_P(buffer, PSTR("Analog in = %5d"), analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
147
+            SERIAL_ECHO(buffer);
148
+          }
149
+          else {
150
+
151
+//MYSERIAL.printf("  GET_PINMODE(pin) 1 = output : %d   ", GET_PINMODE(pin));           
152
+            if (!GET_PINMODE(pin)) {
153
+              //pinMode(pin, INPUT_PULLUP);  // make sure input isn't floating - stopped doing this
154
+                                             // because this could interfere with inductive/capacitive
155
+                                             // sensors (high impedance voltage divider) and with PT100 amplifier
156
+              print_input_or_output(false);
157
+              SERIAL_PROTOCOL(digitalRead_mod(pin));
158
+            }
159
+            #if PWM_ok
160
+              else if (pwm_status(pin)) {
161
+                // do nothing
162
+              }
163
+              #endif
164
+            else {
165
+              print_input_or_output(true);
166
+              SERIAL_PROTOCOL(digitalRead_mod(pin));
167
+            }
168
+          }
169
+          #if PWM_ok
170
+            if (!multi_name_pin && extended) pwm_details(pin);  // report PWM capabilities only on the first pass & only if doing an extended report
171
+          #endif
172
+        }
173
+      }
174
+      SERIAL_EOL();
175
+    }  // end of IF
176
+  } // end of for loop
177
+
178
+  if (!found) {
179
+    GET_PIN_INFO(pin);
180
+    sprintf_P(buffer, PSTR("%sPIN: %3d "), start_string, pin);
181
+    SERIAL_ECHO(buffer);
182
+    PRINT_PORT(pin);
183
+    if (IS_ANALOG(pin)) {
184
+      sprintf_P(buffer, PSTR(" (A%2d)  "), DIGITAL_PIN_TO_ANALOG_PIN(pin));    // analog pin number
185
+      SERIAL_ECHO(buffer);
186
+    }
187
+    else
188
+      SERIAL_ECHO_SP(8);   // add padding if not an analog pin
189
+    SERIAL_ECHOPGM("<unused/unknown>");
190
+    if (extended) {
191
+      if (GET_PINMODE(pin)) {
192
+        SERIAL_PROTOCOL_SP(MAX_NAME_LENGTH - 16);
193
+        print_input_or_output(true);
194
+        SERIAL_PROTOCOL(digitalRead_mod(pin));
195
+      }
196
+      else {
197
+        if (IS_ANALOG(pin)) {
198
+          sprintf_P(buffer, PSTR("   Analog in = %5d"), analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
199
+          SERIAL_ECHO(buffer);
200
+          SERIAL_ECHOPGM("   ");
201
+        }
202
+        else
203
+        SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);   // add padding if not an analog pin
204
+
205
+        print_input_or_output(false);
206
+        SERIAL_PROTOCOL(digitalRead_mod(pin));
207
+      }
208
+      //if (!pwm_status(pin)) SERIAL_CHAR(' ');    // add padding if it's not a PWM pin
209
+      #if PWM_ok
210
+        if (extended) pwm_details(pin);  // report PWM capabilities only if doing an extended report
211
+      #endif
212
+    }
213
+    SERIAL_EOL();
214
+  }
215
+}

+ 92
- 0
Marlin/src/HAL/HAL_LPC1768/pinsDebug_Re_ARM.h View File

@@ -0,0 +1,92 @@
1
+/**
2
+  * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+ 
23
+/**
24
+ * Support routines for Re-ARM board
25
+ */
26
+
27
+
28
+ 
29
+typedef struct {
30
+  int8_t pin;
31
+  bool output;
32
+  bool analog;
33
+  uint8_t resistors;
34
+  bool open_drain;
35
+  char function_string[15];
36
+} pin_info;
37
+
38
+pin_info pin_Re_ARM;
39
+ 
40
+void get_pin_info(int8_t pin) {
41
+  pin_Re_ARM.analog = 0;
42
+  pin_Re_ARM.pin = pin;
43
+  int8_t pin_port = pin_map[pin].port;
44
+  int8_t pin_port_pin = pin_map[pin].pin;
45
+ 
46
+  // active ADC function/mode/code values for PINSEL registers
47
+  int8_t ADC_pin_mode = pin_port == 0 && pin_port_pin == 2  ? 2 :
48
+                        pin_port == 0 && pin_port_pin == 3  ? 2 :
49
+                        pin_port == 0 && pin_port_pin == 23 ? 1 : 
50
+                        pin_port == 0 && pin_port_pin == 24 ? 1 :
51
+                        pin_port == 0 && pin_port_pin == 25 ? 1 :
52
+                        pin_port == 0 && pin_port_pin == 26 ? 1 :
53
+                        pin_port == 1 && pin_port_pin == 30 ? 3 :
54
+                        pin_port == 1 && pin_port_pin == 31 ? 3 : -1;       
55
+  //get appropriate PINSEL register                                         
56
+  volatile uint32_t * pinsel_reg = (pin_port == 0 && pin_port_pin <= 15) ? &LPC_PINCON->PINSEL0 :
57
+                                   (pin_port == 0)                       ? &LPC_PINCON->PINSEL1 :
58
+                                   (pin_port == 1 && pin_port_pin <= 15) ? &LPC_PINCON->PINSEL2 :
59
+                                    pin_port == 1                        ? &LPC_PINCON->PINSEL3 :
60
+                                    pin_port == 2                        ? &LPC_PINCON->PINSEL4 :
61
+                                    pin_port == 3                        ? &LPC_PINCON->PINSEL7 : &LPC_PINCON->PINSEL9;                                                    
62
+
63
+  uint8_t pinsel_start_bit = pin_port_pin > 15 ? 2 * (pin_port_pin - 16) : 2 * pin_port_pin;
64
+  uint8_t pin_mode = (uint8_t) ((*pinsel_reg >> pinsel_start_bit) & 0x3);
65
+  
66
+  uint32_t * FIO_reg[5] PROGMEM = {(uint32_t*) 0x2009C000,(uint32_t*)  0x2009C020,(uint32_t*)  0x2009C040,(uint32_t*)  0x2009C060,(uint32_t*)  0x2009C080};
67
+  pin_Re_ARM.output = (*FIO_reg[pin_map[pin].port] >> pin_map[pin].pin) & 1; //input/output state except if active ADC
68
+
69
+  if (pin_mode) {  // if function/mode/code value not 0 then could be an active analog channel
70
+    if (ADC_pin_mode == pin_mode) {  // found an active analog pin
71
+      pin_Re_ARM.output = 0;
72
+      pin_Re_ARM.analog = 1;
73
+    }  
74
+  }
75
+}
76
+
77
+/**
78
+ * translation of routines & variables used by pinsDebug.h
79
+ */
80
+ 
81
+#define GET_PIN_INFO(pin) get_pin_info(pin)
82
+#define IS_ANALOG(P) (DIGITAL_PIN_TO_ANALOG_PIN(P) >= 0 ? 1 : 0)
83
+#define GET_PINMODE(pin) pin_Re_ARM.output
84
+#define digitalRead_mod(p)  digitalRead(p)
85
+#define digitalPinToPort_DEBUG(p)  0
86
+#define digitalPinToBitMask_DEBUG(pin) 0
87
+#define PRINT_PORT(p) SERIAL_ECHO_SP(10);
88
+#define GET_ARRAY_PIN(p) pin_array[p].pin
89
+#define NAME_FORMAT(p) PSTR("%-##p##s")
90
+//  #define PRINT_ARRAY_NAME(x)  do {sprintf_P(buffer, NAME_FORMAT(MAX_NAME_LENGTH) , pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
91
+#define PRINT_ARRAY_NAME(x)  do {sprintf_P(buffer, PSTR("%-35s") , pin_array[x].name); SERIAL_ECHO(buffer);} while (0)
92
+#define GET_ARRAY_IS_DIGITAL(x)  !pin_Re_ARM.analog

+ 2
- 0
Marlin/src/HAL/HAL_pinsDebug.h View File

@@ -28,6 +28,8 @@
28 28
   #include "HAL_DUE/HAL_pinsDebug_Due.h"
29 29
 #elif IS_32BIT_TEENSY
30 30
   #include "HAL_TEENSY35_36/HAL_pinsDebug_Teensy.h"
31
+#elif defined(TARGET_LPC1768)
32
+  #include "HAL_LPC1768/HAL_pinsDebug.h"
31 33
 #else
32 34
   #error Unsupported Platform!
33 35
 #endif

Loading…
Cancel
Save