My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pinsDebug.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #include "../inc/MarlinConfig.h"
  20. #define MAX_NAME_LENGTH 39 // one place to specify the format of all the sources of names
  21. // "-" left justify, "39" minimum width of name, pad with blanks
  22. /**
  23. * This routine minimizes RAM usage by creating a FLASH resident array to
  24. * store the pin names, pin numbers and analog/digital flag.
  25. *
  26. * Creating the array in FLASH is a two pass process. The first pass puts the
  27. * name strings into FLASH. The second pass actually creates the array.
  28. *
  29. * Both passes use the same pin list. The list contains two macro names. The
  30. * actual macro definitions are changed depending on which pass is being done.
  31. *
  32. */
  33. // first pass - put the name strings into FLASH
  34. #define _ADD_PIN_2(PIN_NAME, ENTRY_NAME) static const char ENTRY_NAME[] PROGMEM = { PIN_NAME };
  35. #define _ADD_PIN(PIN_NAME, COUNTER) _ADD_PIN_2(PIN_NAME, entry_NAME_##COUNTER)
  36. #define REPORT_NAME_DIGITAL(COUNTER, NAME) _ADD_PIN(#NAME, COUNTER)
  37. #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(#NAME, COUNTER)
  38. #include "pinsDebug_list.h"
  39. #line 46
  40. // manually add pins that have names that are macros which don't play well with these macros
  41. #if (AVR_ATmega2560_FAMILY || AVR_ATmega1284_FAMILY || defined(ARDUINO_ARCH_SAM))
  42. #if SERIAL_PORT == 0
  43. static const char RXD_NAME_0[] PROGMEM = { "RXD0" };
  44. static const char TXD_NAME_0[] PROGMEM = { "TXD0" };
  45. #elif SERIAL_PORT == 1
  46. static const char RXD_NAME_1[] PROGMEM = { "RXD1" };
  47. static const char TXD_NAME_1[] PROGMEM = { "TXD1" };
  48. #elif SERIAL_PORT == 2
  49. static const char RXD_NAME_2[] PROGMEM = { "RXD2" };
  50. static const char TXD_NAME_2[] PROGMEM = { "TXD2" };
  51. #elif SERIAL_PORT == 3
  52. static const char RXD_NAME_3[] PROGMEM = { "RXD3" };
  53. static const char TXD_NAME_3[] PROGMEM = { "TXD3" };
  54. #endif
  55. #ifdef SERIAL_PORT_2
  56. #if SERIAL_PORT_2 == 0
  57. static const char RXD_NAME_0[] PROGMEM = { "RXD0" };
  58. static const char TXD_NAME_0[] PROGMEM = { "TXD0" };
  59. #elif SERIAL_PORT_2 == 1
  60. static const char RXD_NAME_1[] PROGMEM = { "RXD1" };
  61. static const char TXD_NAME_1[] PROGMEM = { "TXD1" };
  62. #elif SERIAL_PORT_2 == 2
  63. static const char RXD_NAME_2[] PROGMEM = { "RXD2" };
  64. static const char TXD_NAME_2[] PROGMEM = { "TXD2" };
  65. #elif SERIAL_PORT_2 == 3
  66. static const char RXD_NAME_3[] PROGMEM = { "RXD3" };
  67. static const char TXD_NAME_3[] PROGMEM = { "TXD3" };
  68. #endif
  69. #endif
  70. #endif
  71. /////////////////////////////////////////////////////////////////////////////
  72. // second pass - create the array
  73. #undef _ADD_PIN_2
  74. #undef _ADD_PIN
  75. #undef REPORT_NAME_DIGITAL
  76. #undef REPORT_NAME_ANALOG
  77. #define _ADD_PIN_2(ENTRY_NAME, NAME, IS_DIGITAL) { ENTRY_NAME, NAME, IS_DIGITAL },
  78. #define _ADD_PIN(NAME, COUNTER, IS_DIGITAL) _ADD_PIN_2(entry_NAME_##COUNTER, NAME, IS_DIGITAL)
  79. #define REPORT_NAME_DIGITAL(COUNTER, NAME) _ADD_PIN(NAME, COUNTER, true)
  80. #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(analogInputToDigitalPin(NAME), COUNTER, false)
  81. typedef struct {
  82. PGM_P const name;
  83. pin_t pin;
  84. bool is_digital;
  85. } PinInfo;
  86. const PinInfo pin_array[] PROGMEM = {
  87. /**
  88. * [pin name] [pin number] [is digital or analog] 1 = digital, 0 = analog
  89. * Each entry takes up 6 bytes in FLASH:
  90. * 2 byte pointer to location of the name string
  91. * 2 bytes containing the pin number
  92. * analog pin numbers were convereted to digital when the array was created
  93. * 2 bytes containing the digital/analog bool flag
  94. */
  95. // manually add pins ...
  96. #if SERIAL_PORT == 0
  97. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  98. { RXD_NAME_0, 0, true },
  99. { TXD_NAME_0, 1, true },
  100. #elif AVR_ATmega1284_FAMILY
  101. { RXD_NAME_0, 8, true },
  102. { TXD_NAME_0, 9, true },
  103. #endif
  104. #elif SERIAL_PORT == 1
  105. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  106. { RXD_NAME_1, 19, true },
  107. { TXD_NAME_1, 18, true },
  108. #elif AVR_ATmega1284_FAMILY
  109. { RXD_NAME_1, 10, true },
  110. { TXD_NAME_1, 11, true },
  111. #endif
  112. #elif SERIAL_PORT == 2
  113. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  114. { RXD_NAME_2, 17, true },
  115. { TXD_NAME_2, 16, true },
  116. #endif
  117. #elif SERIAL_PORT == 3
  118. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  119. { RXD_NAME_3, 15, true },
  120. { TXD_NAME_3, 14, true },
  121. #endif
  122. #endif
  123. #ifdef SERIAL_PORT_2
  124. #if SERIAL_PORT_2 == 0
  125. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  126. { RXD_NAME_0, 0, true },
  127. { TXD_NAME_0, 1, true },
  128. #elif AVR_ATmega1284_FAMILY
  129. { RXD_NAME_0, 8, true },
  130. { TXD_NAME_0, 9, true },
  131. #endif
  132. #elif SERIAL_PORT_2 == 1
  133. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  134. { RXD_NAME_1, 19, true },
  135. { TXD_NAME_1, 18, true },
  136. #elif AVR_ATmega1284_FAMILY
  137. { RXD_NAME_1, 10, true },
  138. { TXD_NAME_1, 11, true },
  139. #endif
  140. #elif SERIAL_PORT_2 == 2
  141. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  142. { RXD_NAME_2, 17, true },
  143. { TXD_NAME_2, 16, true },
  144. #endif
  145. #elif SERIAL_PORT_2 == 3
  146. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  147. { RXD_NAME_3, 15, true },
  148. { TXD_NAME_3, 14, true },
  149. #endif
  150. #endif
  151. #endif
  152. #include "pinsDebug_list.h"
  153. #line 172
  154. };
  155. #include HAL_PATH(../HAL, pinsDebug.h) // get the correct support file for this CPU
  156. #ifndef M43_NEVER_TOUCH
  157. #define M43_NEVER_TOUCH(Q) false
  158. #endif
  159. static void print_input_or_output(const bool isout) {
  160. serialprintPGM(isout ? PSTR("Output = ") : PSTR("Input = "));
  161. }
  162. // pretty report with PWM info
  163. inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = false, const char *start_string = "") {
  164. char buffer[MAX_NAME_LENGTH + 1]; // for the sprintf statements
  165. bool found = false, multi_name_pin = false;
  166. for (uint8_t x = 0; x < COUNT(pin_array); x++) { // scan entire array and report all instances of this pin
  167. if (GET_ARRAY_PIN(x) == pin) {
  168. if (found) multi_name_pin = true;
  169. found = true;
  170. if (!multi_name_pin) { // report digital and analog pin number only on the first time through
  171. sprintf_P(buffer, PSTR("%sPIN: "), start_string); // digital pin number
  172. SERIAL_ECHO(buffer);
  173. PRINT_PIN(pin);
  174. PRINT_PORT(pin);
  175. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
  176. sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); // analog pin number
  177. SERIAL_ECHO(buffer);
  178. }
  179. else SERIAL_ECHO_SP(8); // add padding if not an analog pin
  180. }
  181. else {
  182. SERIAL_CHAR('.');
  183. SERIAL_ECHO_SP(MULTI_NAME_PAD + strlen(start_string)); // add padding if not the first instance found
  184. }
  185. PRINT_ARRAY_NAME(x);
  186. if (extended) {
  187. if (pin_is_protected(pin) && !ignore)
  188. SERIAL_ECHOPGM("protected ");
  189. else {
  190. #if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO
  191. if (pin == 46 || pin == 47) {
  192. if (pin == 46) {
  193. print_input_or_output(IS_OUTPUT(46));
  194. SERIAL_CHAR('0' + READ(46));
  195. }
  196. else if (pin == 47) {
  197. print_input_or_output(IS_OUTPUT(47));
  198. SERIAL_CHAR('0' + READ(47));
  199. }
  200. }
  201. else
  202. #endif
  203. {
  204. if (!GET_ARRAY_IS_DIGITAL(x)) {
  205. sprintf_P(buffer, PSTR("Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
  206. SERIAL_ECHO(buffer);
  207. }
  208. else {
  209. if (!GET_PINMODE(pin)) {
  210. //pinMode(pin, INPUT_PULLUP); // make sure input isn't floating - stopped doing this
  211. // because this could interfere with inductive/capacitive
  212. // sensors (high impedance voltage divider) and with Pt100 amplifier
  213. print_input_or_output(false);
  214. SERIAL_ECHO(digitalRead_mod(pin));
  215. }
  216. else if (pwm_status(pin)) {
  217. // do nothing
  218. }
  219. else {
  220. print_input_or_output(true);
  221. SERIAL_ECHO(digitalRead_mod(pin));
  222. }
  223. }
  224. if (!multi_name_pin && extended) pwm_details(pin); // report PWM capabilities only on the first pass & only if doing an extended report
  225. }
  226. }
  227. }
  228. SERIAL_EOL();
  229. } // end of IF
  230. } // end of for loop
  231. if (!found) {
  232. sprintf_P(buffer, PSTR("%sPIN: "), start_string);
  233. SERIAL_ECHO(buffer);
  234. PRINT_PIN(pin);
  235. PRINT_PORT(pin);
  236. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
  237. sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); // analog pin number
  238. SERIAL_ECHO(buffer);
  239. }
  240. else
  241. SERIAL_ECHO_SP(8); // add padding if not an analog pin
  242. SERIAL_ECHOPGM("<unused/unknown>");
  243. if (extended) {
  244. #if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO
  245. if (pin == 46 || pin == 47) {
  246. SERIAL_ECHO_SP(12);
  247. if (pin == 46) {
  248. print_input_or_output(IS_OUTPUT(46));
  249. SERIAL_CHAR('0' + READ(46));
  250. }
  251. else {
  252. print_input_or_output(IS_OUTPUT(47));
  253. SERIAL_CHAR('0' + READ(47));
  254. }
  255. }
  256. else
  257. #endif
  258. {
  259. if (pwm_status(pin)) {
  260. // do nothing
  261. }
  262. else if (GET_PINMODE(pin)) {
  263. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  264. print_input_or_output(true);
  265. SERIAL_ECHO(digitalRead_mod(pin));
  266. }
  267. else {
  268. if (IS_ANALOG(pin)) {
  269. sprintf_P(buffer, PSTR(" Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
  270. SERIAL_ECHO(buffer);
  271. SERIAL_ECHOPGM(" ");
  272. }
  273. else
  274. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16); // add padding if not an analog pin
  275. print_input_or_output(false);
  276. SERIAL_ECHO(digitalRead_mod(pin));
  277. }
  278. //if (!pwm_status(pin)) SERIAL_CHAR(' '); // add padding if it's not a PWM pin
  279. if (extended) {
  280. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  281. pwm_details(pin); // report PWM capabilities only if doing an extended report
  282. }
  283. }
  284. }
  285. SERIAL_EOL();
  286. }
  287. }