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.

tmc_util.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. #ifndef _TMC_UTIL_H_
  23. #define _TMC_UTIL_H_
  24. #include <TMC2130Stepper.h>
  25. #include "../inc/MarlinConfig.h"
  26. extern bool report_tmc_status;
  27. enum TMC_AxisEnum { TMC_X, TMC_X2, TMC_Y, TMC_Y2, TMC_Z, TMC_Z2, TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4 };
  28. constexpr uint32_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) {
  29. return 12650000UL * msteps / (256 * thrs * spmm);
  30. }
  31. void _tmc_say_axis(const TMC_AxisEnum axis);
  32. void _tmc_say_current(const TMC_AxisEnum axis, const uint16_t curr);
  33. void _tmc_say_otpw(const TMC_AxisEnum axis, const bool otpw);
  34. void _tmc_say_otpw_cleared(const TMC_AxisEnum axis);
  35. void _tmc_say_pwmthrs(const TMC_AxisEnum axis, const uint32_t thrs);
  36. void _tmc_say_sgt(const TMC_AxisEnum axis, const int8_t sgt);
  37. template<typename TMC>
  38. void tmc_get_current(TMC &st, const TMC_AxisEnum axis) {
  39. _tmc_say_current(axis, st.getCurrent());
  40. }
  41. template<typename TMC>
  42. void tmc_set_current(TMC &st, const TMC_AxisEnum axis, const int mA) {
  43. st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
  44. tmc_get_current(st, axis);
  45. }
  46. template<typename TMC>
  47. void tmc_report_otpw(TMC &st, const TMC_AxisEnum axis) {
  48. _tmc_say_otpw(axis, st.getOTPW());
  49. }
  50. template<typename TMC>
  51. void tmc_clear_otpw(TMC &st, const TMC_AxisEnum axis) {
  52. st.clear_otpw();
  53. _tmc_say_otpw_cleared(axis);
  54. }
  55. template<typename TMC>
  56. void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) {
  57. _tmc_say_pwmthrs(axis, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm));
  58. }
  59. template<typename TMC>
  60. void tmc_set_pwmthrs(TMC &st, const TMC_AxisEnum axis, const int32_t thrs, const uint32_t spmm) {
  61. st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
  62. tmc_get_pwmthrs(st, axis, spmm);
  63. }
  64. template<typename TMC>
  65. void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) {
  66. _tmc_say_sgt(axis, st.sgt());
  67. }
  68. template<typename TMC>
  69. void tmc_set_sgt(TMC &st, const TMC_AxisEnum axis, const int8_t sgt_val) {
  70. st.sgt(sgt_val);
  71. tmc_get_sgt(st, axis);
  72. }
  73. void monitor_tmc_driver();
  74. #if ENABLED(TMC_DEBUG)
  75. void tmc_set_report_status(const bool status);
  76. void tmc_report_all();
  77. #endif
  78. /**
  79. * TMC2130 specific sensorless homing using stallGuard2.
  80. * stallGuard2 only works when in spreadCycle mode.
  81. * spreadCycle and stealthChop are mutually exclusive.
  82. *
  83. * Defined here because of limitations with templates and headers.
  84. */
  85. #if ENABLED(SENSORLESS_HOMING)
  86. void tmc_sensorless_homing(TMC2130Stepper &st, bool enable=true);
  87. #endif
  88. #if ENABLED(HAVE_TMC2130)
  89. void tmc_init_cs_pins();
  90. #endif
  91. #endif // _TMC_UTIL_H_