Skip to content

Commit

Permalink
use "has"
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Sep 29, 2022
1 parent 84c60af commit 8f7a9ed
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/inc/Conditionals_adv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,9 @@
#undef SHAPING_BUFFER_Y
#endif
#if SHAPING_FREQ_X && SHAPING_BUFFER_X
#define INPUT_SHAPING_X 1
#define HAS_SHAPING_X 1
#endif
#if SHAPING_FREQ_Y && SHAPING_BUFFER_Y
#define INPUT_SHAPING_Y 1
#define HAS_SHAPING_Y 1
#endif
#endif
4 changes: 2 additions & 2 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -4205,13 +4205,13 @@ static_assert(_PLUS_TEST(4), "HOMING_FEEDRATE_MM_M values must be positive.");

// Check requirements for Input Shaping
#if ENABLED(INPUT_SHAPING) && defined(__AVR__)
#if INPUT_SHAPING_X && (SHAPING_FREQ_X) * 2 * 0x10000 < (STEPPER_TIMER_RATE)
#if HAS_SHAPING_X && (SHAPING_FREQ_X) * 2 * 0x10000 < (STEPPER_TIMER_RATE)
#if F_CPU > 16000000
#error "SHAPING_FREQ_X is below the minimum (20) for AVR 20MHz."
#else
#error "SHAPING_FREQ_X is below the minimum (16) for AVR 16MHz."
#endif
#elif INPUT_SHAPING_Y && (SHAPING_FREQ_Y) * 2 * 0x10000 < (STEPPER_TIMER_RATE)
#elif HAS_SHAPING_Y && (SHAPING_FREQ_Y) * 2 * 0x10000 < (STEPPER_TIMER_RATE)
#if F_CPU > 16000000
#error "SHAPING_FREQ_Y is below the minimum (20) for AVR 20MHz."
#else
Expand Down
46 changes: 23 additions & 23 deletions Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ uint32_t Stepper::advance_divisor = 0,
Stepper::la_advance_steps = 0;
#endif

#if INPUT_SHAPING_X
#if HAS_SHAPING_X
DelayQueue<SHAPING_BUFFER_X> Stepper::shaping_queue_x;
#endif
#if INPUT_SHAPING_Y
#if HAS_SHAPING_Y
DelayQueue<SHAPING_BUFFER_Y> Stepper::shaping_queue_y;
#endif

