@@ -55,8 +55,8 @@ FTMotion ftMotion;
55
55
ft_config_t FTMotion::cfg;
56
56
bool FTMotion::busy; // = false
57
57
ft_command_t FTMotion::stepperCmdBuff[FTM_STEPPERCMD_BUFF_SIZE] = {0U }; // Stepper commands buffer.
58
- uint32_t FTMotion::stepperCmdBuff_produceIdx = 0 , // Index of next stepper command write to the buffer.
59
- FTMotion::stepperCmdBuff_consumeIdx = 0 ; // Index of next stepper command read from the buffer.
58
+ int32_t FTMotion::stepperCmdBuff_produceIdx = 0 , // Index of next stepper command write to the buffer.
59
+ FTMotion::stepperCmdBuff_consumeIdx = 0 ; // Index of next stepper command read from the buffer.
60
60
61
61
bool FTMotion::sts_stepperBusy = false ; // The stepper buffer has items and is in use.
62
62
@@ -123,6 +123,8 @@ uint32_t FTMotion::interpIdx = 0, // Index of current data point b
123
123
float FTMotion::e_advanced_z1 = 0 .0f ; // (ms) Unit delay of advanced extruder position.
124
124
#endif
125
125
126
+ constexpr uint32_t last_batchIdx = (FTM_WINDOW_SIZE) - (FTM_BATCH_SIZE);
127
+
126
128
// -----------------------------------------------------------------
127
129
// Function definitions.
128
130
// -----------------------------------------------------------------
@@ -145,8 +147,16 @@ void FTMotion::runoutBlock() {
145
147
ratio.reset ();
146
148
147
149
max_intervals = cfg.modeHasShaper () ? shaper_intervals : 0 ;
148
- if (max_intervals <= TERN (FTM_UNIFIED_BWS, FTM_BW_SIZE, min_max_intervals - (FTM_BATCH_SIZE))) max_intervals = min_max_intervals;
149
- max_intervals += TERN (FTM_UNIFIED_BWS, FTM_BW_SIZE, FTM_WINDOW_SIZE) - makeVector_batchIdx;
150
+ if (max_intervals <= TERN (FTM_UNIFIED_BWS, FTM_BATCH_SIZE, min_max_intervals - (FTM_BATCH_SIZE)))
151
+ max_intervals = min_max_intervals;
152
+
153
+ max_intervals += (
154
+ #if ENABLED(FTM_UNIFIED_BWS)
155
+ FTM_WINDOW_SIZE - makeVector_batchIdx
156
+ #else
157
+ FTM_WINDOW_SIZE - ((last_batchIdx < (FTM_BATCH_SIZE)) ? 0 : makeVector_batchIdx)
158
+ #endif
159
+ );
150
160
blockProcRdy = blockDataIsRunout = true ;
151
161
runoutEna = blockProcDn = false ;
152
162
}
@@ -198,7 +208,7 @@ void FTMotion::loop() {
198
208
);
199
209
200
210
// Shift the time series back in the window
201
- #define TSHIFT (A ) memcpy(traj.A, &traj.A[FTM_BATCH_SIZE], (FTM_WINDOW_SIZE - FTM_BATCH_SIZE) * sizeof (traj.A[0 ]))
211
+ #define TSHIFT (A ) memcpy(traj.A, &traj.A[FTM_BATCH_SIZE], last_batchIdx * sizeof (traj.A[0 ]))
202
212
LOGICAL_AXIS_CODE (
203
213
TSHIFT (e),
204
214
TSHIFT (x), TSHIFT (y), TSHIFT (z),
@@ -219,7 +229,7 @@ void FTMotion::loop() {
219
229
&& (interpIdx - interpIdx_z1 < (FTM_STEPS_PER_LOOP))
220
230
) {
221
231
convertToSteps (interpIdx);
222
- if (++interpIdx == TERN (FTM_UNIFIED_BWS, FTM_BW_SIZE, FTM_BATCH_SIZE) ) {
232
+ if (++interpIdx == FTM_BATCH_SIZE) {
223
233
batchRdyForInterp = false ;
224
234
interpIdx = 0 ;
225
235
}
@@ -449,7 +459,7 @@ void FTMotion::reset() {
449
459
endPosn_prevBlock.reset ();
450
460
451
461
makeVector_idx = makeVector_idx_z1 = 0 ;
452
- makeVector_batchIdx = 0 ;
462
+ makeVector_batchIdx = TERN (FTM_UNIFIED_BWS, 0 , _MAX (last_batchIdx, FTM_BATCH_SIZE)) ;
453
463
454
464
steps.reset ();
455
465
interpIdx = interpIdx_z1 = 0 ;
@@ -464,10 +474,11 @@ void FTMotion::reset() {
464
474
}
465
475
466
476
// Private functions.
477
+
467
478
// Auxiliary function to get number of step commands in the buffer.
468
- uint32_t FTMotion::stepperCmdBuffItems () {
469
- const uint32_t udiff = stepperCmdBuff_produceIdx - stepperCmdBuff_consumeIdx;
470
- return stepperCmdBuff_produceIdx < stepperCmdBuff_consumeIdx ? (FTM_STEPPERCMD_BUFF_SIZE) + udiff : udiff;
479
+ int32_t FTMotion::stepperCmdBuffItems () {
480
+ const int32_t udiff = stepperCmdBuff_produceIdx - stepperCmdBuff_consumeIdx;
481
+ return (udiff < 0 ) ? udiff + (FTM_STEPPERCMD_BUFF_SIZE) : udiff;
471
482
}
472
483
473
484
// Initializes storage variables before startup.
@@ -677,8 +688,8 @@ void FTMotion::makeVector() {
677
688
#endif
678
689
679
690
// Filled up the queue with regular and shaped steps
680
- if (++makeVector_batchIdx == TERN (FTM_UNIFIED_BWS, FTM_BW_SIZE, ( FTM_WINDOW_SIZE - FTM_BATCH_SIZE)) ) {
681
- makeVector_batchIdx = 0 ;
691
+ if (++makeVector_batchIdx == FTM_WINDOW_SIZE) {
692
+ makeVector_batchIdx = last_batchIdx ;
682
693
batchRdy = true ;
683
694
}
684
695
0 commit comments