⚡️ Use AxisFlags for step_needed
Co-Authored-By: tombrazier <68918209+tombrazier@users.noreply.github.com>
This commit is contained in:
@@ -1661,21 +1661,24 @@ void Stepper::pulse_phase_isr() {
|
|||||||
bool firstStep = true;
|
bool firstStep = true;
|
||||||
USING_TIMED_PULSE();
|
USING_TIMED_PULSE();
|
||||||
#endif
|
#endif
|
||||||
xyze_bool_t step_needed{0};
|
|
||||||
|
|
||||||
// Direct Stepping page?
|
// Direct Stepping page?
|
||||||
const bool is_page = current_block->is_page();
|
const bool is_page = current_block->is_page();
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
AxisFlags step_needed{0};
|
||||||
|
|
||||||
#define _APPLY_STEP(AXIS, INV, ALWAYS) AXIS ##_APPLY_STEP(INV, ALWAYS)
|
#define _APPLY_STEP(AXIS, INV, ALWAYS) AXIS ##_APPLY_STEP(INV, ALWAYS)
|
||||||
#define _STEP_STATE(AXIS) STEP_STATE_## AXIS
|
#define _STEP_STATE(AXIS) STEP_STATE_## AXIS
|
||||||
|
|
||||||
// Determine if a pulse is needed using Bresenham
|
// Determine if a pulse is needed using Bresenham
|
||||||
#define PULSE_PREP(AXIS) do{ \
|
#define PULSE_PREP(AXIS) do{ \
|
||||||
delta_error[_AXIS(AXIS)] += advance_dividend[_AXIS(AXIS)]; \
|
int32_t de = delta_error[_AXIS(AXIS)] + advance_dividend[_AXIS(AXIS)]; \
|
||||||
step_needed[_AXIS(AXIS)] = (delta_error[_AXIS(AXIS)] >= 0); \
|
if (de >= 0) { \
|
||||||
if (step_needed[_AXIS(AXIS)]) \
|
step_needed.set(_AXIS(AXIS)); \
|
||||||
delta_error[_AXIS(AXIS)] -= advance_divisor; \
|
de -= advance_divisor; \
|
||||||
|
} \
|
||||||
|
delta_error[_AXIS(AXIS)] = de; \
|
||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
// With input shaping, direction changes can happen with almost only
|
// With input shaping, direction changes can happen with almost only
|
||||||
@@ -1699,7 +1702,7 @@ void Stepper::pulse_phase_isr() {
|
|||||||
#define HYSTERESIS(AXIS) _HYSTERESIS(AXIS)
|
#define HYSTERESIS(AXIS) _HYSTERESIS(AXIS)
|
||||||
|
|
||||||
#define PULSE_PREP_SHAPING(AXIS, DELTA_ERROR, DIVIDEND) do{ \
|
#define PULSE_PREP_SHAPING(AXIS, DELTA_ERROR, DIVIDEND) do{ \
|
||||||
if (step_needed[_AXIS(AXIS)]) { \
|
if (step_needed.test(_AXIS(AXIS))) { \
|
||||||
DELTA_ERROR += (DIVIDEND); \
|
DELTA_ERROR += (DIVIDEND); \
|
||||||
if ((MAXDIR(AXIS) && DELTA_ERROR <= -(64 + HYSTERESIS(AXIS))) || (MINDIR(AXIS) && DELTA_ERROR >= (64 + HYSTERESIS(AXIS)))) { \
|
if ((MAXDIR(AXIS) && DELTA_ERROR <= -(64 + HYSTERESIS(AXIS))) || (MINDIR(AXIS) && DELTA_ERROR >= (64 + HYSTERESIS(AXIS)))) { \
|
||||||
{ USING_TIMED_PULSE(); START_TIMED_PULSE(); AWAIT_LOW_PULSE(); } \
|
{ USING_TIMED_PULSE(); START_TIMED_PULSE(); AWAIT_LOW_PULSE(); } \
|
||||||
@@ -1708,15 +1711,15 @@ void Stepper::pulse_phase_isr() {
|
|||||||
SET_STEP_DIR(AXIS); \
|
SET_STEP_DIR(AXIS); \
|
||||||
DIR_WAIT_AFTER(); \
|
DIR_WAIT_AFTER(); \
|
||||||
} \
|
} \
|
||||||
step_needed[_AXIS(AXIS)] = DELTA_ERROR <= -(64 + HYSTERESIS(AXIS)) || DELTA_ERROR >= (64 + HYSTERESIS(AXIS)); \
|
step_needed.set(_AXIS(AXIS), DELTA_ERROR <= -(64 + HYSTERESIS(AXIS)) || DELTA_ERROR >= (64 + HYSTERESIS(AXIS))); \
|
||||||
if (step_needed[_AXIS(AXIS)]) \
|
if (step_needed.test(_AXIS(AXIS))) \
|
||||||
DELTA_ERROR += MAXDIR(AXIS) ? -128 : 128; \
|
DELTA_ERROR += MAXDIR(AXIS) ? -128 : 128; \
|
||||||
} \
|
} \
|
||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
// Start an active pulse if needed
|
// Start an active pulse if needed
|
||||||
#define PULSE_START(AXIS) do{ \
|
#define PULSE_START(AXIS) do{ \
|
||||||
if (step_needed[_AXIS(AXIS)]) { \
|
if (step_needed.test(_AXIS(AXIS))) { \
|
||||||
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
|
count_position[_AXIS(AXIS)] += count_direction[_AXIS(AXIS)]; \
|
||||||
_APPLY_STEP(AXIS, _STEP_STATE(AXIS), 0); \
|
_APPLY_STEP(AXIS, _STEP_STATE(AXIS), 0); \
|
||||||
} \
|
} \
|
||||||
@@ -1724,7 +1727,7 @@ void Stepper::pulse_phase_isr() {
|
|||||||
|
|
||||||
// Stop an active pulse if needed
|
// Stop an active pulse if needed
|
||||||
#define PULSE_STOP(AXIS) do { \
|
#define PULSE_STOP(AXIS) do { \
|
||||||
if (step_needed[_AXIS(AXIS)]) { \
|
if (step_needed.test(_AXIS(AXIS))) { \
|
||||||
_APPLY_STEP(AXIS, !_STEP_STATE(AXIS), 0); \
|
_APPLY_STEP(AXIS, !_STEP_STATE(AXIS), 0); \
|
||||||
} \
|
} \
|
||||||
}while(0)
|
}while(0)
|
||||||
@@ -1743,8 +1746,8 @@ void Stepper::pulse_phase_isr() {
|
|||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
#define PAGE_PULSE_PREP(AXIS) do{ \
|
#define PAGE_PULSE_PREP(AXIS) do{ \
|
||||||
step_needed[_AXIS(AXIS)] = \
|
step_needed.set(_AXIS(AXIS), \
|
||||||
pgm_read_byte(&segment_table[page_step_state.sd[_AXIS(AXIS)]][page_step_state.segment_steps & 0x7]); \
|
pgm_read_byte(&segment_table[page_step_state.sd[_AXIS(AXIS)]][page_step_state.segment_steps & 0x7])); \
|
||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
switch (page_step_state.segment_steps) {
|
switch (page_step_state.segment_steps) {
|
||||||
@@ -1784,8 +1787,8 @@ void Stepper::pulse_phase_isr() {
|
|||||||
page_step_state.bd[_AXIS(AXIS)] += VALUE;
|
page_step_state.bd[_AXIS(AXIS)] += VALUE;
|
||||||
|
|
||||||
#define PAGE_PULSE_PREP(AXIS) do{ \
|
#define PAGE_PULSE_PREP(AXIS) do{ \
|
||||||
step_needed[_AXIS(AXIS)] = \
|
step_needed.set(_AXIS(AXIS), \
|
||||||
pgm_read_byte(&segment_table[page_step_state.sd[_AXIS(AXIS)]][page_step_state.segment_steps & 0x3]); \
|
pgm_read_byte(&segment_table[page_step_state.sd[_AXIS(AXIS)]][page_step_state.segment_steps & 0x3])); \
|
||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
switch (page_step_state.segment_steps) {
|
switch (page_step_state.segment_steps) {
|
||||||
@@ -1812,10 +1815,10 @@ void Stepper::pulse_phase_isr() {
|
|||||||
|
|
||||||
#elif STEPPER_PAGE_FORMAT == SP_4x1_512
|
#elif STEPPER_PAGE_FORMAT == SP_4x1_512
|
||||||
|
|
||||||
#define PAGE_PULSE_PREP(AXIS, BITS) do{ \
|
#define PAGE_PULSE_PREP(AXIS, NBIT) do{ \
|
||||||
step_needed[_AXIS(AXIS)] = (steps >> BITS) & 0x1; \
|
step_needed.set(_AXIS(AXIS), TEST(steps, NBIT)); \
|
||||||
if (step_needed[_AXIS(AXIS)]) \
|
if (step_needed.test(_AXIS(AXIS))) \
|
||||||
page_step_state.bd[_AXIS(AXIS)]++; \
|
page_step_state.bd[_AXIS(AXIS)]++; \
|
||||||
}while(0)
|
}while(0)
|
||||||
|
|
||||||
uint8_t steps = page_step_state.page[page_step_state.segment_idx >> 1];
|
uint8_t steps = page_step_state.page[page_step_state.segment_idx >> 1];
|
||||||
@@ -1880,8 +1883,8 @@ void Stepper::pulse_phase_isr() {
|
|||||||
|
|
||||||
#if HAS_SHAPING
|
#if HAS_SHAPING
|
||||||
// record an echo if a step is needed in the primary bresenham
|
// record an echo if a step is needed in the primary bresenham
|
||||||
const bool x_step = TERN0(INPUT_SHAPING_X, shaping_x.enabled && step_needed[X_AXIS]),
|
const bool x_step = TERN0(INPUT_SHAPING_X, shaping_x.enabled && step_needed.x),
|
||||||
y_step = TERN0(INPUT_SHAPING_Y, shaping_y.enabled && step_needed[Y_AXIS]);
|
y_step = TERN0(INPUT_SHAPING_Y, shaping_y.enabled && step_needed.y);
|
||||||
if (x_step || y_step)
|
if (x_step || y_step)
|
||||||
ShapingQueue::enqueue(x_step, TERN0(INPUT_SHAPING_X, shaping_x.forward), y_step, TERN0(INPUT_SHAPING_Y, shaping_y.forward));
|
ShapingQueue::enqueue(x_step, TERN0(INPUT_SHAPING_X, shaping_x.forward), y_step, TERN0(INPUT_SHAPING_Y, shaping_y.forward));
|
||||||
|
|
||||||
@@ -1995,15 +1998,15 @@ void Stepper::pulse_phase_isr() {
|
|||||||
#if HAS_SHAPING
|
#if HAS_SHAPING
|
||||||
|
|
||||||
void Stepper::shaping_isr() {
|
void Stepper::shaping_isr() {
|
||||||
xy_bool_t step_needed{0};
|
AxisFlags step_needed{0};
|
||||||
|
|
||||||
// Clear the echoes that are ready to process. If the buffers are too full and risk overflow, also apply echoes early.
|
// Clear the echoes that are ready to process. If the buffers are too full and risk overflow, also apply echoes early.
|
||||||
TERN_(INPUT_SHAPING_X, step_needed[X_AXIS] = !ShapingQueue::peek_x() || ShapingQueue::free_count_x() < steps_per_isr);
|
TERN_(INPUT_SHAPING_X, step_needed.x = !ShapingQueue::peek_x() || ShapingQueue::free_count_x() < steps_per_isr);
|
||||||
TERN_(INPUT_SHAPING_Y, step_needed[Y_AXIS] = !ShapingQueue::peek_y() || ShapingQueue::free_count_y() < steps_per_isr);
|
TERN_(INPUT_SHAPING_Y, step_needed.y = !ShapingQueue::peek_y() || ShapingQueue::free_count_y() < steps_per_isr);
|
||||||
|
|
||||||
if (bool(step_needed)) while (true) {
|
if (bool(step_needed)) while (true) {
|
||||||
#if ENABLED(INPUT_SHAPING_X)
|
#if ENABLED(INPUT_SHAPING_X)
|
||||||
if (step_needed[X_AXIS]) {
|
if (step_needed.x) {
|
||||||
const bool forward = ShapingQueue::dequeue_x();
|
const bool forward = ShapingQueue::dequeue_x();
|
||||||
PULSE_PREP_SHAPING(X, shaping_x.delta_error, shaping_x.factor2 * (forward ? 1 : -1));
|
PULSE_PREP_SHAPING(X, shaping_x.delta_error, shaping_x.factor2 * (forward ? 1 : -1));
|
||||||
PULSE_START(X);
|
PULSE_START(X);
|
||||||
@@ -2011,7 +2014,7 @@ void Stepper::pulse_phase_isr() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLED(INPUT_SHAPING_Y)
|
#if ENABLED(INPUT_SHAPING_Y)
|
||||||
if (step_needed[Y_AXIS]) {
|
if (step_needed.y) {
|
||||||
const bool forward = ShapingQueue::dequeue_y();
|
const bool forward = ShapingQueue::dequeue_y();
|
||||||
PULSE_PREP_SHAPING(Y, shaping_y.delta_error, shaping_y.factor2 * (forward ? 1 : -1));
|
PULSE_PREP_SHAPING(Y, shaping_y.delta_error, shaping_y.factor2 * (forward ? 1 : -1));
|
||||||
PULSE_START(Y);
|
PULSE_START(Y);
|
||||||
@@ -2034,8 +2037,8 @@ void Stepper::pulse_phase_isr() {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TERN_(INPUT_SHAPING_X, step_needed[X_AXIS] = !ShapingQueue::peek_x() || ShapingQueue::free_count_x() < steps_per_isr);
|
TERN_(INPUT_SHAPING_X, step_needed.x = !ShapingQueue::peek_x() || ShapingQueue::free_count_x() < steps_per_isr);
|
||||||
TERN_(INPUT_SHAPING_Y, step_needed[Y_AXIS] = !ShapingQueue::peek_y() || ShapingQueue::free_count_y() < steps_per_isr);
|
TERN_(INPUT_SHAPING_Y, step_needed.y = !ShapingQueue::peek_y() || ShapingQueue::free_count_y() < steps_per_isr);
|
||||||
|
|
||||||
if (!bool(step_needed)) break;
|
if (!bool(step_needed)) break;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user