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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. #define MAX_NAME_LENGTH 35 // one place to specify the format of all the sources of names
  23. // "-" left justify, "35" minimum width of name, pad with blanks
  24. /**
  25. * This routine minimizes RAM usage by creating a FLASH resident array to
  26. * store the pin names, pin numbers and analog/digital flag.
  27. *
  28. * Creating the array in FLASH is a two pass process. The first pass puts the
  29. * name strings into FLASH. The second pass actually creates the array.
  30. *
  31. * Both passes use the same pin list. The list contains two macro names. The
  32. * actual macro definitions are changed depending on which pass is being done.
  33. *
  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(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
  39. #define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(#NAME, COUNTER)
  40. #include "pinsDebug_list.h"
  41. #line 49
  42. // manually add pins that have names that are macros which don't play well with these macros
  43. #if SERIAL_PORT == 0 && (AVR_ATmega2560_FAMILY || AVR_ATmega1284_FAMILY)
  44. static const char RXD_NAME[] PROGMEM = { "RXD" };
  45. static const char TXD_NAME[] PROGMEM = { "TXD" };
  46. #endif
  47. /////////////////////////////////////////////////////////////////////////////
  48. // second pass - create the array
  49. #undef _ADD_PIN_2
  50. #undef _ADD_PIN
  51. #undef REPORT_NAME_DIGITAL
  52. #undef REPORT_NAME_ANALOG
  53. #define _ADD_PIN_2(ENTRY_NAME, NAME, IS_DIGITAL) { ENTRY_NAME, NAME, IS_DIGITAL },
  54. #define _ADD_PIN(NAME, COUNTER, IS_DIGITAL) _ADD_PIN_2(entry_NAME_##COUNTER, NAME, IS_DIGITAL)
  55. #define REPORT_NAME_DIGITAL(NAME, COUNTER) _ADD_PIN(NAME, COUNTER, true)
  56. #define REPORT_NAME_ANALOG(NAME, COUNTER) _ADD_PIN(analogInputToDigitalPin(NAME), COUNTER, false)
  57. typedef struct {
  58. const char * const name;
  59. pin_t pin;
  60. bool is_digital;
  61. } PinInfo;
  62. const PinInfo pin_array[] PROGMEM = {
  63. /**
  64. * [pin name] [pin number] [is digital or analog] 1 = digital, 0 = analog
  65. * Each entry takes up 6 bytes in FLASH:
  66. * 2 byte pointer to location of the name string
  67. * 2 bytes containing the pin number
  68. * analog pin numbers were convereted to digital when the array was created
  69. * 2 bytes containing the digital/analog bool flag
  70. */
  71. // manually add pins ...
  72. #if SERIAL_PORT == 0
  73. #if AVR_ATmega2560_FAMILY
  74. { RXD_NAME, 0, true },
  75. { TXD_NAME, 1, true },
  76. #elif AVR_ATmega1284_FAMILY
  77. { RXD_NAME, 8, true },
  78. { TXD_NAME, 9, true },
  79. #endif
  80. #endif
  81. #include "pinsDebug_list.h"
  82. #line 101
  83. };
  84. #include "../HAL/HAL_pinsDebug.h" // get the correct support file for this CPU
  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[30]; // 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 (IS_ANALOG(pin)) {
  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(26 + 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(GET_OUTPUT(46));
  120. SERIAL_PROTOCOL(READ(46));
  121. }
  122. else if (pin == 47) {
  123. print_input_or_output(GET_OUTPUT(47));
  124. SERIAL_PROTOCOL(READ(47));
  125. }
  126. }
  127. else
  128. #endif
  129. {
  130. if (!GET_ARRAY_IS_DIGITAL(x)) {
  131. sprintf_P(buffer, PSTR("Analog in = %5d"), 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_PROTOCOL(digitalRead_mod(pin));
  141. }
  142. else if (pwm_status(pin)) {
  143. // do nothing
  144. }
  145. else {
  146. print_input_or_output(true);
  147. SERIAL_PROTOCOL(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 (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. }