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

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