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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../inc/MarlinConfig.h"
  23. #define MAX_NAME_LENGTH 39 // one place to specify the format of all the sources of names
  24. // "-" left justify, "39" minimum width of name, pad with blanks
  25. /**
  26. * This routine minimizes RAM usage by creating a FLASH resident array to
  27. * store the pin names, pin numbers and analog/digital flag.
  28. *
  29. * Creating the array in FLASH is a two pass process. The first pass puts the
  30. * name strings into FLASH. The second pass actually creates the array.
  31. *
  32. * Both passes use the same pin list. The list contains two macro names. The
  33. * actual macro definitions are changed depending on which pass is being done.
  34. */
  35. // first pass - put the name strings into FLASH
  36. #define _ADD_PIN_2(PIN_NAME, ENTRY_NAME) static const char ENTRY_NAME[] PROGMEM = { PIN_NAME };
  37. #define _ADD_PIN(PIN_NAME, COUNTER) _ADD_PIN_2(PIN_NAME, entry_NAME_##COUNTER)
  38. #define REPORT_NAME_DIGITAL(COUNTER, NAME) _ADD_PIN(#NAME, COUNTER)
  39. #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(#NAME, COUNTER)
  40. #include "pinsDebug_list.h"
  41. #line 48
  42. // manually add pins that have names that are macros which don't play well with these macros
  43. #if ANY(AVR_ATmega2560_FAMILY, AVR_ATmega1284_FAMILY, ARDUINO_ARCH_SAM, TARGET_LPC1768)
  44. #if CONF_SERIAL_IS(0)
  45. static const char RXD_NAME_0[] PROGMEM = { "RXD0" };
  46. static const char TXD_NAME_0[] PROGMEM = { "TXD0" };
  47. #endif
  48. #if CONF_SERIAL_IS(1)
  49. static const char RXD_NAME_1[] PROGMEM = { "RXD1" };
  50. static const char TXD_NAME_1[] PROGMEM = { "TXD1" };
  51. #endif
  52. #if CONF_SERIAL_IS(2)
  53. static const char RXD_NAME_2[] PROGMEM = { "RXD2" };
  54. static const char TXD_NAME_2[] PROGMEM = { "TXD2" };
  55. #endif
  56. #if CONF_SERIAL_IS(3)
  57. static const char RXD_NAME_3[] PROGMEM = { "RXD3" };
  58. static const char TXD_NAME_3[] PROGMEM = { "TXD3" };
  59. #endif
  60. #endif
  61. /////////////////////////////////////////////////////////////////////////////
  62. // second pass - create the array
  63. #undef _ADD_PIN_2
  64. #undef _ADD_PIN
  65. #undef REPORT_NAME_DIGITAL
  66. #undef REPORT_NAME_ANALOG
  67. #define _ADD_PIN_2(ENTRY_NAME, NAME, IS_DIGITAL) { ENTRY_NAME, NAME, IS_DIGITAL },
  68. #define _ADD_PIN(NAME, COUNTER, IS_DIGITAL) _ADD_PIN_2(entry_NAME_##COUNTER, NAME, IS_DIGITAL)
  69. #define REPORT_NAME_DIGITAL(COUNTER, NAME) _ADD_PIN(NAME, COUNTER, true)
  70. #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(analogInputToDigitalPin(NAME), COUNTER, false)
  71. typedef struct {
  72. PGM_P const name;
  73. pin_t pin;
  74. bool is_digital;
  75. } PinInfo;
  76. const PinInfo pin_array[] PROGMEM = {
  77. /**
  78. * [pin name] [pin number] [is digital or analog] 1 = digital, 0 = analog
  79. * Each entry takes up 6 bytes in FLASH:
  80. * 2 byte pointer to location of the name string
  81. * 2 bytes containing the pin number
  82. * analog pin numbers were converted to digital when the array was created
  83. * 2 bytes containing the digital/analog bool flag
  84. */
  85. #if CONF_SERIAL_IS(0)
  86. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  87. { RXD_NAME_0, 0, true },
  88. { TXD_NAME_0, 1, true },
  89. #elif AVR_ATmega1284_FAMILY
  90. { RXD_NAME_0, 8, true },
  91. { TXD_NAME_0, 9, true },
  92. #elif defined(TARGET_LPC1768) // TX P0_02 RX P0_03
  93. { RXD_NAME_0, 3, true },
  94. { TXD_NAME_0, 2, true },
  95. #endif
  96. #endif
  97. #if CONF_SERIAL_IS(1)
  98. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  99. { RXD_NAME_1, 19, true },
  100. { TXD_NAME_1, 18, true },
  101. #elif AVR_ATmega1284_FAMILY
  102. { RXD_NAME_1, 10, true },
  103. { TXD_NAME_1, 11, true },
  104. #elif defined(TARGET_LPC1768)
  105. #ifdef LPC_PINCFG_UART1_P2_00 // TX P2_00 RX P2_01
  106. { RXD_NAME_1, 0x41, true },
  107. { TXD_NAME_1, 0x40, true },
  108. #else // TX P0_15 RX P0_16
  109. { RXD_NAME_1, 16, true },
  110. { TXD_NAME_1, 15, true },
  111. #endif
  112. #endif
  113. #endif
  114. #if CONF_SERIAL_IS(2)
  115. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  116. { RXD_NAME_2, 17, true },
  117. { TXD_NAME_2, 16, true },
  118. #elif defined(TARGET_LPC1768)
  119. #ifdef LPC_PINCFG_UART2_P2_08 // TX P2_08 RX P2_09
  120. { RXD_NAME_2, 0x49, true },
  121. { TXD_NAME_2, 0x48, true },
  122. #else // TX P0_10 RX P0_11
  123. { RXD_NAME_2, 11, true },
  124. { TXD_NAME_2, 10, true },
  125. #endif
  126. #endif
  127. #endif
  128. #if CONF_SERIAL_IS(3)
  129. #if EITHER(AVR_ATmega2560_FAMILY, ARDUINO_ARCH_SAM)
  130. { RXD_NAME_3, 15, true },
  131. { TXD_NAME_3, 14, true },
  132. #elif defined(TARGET_LPC1768)
  133. #ifdef LPC_PINCFG_UART3_P0_25 // TX P0_25 RX P0_26
  134. { RXD_NAME_3, 0x1A, true },
  135. { TXD_NAME_3, 0x19, true },
  136. #elif defined(LPC_PINCFG_UART3_P4_28) // TX P4_28 RX P4_29
  137. { RXD_NAME_3, 0x9D, true },
  138. { TXD_NAME_3, 0x9C, true },
  139. #else // TX P0_00 RX P0_01
  140. { RXD_NAME_3, 1, true },
  141. { TXD_NAME_3, 0, true },
  142. #endif
  143. #endif
  144. #endif
  145. #include "pinsDebug_list.h"
  146. #line 167
  147. };
  148. #include HAL_PATH(../HAL, pinsDebug.h) // get the correct support file for this CPU
  149. #ifndef M43_NEVER_TOUCH
  150. #define M43_NEVER_TOUCH(Q) false
  151. #endif
  152. static void print_input_or_output(const bool isout) {
  153. SERIAL_ECHOPGM_P(isout ? PSTR("Output = ") : PSTR("Input = "));
  154. }
  155. // pretty report with PWM info
  156. inline void report_pin_state_extended(pin_t pin, const bool ignore, const bool extended=false, FSTR_P const start_string=nullptr) {
  157. char buffer[MAX_NAME_LENGTH + 1]; // for the sprintf statements
  158. bool found = false, multi_name_pin = false;
  159. auto alt_pin_echo = [](const pin_t &pin) {
  160. #if AVR_AT90USB1286_FAMILY
  161. // Use FastIO for pins Teensy doesn't expose
  162. if (pin == 46) {
  163. print_input_or_output(IS_OUTPUT(46));
  164. SERIAL_CHAR('0' + READ(46));
  165. return false;
  166. }
  167. else if (pin == 47) {
  168. print_input_or_output(IS_OUTPUT(47));
  169. SERIAL_CHAR('0' + READ(47));
  170. return false;
  171. }
  172. #endif
  173. return true;
  174. };
  175. LOOP_L_N(x, COUNT(pin_array)) { // scan entire array and report all instances of this pin
  176. if (GET_ARRAY_PIN(x) == pin) {
  177. if (!found) { // report digital and analog pin number only on the first time through
  178. if (start_string) SERIAL_ECHOF(start_string);
  179. SERIAL_ECHOPGM("PIN: ");
  180. PRINT_PIN(pin);
  181. PRINT_PORT(pin);
  182. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) PRINT_PIN_ANALOG(pin); // analog pin number
  183. else SERIAL_ECHO_SP(8); // add padding if not an analog pin
  184. }
  185. else {
  186. SERIAL_CHAR('.');
  187. SERIAL_ECHO_SP(MULTI_NAME_PAD + (start_string ? strlen_P(FTOP(start_string)) : 0)); // add padding if not the first instance found
  188. }
  189. PRINT_ARRAY_NAME(x);
  190. if (extended) {
  191. if (pin_is_protected(pin) && !ignore)
  192. SERIAL_ECHOPGM("protected ");
  193. else {
  194. if (alt_pin_echo(pin)) {
  195. if (!GET_ARRAY_IS_DIGITAL(x)) {
  196. sprintf_P(buffer, PSTR("Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
  197. SERIAL_ECHO(buffer);
  198. }
  199. else {
  200. if (!GET_PINMODE(pin)) {
  201. //pinMode(pin, INPUT_PULLUP); // make sure input isn't floating - stopped doing this
  202. // because this could interfere with inductive/capacitive
  203. // sensors (high impedance voltage divider) and with Pt100 amplifier
  204. print_input_or_output(false);
  205. SERIAL_ECHO(digitalRead_mod(pin));
  206. }
  207. else if (pwm_status(pin)) {
  208. // do nothing
  209. }
  210. else {
  211. print_input_or_output(true);
  212. SERIAL_ECHO(digitalRead_mod(pin));
  213. }
  214. }
  215. if (!multi_name_pin && extended) pwm_details(pin); // report PWM capabilities only on the first pass & only if doing an extended report
  216. }
  217. }
  218. }
  219. SERIAL_EOL();
  220. multi_name_pin = found;
  221. found = true;
  222. } // end of IF
  223. } // end of for loop
  224. if (!found) {
  225. if (start_string) SERIAL_ECHOF(start_string);
  226. SERIAL_ECHOPGM("PIN: ");
  227. PRINT_PIN(pin);
  228. PRINT_PORT(pin);
  229. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) PRINT_PIN_ANALOG(pin); // analog pin number
  230. else SERIAL_ECHO_SP(8); // add padding if not an analog pin
  231. SERIAL_ECHOPGM("<unused/unknown>");
  232. if (extended) {
  233. if (alt_pin_echo(pin)) {
  234. if (pwm_status(pin)) {
  235. // do nothing
  236. }
  237. else if (GET_PINMODE(pin)) {
  238. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  239. print_input_or_output(true);
  240. SERIAL_ECHO(digitalRead_mod(pin));
  241. }
  242. else {
  243. if (IS_ANALOG(pin)) {
  244. sprintf_P(buffer, PSTR(" Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
  245. SERIAL_ECHO(buffer);
  246. SERIAL_ECHOPGM(" ");
  247. }
  248. else
  249. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16); // add padding if not an analog pin
  250. print_input_or_output(false);
  251. SERIAL_ECHO(digitalRead_mod(pin));
  252. }
  253. //if (!pwm_status(pin)) SERIAL_CHAR(' '); // add padding if it's not a PWM pin
  254. if (extended) {
  255. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  256. pwm_details(pin); // report PWM capabilities only if doing an extended report
  257. }
  258. }
  259. }
  260. SERIAL_EOL();
  261. }
  262. }