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 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  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 <https://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. // first pass - put the name strings into FLASH
  33. #define _ADD_PIN_2(PIN_NAME, ENTRY_NAME) static const char ENTRY_NAME[] PROGMEM = { PIN_NAME };
  34. #define _ADD_PIN(PIN_NAME, COUNTER) _ADD_PIN_2(PIN_NAME, entry_NAME_##COUNTER)
  35. #define REPORT_NAME_DIGITAL(COUNTER, NAME) _ADD_PIN(#NAME, COUNTER)
  36. #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(#NAME, COUNTER)
  37. #include "pinsDebug_list.h"
  38. #line 46
  39. // manually add pins that have names that are macros which don't play well with these macros
  40. #if ANY(AVR_ATmega2560_FAMILY, AVR_ATmega1284_FAMILY, ARDUINO_ARCH_SAM, TARGET_LPC1768)
  41. #if SERIAL_PORT == 0
  42. static const char RXD_NAME_0[] PROGMEM = { "RXD0" };
  43. static const char TXD_NAME_0[] PROGMEM = { "TXD0" };
  44. #elif SERIAL_PORT == 1
  45. static const char RXD_NAME_1[] PROGMEM = { "RXD1" };
  46. static const char TXD_NAME_1[] PROGMEM = { "TXD1" };
  47. #elif SERIAL_PORT == 2
  48. static const char RXD_NAME_2[] PROGMEM = { "RXD2" };
  49. static const char TXD_NAME_2[] PROGMEM = { "TXD2" };
  50. #elif SERIAL_PORT == 3
  51. static const char RXD_NAME_3[] PROGMEM = { "RXD3" };
  52. static const char TXD_NAME_3[] PROGMEM = { "TXD3" };
  53. #endif
  54. #ifdef SERIAL_PORT_2
  55. #if SERIAL_PORT_2 == 0
  56. static const char RXD_NAME_0[] PROGMEM = { "RXD0" };
  57. static const char TXD_NAME_0[] PROGMEM = { "TXD0" };
  58. #elif SERIAL_PORT_2 == 1
  59. static const char RXD_NAME_1[] PROGMEM = { "RXD1" };
  60. static const char TXD_NAME_1[] PROGMEM = { "TXD1" };
  61. #elif SERIAL_PORT_2 == 2
  62. static const char RXD_NAME_2[] PROGMEM = { "RXD2" };
  63. static const char TXD_NAME_2[] PROGMEM = { "TXD2" };
  64. #elif SERIAL_PORT_2 == 3
  65. static const char RXD_NAME_3[] PROGMEM = { "RXD3" };
  66. static const char TXD_NAME_3[] PROGMEM = { "TXD3" };
  67. #endif
  68. #endif
  69. #endif
  70. /////////////////////////////////////////////////////////////////////////////
  71. // second pass - create the array
  72. #undef _ADD_PIN_2
  73. #undef _ADD_PIN
  74. #undef REPORT_NAME_DIGITAL
  75. #undef REPORT_NAME_ANALOG
  76. #define _ADD_PIN_2(ENTRY_NAME, NAME, IS_DIGITAL) { ENTRY_NAME, NAME, IS_DIGITAL },
  77. #define _ADD_PIN(NAME, COUNTER, IS_DIGITAL) _ADD_PIN_2(entry_NAME_##COUNTER, NAME, IS_DIGITAL)
  78. #define REPORT_NAME_DIGITAL(COUNTER, NAME) _ADD_PIN(NAME, COUNTER, true)
  79. #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(analogInputToDigitalPin(NAME), COUNTER, false)
  80. typedef struct {
  81. PGM_P const name;
  82. pin_t pin;
  83. bool is_digital;
  84. } PinInfo;
  85. const PinInfo pin_array[] PROGMEM = {
  86. /**
  87. * [pin name] [pin number] [is digital or analog] 1 = digital, 0 = analog
  88. * Each entry takes up 6 bytes in FLASH:
  89. * 2 byte pointer to location of the name string
  90. * 2 bytes containing the pin number
  91. * analog pin numbers were convereted to digital when the array was created
  92. * 2 bytes containing the digital/analog bool flag
  93. */
  94. // manually add pins ...
  95. #if SERIAL_PORT == 0
  96. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  97. { RXD_NAME_0, 0, true },
  98. { TXD_NAME_0, 1, true },
  99. #elif AVR_ATmega1284_FAMILY
  100. { RXD_NAME_0, 8, true },
  101. { TXD_NAME_0, 9, true },
  102. #elif defined(TARGET_LPC1768) // TX P0_02 RX P0_03
  103. { RXD_NAME_0, 3, true },
  104. { TXD_NAME_0, 2, true },
  105. #endif
  106. #elif SERIAL_PORT == 1
  107. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  108. { RXD_NAME_1, 19, true },
  109. { TXD_NAME_1, 18, true },
  110. #elif AVR_ATmega1284_FAMILY
  111. { RXD_NAME_1, 10, true },
  112. { TXD_NAME_1, 11, true },
  113. #elif defined(TARGET_LPC1768)
  114. #ifdef LPC_PINCFG_UART1_P2_00 // TX P2_00 RX P2_01
  115. { RXD_NAME_1, 0x41, true },
  116. { TXD_NAME_1, 0x40, true },
  117. #else // TX P0_15 RX P0_16
  118. { RXD_NAME_1, 16, true },
  119. { TXD_NAME_1, 15, true },
  120. #endif
  121. #endif
  122. #elif SERIAL_PORT == 2
  123. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  124. { RXD_NAME_2, 17, true },
  125. { TXD_NAME_2, 16, true },
  126. #elif defined(TARGET_LPC1768)
  127. #ifdef LPC_PINCFG_UART2_P2_08 // TX P2_08 RX P2_09
  128. { RXD_NAME_2, 0x49, true },
  129. { TXD_NAME_2, 0x48, true },
  130. #else // TX P0_10 RX P0_11
  131. { RXD_NAME_2, 11, true },
  132. { TXD_NAME_2, 10, true },
  133. #endif
  134. #endif
  135. #elif SERIAL_PORT == 3
  136. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  137. { RXD_NAME_3, 15, true },
  138. { TXD_NAME_3, 14, true },
  139. #elif defined(TARGET_LPC1768)
  140. #ifdef LPC_PINCFG_UART3_P0_25 // TX P0_25 RX P0_26
  141. { RXD_NAME_3, 0x1A, true },
  142. { TXD_NAME_3, 0x19, true },
  143. #elif defined(LPC_PINCFG_UART3_P4_28) // TX P4_28 RX P4_29
  144. { RXD_NAME_3, 0x9D, true },
  145. { TXD_NAME_3, 0x9C, true },
  146. #else // TX P0_00 RX P0_01
  147. { RXD_NAME_3, 1, true },
  148. { TXD_NAME_3, 0, true },
  149. #endif
  150. #endif
  151. #endif
  152. #ifdef SERIAL_PORT_2
  153. #if SERIAL_PORT_2 == 0
  154. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  155. { RXD_NAME_0, 0, true },
  156. { TXD_NAME_0, 1, true },
  157. #elif AVR_ATmega1284_FAMILY
  158. { RXD_NAME_0, 8, true },
  159. { TXD_NAME_0, 9, true },
  160. #elif defined(TARGET_LPC1768) // TX P0_02 RX P0_03
  161. { RXD_NAME_0, 3, true },
  162. { TXD_NAME_0, 2, true },
  163. #endif
  164. #elif SERIAL_PORT_2 == 1
  165. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  166. { RXD_NAME_1, 19, true },
  167. { TXD_NAME_1, 18, true },
  168. #elif AVR_ATmega1284_FAMILY
  169. { RXD_NAME_1, 10, true },
  170. { TXD_NAME_1, 11, true },
  171. #elif defined(TARGET_LPC1768)
  172. #ifdef LPC_PINCFG_UART1_P2_00 // TX P2_00 RX P2_01
  173. { RXD_NAME_1, 0x41, true },
  174. { TXD_NAME_1, 0x40, true },
  175. #else // TX P0_15 RX P0_16
  176. { RXD_NAME_1, 16, true },
  177. { TXD_NAME_1, 15, true },
  178. #endif
  179. #endif
  180. #elif SERIAL_PORT_2 == 2
  181. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  182. { RXD_NAME_2, 17, true },
  183. { TXD_NAME_2, 16, true },
  184. #elif defined(TARGET_LPC1768)
  185. #ifdef LPC_PINCFG_UART2_P2_08 // TX P2_08 RX P2_09
  186. { RXD_NAME_2, 0x49, true },
  187. { TXD_NAME_2, 0x48, true },
  188. #else // TX P0_10 RX P0_11
  189. { RXD_NAME_2, 11, true },
  190. { TXD_NAME_2, 10, true },
  191. #endif
  192. #endif
  193. #elif SERIAL_PORT_2 == 3
  194. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  195. { RXD_NAME_3, 15, true },
  196. { TXD_NAME_3, 14, true },
  197. #elif defined(TARGET_LPC1768)
  198. #ifdef LPC_PINCFG_UART3_P0_25 // TX P0_25 RX P0_26
  199. { RXD_NAME_3, 0x1A, true },
  200. { TXD_NAME_3, 0x19, true },
  201. #elif defined(LPC_PINCFG_UART3_P4_28) // TX P4_28 RX P4_29
  202. { RXD_NAME_3, 0x9D, true },
  203. { TXD_NAME_3, 0x9C, true },
  204. #else // TX P0_00 RX P0_01
  205. { RXD_NAME_3, 1, true },
  206. { TXD_NAME_3, 0, true },
  207. #endif
  208. #endif
  209. #endif
  210. #endif
  211. #include "pinsDebug_list.h"
  212. #line 172
  213. };
  214. #include HAL_PATH(../HAL, pinsDebug.h) // get the correct support file for this CPU
  215. #ifndef M43_NEVER_TOUCH
  216. #define M43_NEVER_TOUCH(Q) false
  217. #endif
  218. static void print_input_or_output(const bool isout) {
  219. serialprintPGM(isout ? PSTR("Output = ") : PSTR("Input = "));
  220. }
  221. // pretty report with PWM info
  222. inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool extended=false, PGM_P const start_string=nullptr) {
  223. char buffer[MAX_NAME_LENGTH + 1]; // for the sprintf statements
  224. bool found = false, multi_name_pin = false;
  225. auto alt_pin_echo = [](const pin_t &pin) {
  226. #if AVR_AT90USB1286_FAMILY
  227. // Use FastIO for pins Teensy doesn't expose
  228. if (pin == 46) {
  229. print_input_or_output(IS_OUTPUT(46));
  230. SERIAL_CHAR('0' + READ(46));
  231. return false;
  232. }
  233. else if (pin == 47) {
  234. print_input_or_output(IS_OUTPUT(47));
  235. SERIAL_CHAR('0' + READ(47));
  236. return false;
  237. }
  238. #endif
  239. return true;
  240. };
  241. LOOP_L_N(x, COUNT(pin_array)) { // scan entire array and report all instances of this pin
  242. if (GET_ARRAY_PIN(x) == pin) {
  243. if (!found) { // report digital and analog pin number only on the first time through
  244. if (start_string) serialprintPGM(start_string);
  245. serialprintPGM(PSTR("PIN: "));
  246. PRINT_PIN(pin);
  247. PRINT_PORT(pin);
  248. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
  249. sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); // analog pin number
  250. SERIAL_ECHO(buffer);
  251. }
  252. else SERIAL_ECHO_SP(8); // add padding if not an analog pin
  253. }
  254. else {
  255. SERIAL_CHAR('.');
  256. SERIAL_ECHO_SP(MULTI_NAME_PAD + (start_string ? strlen_P(start_string) : 0)); // add padding if not the first instance found
  257. }
  258. PRINT_ARRAY_NAME(x);
  259. if (extended) {
  260. if (pin_is_protected(pin) && !ignore)
  261. SERIAL_ECHOPGM("protected ");
  262. else {
  263. if (alt_pin_echo(pin)) {
  264. if (!GET_ARRAY_IS_DIGITAL(x)) {
  265. sprintf_P(buffer, PSTR("Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
  266. SERIAL_ECHO(buffer);
  267. }
  268. else {
  269. if (!GET_PINMODE(pin)) {
  270. //pinMode(pin, INPUT_PULLUP); // make sure input isn't floating - stopped doing this
  271. // because this could interfere with inductive/capacitive
  272. // sensors (high impedance voltage divider) and with Pt100 amplifier
  273. print_input_or_output(false);
  274. SERIAL_ECHO(digitalRead_mod(pin));
  275. }
  276. else if (pwm_status(pin)) {
  277. // do nothing
  278. }
  279. else {
  280. print_input_or_output(true);
  281. SERIAL_ECHO(digitalRead_mod(pin));
  282. }
  283. }
  284. if (!multi_name_pin && extended) pwm_details(pin); // report PWM capabilities only on the first pass & only if doing an extended report
  285. }
  286. }
  287. }
  288. SERIAL_EOL();
  289. multi_name_pin = found;
  290. found = true;
  291. } // end of IF
  292. } // end of for loop
  293. if (!found) {
  294. if (start_string) serialprintPGM(start_string);
  295. serialprintPGM(PSTR("PIN: "));
  296. PRINT_PIN(pin);
  297. PRINT_PORT(pin);
  298. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
  299. sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); // analog pin number
  300. SERIAL_ECHO(buffer);
  301. }
  302. else
  303. SERIAL_ECHO_SP(8); // add padding if not an analog pin
  304. SERIAL_ECHOPGM("<unused/unknown>");
  305. if (extended) {
  306. if (alt_pin_echo(pin)) {
  307. if (pwm_status(pin)) {
  308. // do nothing
  309. }
  310. else if (GET_PINMODE(pin)) {
  311. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  312. print_input_or_output(true);
  313. SERIAL_ECHO(digitalRead_mod(pin));
  314. }
  315. else {
  316. if (IS_ANALOG(pin)) {
  317. sprintf_P(buffer, PSTR(" Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
  318. SERIAL_ECHO(buffer);
  319. SERIAL_ECHOPGM(" ");
  320. }
  321. else
  322. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16); // add padding if not an analog pin
  323. print_input_or_output(false);
  324. SERIAL_ECHO(digitalRead_mod(pin));
  325. }
  326. //if (!pwm_status(pin)) SERIAL_CHAR(' '); // add padding if it's not a PWM pin
  327. if (extended) {
  328. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  329. pwm_details(pin); // report PWM capabilities only if doing an extended report
  330. }
  331. }
  332. }
  333. SERIAL_EOL();
  334. }
  335. }