My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

HAL_pinsDebug_AVR.h 20KB

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