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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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. #define MAX_NAME_LENGTH 39 // one place to specify the format of all the sources of names
  20. // "-" left justify, "39" minimum width of name, pad with blanks
  21. /**
  22. * This routine minimizes RAM usage by creating a FLASH resident array to
  23. * store the pin names, pin numbers and analog/digital flag.
  24. *
  25. * Creating the array in FLASH is a two pass process. The first pass puts the
  26. * name strings into FLASH. The second pass actually creates the array.
  27. *
  28. * Both passes use the same pin list. The list contains two macro names. The
  29. * actual macro definitions are changed depending on which pass is being done.
  30. *
  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 47
  39. // manually add pins that have names that are macros which don't play well with these macros
  40. #if SERIAL_PORT == 0 && (AVR_ATmega2560_FAMILY || AVR_ATmega1284_FAMILY || defined(ARDUINO_ARCH_SAM))
  41. static const char RXD_NAME[] PROGMEM = { "RXD" };
  42. static const char TXD_NAME[] PROGMEM = { "TXD" };
  43. #endif
  44. /////////////////////////////////////////////////////////////////////////////
  45. // second pass - create the array
  46. #undef _ADD_PIN_2
  47. #undef _ADD_PIN
  48. #undef REPORT_NAME_DIGITAL
  49. #undef REPORT_NAME_ANALOG
  50. #define _ADD_PIN_2(ENTRY_NAME, NAME, IS_DIGITAL) { ENTRY_NAME, NAME, IS_DIGITAL },
  51. #define _ADD_PIN(NAME, COUNTER, IS_DIGITAL) _ADD_PIN_2(entry_NAME_##COUNTER, NAME, IS_DIGITAL)
  52. #define REPORT_NAME_DIGITAL(COUNTER, NAME) _ADD_PIN(NAME, COUNTER, true)
  53. #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(analogInputToDigitalPin(NAME), COUNTER, false)
  54. typedef struct {
  55. PGM_P const name;
  56. pin_t pin;
  57. bool is_digital;
  58. } PinInfo;
  59. const PinInfo pin_array[] PROGMEM = {
  60. /**
  61. * [pin name] [pin number] [is digital or analog] 1 = digital, 0 = analog
  62. * Each entry takes up 6 bytes in FLASH:
  63. * 2 byte pointer to location of the name string
  64. * 2 bytes containing the pin number
  65. * analog pin numbers were convereted to digital when the array was created
  66. * 2 bytes containing the digital/analog bool flag
  67. */
  68. // manually add pins ...
  69. #if SERIAL_PORT == 0
  70. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  71. { RXD_NAME, 0, true },
  72. { TXD_NAME, 1, true },
  73. #elif AVR_ATmega1284_FAMILY
  74. { RXD_NAME, 8, true },
  75. { TXD_NAME, 9, true },
  76. #endif
  77. #endif
  78. #include "pinsDebug_list.h"
  79. #line 99
  80. };
  81. #include HAL_PATH(../HAL, pinsDebug.h) // get the correct support file for this CPU
  82. #ifndef M43_NEVER_TOUCH
  83. #define M43_NEVER_TOUCH(Q) false
  84. #endif
  85. static void print_input_or_output(const bool isout) {
  86. serialprintPGM(isout ? PSTR("Output = ") : PSTR("Input = "));
  87. }
  88. // pretty report with PWM info
  89. inline void report_pin_state_extended(pin_t pin, bool ignore, bool extended = false, const char *start_string = "") {
  90. char buffer[MAX_NAME_LENGTH + 1]; // for the sprintf statements
  91. bool found = false, multi_name_pin = false;
  92. for (uint8_t x = 0; x < COUNT(pin_array); x++) { // scan entire array and report all instances of this pin
  93. if (GET_ARRAY_PIN(x) == pin) {
  94. if (found) multi_name_pin = true;
  95. found = true;
  96. if (!multi_name_pin) { // report digitial and analog pin number only on the first time through
  97. sprintf_P(buffer, PSTR("%sPIN: "), start_string); // digital pin number
  98. SERIAL_ECHO(buffer);
  99. PRINT_PIN(pin);
  100. PRINT_PORT(pin);
  101. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
  102. sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); // analog pin number
  103. SERIAL_ECHO(buffer);
  104. }
  105. else SERIAL_ECHO_SP(8); // add padding if not an analog pin
  106. }
  107. else {
  108. SERIAL_CHAR('.');
  109. SERIAL_ECHO_SP(MULTI_NAME_PAD + strlen(start_string)); // add padding if not the first instance found
  110. }
  111. PRINT_ARRAY_NAME(x);
  112. if (extended) {
  113. if (pin_is_protected(pin) && !ignore)
  114. SERIAL_ECHOPGM("protected ");
  115. else {
  116. #if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO
  117. if (pin == 46 || pin == 47) {
  118. if (pin == 46) {
  119. print_input_or_output(IS_OUTPUT(46));
  120. SERIAL_CHAR('0' + READ(46));
  121. }
  122. else if (pin == 47) {
  123. print_input_or_output(IS_OUTPUT(47));
  124. SERIAL_CHAR('0' + READ(47));
  125. }
  126. }
  127. else
  128. #endif
  129. {
  130. if (!GET_ARRAY_IS_DIGITAL(x)) {
  131. sprintf_P(buffer, PSTR("Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
  132. SERIAL_ECHO(buffer);
  133. }
  134. else {
  135. if (!GET_PINMODE(pin)) {
  136. //pinMode(pin, INPUT_PULLUP); // make sure input isn't floating - stopped doing this
  137. // because this could interfere with inductive/capacitive
  138. // sensors (high impedance voltage divider) and with PT100 amplifier
  139. print_input_or_output(false);
  140. SERIAL_ECHO(digitalRead_mod(pin));
  141. }
  142. else if (pwm_status(pin)) {
  143. // do nothing
  144. }
  145. else {
  146. print_input_or_output(true);
  147. SERIAL_ECHO(digitalRead_mod(pin));
  148. }
  149. }
  150. if (!multi_name_pin && extended) pwm_details(pin); // report PWM capabilities only on the first pass & only if doing an extended report
  151. }
  152. }
  153. }
  154. SERIAL_EOL();
  155. } // end of IF
  156. } // end of for loop
  157. if (!found) {
  158. sprintf_P(buffer, PSTR("%sPIN: "), start_string);
  159. SERIAL_ECHO(buffer);
  160. PRINT_PIN(pin);
  161. PRINT_PORT(pin);
  162. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
  163. sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); // analog pin number
  164. SERIAL_ECHO(buffer);
  165. }
  166. else
  167. SERIAL_ECHO_SP(8); // add padding if not an analog pin
  168. SERIAL_ECHOPGM("<unused/unknown>");
  169. if (extended) {
  170. #if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO
  171. if (pin == 46 || pin == 47) {
  172. SERIAL_ECHO_SP(12);
  173. if (pin == 46) {
  174. print_input_or_output(IS_OUTPUT(46));
  175. SERIAL_CHAR('0' + READ(46));
  176. }
  177. else {
  178. print_input_or_output(IS_OUTPUT(47));
  179. SERIAL_CHAR('0' + READ(47));
  180. }
  181. }
  182. else
  183. #endif
  184. {
  185. if (pwm_status(pin)) {
  186. // do nothing
  187. }
  188. else if (GET_PINMODE(pin)) {
  189. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  190. print_input_or_output(true);
  191. SERIAL_ECHO(digitalRead_mod(pin));
  192. }
  193. else {
  194. if (IS_ANALOG(pin)) {
  195. sprintf_P(buffer, PSTR(" Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
  196. SERIAL_ECHO(buffer);
  197. SERIAL_ECHOPGM(" ");
  198. }
  199. else
  200. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16); // add padding if not an analog pin
  201. print_input_or_output(false);
  202. SERIAL_ECHO(digitalRead_mod(pin));
  203. }
  204. //if (!pwm_status(pin)) SERIAL_CHAR(' '); // add padding if it's not a PWM pin
  205. if (extended) {
  206. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  207. pwm_details(pin); // report PWM capabilities only if doing an extended report
  208. }
  209. }
  210. }
  211. SERIAL_EOL();
  212. }
  213. }