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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. #include "../inc/MarlinConfig.h"
  20. #define MAX_NAME_LENGTH 39 // one place to specify the format of all the sources of names
  21. // "-" left justify, "39" minimum width of name, pad with blanks
  22. /**
  23. * This routine minimizes RAM usage by creating a FLASH resident array to
  24. * store the pin names, pin numbers and analog/digital flag.
  25. *
  26. * Creating the array in FLASH is a two pass process. The first pass puts the
  27. * name strings into FLASH. The second pass actually creates the array.
  28. *
  29. * Both passes use the same pin list. The list contains two macro names. The
  30. * actual macro definitions are changed depending on which pass is being done.
  31. *
  32. */
  33. // first pass - put the name strings into FLASH
  34. #define _ADD_PIN_2(PIN_NAME, ENTRY_NAME) static const char ENTRY_NAME[] PROGMEM = { PIN_NAME };
  35. #define _ADD_PIN(PIN_NAME, COUNTER) _ADD_PIN_2(PIN_NAME, entry_NAME_##COUNTER)
  36. #define REPORT_NAME_DIGITAL(COUNTER, NAME) _ADD_PIN(#NAME, COUNTER)
  37. #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(#NAME, COUNTER)
  38. #include "pinsDebug_list.h"
  39. #line 46
  40. // manually add pins that have names that are macros which don't play well with these macros
  41. #if SERIAL_PORT == 0 && (AVR_ATmega2560_FAMILY || AVR_ATmega1284_FAMILY || defined(ARDUINO_ARCH_SAM))
  42. static const char RXD_NAME[] PROGMEM = { "RXD" };
  43. static const char TXD_NAME[] PROGMEM = { "TXD" };
  44. #endif
  45. /////////////////////////////////////////////////////////////////////////////
  46. // second pass - create the array
  47. #undef _ADD_PIN_2
  48. #undef _ADD_PIN
  49. #undef REPORT_NAME_DIGITAL
  50. #undef REPORT_NAME_ANALOG
  51. #define _ADD_PIN_2(ENTRY_NAME, NAME, IS_DIGITAL) { ENTRY_NAME, NAME, IS_DIGITAL },
  52. #define _ADD_PIN(NAME, COUNTER, IS_DIGITAL) _ADD_PIN_2(entry_NAME_##COUNTER, NAME, IS_DIGITAL)
  53. #define REPORT_NAME_DIGITAL(COUNTER, NAME) _ADD_PIN(NAME, COUNTER, true)
  54. #define REPORT_NAME_ANALOG(COUNTER, NAME) _ADD_PIN(analogInputToDigitalPin(NAME), COUNTER, false)
  55. typedef struct {
  56. PGM_P const name;
  57. pin_t pin;
  58. bool is_digital;
  59. } PinInfo;
  60. const PinInfo pin_array[] PROGMEM = {
  61. /**
  62. * [pin name] [pin number] [is digital or analog] 1 = digital, 0 = analog
  63. * Each entry takes up 6 bytes in FLASH:
  64. * 2 byte pointer to location of the name string
  65. * 2 bytes containing the pin number
  66. * analog pin numbers were convereted to digital when the array was created
  67. * 2 bytes containing the digital/analog bool flag
  68. */
  69. // manually add pins ...
  70. #if SERIAL_PORT == 0
  71. #if (AVR_ATmega2560_FAMILY || defined(ARDUINO_ARCH_SAM))
  72. { RXD_NAME, 0, true },
  73. { TXD_NAME, 1, true },
  74. #elif AVR_ATmega1284_FAMILY
  75. { RXD_NAME, 8, true },
  76. { TXD_NAME, 9, true },
  77. #endif
  78. #endif
  79. #include "pinsDebug_list.h"
  80. #line 98
  81. };
  82. #include HAL_PATH(../HAL, pinsDebug.h) // get the correct support file for this CPU
  83. #ifndef M43_NEVER_TOUCH
  84. #define M43_NEVER_TOUCH(Q) false
  85. #endif
  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(pin_t pin, bool ignore, bool extended = false, const char *start_string = "") {
  91. char buffer[MAX_NAME_LENGTH + 1]; // 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. if (found) multi_name_pin = true;
  96. found = true;
  97. if (!multi_name_pin) { // report digital and analog pin number only on the first time through
  98. sprintf_P(buffer, PSTR("%sPIN: "), start_string); // digital pin number
  99. SERIAL_ECHO(buffer);
  100. PRINT_PIN(pin);
  101. PRINT_PORT(pin);
  102. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
  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(MULTI_NAME_PAD + 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(IS_OUTPUT(46));
  121. SERIAL_CHAR('0' + READ(46));
  122. }
  123. else if (pin == 47) {
  124. print_input_or_output(IS_OUTPUT(47));
  125. SERIAL_CHAR('0' + READ(47));
  126. }
  127. }
  128. else
  129. #endif
  130. {
  131. if (!GET_ARRAY_IS_DIGITAL(x)) {
  132. sprintf_P(buffer, PSTR("Analog in = %5ld"), (long)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_ECHO(digitalRead_mod(pin));
  142. }
  143. else if (pwm_status(pin)) {
  144. // do nothing
  145. }
  146. else {
  147. print_input_or_output(true);
  148. SERIAL_ECHO(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: "), start_string);
  160. SERIAL_ECHO(buffer);
  161. PRINT_PIN(pin);
  162. PRINT_PORT(pin);
  163. if (int8_t(DIGITAL_PIN_TO_ANALOG_PIN(pin)) >= 0) {
  164. sprintf_P(buffer, PSTR(" (A%2d) "), DIGITAL_PIN_TO_ANALOG_PIN(pin)); // analog pin number
  165. SERIAL_ECHO(buffer);
  166. }
  167. else
  168. SERIAL_ECHO_SP(8); // add padding if not an analog pin
  169. SERIAL_ECHOPGM("<unused/unknown>");
  170. if (extended) {
  171. #if AVR_AT90USB1286_FAMILY //Teensy IDEs don't know about these pins so must use FASTIO
  172. if (pin == 46 || pin == 47) {
  173. SERIAL_ECHO_SP(12);
  174. if (pin == 46) {
  175. print_input_or_output(IS_OUTPUT(46));
  176. SERIAL_CHAR('0' + READ(46));
  177. }
  178. else {
  179. print_input_or_output(IS_OUTPUT(47));
  180. SERIAL_CHAR('0' + READ(47));
  181. }
  182. }
  183. else
  184. #endif
  185. {
  186. if (pwm_status(pin)) {
  187. // do nothing
  188. }
  189. else if (GET_PINMODE(pin)) {
  190. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  191. print_input_or_output(true);
  192. SERIAL_ECHO(digitalRead_mod(pin));
  193. }
  194. else {
  195. if (IS_ANALOG(pin)) {
  196. sprintf_P(buffer, PSTR(" Analog in = %5ld"), (long)analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)));
  197. SERIAL_ECHO(buffer);
  198. SERIAL_ECHOPGM(" ");
  199. }
  200. else
  201. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16); // add padding if not an analog pin
  202. print_input_or_output(false);
  203. SERIAL_ECHO(digitalRead_mod(pin));
  204. }
  205. //if (!pwm_status(pin)) SERIAL_CHAR(' '); // add padding if it's not a PWM pin
  206. if (extended) {
  207. SERIAL_ECHO_SP(MAX_NAME_LENGTH - 16);
  208. pwm_details(pin); // report PWM capabilities only if doing an extended report
  209. }
  210. }
  211. }
  212. SERIAL_EOL();
  213. }
  214. }