|
@@ -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
|
+}
|