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.

babystep.h 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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. #include "../inc/MarlinConfigPre.h"
  24. #if ENABLED(INTEGRATED_BABYSTEPPING)
  25. #define BABYSTEPS_PER_SEC 1000UL
  26. #define BABYSTEP_TICKS ((STEPPER_TIMER_RATE) / (BABYSTEPS_PER_SEC))
  27. #else
  28. #define BABYSTEPS_PER_SEC 976UL
  29. #define BABYSTEP_TICKS ((TEMP_TIMER_RATE) / (BABYSTEPS_PER_SEC))
  30. #endif
  31. #if IS_CORE || EITHER(BABYSTEP_XY, I2C_POSITION_ENCODERS)
  32. #define BS_AXIS_IND(A) A
  33. #define BS_AXIS(I) AxisEnum(I)
  34. #else
  35. #define BS_AXIS_IND(A) 0
  36. #define BS_AXIS(I) Z_AXIS
  37. #endif
  38. #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
  39. #if ENABLED(BABYSTEP_XY)
  40. #define BS_TOTAL_IND(A) A
  41. #else
  42. #define BS_TOTAL_IND(A) 0
  43. #endif
  44. #endif
  45. class Babystep {
  46. public:
  47. static volatile int16_t steps[BS_AXIS_IND(Z_AXIS) + 1];
  48. static int16_t accum; // Total babysteps in current edit
  49. #if ENABLED(BABYSTEP_DISPLAY_TOTAL)
  50. static int16_t axis_total[BS_TOTAL_IND(Z_AXIS) + 1]; // Total babysteps since G28
  51. static inline void reset_total(const AxisEnum axis) {
  52. if (true
  53. #if ENABLED(BABYSTEP_XY)
  54. && axis == Z_AXIS
  55. #endif
  56. ) axis_total[BS_TOTAL_IND(axis)] = 0;
  57. }
  58. #endif
  59. static void add_steps(const AxisEnum axis, const int16_t distance);
  60. static void add_mm(const AxisEnum axis, const float &mm);
  61. static inline bool has_steps() {
  62. return steps[BS_AXIS_IND(X_AXIS)] || steps[BS_AXIS_IND(Y_AXIS)] || steps[BS_AXIS_IND(Z_AXIS)];
  63. }
  64. //
  65. // Called by the Temperature or Stepper ISR to
  66. // apply accumulated babysteps to the axes.
  67. //
  68. static inline void task() {
  69. LOOP_LE_N(i, BS_AXIS_IND(Z_AXIS)) step_axis(BS_AXIS(i));
  70. }
  71. private:
  72. static void step_axis(const AxisEnum axis);
  73. };
  74. extern Babystep babystep;