My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

HAL_pinsDebug_AVR.h 20KB

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