2019-04-06 18:04:34 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2019-04-06 18:04:34 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2019-04-06 18:04:34 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-22 22:20:14 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2019-04-06 18:04:34 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../inc/MarlinConfigPre.h"
|
|
|
|
|
2020-02-15 21:42:28 -06:00
|
|
|
#if ENABLED(INTEGRATED_BABYSTEPPING)
|
|
|
|
#define BABYSTEPS_PER_SEC 1000UL
|
|
|
|
#define BABYSTEP_TICKS ((STEPPER_TIMER_RATE) / (BABYSTEPS_PER_SEC))
|
|
|
|
#else
|
|
|
|
#define BABYSTEPS_PER_SEC 976UL
|
|
|
|
#define BABYSTEP_TICKS ((TEMP_TIMER_RATE) / (BABYSTEPS_PER_SEC))
|
|
|
|
#endif
|
|
|
|
|
2019-04-06 18:04:34 -05:00
|
|
|
#if IS_CORE || EITHER(BABYSTEP_XY, I2C_POSITION_ENCODERS)
|
2020-02-24 05:29:13 -06:00
|
|
|
#define BS_AXIS_IND(A) A
|
|
|
|
#define BS_AXIS(I) AxisEnum(I)
|
2019-04-06 18:04:34 -05:00
|
|
|
#else
|
2020-02-24 05:29:13 -06:00
|
|
|
#define BS_AXIS_IND(A) 0
|
|
|
|
#define BS_AXIS(I) Z_AXIS
|
2019-04-06 18:04:34 -05:00
|
|
|
#endif
|
|
|
|
|
2019-09-28 16:58:48 -05:00
|
|
|
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
|
2019-04-06 18:04:34 -05:00
|
|
|
#if ENABLED(BABYSTEP_XY)
|
2020-02-24 06:11:31 -06:00
|
|
|
#define BS_TOTAL_IND(A) A
|
2019-04-06 18:04:34 -05:00
|
|
|
#else
|
2020-02-24 06:11:31 -06:00
|
|
|
#define BS_TOTAL_IND(A) 0
|
2019-04-06 18:04:34 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class Babystep {
|
|
|
|
public:
|
2020-02-24 05:29:13 -06:00
|
|
|
static volatile int16_t steps[BS_AXIS_IND(Z_AXIS) + 1];
|
2019-09-28 16:58:48 -05:00
|
|
|
static int16_t accum; // Total babysteps in current edit
|
|
|
|
|
|
|
|
#if ENABLED(BABYSTEP_DISPLAY_TOTAL)
|
2020-02-24 06:11:31 -06:00
|
|
|
static int16_t axis_total[BS_TOTAL_IND(Z_AXIS) + 1]; // Total babysteps since G28
|
2019-09-28 16:58:48 -05:00
|
|
|
static inline void reset_total(const AxisEnum axis) {
|
2020-04-22 16:35:03 -05:00
|
|
|
if (TERN1(BABYSTEP_XY, axis == Z_AXIS))
|
|
|
|
axis_total[BS_TOTAL_IND(axis)] = 0;
|
2019-09-28 16:58:48 -05:00
|
|
|
}
|
2019-04-06 18:04:34 -05:00
|
|
|
#endif
|
2019-09-16 15:01:46 -05:00
|
|
|
|
2019-04-10 18:34:38 -05:00
|
|
|
static void add_steps(const AxisEnum axis, const int16_t distance);
|
2019-04-06 18:04:34 -05:00
|
|
|
static void add_mm(const AxisEnum axis, const float &mm);
|
2020-02-14 05:14:37 -06:00
|
|
|
|
2020-02-15 21:42:28 -06:00
|
|
|
static inline bool has_steps() {
|
2020-02-24 05:29:13 -06:00
|
|
|
return steps[BS_AXIS_IND(X_AXIS)] || steps[BS_AXIS_IND(Y_AXIS)] || steps[BS_AXIS_IND(Z_AXIS)];
|
2020-02-15 21:42:28 -06:00
|
|
|
}
|
|
|
|
|
2020-02-14 05:14:37 -06:00
|
|
|
//
|
2020-02-15 21:42:28 -06:00
|
|
|
// Called by the Temperature or Stepper ISR to
|
2020-02-14 05:14:37 -06:00
|
|
|
// apply accumulated babysteps to the axes.
|
|
|
|
//
|
|
|
|
static inline void task() {
|
2020-02-24 05:29:13 -06:00
|
|
|
LOOP_LE_N(i, BS_AXIS_IND(Z_AXIS)) step_axis(BS_AXIS(i));
|
2020-02-14 05:14:37 -06:00
|
|
|
}
|
|
|
|
|
2019-04-06 18:04:34 -05:00
|
|
|
private:
|
|
|
|
static void step_axis(const AxisEnum axis);
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Babystep babystep;
|