Skip to content

Commit d554844

Browse files
⚡️ Use cached la_active state
Co-Authored-By: tombrazier <[email protected]>
1 parent 194f587 commit d554844

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Marlin/src/module/stepper.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ uint32_t Stepper::advance_divisor = 0,
230230
int32_t Stepper::la_delta_error = 0,
231231
Stepper::la_dividend = 0,
232232
Stepper::la_advance_steps = 0;
233+
bool Stepper::la_active = false;
233234
#endif
234235

235236
#if HAS_SHAPING
@@ -1868,7 +1869,7 @@ void Stepper::pulse_phase_isr() {
18681869
PULSE_PREP(E);
18691870

18701871
#if ENABLED(LIN_ADVANCE)
1871-
if (step_needed.e && current_block->la_advance_rate) {
1872+
if (la_active && step_needed.e) {
18721873
// don't actually step here, but do subtract movements steps
18731874
// from the linear advance step count
18741875
step_needed.e = false;
@@ -2170,7 +2171,7 @@ hal_timer_t Stepper::block_phase_isr() {
21702171
acceleration_time += interval;
21712172

21722173
#if ENABLED(LIN_ADVANCE)
2173-
if (current_block->la_advance_rate) {
2174+
if (la_active) {
21742175
const uint32_t la_step_rate = la_advance_steps < current_block->max_adv_steps ? current_block->la_advance_rate : 0;
21752176
la_interval = calc_timer_interval(acc_step_rate + la_step_rate) << current_block->la_scaling;
21762177
}
@@ -2240,7 +2241,7 @@ hal_timer_t Stepper::block_phase_isr() {
22402241
deceleration_time += interval;
22412242

22422243
#if ENABLED(LIN_ADVANCE)
2243-
if (current_block->la_advance_rate) {
2244+
if (la_active) {
22442245
const uint32_t la_step_rate = la_advance_steps > current_block->final_adv_steps ? current_block->la_advance_rate : 0;
22452246
if (la_step_rate != step_rate) {
22462247
bool reverse_e = la_step_rate > step_rate;
@@ -2301,7 +2302,7 @@ hal_timer_t Stepper::block_phase_isr() {
23012302
ticks_nominal = calc_timer_interval(current_block->nominal_rate << oversampling_factor, steps_per_isr);
23022303

23032304
#if ENABLED(LIN_ADVANCE)
2304-
if (current_block->la_advance_rate)
2305+
if (la_active)
23052306
la_interval = calc_timer_interval(current_block->nominal_rate) << current_block->la_scaling;
23062307
#endif
23072308
}
@@ -2556,11 +2557,12 @@ hal_timer_t Stepper::block_phase_isr() {
25562557

25572558
// Initialize the trapezoid generator from the current block.
25582559
#if ENABLED(LIN_ADVANCE)
2560+
la_active = (current_block->la_advance_rate != 0);
25592561
#if DISABLED(MIXING_EXTRUDER) && E_STEPPERS > 1
25602562
// If the now active extruder wasn't in use during the last move, its pressure is most likely gone.
25612563
if (stepper_extruder != last_moved_extruder) la_advance_steps = 0;
25622564
#endif
2563-
if (current_block->la_advance_rate) {
2565+
if (la_active) {
25642566
// Apply LA scaling and discount the effect of frequency scaling
25652567
la_dividend = (advance_dividend.e << current_block->la_scaling) << oversampling_factor;
25662568
}
@@ -2621,7 +2623,7 @@ hal_timer_t Stepper::block_phase_isr() {
26212623
acceleration_time += interval;
26222624

26232625
#if ENABLED(LIN_ADVANCE)
2624-
if (current_block->la_advance_rate) {
2626+
if (la_active) {
26252627
const uint32_t la_step_rate = la_advance_steps < current_block->max_adv_steps ? current_block->la_advance_rate : 0;
26262628
la_interval = calc_timer_interval(current_block->initial_rate + la_step_rate) << current_block->la_scaling;
26272629
}

Marlin/src/module/stepper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ class Stepper {
574574
static int32_t la_delta_error, // Analogue of delta_error.e for E steps in LA ISR
575575
la_dividend, // Analogue of advance_dividend.e for E steps in LA ISR
576576
la_advance_steps; // Count of steps added to increase nozzle pressure
577+
static bool la_active; // Whether linear advance is used on the present segment.
577578
#endif
578579

579580
#if ENABLED(INTEGRATED_BABYSTEPPING)

0 commit comments

Comments
 (0)