|
@@ -80,16 +80,16 @@ bool endstop_monitor_flag = false;
|
80
|
80
|
|
81
|
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
|
93
|
#if SERIAL_PORT == 0
|
94
|
94
|
#if AVR_ATmega2560_FAMILY
|
95
|
95
|
{RXD_NAME, 0, 1},
|
|
@@ -109,7 +109,8 @@ const char* const pin_array[][3] PROGMEM = {
|
109
|
109
|
|
110
|
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
|
114
|
#include "pinsDebug_Teensyduino.h"
|
114
|
115
|
#endif
|
115
|
116
|
|
|
@@ -132,7 +133,7 @@ static bool pwm_status(uint8_t pin) {
|
132
|
133
|
switch(digitalPinToTimer(pin)) {
|
133
|
134
|
|
134
|
135
|
#if defined(TCCR0A) && defined(COM0A1)
|
135
|
|
- #if defined (TIMER0A)
|
|
136
|
+ #ifdef TIMER0A
|
136
|
137
|
PWM_CASE(0,A);
|
137
|
138
|
#endif
|
138
|
139
|
PWM_CASE(0,B);
|
|
@@ -141,7 +142,7 @@ static bool pwm_status(uint8_t pin) {
|
141
|
142
|
#if defined(TCCR1A) && defined(COM1A1)
|
142
|
143
|
PWM_CASE(1,A);
|
143
|
144
|
PWM_CASE(1,B);
|
144
|
|
- #if defined(COM1C1) && defined (TIMER1C)
|
|
145
|
+ #if defined(COM1C1) && defined(TIMER1C)
|
145
|
146
|
PWM_CASE(1,C);
|
146
|
147
|
#endif
|
147
|
148
|
#endif
|
|
@@ -200,13 +201,13 @@ const uint8_t* const PWM_other[][3] PROGMEM = {
|
200
|
201
|
|
201
|
202
|
const uint8_t* const PWM_OCR[][3] PROGMEM = {
|
202
|
203
|
|
203
|
|
- #if defined (TIMER0A)
|
|
204
|
+ #ifdef TIMER0A
|
204
|
205
|
{&OCR0A,&OCR0B,0},
|
205
|
206
|
#else
|
206
|
207
|
{0,&OCR0B,0},
|
207
|
208
|
#endif
|
208
|
209
|
|
209
|
|
- #if defined(COM1C1) && defined (TIMER1C)
|
|
210
|
+ #if defined(COM1C1) && defined(TIMER1C)
|
210
|
211
|
{ (const uint8_t*) &OCR1A, (const uint8_t*) &OCR1B, (const uint8_t*) &OCR1C},
|
211
|
212
|
#else
|
212
|
213
|
{ (const uint8_t*) &OCR1A, (const uint8_t*) &OCR1B,0},
|
|
@@ -217,7 +218,7 @@ const uint8_t* const PWM_OCR[][3] PROGMEM = {
|
217
|
218
|
#endif
|
218
|
219
|
|
219
|
220
|
#if defined(TCCR3A) && defined(COM3A1)
|
220
|
|
- #if defined(COM3C1)
|
|
221
|
+ #ifdef COM3C1
|
221
|
222
|
{ (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B, (const uint8_t*) &OCR3C},
|
222
|
223
|
#else
|
223
|
224
|
{ (const uint8_t*) &OCR3A, (const uint8_t*) &OCR3B,0},
|
|
@@ -279,12 +280,12 @@ void com_print(uint8_t N, uint8_t Z) {
|
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
|
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
|
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
|
290
|
SERIAL_PROTOCOLPGM(" TIMER");
|
290
|
291
|
SERIAL_PROTOCOLCHAR(T + '0');
|
|
@@ -323,18 +324,15 @@ void timer_prefix(uint8_t T, char L, uint8_t N){ // T - timer L - pwm n - W
|
323
|
324
|
if (TEST(*TMSK, TOIE)) err_prob_interrupt();
|
324
|
325
|
}
|
325
|
326
|
|
326
|
|
-
|
327
|
|
-
|
328
|
327
|
static void pwm_details(uint8_t pin) {
|
329
|
328
|
char buffer[20]; // for the sprintf statements
|
330
|
329
|
uint8_t WGM;
|
331
|
330
|
|
332
|
331
|
switch(digitalPinToTimer(pin)) {
|
333
|
332
|
|
334
|
|
-
|
335
|
333
|
#if defined(TCCR0A) && defined(COM0A1)
|
336
|
334
|
|
337
|
|
- #if defined (TIMER0A)
|
|
335
|
+ #ifdef TIMER0A
|
338
|
336
|
case TIMER0A:
|
339
|
337
|
timer_prefix(0,'A',3);
|
340
|
338
|
break;
|
|
@@ -351,7 +349,7 @@ static void pwm_details(uint8_t pin) {
|
351
|
349
|
case TIMER1B:
|
352
|
350
|
timer_prefix(1,'B',4);
|
353
|
351
|
break;
|
354
|
|
- #if defined(COM1C1) && defined (TIMER1C)
|
|
352
|
+ #if defined(COM1C1) && defined(TIMER1C)
|
355
|
353
|
case TIMER1C:
|
356
|
354
|
timer_prefix(1,'C',4);
|
357
|
355
|
break;
|
|
@@ -374,7 +372,7 @@ static void pwm_details(uint8_t pin) {
|
374
|
372
|
case TIMER3B:
|
375
|
373
|
timer_prefix(3,'B',4);
|
376
|
374
|
break;
|
377
|
|
- #if defined(COM3C1)
|
|
375
|
+ #ifdef COM3C1
|
378
|
376
|
case TIMER3C:
|
379
|
377
|
timer_prefix(3,'C',4);
|
380
|
378
|
break;
|
|
@@ -410,17 +408,15 @@ static void pwm_details(uint8_t pin) {
|
410
|
408
|
}
|
411
|
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
|
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
|
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
|
417
|
timer_prefix(1,'C',4);
|
421
|
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
|
420
|
timer_prefix(0,'A',3);
|
425
|
421
|
#endif
|
426
|
422
|
}
|
|
@@ -429,7 +425,7 @@ static void pwm_details(uint8_t pin) {
|
429
|
425
|
|
430
|
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
|
429
|
int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
|
434
|
430
|
uint8_t port = digitalPinToPort(pin);
|
435
|
431
|
return (port != NOT_A_PIN) && (*portInputRegister(port) & digitalPinToBitMask(pin)) ? HIGH : LOW;
|
|
@@ -437,34 +433,31 @@ bool get_pinMode(int8_t pin) { return *portModeRegister(digitalPinToPort(pin)) &
|
437
|
433
|
#endif
|
438
|
434
|
|
439
|
435
|
void print_port(int8_t pin) { // print port number
|
440
|
|
- #if defined(digitalPinToPort)
|
|
436
|
+ #ifdef digitalPinToPort
|
441
|
437
|
SERIAL_PROTOCOLPGM(" Port: ");
|
442
|
438
|
uint8_t x = digitalPinToPort(pin) + 64;
|
443
|
439
|
SERIAL_CHAR(x);
|
444
|
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
|
442
|
SERIAL_CHAR(x);
|
449
|
443
|
#else
|
450
|
|
- SERIAL_PROTOCOLPGM(" ")
|
|
444
|
+ SERIAL_PROTOCOLPGM(" ");
|
451
|
445
|
#endif
|
452
|
446
|
}
|
453
|
447
|
|
454
|
|
-
|
455
|
448
|
// pretty report with PWM info
|
456
|
449
|
inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = true) {
|
457
|
450
|
uint8_t temp_char;
|
458
|
451
|
char *name_mem_pointer;
|
459
|
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
|
455
|
for (uint8_t x = 0; x < n_array; x++) { // scan entire array and report all instances of this pin
|
463
|
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
|
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
|
461
|
SERIAL_ECHO(buffer);
|
469
|
462
|
print_port(pin);
|
470
|
463
|
if (IS_ANALOG(pin)) {
|
|
@@ -479,7 +472,7 @@ inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = t
|
479
|
472
|
temp_char = pgm_read_byte(name_mem_pointer + y);
|
480
|
473
|
if (temp_char != 0) MYSERIAL.write(temp_char);
|
481
|
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
|
476
|
break;
|
484
|
477
|
}
|
485
|
478
|
}
|
|
@@ -487,12 +480,12 @@ inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = t
|
487
|
480
|
SERIAL_ECHOPGM("protected ");
|
488
|
481
|
else {
|
489
|
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
|
484
|
SERIAL_ECHO(buffer);
|
492
|
485
|
}
|
493
|
486
|
else {
|
494
|
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
|
489
|
// because this could interfere with inductive/capacitive
|
497
|
490
|
// sensors (high impedance voltage divider) and with PT100 amplifier
|
498
|
491
|
SERIAL_PROTOCOLPAIR("Input = ", digitalRead_mod(pin));
|
|
@@ -502,43 +495,41 @@ inline void report_pin_state_extended(int8_t pin, bool ignore, bool extended = t
|
502
|
495
|
}
|
503
|
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
|
500
|
SERIAL_EOL;
|
508
|
501
|
} // end of IF
|
509
|
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
|
506
|
SERIAL_ECHO(buffer);
|
514
|
507
|
print_port(pin);
|
515
|
508
|
if (IS_ANALOG(pin)) {
|
516
|
509
|
sprintf(buffer, " (A%2d) ", int(pin - analogInputToDigitalPin(0))); // analog pin number
|
517
|
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
|
514
|
SERIAL_ECHOPGM("<unused/unknown>");
|
521
|
|
- if (get_pinMode(pin)) {
|
|
515
|
+ if (get_pinMode(pin))
|
522
|
516
|
SERIAL_PROTOCOLPAIR(" Output = ", digitalRead_mod(pin));
|
523
|
|
- }
|
524
|
517
|
else {
|
525
|
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
|
520
|
SERIAL_ECHO(buffer);
|
528
|
521
|
}
|
529
|
|
- else {
|
|
522
|
+ else
|
530
|
523
|
SERIAL_ECHOPGM(" "); // add padding if not an analog pin
|
531
|
|
- }
|
|
524
|
+
|
532
|
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
|
528
|
if (extended) pwm_details(pin); // report PWM capabilities only if doing an extended report
|
536
|
529
|
SERIAL_EOL;
|
537
|
530
|
}
|
538
|
531
|
}
|
539
|
532
|
|
540
|
533
|
inline void report_pin_state(int8_t pin) {
|
541
|
|
-
|
542
|
534
|
report_pin_state_extended(pin, false, false);
|
543
|
|
-
|
544
|
535
|
}
|