My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

pinsDebug.h 18KB

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