From ae706233a8bf4590a2e25468f0283f41194bdc5a Mon Sep 17 00:00:00 2001 From: Bob-the-Kuhn Date: Thu, 5 Jan 2017 23:38:30 -0600 Subject: [PATCH] pinsDebug for 644/1284 & USB646/1286 families added conditional compilation for PWMs 1C & 3C add Teensyduino compatibility ========================================== changes per review - minor formatting changes 1) remove non-printable character at the end of line 687 2) split a really long comment into two lines 3) got rid of some trailing spaces ============================================ Made pinsDebug_Teensyduino.h the same between this PR and PR 5668 which is for a re-written pinsDebug.h file. The changes were: 1) added copyright @ GNU license header 2) a blank line crept in. --- Marlin/pinsDebug.h | 43 ++++++++----- Marlin/pinsDebug_Teensyduino.h | 110 +++++++++++++++++++++++++++++++++ 2 files changed, 137 insertions(+), 16 deletions(-) create mode 100644 Marlin/pinsDebug_Teensyduino.h diff --git a/Marlin/pinsDebug.h b/Marlin/pinsDebug.h index eb5584d65..b4016437a 100644 --- a/Marlin/pinsDebug.h +++ b/Marlin/pinsDebug.h @@ -22,6 +22,10 @@ bool endstop_monitor_flag = false; +#if !defined(TIMER1B) // working with Teensyduino extension so need to re-define some things + #include "pinsDebug_Teensyduino.h" +#endif + #define NAME_FORMAT "%-28s" // one place to specify the format of all the sources of names // "-" left justify, "28" minimum width of name, pad with blanks @@ -683,7 +687,9 @@ static bool pwm_status(uint8_t pin) { #if defined(TCCR1A) && defined(COM1A1) PWM_CASE(1,A); PWM_CASE(1,B); - PWM_CASE(1,C); + #if defined(COM1C1) && defined(TIMER1C) + PWM_CASE(1,C); + #endif #endif #if defined(TCCR2A) && defined(COM2A1) @@ -694,7 +700,9 @@ static bool pwm_status(uint8_t pin) { #if defined(TCCR3A) && defined(COM3A1) PWM_CASE(3,A); PWM_CASE(3,B); - PWM_CASE(3,C); + #if defined(COM3C1) + PWM_CASE(3,C); + #endif #endif #ifdef TCCR4A @@ -778,13 +786,15 @@ static void pwm_details(uint8_t pin) { else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1))) err_prob_interrupt(); else can_be_used(); break; - case TIMER1C: - TIMER_PREFIX(1,C,4); - if (WGM_TEST2) err_is_counter(); - else if (TEST(TIMSK1, OCIE1C)) err_is_interrupt(); - else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1))) err_prob_interrupt(); - else can_be_used(); - break; + #if defined(COM1C1) && defined(TIMER1C) + case TIMER1C: + TIMER_PREFIX(1,C,4); + if (WGM_TEST2) err_is_counter(); + else if (TEST(TIMSK1, OCIE1C)) err_is_interrupt(); + else if (TIMSK1 & (_BV(TOIE1) | _BV(ICIE1))) err_prob_interrupt(); + else can_be_used(); + break; + #endif #endif #if defined(TCCR2A) && defined(COM2A1) @@ -819,13 +829,15 @@ static void pwm_details(uint8_t pin) { else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3))) err_prob_interrupt(); else can_be_used(); break; + #if defined(COM3C1) case TIMER3C: - TIMER_PREFIX(3,C,3); - if (WGM_TEST2) err_is_counter(); - else if (TEST(TIMSK3, OCIE3C)) err_is_interrupt(); - else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3))) err_prob_interrupt(); - else can_be_used(); - break; + TIMER_PREFIX(3,C,3); + if (WGM_TEST2) err_is_counter(); + else if (TEST(TIMSK3, OCIE3C)) err_is_interrupt(); + else if (TIMSK3 & (_BV(TOIE3) | _BV(ICIE3))) err_prob_interrupt(); + else can_be_used(); + break; + #endif #endif #ifdef TCCR4A @@ -942,4 +954,3 @@ inline void report_pin_state_extended(int8_t pin, bool ignore) { pwm_details(pin); SERIAL_EOL; } - diff --git a/Marlin/pinsDebug_Teensyduino.h b/Marlin/pinsDebug_Teensyduino.h new file mode 100644 index 000000000..fc5c03abe --- /dev/null +++ b/Marlin/pinsDebug_Teensyduino.h @@ -0,0 +1,110 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +// +// some of the pin mapping functions of the Teensduino extension to the Arduino IDE +// do not function the same as the other Arduino extensions +// + + +#define TEENSYDUINO_IDE + +//digitalPinToTimer(pin) function works like Arduino but Timers are not defined +#define TIMER0B 1 +#define TIMER1A 7 +#define TIMER1B 8 +#define TIMER1C 9 +#define TIMER2A 6 +#define TIMER2B 2 +#define TIMER3A 5 +#define TIMER3B 4 +#define TIMER3C 3 + +// digitalPinToPort function just returns the pin number so need to create our own +#define PA 1 +#define PB 2 +#define PC 3 +#define PD 4 +#define PE 5 +#define PF 6 + +#undef digitalPinToPort + +const uint8_t PROGMEM digital_pin_to_port_PGM[] = { + PD, // 0 - PD0 - INT0 - PWM + PD, // 1 - PD1 - INT1 - PWM + PD, // 2 - PD2 - INT2 - RX + PD, // 3 - PD3 - INT3 - TX + PD, // 4 - PD4 + PD, // 5 - PD5 + PD, // 6 - PD6 + PD, // 7 - PD7 + PE, // 8 - PE0 + PE, // 9 - PE1 + PC, // 10 - PC0 + PC, // 11 - PC1 + PC, // 12 - PC2 + PC, // 13 - PC3 + PC, // 14 - PC4 - PWM + PC, // 15 - PC5 - PWM + PC, // 16 - PC6 - PWM + PC, // 17 - PC7 + PE, // 18 - PE6 - INT6 + PE, // 19 - PE7 - INT7 + PB, // 20 - PB0 + PB, // 21 - PB1 + PB, // 22 - PB2 + PB, // 23 - PB3 + PB, // 24 - PB4 - PWM + PB, // 25 - PB5 - PWM + PB, // 26 - PB6 - PWM + PB, // 27 - PB7 - PWM + PA, // 28 - PA0 + PA, // 29 - PA1 + PA, // 30 - PA2 + PA, // 31 - PA3 + PA, // 32 - PA4 + PA, // 33 - PA5 + PA, // 34 - PA6 + PA, // 35 - PA7 + PE, // 36 - PE4 - INT4 + PE, // 37 - PE5 - INT5 + PF, // 38 - PF0 - A0 + PF, // 39 - PF1 - A1 + PF, // 40 - PF2 - A2 + PF, // 41 - PF3 - A3 + PF, // 42 - PF4 - A4 + PF, // 43 - PF5 - A5 + PF, // 44 - PF6 - A6 + PF, // 45 - PF7 - A7 + PE, // 46 - PE2 (not defined in teensyduino) + PE, // 47 - PE3 (not defined in teensyduino) +}; + +#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) ) + +// digitalPinToBitMask(pin) is OK + +#define digitalRead_mod(p) digitalRead(p) // Teensyduino's version of digitalRead doesn't + // disable the PWMs so we can use it as is + +// portModeRegister(pin) is OK