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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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_Z4_LABEL 'Z', '4'
  48. #define TMC_E0_LABEL 'E', '0'
  49. #define TMC_E1_LABEL 'E', '1'
  50. #define TMC_E2_LABEL 'E', '2'
  51. #define TMC_E3_LABEL 'E', '3'
  52. #define TMC_E4_LABEL 'E', '4'
  53. #define TMC_E5_LABEL 'E', '5'
  54. #define __TMC_CLASS(TYPE, L, I, A) TMCMarlin<CLASS_##TYPE, L, I, A>
  55. #define _TMC_CLASS(TYPE, LandI, A) __TMC_CLASS(TYPE, LandI, A)
  56. #define TMC_CLASS(ST, A) _TMC_CLASS(ST##_DRIVER_TYPE, TMC_##ST##_LABEL, A##_AXIS)
  57. #if ENABLED(DISTINCT_E_FACTORS)
  58. #define TMC_CLASS_E(N) TMC_CLASS(E##N, E##N)
  59. #else
  60. #define TMC_CLASS_E(N) TMC_CLASS(E##N, E)
  61. #endif
  62. typedef struct {
  63. uint8_t toff;
  64. int8_t hend;
  65. uint8_t hstrt;
  66. } chopper_timing_t;
  67. static constexpr chopper_timing_t chopper_timing = CHOPPER_TIMING;
  68. #if HAS_TMC220x
  69. void tmc_serial_begin();
  70. #endif
  71. void restore_trinamic_drivers();
  72. void reset_trinamic_drivers();
  73. #define AXIS_HAS_SQUARE_WAVE(A) (AXIS_IS_TMC(A) && ENABLED(SQUARE_WAVE_STEPPING))
  74. // X Stepper
  75. #if AXIS_IS_TMC(X)
  76. extern TMC_CLASS(X, X) stepperX;
  77. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  78. #define X_ENABLE_INIT() NOOP
  79. #define X_ENABLE_WRITE(STATE) stepperX.toff((STATE)==X_ENABLE_ON ? chopper_timing.toff : 0)
  80. #define X_ENABLE_READ() stepperX.isEnabled()
  81. #endif
  82. #if AXIS_HAS_SQUARE_WAVE(X)
  83. #define X_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(X_STEP_PIN); }while(0)
  84. #endif
  85. #endif
  86. // Y Stepper
  87. #if AXIS_IS_TMC(Y)
  88. extern TMC_CLASS(Y, Y) stepperY;
  89. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  90. #define Y_ENABLE_INIT() NOOP
  91. #define Y_ENABLE_WRITE(STATE) stepperY.toff((STATE)==Y_ENABLE_ON ? chopper_timing.toff : 0)
  92. #define Y_ENABLE_READ() stepperY.isEnabled()
  93. #endif
  94. #if AXIS_HAS_SQUARE_WAVE(Y)
  95. #define Y_STEP_WRITE(STATE) do{ if (STATE) TOGGLE(Y_STEP_PIN); }while(0)
  96. #endif
  97. #endif
  98. // Z Stepper
  99. #if AXIS_IS_TMC(Z)
  100. extern TMC_CLASS(Z, Z) stepperZ;
  101. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  102. #define Z_ENABLE_INIT() NOOP
  103. #define Z_ENABLE_WRITE(STATE) stepperZ.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
  104. #define Z_ENABLE_READ() stepperZ.isEnabled()
  105. #endif
  106. #if AXIS_HAS_SQUARE_WAVE(Z)
  107. #define Z_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(Z_STEP_PIN); }while(0)
  108. #endif
  109. #endif
  110. // X2 Stepper
  111. #if HAS_X2_ENABLE && AXIS_IS_TMC(X2)
  112. extern TMC_CLASS(X2, X) stepperX2;
  113. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  114. #define X2_ENABLE_INIT() NOOP
  115. #define X2_ENABLE_WRITE(STATE) stepperX2.toff((STATE)==X_ENABLE_ON ? chopper_timing.toff : 0)
  116. #define X2_ENABLE_READ() stepperX2.isEnabled()
  117. #endif
  118. #if AXIS_HAS_SQUARE_WAVE(X2)
  119. #define X2_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(X2_STEP_PIN); }while(0)
  120. #endif
  121. #endif
  122. // Y2 Stepper
  123. #if HAS_Y2_ENABLE && AXIS_IS_TMC(Y2)
  124. extern TMC_CLASS(Y2, Y) stepperY2;
  125. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  126. #define Y2_ENABLE_INIT() NOOP
  127. #define Y2_ENABLE_WRITE(STATE) stepperY2.toff((STATE)==Y_ENABLE_ON ? chopper_timing.toff : 0)
  128. #define Y2_ENABLE_READ() stepperY2.isEnabled()
  129. #endif
  130. #if AXIS_HAS_SQUARE_WAVE(Y2)
  131. #define Y2_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(Y2_STEP_PIN); }while(0)
  132. #endif
  133. #endif
  134. // Z2 Stepper
  135. #if HAS_Z2_ENABLE && AXIS_IS_TMC(Z2)
  136. extern TMC_CLASS(Z2, Z) stepperZ2;
  137. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(Z2)
  138. #define Z2_ENABLE_INIT() NOOP
  139. #define Z2_ENABLE_WRITE(STATE) stepperZ2.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
  140. #define Z2_ENABLE_READ() stepperZ2.isEnabled()
  141. #endif
  142. #if AXIS_HAS_SQUARE_WAVE(Z2)
  143. #define Z2_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(Z2_STEP_PIN); }while(0)
  144. #endif
  145. #endif
  146. // Z3 Stepper
  147. #if HAS_Z3_ENABLE && AXIS_IS_TMC(Z3)
  148. extern TMC_CLASS(Z3, Z) stepperZ3;
  149. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  150. #define Z3_ENABLE_INIT() NOOP
  151. #define Z3_ENABLE_WRITE(STATE) stepperZ3.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
  152. #define Z3_ENABLE_READ() stepperZ3.isEnabled()
  153. #endif
  154. #if AXIS_HAS_SQUARE_WAVE(Z3)
  155. #define Z3_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(Z3_STEP_PIN); }while(0)
  156. #endif
  157. #endif
  158. // Z4 Stepper
  159. #if HAS_Z4_ENABLE && AXIS_IS_TMC(Z4)
  160. extern TMC_CLASS(Z4, Z) stepperZ4;
  161. #if ENABLED(SOFTWARE_DRIVER_ENABLE)
  162. #define Z4_ENABLE_INIT() NOOP
  163. #define Z4_ENABLE_WRITE(STATE) stepperZ4.toff((STATE)==Z_ENABLE_ON ? chopper_timing.toff : 0)
  164. #define Z4_ENABLE_READ() stepperZ4.isEnabled()
  165. #endif
  166. #if AXIS_HAS_SQUARE_WAVE(Z4)
  167. #define Z4_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(Z4_STEP_PIN); }while(0)
  168. #endif
  169. #endif
  170. // E0 Stepper
  171. #if AXIS_IS_TMC(E0)
  172. extern TMC_CLASS_E(0) stepperE0;
  173. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E0)
  174. #define E0_ENABLE_INIT() NOOP
  175. #define E0_ENABLE_WRITE(STATE) stepperE0.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  176. #define E0_ENABLE_READ() stepperE0.isEnabled()
  177. #endif
  178. #if AXIS_HAS_SQUARE_WAVE(E0)
  179. #define E0_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E0_STEP_PIN); }while(0)
  180. #endif
  181. #endif
  182. // E1 Stepper
  183. #if AXIS_IS_TMC(E1)
  184. extern TMC_CLASS_E(1) stepperE1;
  185. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E1)
  186. #define E1_ENABLE_INIT() NOOP
  187. #define E1_ENABLE_WRITE(STATE) stepperE1.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  188. #define E1_ENABLE_READ() stepperE1.isEnabled()
  189. #endif
  190. #if AXIS_HAS_SQUARE_WAVE(E1)
  191. #define E1_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E1_STEP_PIN); }while(0)
  192. #endif
  193. #endif
  194. // E2 Stepper
  195. #if AXIS_IS_TMC(E2)
  196. extern TMC_CLASS_E(2) stepperE2;
  197. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E2)
  198. #define E2_ENABLE_INIT() NOOP
  199. #define E2_ENABLE_WRITE(STATE) stepperE2.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  200. #define E2_ENABLE_READ() stepperE2.isEnabled()
  201. #endif
  202. #if AXIS_HAS_SQUARE_WAVE(E2)
  203. #define E2_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E2_STEP_PIN); }while(0)
  204. #endif
  205. #endif
  206. // E3 Stepper
  207. #if AXIS_IS_TMC(E3)
  208. extern TMC_CLASS_E(3) stepperE3;
  209. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E3)
  210. #define E3_ENABLE_INIT() NOOP
  211. #define E3_ENABLE_WRITE(STATE) stepperE3.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  212. #define E3_ENABLE_READ() stepperE3.isEnabled()
  213. #endif
  214. #if AXIS_HAS_SQUARE_WAVE(E3)
  215. #define E3_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E3_STEP_PIN); }while(0)
  216. #endif
  217. #endif
  218. // E4 Stepper
  219. #if AXIS_IS_TMC(E4)
  220. extern TMC_CLASS_E(4) stepperE4;
  221. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E4)
  222. #define E4_ENABLE_INIT() NOOP
  223. #define E4_ENABLE_WRITE(STATE) stepperE4.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  224. #define E4_ENABLE_READ() stepperE4.isEnabled()
  225. #endif
  226. #if AXIS_HAS_SQUARE_WAVE(E4)
  227. #define E4_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E4_STEP_PIN); }while(0)
  228. #endif
  229. #endif
  230. // E5 Stepper
  231. #if AXIS_IS_TMC(E5)
  232. extern TMC_CLASS_E(5) stepperE5;
  233. #if ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E5)
  234. #define E5_ENABLE_INIT() NOOP
  235. #define E5_ENABLE_WRITE(STATE) stepperE5.toff((STATE)==E_ENABLE_ON ? chopper_timing.toff : 0)
  236. #define E5_ENABLE_READ() stepperE5.isEnabled()
  237. #endif
  238. #if AXIS_HAS_SQUARE_WAVE(E5)
  239. #define E5_STEP_WRITE(STATE) do{ if(STATE) TOGGLE(E5_STEP_PIN); }while(0)
  240. #endif
  241. #endif