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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  17. *
  18. */
  19. #pragma once
  20. #warning "PINS_DEBUGGING is not fully supported for Teensy 4.0 / 4.1 so 'M43' may cause hangs."
  21. #define NUMBER_PINS_TOTAL NUM_DIGITAL_PINS
  22. #define digitalRead_mod(p) extDigitalRead(p) // AVR digitalRead disabled PWM before it read the pin
  23. #define PRINT_PORT(p)
  24. #define PRINT_ARRAY_NAME(x) do{ sprintf_P(buffer, PSTR("%-" STRINGIFY(MAX_NAME_LENGTH) "s"), pin_array[x].name); SERIAL_ECHO(buffer); }while(0)
  25. #define PRINT_PIN(p) do{ sprintf_P(buffer, PSTR("%02d"), p); SERIAL_ECHO(buffer); }while(0)
  26. #define GET_ARRAY_PIN(p) pin_array[p].pin
  27. #define GET_ARRAY_IS_DIGITAL(p) pin_array[p].is_digital
  28. #define VALID_PIN(pin) (pin >= 0 && pin < (int8_t)NUMBER_PINS_TOTAL ? 1 : 0)
  29. #define DIGITAL_PIN_TO_ANALOG_PIN(p) int(p - analogInputToDigitalPin(0))
  30. #define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && (P) <= analogInputToDigitalPin(13)) || ((P) >= analogInputToDigitalPin(14) && (P) <= analogInputToDigitalPin(17))
  31. #define pwm_status(pin) HAL_pwm_status(pin)
  32. #define GET_PINMODE(PIN) (VALID_PIN(pin) && IS_OUTPUT(pin))
  33. #define MULTI_NAME_PAD 16 // space needed to be pretty if not first name assigned to a pin
  34. struct pwm_pin_info_struct {
  35. uint8_t type; // 0=no pwm, 1=flexpwm, 2=quad
  36. uint8_t module; // 0-3, 0-3
  37. uint8_t channel; // 0=X, 1=A, 2=B
  38. uint8_t muxval; //
  39. };
  40. #define M(a, b) ((((a) - 1) << 4) | (b))
  41. const struct pwm_pin_info_struct pwm_pin_info[] = {
  42. {1, M(1, 1), 0, 4}, // FlexPWM1_1_X 0 // AD_B0_03
  43. {1, M(1, 0), 0, 4}, // FlexPWM1_0_X 1 // AD_B0_02
  44. {1, M(4, 2), 1, 1}, // FlexPWM4_2_A 2 // EMC_04
  45. {1, M(4, 2), 2, 1}, // FlexPWM4_2_B 3 // EMC_05
  46. {1, M(2, 0), 1, 1}, // FlexPWM2_0_A 4 // EMC_06
  47. {1, M(2, 1), 1, 1}, // FlexPWM2_1_A 5 // EMC_08
  48. {1, M(2, 2), 1, 2}, // FlexPWM2_2_A 6 // B0_10
  49. {1, M(1, 3), 2, 6}, // FlexPWM1_3_B 7 // B1_01
  50. {1, M(1, 3), 1, 6}, // FlexPWM1_3_A 8 // B1_00
  51. {1, M(2, 2), 2, 2}, // FlexPWM2_2_B 9 // B0_11
  52. {2, M(1, 0), 0, 1}, // QuadTimer1_0 10 // B0_00
  53. {2, M(1, 2), 0, 1}, // QuadTimer1_2 11 // B0_02
  54. {2, M(1, 1), 0, 1}, // QuadTimer1_1 12 // B0_01
  55. {2, M(2, 0), 0, 1}, // QuadTimer2_0 13 // B0_03
  56. {2, M(3, 2), 0, 1}, // QuadTimer3_2 14 // AD_B1_02
  57. {2, M(3, 3), 0, 1}, // QuadTimer3_3 15 // AD_B1_03
  58. {0, M(1, 0), 0, 0},
  59. {0, M(1, 0), 0, 0},
  60. {2, M(3, 1), 0, 1}, // QuadTimer3_1 18 // AD_B1_01
  61. {2, M(3, 0), 0, 1}, // QuadTimer3_0 19 // AD_B1_00
  62. {0, M(1, 0), 0, 0},
  63. {0, M(1, 0), 0, 0},
  64. {1, M(4, 0), 1, 1}, // FlexPWM4_0_A 22 // AD_B1_08
  65. {1, M(4, 1), 1, 1}, // FlexPWM4_1_A 23 // AD_B1_09
  66. {1, M(1, 2), 0, 4}, // FlexPWM1_2_X 24 // AD_B0_12
  67. {1, M(1, 3), 0, 4}, // FlexPWM1_3_X 25 // AD_B0_13
  68. {0, M(1, 0), 0, 0},
  69. {0, M(1, 0), 0, 0},
  70. {1, M(3, 1), 2, 1}, // FlexPWM3_1_B 28 // EMC_32
  71. {1, M(3, 1), 1, 1}, // FlexPWM3_1_A 29 // EMC_31
  72. {0, M(1, 0), 0, 0},
  73. {0, M(1, 0), 0, 0},
  74. {0, M(1, 0), 0, 0},
  75. {1, M(2, 0), 2, 1}, // FlexPWM2_0_B 33 // EMC_07
  76. #ifdef ARDUINO_TEENSY40
  77. {1, M(1, 1), 2, 1}, // FlexPWM1_1_B 34 // SD_B0_03
  78. {1, M(1, 1), 1, 1}, // FlexPWM1_1_A 35 // SD_B0_02
  79. {1, M(1, 0), 2, 1}, // FlexPWM1_0_B 36 // SD_B0_01
  80. {1, M(1, 0), 1, 1}, // FlexPWM1_0_A 37 // SD_B0_00
  81. {1, M(1, 2), 2, 1}, // FlexPWM1_2_B 38 // SD_B0_05
  82. {1, M(1, 2), 1, 1}, // FlexPWM1_2_A 39 // SD_B0_04
  83. #endif
  84. #ifdef ARDUINO_TEENSY41
  85. {0, M(1, 0), 0, 0},
  86. {0, M(1, 0), 0, 0},
  87. {1, M(2, 3), 1, 6}, // FlexPWM2_3_A 36 // B1_00
  88. {1, M(2, 3), 2, 6}, // FlexPWM2_3_B 37 // B1_01
  89. {0, M(1, 0), 0, 0},
  90. {0, M(1, 0), 0, 0},
  91. {0, M(1, 0), 0, 0},
  92. {0, M(1, 0), 0, 0},
  93. {1, M(1, 1), 2, 1}, // FlexPWM1_1_B 42 // SD_B0_03
  94. {1, M(1, 1), 1, 1}, // FlexPWM1_1_A 43 // SD_B0_02
  95. {1, M(1, 0), 2, 1}, // FlexPWM1_0_B 44 // SD_B0_01
  96. {1, M(1, 0), 1, 1}, // FlexPWM1_0_A 45 // SD_B0_00
  97. {1, M(1, 2), 2, 1}, // FlexPWM1_2_B 46 // SD_B0_05
  98. {1, M(1, 2), 1, 1}, // FlexPWM1_2_A 47 // SD_B0_04
  99. {0, M(1, 0), 0, 0}, // duplicate FlexPWM1_0_B
  100. {0, M(1, 0), 0, 0}, // duplicate FlexPWM1_2_A
  101. {0, M(1, 0), 0, 0}, // duplicate FlexPWM1_2_B
  102. {1, M(3, 3), 2, 1}, // FlexPWM3_3_B 51 // EMC_22
  103. {0, M(1, 0), 0, 0}, // duplicate FlexPWM1_1_B
  104. {0, M(1, 0), 0, 0}, // duplicate FlexPWM1_1_A
  105. {1, M(3, 0), 1, 1}, // FlexPWM3_0_A 53 // EMC_29
  106. #endif
  107. };
  108. void HAL_print_analog_pin(char buffer[], int8_t pin) {
  109. if (pin <= 23) sprintf_P(buffer, PSTR("(A%2d) "), int(pin - 14));
  110. else if (pin <= 41) sprintf_P(buffer, PSTR("(A%2d) "), int(pin - 24));
  111. }
  112. void HAL_analog_pin_state(char buffer[], int8_t pin) {
  113. if (pin <= 23) sprintf_P(buffer, PSTR("Analog in =% 5d"), analogRead(pin - 14));
  114. else if (pin <= 41) sprintf_P(buffer, PSTR("Analog in =% 5d"), analogRead(pin - 24));
  115. }
  116. #define PWM_PRINT(V) do{ sprintf_P(buffer, PSTR("PWM: %4d"), V); SERIAL_ECHO(buffer); }while(0)
  117. /**
  118. * Print a pin's PWM status.
  119. * Return true if it's currently a PWM pin.
  120. */
  121. bool HAL_pwm_status(int8_t pin) {
  122. char buffer[20]; // for the sprintf statements
  123. const struct pwm_pin_info_struct *info;
  124. if (pin >= CORE_NUM_DIGITAL) return 0;
  125. info = pwm_pin_info + pin;
  126. if (info->type == 0) return 0;
  127. /* TODO decode pwm value from timers */
  128. // for now just indicate if output is set as pwm
  129. PWM_PRINT(*(portConfigRegister(pin)) == info->muxval);
  130. return (*(portConfigRegister(pin)) == info->muxval);
  131. }
  132. static void pwm_details(uint8_t pin) { /* TODO */ }