Skip to content

Commit 4a0cb4f

Browse files
⚡️ Use AxisFlags for step_needed
Co-Authored-By: tombrazier <[email protected]>
1 parent d554844 commit 4a0cb4f

File tree

1 file changed

+30
-27
lines changed

1 file changed

+30
-27
lines changed

Marlin/src/module/stepper.cpp

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,21 +1661,24 @@ void Stepper::pulse_phase_isr() {
16611661
bool firstStep = true;
16621662
USING_TIMED_PULSE();
16631663
#endif
1664-
xyze_bool_t step_needed{0};
16651664

16661665
// Direct Stepping page?
16671666
const bool is_page = current_block->is_page();
16681667

16691668
do {
1669+
AxisFlags step_needed{0};
1670+
16701671
#define _APPLY_STEP(AXIS, INV, ALWAYS) AXIS ##_APPLY_STEP(INV, ALWAYS)
16711672
#define _STEP_STATE(AXIS) STEP_STATE_## AXIS
16721673

16731674
// Determine if a pulse is needed using Bresenham
16741675
#define PULSE_PREP(AXIS) do{ \
1675-
delta_error[_AXIS(AXIS)] += advance_dividend[_AXIS(AXIS)]; \
1676-
step_needed[_AXIS(AXIS)] = (delta_error[_AXIS(AXIS)] >= 0); \
1677-
if (step_needed[_AXIS(AXIS)]) \
1678-
delta_error[_AXIS(AXIS)] -= advance_divisor; \
1676+
int32_t de = delta_error[_AXIS(AXIS)] + advance_dividend[_AXIS(AXIS)]; \
1677+
if (de >= 0) { \
1678+
step_needed.set(_AXIS(AXIS)); \
1679+
de -= advance_divisor; \
1680+
} \
1681+
delta_error[_AXIS(AXIS)] = de; \
16791682
}while(0)
16801683

16811684
// With input shaping, direction changes can happen with almost only
@@ -1699,7 +1702,7 @@ void Stepper::pulse_phase_isr() {
16991702
#define HYSTERESIS(AXIS) _HYSTERESIS(AXIS)
17001703

17011704
#define PULSE_PREP_SHAPING(AXIS, DELTA_ERROR, DIVIDEND) do{ \
1702-
if (step_needed[_AXIS(AXIS)]) { \
1705+
if (step_needed.test(_AXIS(AXIS))) { \
17031706
DELTA_ERROR += (DIVIDEND); \
17041707
if ((MAXDIR(AXIS) && DELTA_ERROR <= -(64 + HYSTERESIS(AXIS))) || (MINDIR(AXIS) && DELTA_ERROR >= (64 + HYSTERESIS(AXIS)))) { \
17051708
{ USING_TIMED_PULSE(); START_TIMED_PULSE(); AWAIT_LOW_PULSE(); } \
@@ -1708,23 +1711,23 @@ void Stepper::pulse_phase_isr() {
17081711
SET_STEP_DIR(AXIS); \
17091712
DIR_WAIT_AFTER(); \
17101713
} \
1711-
step_needed[_AXIS(AXIS)] = DELTA_ERROR <= -(64 + HYSTERESIS(AXIS)) || DELTA_ERROR >= (64 + HYSTERESIS(AXIS)); \
1712-
if (step_needed[_AXIS(AXIS)]) \
1714+
step_needed.set(_AXIS(AXIS), DELTA_ERROR <= -(64 + HYSTERESIS(AXIS)) || DELTA_ERROR >= (64 + HYSTERESIS(AXIS))); \
1715+
if (step_needed.test(_AXIS(AXIS))) \
17131716
DELTA_ERROR += MAXDIR(AXIS) ? -128 : 128; \
17141717
} \
17151718
}while(0)
17161719

17171720
// Start an active pulse if needed
17181721
#define PULSE_START(AXIS) do{ \
1719-
if (step_needed[_AXIS(AXIS)]) { \
1722+
if (step_needed.test(_AXIS(AXIS))) { \
17201723
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
17211724
_APPLY_STEP(AXIS, _STEP_STATE(AXIS), 0); \
17221725
} \
17231726
}while(0)
17241727

17251728
// Stop an active pulse if needed
17261729
#define PULSE_STOP(AXIS) do { \
1727-
if (step_needed[_AXIS(AXIS)]) { \
1730+
if (step_needed.test(_AXIS(AXIS))) { \
17281731
_APPLY_STEP(AXIS, !_STEP_STATE(AXIS), 0); \
17291732
} \
17301733
}while(0)
@@ -1743,8 +1746,8 @@ void Stepper::pulse_phase_isr() {
17431746
}while(0)
17441747

17451748
#define PAGE_PULSE_PREP(AXIS) do{ \
1746-
step_needed[_AXIS(AXIS)] = \
1747-
pgm_read_byte(&segment_table[page_step_state.sd[_AXIS(AXIS)]][page_step_state.segment_steps & 0x7]); \
1749+
step_needed.set(_AXIS(AXIS), \
1750+
pgm_read_byte(&segment_table[page_step_state.sd[_AXIS(AXIS)]][page_step_state.segment_steps & 0x7])); \
17481751
}while(0)
17491752

17501753
switch (page_step_state.segment_steps) {
@@ -1784,8 +1787,8 @@ void Stepper::pulse_phase_isr() {
17841787
page_step_state.bd[_AXIS(AXIS)] += VALUE;
17851788

17861789
#define PAGE_PULSE_PREP(AXIS) do{ \
1787-
step_needed[_AXIS(AXIS)] = \
1788-
pgm_read_byte(&segment_table[page_step_state.sd[_AXIS(AXIS)]][page_step_state.segment_steps & 0x3]); \
1790+
step_needed.set(_AXIS(AXIS), \
1791+
pgm_read_byte(&segment_table[page_step_state.sd[_AXIS(AXIS)]][page_step_state.segment_steps & 0x3])); \
17891792
}while(0)
17901793

17911794
switch (page_step_state.segment_steps) {
@@ -1812,10 +1815,10 @@ void Stepper::pulse_phase_isr() {
18121815

18131816
#elif STEPPER_PAGE_FORMAT == SP_4x1_512
18141817

1815-
#define PAGE_PULSE_PREP(AXIS, BITS) do{ \
1816-
step_needed[_AXIS(AXIS)] = (steps >> BITS) & 0x1; \
1817-
if (step_needed[_AXIS(AXIS)]) \
1818-
page_step_state.bd[_AXIS(AXIS)]++; \
1818+
#define PAGE_PULSE_PREP(AXIS, NBIT) do{ \
1819+
step_needed.set(_AXIS(AXIS), TEST(steps, NBIT)); \
1820+
if (step_needed.test(_AXIS(AXIS))) \
1821+
page_step_state.bd[_AXIS(AXIS)]++; \
18191822
}while(0)
18201823

18211824
uint8_t steps = page_step_state.page[page_step_state.segment_idx >> 1];
@@ -1880,8 +1883,8 @@ void Stepper::pulse_phase_isr() {
18801883

18811884
#if HAS_SHAPING
18821885
// record an echo if a step is needed in the primary bresenham
1883-
const bool x_step = TERN0(INPUT_SHAPING_X, shaping_x.enabled && step_needed[X_AXIS]),
1884-
y_step = TERN0(INPUT_SHAPING_Y, shaping_y.enabled && step_needed[Y_AXIS]);
1886+
const bool x_step = TERN0(INPUT_SHAPING_X, shaping_x.enabled && step_needed.x),
1887+
y_step = TERN0(INPUT_SHAPING_Y, shaping_y.enabled && step_needed.y);
18851888
if (x_step || y_step)
18861889
ShapingQueue::enqueue(x_step, TERN0(INPUT_SHAPING_X, shaping_x.forward), y_step, TERN0(INPUT_SHAPING_Y, shaping_y.forward));
18871890

@@ -1995,23 +1998,23 @@ void Stepper::pulse_phase_isr() {
19951998
#if HAS_SHAPING
19961999

19972000
void Stepper::shaping_isr() {
1998-
xy_bool_t step_needed{0};
2001+
AxisFlags step_needed{0};
19992002

20002003
// Clear the echoes that are ready to process. If the buffers are too full and risk overflow, also apply echoes early.
2001-
TERN_(INPUT_SHAPING_X, step_needed[X_AXIS] = !ShapingQueue::peek_x() || ShapingQueue::free_count_x() < steps_per_isr);
2002-
TERN_(INPUT_SHAPING_Y, step_needed[Y_AXIS] = !ShapingQueue::peek_y() || ShapingQueue::free_count_y() < steps_per_isr);
2004+
TERN_(INPUT_SHAPING_X, step_needed.x = !ShapingQueue::peek_x() || ShapingQueue::free_count_x() < steps_per_isr);
2005+
TERN_(INPUT_SHAPING_Y, step_needed.y = !ShapingQueue::peek_y() || ShapingQueue::free_count_y() < steps_per_isr);
20032006

20042007
if (bool(step_needed)) while (true) {
20052008
#if ENABLED(INPUT_SHAPING_X)
2006-
if (step_needed[X_AXIS]) {
2009+
if (step_needed.x) {
20072010
const bool forward = ShapingQueue::dequeue_x();
20082011
PULSE_PREP_SHAPING(X, shaping_x.delta_error, shaping_x.factor2 * (forward ? 1 : -1));
20092012
PULSE_START(X);
20102013
}
20112014
#endif
20122015

20132016
#if ENABLED(INPUT_SHAPING_Y)
2014-
if (step_needed[Y_AXIS]) {
2017+
if (step_needed.y) {
20152018
const bool forward = ShapingQueue::dequeue_y();
20162019
PULSE_PREP_SHAPING(Y, shaping_y.delta_error, shaping_y.factor2 * (forward ? 1 : -1));
20172020
PULSE_START(Y);
@@ -2034,8 +2037,8 @@ void Stepper::pulse_phase_isr() {
20342037
#endif
20352038
}
20362039

2037-
TERN_(INPUT_SHAPING_X, step_needed[X_AXIS] = !ShapingQueue::peek_x() || ShapingQueue::free_count_x() < steps_per_isr);
2038-
TERN_(INPUT_SHAPING_Y, step_needed[Y_AXIS] = !ShapingQueue::peek_y() || ShapingQueue::free_count_y() < steps_per_isr);
2040+
TERN_(INPUT_SHAPING_X, step_needed.x = !ShapingQueue::peek_x() || ShapingQueue::free_count_x() < steps_per_isr);
2041+
TERN_(INPUT_SHAPING_Y, step_needed.y = !ShapingQueue::peek_y() || ShapingQueue::free_count_y() < steps_per_isr);
20392042

20402043
if (!bool(step_needed)) break;
20412044

0 commit comments

Comments
 (0)