My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

trinamic.h 9.4KB

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