|
@@ -1,591 +0,0 @@
|
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
|
|
-#ifndef _HAL_PINSDEBUG_AVR_H_
|
24
|
|
-#define _HAL_PINSDEBUG_AVR_H_
|
25
|
|
-
|
26
|
|
-#include "../../inc/MarlinConfig.h"
|
27
|
|
-
|
28
|
|
-void HAL_print_analog_pin(char buffer[], int8_t pin) {
|
29
|
|
- sprintf(buffer, "(A%2d) ", int(pin - analogInputToDigitalPin(0)));
|
30
|
|
-}
|
31
|
|
-
|
32
|
|
-void HAL_analog_pin_state(char buffer[], int8_t pin) {
|
33
|
|
- sprintf(buffer, "Analog in =% 5d", analogRead(pin - analogInputToDigitalPin(0)));
|
34
|
|
-}
|
35
|
|
-
|
36
|
|
-#define NAME_FORMAT "%-35s" // one place to specify the format of all the sources of names
|
37
|
|
- // "-" left justify, "28" minimum width of name, pad with blanks
|
38
|
|
-
|
39
|
|
-#define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(7)))
|
40
|
|
-
|
41
|
|
-/**
|
42
|
|
- * This routine minimizes RAM usage by creating a FLASH resident array to
|
43
|
|
- * store the pin names, pin numbers and analog/digital flag.
|
44
|
|
- *
|
45
|
|
- * Creating the array in FLASH is a two pass process. The first pass puts the
|
46
|
|
- * name strings into FLASH. The second pass actually creates the array.
|
47
|
|
- *
|
48
|
|
- * Both passes use the same pin list. The list contains two macro names. The
|
49
|
|
- * actual macro definitions are changed depending on which pass is being done.
|
50
|
|
- *
|
51
|
|
- */
|
52
|
|
-
|
53
|
|
-// first pass - put the name strings into FLASH
|
54
|
|
-
|
55
|
|
-#define _ADD_PIN_2(PIN_NAME, ENTRY_NAME) static const char ENTRY_NAME[] PROGMEM = { PIN_NAME };
|
56
|
|
-#define _ADD_PIN(PIN_NAME, COUNTER) _ADD_PIN_2(PIN_NAME, entry_NAME_##COUNTER)
|
57
|
|
-#define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
|
58
|
|
-#define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
|
59
|
|
-
|
60
|
|
-#include "../../pins/pinsDebug_list.h"
|
61
|
|
-#line 62
|
62
|
|
-
|
63
|
|
-// manually add pins that have names that are macros which don't play well with these macros
|
64
|
|
-#if SERIAL_PORT == 0 && (AVR_ATmega2560_FAMILY || AVR_ATmega1284_FAMILY)
|
65
|
|
- static const char RXD_NAME[] PROGMEM = { "RXD" };
|
66
|
|
- static const char TXD_NAME[] PROGMEM = { "TXD" };
|
67
|
|
-#endif
|
68
|
|
-
|
69
|
|
-/////////////////////////////////////////////////////////////////////////////
|
70
|
|
-
|
71
|
|
-// second pass - create the array
|
72
|
|
-
|
73
|
|
-#undef _ADD_PIN_2
|
74
|
|
-#undef _ADD_PIN
|
75
|
|
-#undef REPORT_NAME_DIGITAL
|
76
|
|
-#undef REPORT_NAME_ANALOG
|
77
|
|
-
|
78
|
|
-#define _ADD_PIN_2(ENTRY_NAME, NAME, IS_DIGITAL) { ENTRY_NAME, NAME, IS_DIGITAL },
|
79
|
|
-#define _ADD_PIN(NAME, COUNTER, IS_DIGITAL) _ADD_PIN_2(entry_NAME_##COUNTER, NAME, IS_DIGITAL)
|
80
|
|
-#define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(NAME, COUNTER, true)
|
81
|
|
-#define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(analogInputToDigitalPin(NAME), COUNTER, false)
|
82
|
|
-
|
83
|
|
-typedef struct {
|
84
|
|
- const char * const name;
|
85
|
|
- pin_t pin;
|
86
|
|
- bool is_digital;
|
87
|
|
-} PinInfo;
|
88
|
|
-
|
89
|
|
-const PinInfo pin_array[] PROGMEM = {
|
90
|
|
-
|
91
|
|
- /**
|
92
|
|
- * [pin name] [pin number] [is digital or analog] 1 = digital, 0 = analog
|
93
|
|
- * Each entry takes up 6 bytes in FLASH:
|
94
|
|
- * 2 byte pointer to location of the name string
|
95
|
|
- * 2 bytes containing the pin number
|
96
|
|
- * analog pin numbers were convereted to digital when the array was created
|
97
|
|
- * 2 bytes containing the digital/analog bool flag
|
98
|
|
- */
|
99
|
|
-
|
100
|
|
- // manually add pins ...
|
101
|
|
- #if SERIAL_PORT == 0
|
102
|
|
- #if AVR_ATmega2560_FAMILY
|
103
|
|
- { RXD_NAME, 0, true },
|
104
|
|
- { TXD_NAME, 1, true },
|
105
|
|
- #elif AVR_ATmega1284_FAMILY
|
106
|
|
- { RXD_NAME, 8, true },
|
107
|
|
- { TXD_NAME, 9, true },
|
108
|
|
- #endif
|
109
|
|
- #endif
|
110
|
|
-
|
111
|
|
- #include "../../pins/pinsDebug_list.h"
|
112
|
|
- #line 113
|
113
|
|
-
|
114
|
|
-};
|
115
|
|
-
|
116
|
|
-#if AVR_AT90USB1286_FAMILY
|
117
|
|
- // Working with Teensyduino extension so need to re-define some things
|
118
|
|
- #include "pinsDebug_Teensyduino.h"
|
119
|
|
- // Can't use the "digitalPinToPort" function from the Teensyduino type IDEs
|
120
|
|
- // portModeRegister takes a different argument
|
121
|
|
- #define digitalPinToTimer_DEBUG(p) digitalPinToTimer(p)
|
122
|
|
- #define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask(p)
|
123
|
|
- #define digitalPinToPort_DEBUG(p) digitalPinToPort_Teensy(p)
|
124
|
|
- #define get_pinMode(pin) (*portModeRegister(pin) & digitalPinToBitMask_DEBUG(pin))
|
125
|
|
-#elif AVR_ATmega2560_FAMILY_PLUS_70 // So we can access/display all the pins on boards using more than 70
|
126
|
|
- #include "pinsDebug_plus_70.h"
|
127
|
|
- #define digitalPinToTimer_DEBUG(p) digitalPinToTimer_plus_70(p)
|
128
|
|
- #define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask_plus_70(p)
|
129
|
|
- #define digitalPinToPort_DEBUG(p) digitalPinToPort_plus_70(p)
|
130
|
|
- bool get_pinMode(int8_t pin) {return *portModeRegister(digitalPinToPort_DEBUG(pin)) & digitalPinToBitMask_DEBUG(pin); }
|
131
|
|
-#else
|
132
|
|
- #define digitalPinToTimer_DEBUG(p) digitalPinToTimer(p)
|
133
|
|
- #define digitalPinToBitMask_DEBUG(p) digitalPinToBitMask(p)
|
134
|
|
- #define digitalPinToPort_DEBUG(p) digitalPinToPort(p)
|
135
|
|
- bool get_pinMode(int8_t pin) {return *portModeRegister(digitalPinToPort_DEBUG(pin)) & digitalPinToBitMask_DEBUG(pin); }
|
136
|
|
-#endif
|
137
|
|
-
|
138
|
|
-#if defined(__AVR_ATmega1284P__) // 1284 IDE extensions set this to the number of
|
139
|
|
- #undef NUM_DIGITAL_PINS // digital only pins while all other CPUs have it
|
140
|
|
- #define NUM_DIGITAL_PINS 32 // set to digital only + digital/analog
|
141
|
|
-#endif
|
142
|
|
-
|
143
|
|
-#define PWM_PRINT(V) do{ sprintf_P(buffer, PSTR("PWM: %4d"), V); SERIAL_ECHO(buffer); }while(0)
|
144
|
|
-#define PWM_CASE(N,Z) \
|
145
|
|
- case TIMER##N##Z: \
|
146
|
|
- if (TCCR##N##A & (_BV(COM##N##Z##1) | _BV(COM##N##Z##0))) { \
|
147
|
|
- PWM_PRINT(OCR##N##Z); \
|
148
|
|
- return true; \
|
149
|
|
- } else return false
|
150
|
|
-
|
151
|
|
-/**
|
152
|
|
- * Print a pin's PWM status.
|
153
|
|
- * Return true if it's currently a PWM pin.
|
154
|
|
- */
|
155
|
|
-static bool HAL_pwm_status(uint8_t pin) {
|
156
|
|
- char buffer[20]; // for the sprintf statements
|
157
|
|
-
|
158
|
|
- switch (digitalPinToTimer_DEBUG(pin)) {
|
159
|
|
-
|
160
|
|
- #if defined(TCCR0A) && defined(COM0A1)
|
161
|
|
- #ifdef TIMER0A
|
162
|
|
- #if !AVR_AT90USB1286_FAMILY // not available in Teensyduino type IDEs
|
163
|
|
- PWM_CASE(0, A);
|
164
|
|
- #endif
|
165
|
|
- #endif
|
166
|
|
- PWM_CASE(0, B);
|
167
|
|
- #endif
|
168
|
|
-
|
169
|
|
- #if defined(TCCR1A) && defined(COM1A1)
|
170
|
|
- PWM_CASE(1, A);
|
171
|
|
- PWM_CASE(1, B);
|
172
|
|
- #if defined(COM1C1) && defined(TIMER1C)
|
173
|
|
- PWM_CASE(1, C);
|
174
|
|
- #endif
|
175
|
|
- #endif
|
176
|
|
-
|
177
|
|
- #if defined(TCCR2A) && defined(COM2A1)
|
178
|
|
- PWM_CASE(2, A);
|
179
|
|
- PWM_CASE(2, B);
|
180
|
|
- #endif
|
181
|
|
-
|
182
|
|
- #if defined(TCCR3A) && defined(COM3A1)
|
183
|
|
- PWM_CASE(3, A);
|
184
|
|
- PWM_CASE(3, B);
|
185
|
|
- #ifdef COM3C1
|
186
|
|
- PWM_CASE(3, C);
|
187
|
|
- #endif
|
188
|
|
- #endif
|
189
|
|
-
|
190
|
|
- #ifdef TCCR4A
|
191
|
|
- PWM_CASE(4, A);
|
192
|
|
- PWM_CASE(4, B);
|
193
|
|
- PWM_CASE(4, C);
|
194
|
|
- #endif
|
195
|
|
-
|
196
|
|
- #if defined(TCCR5A) && defined(COM5A1)
|
197
|
|
- PWM_CASE(5, A);
|
198
|
|
- PWM_CASE(5, B);
|
199
|
|
- PWM_CASE(5, C);
|
200
|
|
- #endif
|
201
|
|
-
|
202
|
|
- case NOT_ON_TIMER:
|
203
|
|
- default:
|
204
|
|
- return false;
|
205
|
|
- }
|
206
|
|
- SERIAL_PROTOCOL_SP(2);
|
207
|
|
-} // pwm_status
|
208
|
|
-
|
209
|
|
-
|
210
|
|
-const volatile uint8_t* const PWM_other[][3] PROGMEM = {
|
211
|
|
- { &TCCR0A, &TCCR0B, &TIMSK0 },
|
212
|
|
- { &TCCR1A, &TCCR1B, &TIMSK1 },
|
213
|
|
- #if defined(TCCR2A) && defined(COM2A1)
|
214
|
|
- { &TCCR2A, &TCCR2B, &TIMSK2 },
|
215
|
|
- #endif
|
216
|
|
- #if defined(TCCR3A) && defined(COM3A1)
|
217
|
|
- { &TCCR3A, &TCCR3B, &TIMSK3 },
|
218
|
|
- #endif
|
219
|
|
- #ifdef TCCR4A
|
220
|
|
- { &TCCR4A, &TCCR4B, &TIMSK4 },
|
221
|
|
- #endif
|
222
|
|
- #if defined(TCCR5A) && defined(COM5A1)
|
223
|
|
- { &TCCR5A, &TCCR5B, &TIMSK5 },
|
224
|
|
- #endif
|
225
|
|
-};
|
226
|
|
-
|
227
|
|
-
|
228
|
|
-const volatile uint8_t* const PWM_OCR[][3] PROGMEM = {
|
229
|
|
-
|
230
|
|
- #ifdef TIMER0A
|
231
|
|
- { &OCR0A, &OCR0B, 0 },
|
232
|
|
- #else
|
233
|
|
- { 0, &OCR0B, 0 },
|
234
|
|
- #endif
|
235
|
|
-
|
236
|
|
- #if defined(COM1C1) && defined(TIMER1C)
|
237
|
|
- { (const uint8_t*)&OCR1A, (const uint8_t*)&OCR1B, (const uint8_t*)&OCR1C },
|
238
|
|
- #else
|
239
|
|
- { (const uint8_t*)&OCR1A, (const uint8_t*)&OCR1B, 0 },
|
240
|
|
- #endif
|
241
|
|
-
|
242
|
|
- #if defined(TCCR2A) && defined(COM2A1)
|
243
|
|
- { &OCR2A, &OCR2B, 0 },
|
244
|
|
- #endif
|
245
|
|
-
|
246
|
|
- #if defined(TCCR3A) && defined(COM3A1)
|
247
|
|
- #ifdef COM3C1
|
248
|
|
- { (const uint8_t*)&OCR3A, (const uint8_t*)&OCR3B, (const uint8_t*)&OCR3C },
|
249
|
|
- #else
|
250
|
|
- { (const uint8_t*)&OCR3A, (const uint8_t*)&OCR3B, 0 },
|
251
|
|
- #endif
|
252
|
|
- #endif
|
253
|
|
-
|
254
|
|
- #ifdef TCCR4A
|
255
|
|
- { (const uint8_t*)&OCR4A, (const uint8_t*)&OCR4B, (const uint8_t*)&OCR4C },
|
256
|
|
- #endif
|
257
|
|
-
|
258
|
|
- #if defined(TCCR5A) && defined(COM5A1)
|
259
|
|
- { (const uint8_t*)&OCR5A, (const uint8_t*)&OCR5B, (const uint8_t*)&OCR5C },
|
260
|
|
- #endif
|
261
|
|
-};
|
262
|
|
-
|
263
|
|
-
|
264
|
|
-#define TCCR_A(T) pgm_read_word(&PWM_other[T][0])
|
265
|
|
-#define TCCR_B(T) pgm_read_word(&PWM_other[T][1])
|
266
|
|
-#define TIMSK(T) pgm_read_word(&PWM_other[T][2])
|
267
|
|
-#define CS_0 0
|
268
|
|
-#define CS_1 1
|
269
|
|
-#define CS_2 2
|
270
|
|
-#define WGM_0 0
|
271
|
|
-#define WGM_1 1
|
272
|
|
-#define WGM_2 3
|
273
|
|
-#define WGM_3 4
|
274
|
|
-#define TOIE 0
|
275
|
|
-
|
276
|
|
-#define OCR_VAL(T, L) pgm_read_word(&PWM_OCR[T][L])
|
277
|
|
-
|
278
|
|
-static void err_is_counter() { SERIAL_PROTOCOLPGM(" non-standard PWM mode"); }
|
279
|
|
-static void err_is_interrupt() { SERIAL_PROTOCOLPGM(" compare interrupt enabled"); }
|
280
|
|
-static void err_prob_interrupt() { SERIAL_PROTOCOLPGM(" overflow interrupt enabled"); }
|
281
|
|
-
|
282
|
|
-#if AVR_ATmega2560_FAMILY || AVR_AT90USB1286_FAMILY
|
283
|
|
- static void print_is_also_tied() { SERIAL_PROTOCOLPGM(" is also tied to this pin"); SERIAL_PROTOCOL_SP(14); }
|
284
|
|
-#endif
|
285
|
|
-
|
286
|
|
-void com_print(uint8_t N, uint8_t Z) {
|
287
|
|
- const uint8_t *TCCRA = (uint8_t*)TCCR_A(N);
|
288
|
|
- SERIAL_PROTOCOLPGM(" COM");
|
289
|
|
- SERIAL_PROTOCOLCHAR(N + '0');
|
290
|
|
- switch (Z) {
|
291
|
|
- case 'A':
|
292
|
|
- SERIAL_PROTOCOLPAIR("A: ", ((*TCCRA & (_BV(7) | _BV(6))) >> 6));
|
293
|
|
- break;
|
294
|
|
- case 'B':
|
295
|
|
- SERIAL_PROTOCOLPAIR("B: ", ((*TCCRA & (_BV(5) | _BV(4))) >> 4));
|
296
|
|
- break;
|
297
|
|
- case 'C':
|
298
|
|
- SERIAL_PROTOCOLPAIR("C: ", ((*TCCRA & (_BV(3) | _BV(2))) >> 2));
|
299
|
|
- break;
|
300
|
|
- }
|
301
|
|
-}
|
302
|
|
-
|
303
|
|
-void timer_prefix(uint8_t T, char L, uint8_t N) { // T - timer L - pwm N - WGM bit layout
|
304
|
|
- char buffer[20]; // for the sprintf statements
|
305
|
|
- const uint8_t *TCCRB = (uint8_t*)TCCR_B(T),
|
306
|
|
- *TCCRA = (uint8_t*)TCCR_A(T);
|
307
|
|
- uint8_t WGM = (((*TCCRB & _BV(WGM_2)) >> 1) | (*TCCRA & (_BV(WGM_0) | _BV(WGM_1))));
|
308
|
|
- if (N == 4) WGM |= ((*TCCRB & _BV(WGM_3)) >> 1);
|
309
|
|
-
|
310
|
|
- SERIAL_PROTOCOLPGM(" TIMER");
|
311
|
|
- SERIAL_PROTOCOLCHAR(T + '0');
|
312
|
|
- SERIAL_PROTOCOLCHAR(L);
|
313
|
|
- SERIAL_PROTOCOL_SP(3);
|
314
|
|
-
|
315
|
|
- if (N == 3) {
|
316
|
|
- const uint8_t *OCRVAL8 = (uint8_t*)OCR_VAL(T, L - 'A');
|
317
|
|
- PWM_PRINT(*OCRVAL8);
|
318
|
|
- }
|
319
|
|
- else {
|
320
|
|
- const uint16_t *OCRVAL16 = (uint16_t*)OCR_VAL(T, L - 'A');
|
321
|
|
- PWM_PRINT(*OCRVAL16);
|
322
|
|
- }
|
323
|
|
- SERIAL_PROTOCOLPAIR(" WGM: ", WGM);
|
324
|
|
- com_print(T,L);
|
325
|
|
- SERIAL_PROTOCOLPAIR(" CS: ", (*TCCRB & (_BV(CS_0) | _BV(CS_1) | _BV(CS_2)) ));
|
326
|
|
-
|
327
|
|
- SERIAL_PROTOCOLPGM(" TCCR");
|
328
|
|
- SERIAL_PROTOCOLCHAR(T + '0');
|
329
|
|
- SERIAL_PROTOCOLPAIR("A: ", *TCCRA);
|
330
|
|
-
|
331
|
|
- SERIAL_PROTOCOLPGM(" TCCR");
|
332
|
|
- SERIAL_PROTOCOLCHAR(T + '0');
|
333
|
|
- SERIAL_PROTOCOLPAIR("B: ", *TCCRB);
|
334
|
|
-
|
335
|
|
- const uint8_t *TMSK = (uint8_t*)TIMSK(T);
|
336
|
|
- SERIAL_PROTOCOLPGM(" TIMSK");
|
337
|
|
- SERIAL_PROTOCOLCHAR(T + '0');
|
338
|
|
- SERIAL_PROTOCOLPAIR(": ", *TMSK);
|
339
|
|
-
|
340
|
|
- const uint8_t OCIE = L - 'A' + 1;
|
341
|
|
- if (N == 3) { if (WGM == 0 || WGM == 2 || WGM == 4 || WGM == 6) err_is_counter(); }
|
342
|
|
- else { if (WGM == 0 || WGM == 4 || WGM == 12 || WGM == 13) err_is_counter(); }
|
343
|
|
- if (TEST(*TMSK, OCIE)) err_is_interrupt();
|
344
|
|
- if (TEST(*TMSK, TOIE)) err_prob_interrupt();
|
345
|
|
-}
|
346
|
|
-
|
347
|
|
-static void HAL_pwm_details(uint8_t pin) {
|
348
|
|
- switch (digitalPinToTimer_DEBUG(pin)) {
|
349
|
|
-
|
350
|
|
- #if defined(TCCR0A) && defined(COM0A1)
|
351
|
|
- #ifdef TIMER0A
|
352
|
|
- #if !AVR_AT90USB1286_FAMILY // not available in Teensyduino type IDEs
|
353
|
|
- case TIMER0A: timer_prefix(0, 'A', 3); break;
|
354
|
|
- #endif
|
355
|
|
- #endif
|
356
|
|
- case TIMER0B: timer_prefix(0, 'B', 3); break;
|
357
|
|
- #endif
|
358
|
|
-
|
359
|
|
- #if defined(TCCR1A) && defined(COM1A1)
|
360
|
|
- case TIMER1A: timer_prefix(1, 'A', 4); break;
|
361
|
|
- case TIMER1B: timer_prefix(1, 'B', 4); break;
|
362
|
|
- #if defined(COM1C1) && defined(TIMER1C)
|
363
|
|
- case TIMER1C: timer_prefix(1, 'C', 4); break;
|
364
|
|
- #endif
|
365
|
|
- #endif
|
366
|
|
-
|
367
|
|
- #if defined(TCCR2A) && defined(COM2A1)
|
368
|
|
- case TIMER2A: timer_prefix(2, 'A', 3); break;
|
369
|
|
- case TIMER2B: timer_prefix(2, 'B', 3); break;
|
370
|
|
- #endif
|
371
|
|
-
|
372
|
|
- #if defined(TCCR3A) && defined(COM3A1)
|
373
|
|
- case TIMER3A: timer_prefix(3, 'A', 4); break;
|
374
|
|
- case TIMER3B: timer_prefix(3, 'B', 4); break;
|
375
|
|
- #ifdef COM3C1
|
376
|
|
- case TIMER3C: timer_prefix(3, 'C', 4); break;
|
377
|
|
- #endif
|
378
|
|
- #endif
|
379
|
|
-
|
380
|
|
- #ifdef TCCR4A
|
381
|
|
- case TIMER4A: timer_prefix(4, 'A', 4); break;
|
382
|
|
- case TIMER4B: timer_prefix(4, 'B', 4); break;
|
383
|
|
- case TIMER4C: timer_prefix(4, 'C', 4); break;
|
384
|
|
- #endif
|
385
|
|
-
|
386
|
|
- #if defined(TCCR5A) && defined(COM5A1)
|
387
|
|
- case TIMER5A: timer_prefix(5, 'A', 4); break;
|
388
|
|
- case TIMER5B: timer_prefix(5, 'B', 4); break;
|
389
|
|
- case TIMER5C: timer_prefix(5, 'C', 4); break;
|
390
|
|
- #endif
|
391
|
|
-
|
392
|
|
- case NOT_ON_TIMER: break;
|
393
|
|
-
|
394
|
|
- }
|
395
|
|
- SERIAL_PROTOCOLPGM(" ");
|
396
|
|
-
|
397
|
|
- // on pins that have two PWMs, print info on second PWM
|
398
|
|
- #if AVR_ATmega2560_FAMILY || AVR_AT90USB1286_FAMILY
|
399
|
|
- // looking for port B7 - PWMs 0A and 1C
|
400
|
|
- if (digitalPinToPort_DEBUG(pin) == 'B' - 64 && 0x80 == digitalPinToBitMask_DEBUG(pin)) {
|
401
|
|
- #if !AVR_AT90USB1286_FAMILY
|
402
|
|
- SERIAL_PROTOCOLPGM("\n .");
|
403
|
|
- SERIAL_PROTOCOL_SP(18);
|
404
|
|
- SERIAL_PROTOCOLPGM("TIMER1C");
|
405
|
|
- print_is_also_tied();
|
406
|
|
- timer_prefix(1, 'C', 4);
|
407
|
|
- #else
|
408
|
|
- SERIAL_PROTOCOLPGM("\n .");
|
409
|
|
- SERIAL_PROTOCOL_SP(18);
|
410
|
|
- SERIAL_PROTOCOLPGM("TIMER0A");
|
411
|
|
- print_is_also_tied();
|
412
|
|
- timer_prefix(0, 'A', 3);
|
413
|
|
- #endif
|
414
|
|
- }
|
415
|
|
- #endif
|
416
|
|
-} // pwm_details
|
417
|
|
-
|
418
|
|
-#ifndef digitalRead_mod // Use Teensyduino's version of digitalRead - it doesn't disable the PWMs
|
419
|
|
- int digitalRead_mod(const int8_t pin) { // same as digitalRead except the PWM stop section has been removed
|
420
|
|
- const uint8_t port = digitalPinToPort_DEBUG(pin);
|
421
|
|
- return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask_DEBUG(pin)) ? HIGH : LOW;
|
422
|
|
- }
|
423
|
|
-#endif
|
424
|
|
-
|
425
|
|
-void print_port(int8_t pin) { // print port number
|
426
|
|
- #ifdef digitalPinToPort_DEBUG
|
427
|
|
- uint8_t x;
|
428
|
|
- SERIAL_PROTOCOLPGM(" Port: ");
|
429
|
|
- #if AVR_AT90USB1286_FAMILY
|
430
|
|
- x = (pin == 46 || pin == 47) ? 'E' : digitalPinToPort_DEBUG(pin) + 64;
|
431
|
|
- #else
|
432
|
|
- x = digitalPinToPort_DEBUG(pin) + 64;
|
433
|
|
- #endif
|
434
|
|
- SERIAL_CHAR(x);
|
435
|
|
-
|
436
|
|
- #if AVR_AT90USB1286_FAMILY
|
437
|
|
- if (pin == 46)
|
438
|
|
- x = '2';
|
439
|
|
- else if (pin == 47)
|
440
|
|
- x = '3';
|
441
|
|
- else {
|
442
|
|
- uint8_t temp = digitalPinToBitMask_DEBUG(pin);
|
443
|
|
- for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
|
444
|
|
- }
|
445
|
|
- #else
|
446
|
|
- uint8_t temp = digitalPinToBitMask_DEBUG(pin);
|
447
|
|
- for (x = '0'; x < '9' && temp != 1; x++) temp >>= 1;
|
448
|
|
- #endif
|
449
|
|
- SERIAL_CHAR(x);
|
450
|
|
- #else
|
451
|
|
- SERIAL_PROTOCOL_SP(10);
|
452
|
|
- #endif
|
453
|
|
-}
|
454
|
|
-
|
455
|
|
-static void print_input_or_output(const bool isout) {
|
456
|
|
- serialprintPGM(isout ? PSTR("Output = ") : PSTR("Input = "));
|
457
|
|
-}
|
458
|
|
-
|
459
|
|
-// pretty report with PWM info
|
460
|
|
-inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = false, const char *start_string = "") {
|
461
|
|
- uint8_t temp_char;
|
462
|
|
- char *name_mem_pointer, buffer[30]; // for the sprintf statements
|
463
|
|
- bool found = false, multi_name_pin = false;
|
464
|
|
- for (uint8_t x = 0; x < COUNT(pin_array); x++) { // scan entire array and report all instances of this pin
|
465
|
|
- if (pgm_read_byte(&pin_array[x].pin) == pin) {
|
466
|
|
- if (found) multi_name_pin = true;
|
467
|
|
- found = true;
|
468
|
|
- if (!multi_name_pin) { // report digitial and analog pin number only on the first time through
|
469
|
|
- sprintf_P(buffer, PSTR("%sPIN: %3d "), start_string, pin); // digital pin number
|
470
|
|
- SERIAL_ECHO(buffer);
|
471
|
|
- print_port(pin);
|
472
|
|
- if (IS_ANALOG(pin)) {
|
473
|
|
- sprintf_P(buffer, PSTR(" (A%2d) "), int(pin - analogInputToDigitalPin(0))); // analog pin number
|
474
|
|
- SERIAL_ECHO(buffer);
|
475
|
|
- }
|
476
|
|
- else SERIAL_ECHO_SP(8); // add padding if not an analog pin
|
477
|
|
- }
|
478
|
|
- else {
|
479
|
|
- SERIAL_CHAR('.');
|
480
|
|
- SERIAL_ECHO_SP(26 + strlen(start_string)); // add padding if not the first instance found
|
481
|
|
- }
|
482
|
|
- name_mem_pointer = (char*)pgm_read_ptr(&pin_array[x].name);
|
483
|
|
- for (uint8_t y = 0; y < 28; y++) { // always print pin name
|
484
|
|
- temp_char = pgm_read_byte(name_mem_pointer + y);
|
485
|
|
- if (temp_char != 0)
|
486
|
|
- SERIAL_CHAR(temp_char);
|
487
|
|
- else {
|
488
|
|
- for (uint8_t i = 0; i < 28 - y; i++) SERIAL_CHAR(' ');
|
489
|
|
- break;
|
490
|
|
- }
|
491
|
|
- }
|
492
|
|
- if (extended) {
|
493
|
|
- if (pin_is_protected(pin) && !ignore)
|
494
|
|
- SERIAL_ECHOPGM("protected ");
|
495
|
|
- else {
|
496
|
|
- #if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO
|
497
|
|
- if (pin == 46 || pin == 47) {
|
498
|
|
- if (pin == 46) {
|
499
|
|
- print_input_or_output(GET_OUTPUT(46));
|
500
|
|
- SERIAL_PROTOCOL(READ(46));
|
501
|
|
- }
|
502
|
|
- else if (pin == 47) {
|
503
|
|
- print_input_or_output(GET_OUTPUT(47));
|
504
|
|
- SERIAL_PROTOCOL(READ(47));
|
505
|
|
- }
|
506
|
|
- }
|
507
|
|
- else
|
508
|
|
- #endif
|
509
|
|
- {
|
510
|
|
- if (!(pgm_read_byte(&pin_array[x].is_digital))) {
|
511
|
|
- sprintf_P(buffer, PSTR("Analog in = %5d"), analogRead(pin - analogInputToDigitalPin(0)));
|
512
|
|
- SERIAL_ECHO(buffer);
|
513
|
|
- }
|
514
|
|
- else {
|
515
|
|
-
|
516
|
|
- if (!get_pinMode(pin)) {
|
517
|
|
- //pinMode(pin, INPUT_PULLUP); // make sure input isn't floating - stopped doing this
|
518
|
|
- // because this could interfere with inductive/capacitive
|
519
|
|
- // sensors (high impedance voltage divider) and with PT100 amplifier
|
520
|
|
- print_input_or_output(false);
|
521
|
|
- SERIAL_PROTOCOL(digitalRead_mod(pin));
|
522
|
|
- }
|
523
|
|
- else if (HAL_pwm_status(pin)) {
|
524
|
|
- // do nothing
|
525
|
|
- }
|
526
|
|
- else {
|
527
|
|
- print_input_or_output(true);
|
528
|
|
- SERIAL_PROTOCOL(digitalRead_mod(pin));
|
529
|
|
- }
|
530
|
|
- }
|
531
|
|
- if (!multi_name_pin && extended) HAL_pwm_details(pin); // report PWM capabilities only on the first pass & only if doing an extended report
|
532
|
|
- }
|
533
|
|
- }
|
534
|
|
- }
|
535
|
|
- SERIAL_EOL();
|
536
|
|
- } // end of IF
|
537
|
|
- } // end of for loop
|
538
|
|
-
|
539
|
|
- if (!found) {
|
540
|
|
- sprintf_P(buffer, PSTR("%sPIN: %3d "), start_string, pin);
|
541
|
|
- SERIAL_ECHO(buffer);
|
542
|
|
- print_port(pin);
|
543
|
|
- if (IS_ANALOG(pin)) {
|
544
|
|
- sprintf_P(buffer, PSTR(" (A%2d) "), int(pin - analogInputToDigitalPin(0))); // analog pin number
|
545
|
|
- SERIAL_ECHO(buffer);
|
546
|
|
- }
|
547
|
|
- else
|
548
|
|
- SERIAL_ECHO_SP(8); // add padding if not an analog pin
|
549
|
|
- SERIAL_ECHOPGM("<unused/unknown>");
|
550
|
|
- if (extended) {
|
551
|
|
- #if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO
|
552
|
|
- if (pin == 46 || pin == 47) {
|
553
|
|
- SERIAL_PROTOCOL_SP(12);
|
554
|
|
- if (pin == 46) {
|
555
|
|
- print_input_or_output(GET_OUTPUT(46));
|
556
|
|
- SERIAL_PROTOCOL(READ(46));
|
557
|
|
- }
|
558
|
|
- else {
|
559
|
|
- print_input_or_output(GET_OUTPUT(47));
|
560
|
|
- SERIAL_PROTOCOL(READ(47));
|
561
|
|
- }
|
562
|
|
- }
|
563
|
|
- else
|
564
|
|
- #endif
|
565
|
|
- {
|
566
|
|
- if (get_pinMode(pin)) {
|
567
|
|
- SERIAL_PROTOCOL_SP(12);
|
568
|
|
- print_input_or_output(true);
|
569
|
|
- SERIAL_PROTOCOL(digitalRead_mod(pin));
|
570
|
|
- }
|
571
|
|
- else {
|
572
|
|
- if (IS_ANALOG(pin)) {
|
573
|
|
- sprintf_P(buffer, PSTR(" Analog in = %5d"), analogRead(pin - analogInputToDigitalPin(0)));
|
574
|
|
- SERIAL_ECHO(buffer);
|
575
|
|
- SERIAL_ECHOPGM(" ");
|
576
|
|
- }
|
577
|
|
- else
|
578
|
|
- SERIAL_ECHO_SP(12); // add padding if not an analog pin
|
579
|
|
-
|
580
|
|
- print_input_or_output(false);
|
581
|
|
- SERIAL_PROTOCOL(digitalRead_mod(pin));
|
582
|
|
- }
|
583
|
|
- //if (!pwm_status(pin)) SERIAL_CHAR(' '); // add padding if it's not a PWM pin
|
584
|
|
- if (extended) pwm_details(pin); // report PWM capabilities only if doing an extended report
|
585
|
|
- }
|
586
|
|
- }
|
587
|
|
- SERIAL_EOL();
|
588
|
|
- }
|
589
|
|
-}
|
590
|
|
-
|
591
|
|
-#endif // _HAL_PINSDEBUG_AVR_H_
|