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.

trinamic.h 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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. #pragma once
  23. /**
  24. * stepper/trinamic.h
  25. * Stepper driver indirection for Trinamic
  26. */
  27. #include <TMCStepper.h>
  28. #if TMCSTEPPER_VERSION < 0x000500
  29. #error "Update TMCStepper library to 0.5.0 or newer."
  30. #endif
  31. #include "../../inc/MarlinConfig.h"
  32. #include "../../feature/tmc_util.h"
  33. #define CLASS_TMC2130 TMC2130Stepper
  34. #define CLASS_TMC2160 TMC2160Stepper
  35. #define CLASS_TMC2208 TMC2208Stepper
  36. #define CLASS_TMC2209 TMC2209Stepper
  37. #define CLASS_TMC2660 TMC2660Stepper
  38. #define CLASS_TMC5130 TMC5130Stepper
  39. #define CLASS_TMC5160 TMC5160Stepper
  40. #define TMC_X_LABEL 'X', '0'
  41. #define TMC_Y_LABEL 'Y', '0'
  42. #define TMC_Z_LABEL 'Z', '0'
  43. #define TMC_X2_LABEL 'X', '2'
  44. #define TMC_Y2_LABEL 'Y', '2'
  45. #define TMC_Z2_LABEL 'Z', '2'
  46. #define TMC_Z3_LABEL 'Z', '3'
  47. #define TMC_E0_LABEL 'E', '0'
  48. #define TMC_E1_LABEL 'E', '1'
  49. #define TMC_E2_LABEL 'E', '2'
  50. #define TMC_E3_LABEL 'E', '3'
  51. #define TMC_E4_LABEL 'E', '4'
  52. #define TMC_E5_LABEL 'E', '5'
  53. #define __TMC_CLASS(TYPE, L, I, A) TMCMarlin<CLASS_##TYPE, L, I, A>
  54. #define _TMC_CLASS(TYPE, LandI, A) __TMC_CLASS(TYPE, LandI, A)
  55. #define TMC_CLASS(ST, A) _TMC_CLASS(ST##_DRIVER_TYPE, TMC_##ST##_LABEL, A##_AXIS)
  56. #if ENABLED(DISTINCT_E_FACTORS)
  57. #define TMC_CLASS_E(N) TMC_CLASS(E##N, E##N)
  58. #else
  59. #define TMC_CLASS_E(N) TMC_CLASS(E##N, E)
  60. #endif
  61. typedef struct {
  62. uint8_t toff;
  63. int8_t hend;
  64. uint8_t hstrt;
  65. } chopper_timing_t;
  66. static constexpr chopper_timing_t chopper_timing = CHOPPER_TIMING;
  67. #if HAS_TMC220x
  68. void tmc_serial_begin();
  69. #endif
  70. void restore_trinamic_drivers();
  71. void reset_trinamic_drivers();
  72. #define AXIS_HAS_SQUARE_WAVE(A) (AXIS_IS_TMC(A) && ENABLED(SQUARE_WAVE_STEPPING))
  73. // X Stepper
  74. #if AXIS_IS_TMC(X)
  75. extern TMC_CLASS(X, X) stepperX;
  76. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  77. #define X_ENABLE_INIT NOOP
  78. #define X_ENABLE_WRITE(STATE) stepperX.toff((STATE)==X_ENABLE_ON ? chopper_timing.toff : 0)
  79. #define X_ENABLE_READ() stepperX.isEnabled()
  80. #endif
  81. #if AXIS_HAS_SQUARE_WAVE(X)
  82. #define X_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(X_STEP_PIN); }while(0)
  83. #endif
  84. #endif
  85. // Y Stepper
  86. #if AXIS_IS_TMC(Y)
  87. extern TMC_CLASS(Y, Y) stepperY;
  88. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  89. #define Y_ENABLE_INIT NOOP
  90. #define Y_ENABLE_WRITE(STATE) stepperY.toff((STATE)==Y_ENABLE_ON ? chopper_timing.toff : 0)
  91. #define Y_ENABLE_READ() stepperY.isEnabled()
  92. #endif
  93. #if AXIS_HAS_SQUARE_WAVE(Y)
  94. #define Y_STEP_WRITE(STATE) do{ if (STATE) TOGGLE(Y_STEP_PIN); }while(0)
  95. #endif
  96. #endif
  97. // Z Stepper
  98. #if AXIS_IS_TMC(Z)
  99. extern TMC_CLASS(Z, Z) stepperZ;
  100. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  101. #define Z_ENABLE_INIT NOOP
  102. #define Z_ENABLE_WRITE(STATE) stepperZ.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
  103. #define Z_ENABLE_READ() stepperZ.isEnabled()
  104. #endif
  105. #if AXIS_HAS_SQUARE_WAVE(Z)
  106. #define Z_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(Z_STEP_PIN); }while(0)
  107. #endif
  108. #endif
  109. // X2 Stepper
  110. #if HAS_X2_ENABLE && AXIS_IS_TMC(X2)
  111. extern TMC_CLASS(X2, X) stepperX2;
  112. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  113. #define X2_ENABLE_INIT NOOP
  114. #define X2_ENABLE_WRITE(STATE) stepperX2.toff((STATE)==X_ENABLE_ON ? chopper_timing.toff : 0)
  115. #define X2_ENABLE_READ() stepperX2.isEnabled()
  116. #endif
  117. #if AXIS_HAS_SQUARE_WAVE(X2)
  118. #define X2_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(X2_STEP_PIN); }while(0)
  119. #endif
  120. #endif
  121. // Y2 Stepper
  122. #if HAS_Y2_ENABLE && AXIS_IS_TMC(Y2)
  123. extern TMC_CLASS(Y2, Y) stepperY2;
  124. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  125. #define Y2_ENABLE_INIT NOOP
  126. #define Y2_ENABLE_WRITE(STATE) stepperY2.toff((STATE)==Y_ENABLE_ON ? chopper_timing.toff : 0)
  127. #define Y2_ENABLE_READ() stepperY2.isEnabled()
  128. #endif
  129. #if AXIS_HAS_SQUARE_WAVE(Y2)
  130. #define Y2_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(Y2_STEP_PIN); }while(0)
  131. #endif
  132. #endif
  133. // Z2 Stepper
  134. #if HAS_Z2_ENABLE && AXIS_IS_TMC(Z2)
  135. extern TMC_CLASS(Z2, Z) stepperZ2;
  136. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(Z2)
  137. #define Z2_ENABLE_INIT NOOP
  138. #define Z2_ENABLE_WRITE(STATE) stepperZ2.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
  139. #define Z2_ENABLE_READ() stepperZ2.isEnabled()
  140. #endif
  141. #if AXIS_HAS_SQUARE_WAVE(Z2)
  142. #define Z2_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(Z2_STEP_PIN); }while(0)
  143. #endif
  144. #endif
  145. // Z3 Stepper
  146. #if HAS_Z3_ENABLE && AXIS_IS_TMC(Z3)
  147. extern TMC_CLASS(Z3, Z) stepperZ3;
  148. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  149. #define Z3_ENABLE_INIT NOOP
  150. #define Z3_ENABLE_WRITE(STATE) stepperZ3.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
  151. #define Z3_ENABLE_READ() stepperZ3.isEnabled()
  152. #endif
  153. #if AXIS_HAS_SQUARE_WAVE(Z3)
  154. #define Z3_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(Z3_STEP_PIN); }while(0)
  155. #endif
  156. #endif
  157. // E0 Stepper
  158. #if AXIS_IS_TMC(E0)
  159. extern TMC_CLASS_E(0) stepperE0;
  160. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E0)
  161. #define E0_ENABLE_INIT NOOP
  162. #define E0_ENABLE_WRITE(STATE) stepperE0.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  163. #define E0_ENABLE_READ() stepperE0.isEnabled()
  164. #endif
  165. #if AXIS_HAS_SQUARE_WAVE(E0)
  166. #define E0_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E0_STEP_PIN); }while(0)
  167. #endif
  168. #endif
  169. // E1 Stepper
  170. #if AXIS_IS_TMC(E1)
  171. extern TMC_CLASS_E(1) stepperE1;
  172. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E1)
  173. #define E1_ENABLE_INIT NOOP
  174. #define E1_ENABLE_WRITE(STATE) stepperE1.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  175. #define E1_ENABLE_READ() stepperE1.isEnabled()
  176. #endif
  177. #if AXIS_HAS_SQUARE_WAVE(E1)
  178. #define E1_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E1_STEP_PIN); }while(0)
  179. #endif
  180. #endif
  181. // E2 Stepper
  182. #if AXIS_IS_TMC(E2)
  183. extern TMC_CLASS_E(2) stepperE2;
  184. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E2)
  185. #define E2_ENABLE_INIT NOOP
  186. #define E2_ENABLE_WRITE(STATE) stepperE2.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  187. #define E2_ENABLE_READ() stepperE2.isEnabled()
  188. #endif
  189. #if AXIS_HAS_SQUARE_WAVE(E2)
  190. #define E2_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E2_STEP_PIN); }while(0)
  191. #endif
  192. #endif
  193. // E3 Stepper
  194. #if AXIS_IS_TMC(E3)
  195. extern TMC_CLASS_E(3) stepperE3;
  196. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E3)
  197. #define E3_ENABLE_INIT NOOP
  198. #define E3_ENABLE_WRITE(STATE) stepperE3.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  199. #define E3_ENABLE_READ() stepperE3.isEnabled()
  200. #endif
  201. #if AXIS_HAS_SQUARE_WAVE(E3)
  202. #define E3_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E3_STEP_PIN); }while(0)
  203. #endif
  204. #endif
  205. // E4 Stepper
  206. #if AXIS_IS_TMC(E4)
  207. extern TMC_CLASS_E(4) stepperE4;
  208. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E4)
  209. #define E4_ENABLE_INIT NOOP
  210. #define E4_ENABLE_WRITE(STATE) stepperE4.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  211. #define E4_ENABLE_READ() stepperE4.isEnabled()
  212. #endif
  213. #if AXIS_HAS_SQUARE_WAVE(E4)
  214. #define E4_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E4_STEP_PIN); }while(0)
  215. #endif
  216. #endif
  217. // E5 Stepper
  218. #if AXIS_IS_TMC(E5)
  219. extern TMC_CLASS_E(5) stepperE5;
  220. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E5)
  221. #define E5_ENABLE_INIT NOOP
  222. #define E5_ENABLE_WRITE(STATE) stepperE5.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  223. #define E5_ENABLE_READ() stepperE5.isEnabled()
  224. #endif
  225. #if AXIS_HAS_SQUARE_WAVE(E5)
  226. #define E5_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E5_STEP_PIN); }while(0)
  227. #endif
  228. #endif