Expand Down Expand Up @@ -1476,8 +1476,8 @@ void Stepper::isr() {

if (!nextMainISR) pulse_phase_isr(); // 0 = Do coordinated axes Stepper pulses

TERN_(INPUT_SHAPING_X, if (!shaping_queue_x.peek()) shaping_isr_x());
TERN_(INPUT_SHAPING_Y, if (!shaping_queue_y.peek()) shaping_isr_y());
TERN_(HAS_SHAPING_X, if (!shaping_queue_x.peek()) shaping_isr_x());
TERN_(HAS_SHAPING_Y, if (!shaping_queue_y.peek()) shaping_isr_y());

#if ENABLED(LIN_ADVANCE)
if (!nextAdvanceISR) { // 0 = Do Linear Advance E Stepper pulses
Expand Down Expand Up @@ -1509,8 +1509,8 @@ void Stepper::isr() {
const uint32_t interval = _MIN(
uint32_t(HAL_TIMER_TYPE_MAX), // Come back in a very long time
nextMainISR // Time until the next Pulse / Block phase
OPTARG(INPUT_SHAPING_X, shaping_queue_x.peek()) // Time until next input shaping echo for X
OPTARG(INPUT_SHAPING_Y, shaping_queue_y.peek()) // Time until next input shaping echo for Y
OPTARG(HAS_SHAPING_X, shaping_queue_x.peek()) // Time until next input shaping echo for X
OPTARG(HAS_SHAPING_Y, shaping_queue_y.peek()) // Time until next input shaping echo for Y
OPTARG(LIN_ADVANCE, nextAdvanceISR) // Come back early for Linear Advance?
OPTARG(INTEGRATED_BABYSTEPPING, nextBabystepISR) // Come back early for Babystepping?
);
Expand All @@ -1523,8 +1523,8 @@ void Stepper::isr() {
//

nextMainISR -= interval;
TERN_(INPUT_SHAPING_X, shaping_queue_x.decrement_delays(interval));
TERN_(INPUT_SHAPING_Y, shaping_queue_y.decrement_delays(interval));
TERN_(HAS_SHAPING_X, shaping_queue_x.decrement_delays(interval));
TERN_(HAS_SHAPING_Y, shaping_queue_y.decrement_delays(interval));

#if ENABLED(LIN_ADVANCE)
if (nextAdvanceISR != LA_ADV_NEVER) nextAdvanceISR -= interval;
Expand Down Expand Up @@ -1788,15 +1788,15 @@ void Stepper::pulse_phase_isr() {
#endif // DIRECT_STEPPING

if (!is_page) {
TERN_(INPUT_SHAPING_X, shaping_queue_x.enqueue(shaping_delay_x));
TERN_(INPUT_SHAPING_Y, shaping_queue_y.enqueue(shaping_delay_y));
TERN_(HAS_SHAPING_X, shaping_queue_x.enqueue(shaping_delay_x));
TERN_(HAS_SHAPING_Y, shaping_queue_y.enqueue(shaping_delay_y));

// Determine if pulses are needed
#if HAS_X_STEP
TERN(INPUT_SHAPING_X, PULSE_PREP_INPUT_SHAPING(X), PULSE_PREP(X));
TERN(HAS_SHAPING_X, PULSE_PREP_INPUT_SHAPING(X), PULSE_PREP(X));
#endif
#if HAS_Y_STEP
TERN(INPUT_SHAPING_Y, PULSE_PREP_INPUT_SHAPING(Y), PULSE_PREP(Y));
TERN(HAS_SHAPING_Y, PULSE_PREP_INPUT_SHAPING(Y), PULSE_PREP(Y));
#endif
#if HAS_Z_STEP
PULSE_PREP(Z);
Expand Down Expand Up @@ -1927,7 +1927,7 @@ void Stepper::pulse_phase_isr() {
} while (--events_to_do);
}

#if INPUT_SHAPING_X
#if HAS_SHAPING_X
void Stepper::shaping_isr_x() {
shaping_queue_x.dequeue();

Expand All @@ -1948,7 +1948,7 @@ void Stepper::pulse_phase_isr() {
}
#endif

#if INPUT_SHAPING_Y
#if HAS_SHAPING_Y
void Stepper::shaping_isr_y() {
shaping_queue_y.dequeue();

Expand Down Expand Up @@ -2046,10 +2046,10 @@ uint32_t Stepper::block_phase_isr() {
// If current block is finished, reset pointer and finalize state
if (step_events_completed >= step_event_count) {
// Only end block when input shaping echoes are complete and idle in the meantime
if (TERN0(INPUT_SHAPING_X, !shaping_queue_x.empty()) || TERN0(INPUT_SHAPING_Y, !shaping_queue_y.empty())) {
if (TERN0(HAS_SHAPING_X, !shaping_queue_x.empty()) || TERN0(HAS_SHAPING_Y, !shaping_queue_y.empty())) {
interval = 0;
TERN_(INPUT_SHAPING_X, NOLESS(interval, shaping_queue_x.peek_tail() + 1));
TERN_(INPUT_SHAPING_Y, NOLESS(interval, shaping_queue_y.peek_tail() + 1));
TERN_(HAS_SHAPING_X, NOLESS(interval, shaping_queue_x.peek_tail() + 1));
TERN_(HAS_SHAPING_Y, NOLESS(interval, shaping_queue_y.peek_tail() + 1));
}
else {
#if ENABLED(DIRECT_STEPPING)
Expand Down Expand Up @@ -2449,13 +2449,13 @@ uint32_t Stepper::block_phase_isr() {

// for input shaped axes, advance_divisor is replaced with 0x40000000
// and steps are repeated twice so dividends have to be scaled and halved
TERN_(INPUT_SHAPING_X, delta_error.x = 0);
TERN_(INPUT_SHAPING_Y, delta_error.y = 0);
TERN_(INPUT_SHAPING_X, advance_dividend.x = (uint64_t(current_block->steps.x) << 29) / step_event_count);
TERN_(INPUT_SHAPING_Y, advance_dividend.y = (uint64_t(current_block->steps.y) << 29) / step_event_count);
TERN_(HAS_SHAPING_X, delta_error.x = 0);
TERN_(HAS_SHAPING_Y, delta_error.y = 0);
TERN_(HAS_SHAPING_X, advance_dividend.x = (uint64_t(current_block->steps.x) << 29) / step_event_count);
TERN_(HAS_SHAPING_Y, advance_dividend.y = (uint64_t(current_block->steps.y) << 29) / step_event_count);
// finally, the scaling operation above introduces rounding errors which must now be removed
TERN_(INPUT_SHAPING_X, delta_error.x += (0x40000000L - advance_dividend.x * step_event_count) & 0x3FFFFFFFUL);
TERN_(INPUT_SHAPING_Y, delta_error.y += (0x40000000L - advance_dividend.y * step_event_count) & 0x3FFFFFFFUL);
TERN_(HAS_SHAPING_X, delta_error.x += (0x40000000L - advance_dividend.x * step_event_count) & 0x3FFFFFFFUL);
TERN_(HAS_SHAPING_Y, delta_error.y += (0x40000000L - advance_dividend.y * step_event_count) & 0x3FFFFFFFUL);

// No step events completed so far
step_events_completed = 0;
Expand Down
12 changes: 6 additions & 6 deletions Marlin/src/module/stepper.h
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,11 @@ class Stepper {
#endif

#if ENABLED(INPUT_SHAPING)
#if INPUT_SHAPING_X
#if HAS_SHAPING_X
static DelayQueue<SHAPING_BUFFER_X> shaping_queue_x;
static constexpr shaping_time_t shaping_delay_x = uint32_t(STEPPER_TIMER_RATE) / (SHAPING_FREQ_X) / 2;
#endif
#if INPUT_SHAPING_Y
#if HAS_SHAPING_Y
static DelayQueue<SHAPING_BUFFER_Y> shaping_queue_y;
static constexpr shaping_time_t shaping_delay_y = uint32_t(STEPPER_TIMER_RATE) / (SHAPING_FREQ_Y) / 2;
#endif
Expand Down Expand Up @@ -516,10 +516,10 @@ class Stepper {
// The stepper block processing ISR phase
static uint32_t block_phase_isr();

#if INPUT_SHAPING_X
#if HAS_SHAPING_X
static void shaping_isr_x();
#endif
#if INPUT_SHAPING_Y
#if HAS_SHAPING_Y
static void shaping_isr_y();
#endif

Expand Down Expand Up @@ -562,8 +562,8 @@ class Stepper {
axis_did_move = 0;
planner.release_current_block();
TERN_(LIN_ADVANCE, la_interval = nextAdvanceISR = LA_ADV_NEVER);
TERN_(INPUT_SHAPING_X, shaping_queue_x.purge());
TERN_(INPUT_SHAPING_Y, shaping_queue_y.purge());
TERN_(HAS_SHAPING_X, shaping_queue_x.purge());
TERN_(HAS_SHAPING_Y, shaping_queue_y.purge());
}

// Quickly stop all steppers
Expand Down

0 comments on commit 8f7a9ed

Please sign in to comment.