@@ -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,9 +123,7 @@ 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
- #if DISABLED(FTM_UNIFIED_BWS)
127
- constexpr uint32_t last_batchIdx = (FTM_WINDOW_SIZE) - (FTM_BATCH_SIZE);
128
- #endif
126
+ constexpr uint32_t last_batchIdx = TERN(FTM_UNIFIED_BWS, 0 , (FTM_WINDOW_SIZE) - (FTM_BATCH_SIZE));
129
127
130
128
// -----------------------------------------------------------------
131
129
// Function definitions.
@@ -149,12 +147,16 @@ void FTMotion::runoutBlock() {
149
147
ratio.reset ();
150
148
151
149
max_intervals = cfg.modeHasShaper () ? shaper_intervals : 0 ;
152
- if (max_intervals <= TERN (FTM_UNIFIED_BWS, FTM_BW_SIZE, min_max_intervals - (FTM_BATCH_SIZE))) max_intervals = min_max_intervals;
153
- #if DISABLED(FTM_UNIFIED_BWS)
154
- max_intervals += FTM_WINDOW_SIZE - ((FTM_BATCH_SIZE > last_batchIdx)? 0 :makeVector_batchIdx);
155
- #else
156
- max_intervals += FTM_BW_SIZE - makeVector_batchIdx;
157
- #endif
150
+ if (max_intervals <= TERN (FTM_UNIFIED_BWS, FTM_BW_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_BW_SIZE - makeVector_batchIdx
156
+ #else
157
+ FTM_WINDOW_SIZE - ((last_batchIdx < (FTM_BATCH_SIZE)) ? 0 : makeVector_batchIdx)
158
+ #endif
159
+ );
158
160
blockProcRdy = blockDataIsRunout = true ;
159
161
runoutEna = blockProcDn = false ;
160
162
}
@@ -457,7 +459,7 @@ void FTMotion::reset() {
457
459
endPosn_prevBlock.reset ();
458
460
459
461
makeVector_idx = makeVector_idx_z1 = 0 ;
460
- makeVector_batchIdx = TERN (FTM_UNIFIED_BWS, 0 , (FTM_BATCH_SIZE > last_batchIdx)? FTM_BATCH_SIZE:last_batchIdx );
462
+ makeVector_batchIdx = TERN (FTM_UNIFIED_BWS, 0 , _MAX ( last_batchIdx, FTM_BATCH_SIZE) );
461
463
462
464
steps.reset ();
463
465
interpIdx = interpIdx_z1 = 0 ;
@@ -472,10 +474,11 @@ void FTMotion::reset() {
472
474
}
473
475
474
476
// Private functions.
477
+
475
478
// Auxiliary function to get number of step commands in the buffer.
476
- uint32_t FTMotion::stepperCmdBuffItems () {
477
- const uint32_t udiff = stepperCmdBuff_produceIdx - stepperCmdBuff_consumeIdx;
478
- 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;
479
482
}
480
483
481
484
// Initializes storage variables before startup.
@@ -686,7 +689,7 @@ void FTMotion::makeVector() {
686
689
687
690
// Filled up the queue with regular and shaped steps
688
691
if (++makeVector_batchIdx == TERN (FTM_UNIFIED_BWS, FTM_BW_SIZE, FTM_WINDOW_SIZE)) {
689
- makeVector_batchIdx = TERN (FTM_UNIFIED_BWS, 0 , last_batchIdx) ;
692
+ makeVector_batchIdx = last_batchIdx;
690
693
batchRdy = true ;
691
694
}
692
695
0 commit comments