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.3KB

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