Skip to content

Commit ccf4ef8

Browse files
committed
use _MAX and other style tweaks
1 parent e92d929 commit ccf4ef8

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

Marlin/src/module/ft_motion.cpp

+19-16
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ FTMotion ftMotion;
5555
ft_config_t FTMotion::cfg;
5656
bool FTMotion::busy; // = false
5757
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.
6060

6161
bool FTMotion::sts_stepperBusy = false; // The stepper buffer has items and is in use.
6262

@@ -123,9 +123,7 @@ uint32_t FTMotion::interpIdx = 0, // Index of current data point b
123123
float FTMotion::e_advanced_z1 = 0.0f; // (ms) Unit delay of advanced extruder position.
124124
#endif
125125

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));
129127

130128
//-----------------------------------------------------------------
131129
// Function definitions.
@@ -149,12 +147,16 @@ void FTMotion::runoutBlock() {
149147
ratio.reset();
150148

151149
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+
);
158160
blockProcRdy = blockDataIsRunout = true;
159161
runoutEna = blockProcDn = false;
160162
}
@@ -457,7 +459,7 @@ void FTMotion::reset() {
457459
endPosn_prevBlock.reset();
458460

459461
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));
461463

462464
steps.reset();
463465
interpIdx = interpIdx_z1 = 0;
@@ -472,10 +474,11 @@ void FTMotion::reset() {
472474
}
473475

474476
// Private functions.
477+
475478
// 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;
479482
}
480483

481484
// Initializes storage variables before startup.
@@ -686,7 +689,7 @@ void FTMotion::makeVector() {
686689

687690
// Filled up the queue with regular and shaped steps
688691
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;
690693
batchRdy = true;
691694
}
692695

Marlin/src/module/ft_motion.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,11 @@ class FTMotion {
102102
}
103103

104104
static ft_command_t stepperCmdBuff[FTM_STEPPERCMD_BUFF_SIZE]; // Buffer of stepper commands.
105-
static uint32_t stepperCmdBuff_produceIdx, // Index of next stepper command write to the buffer.
106-
stepperCmdBuff_consumeIdx; // Index of next stepper command read from the buffer.
105+
static int32_t stepperCmdBuff_produceIdx, // Index of next stepper command write to the buffer.
106+
stepperCmdBuff_consumeIdx; // Index of next stepper command read from the buffer.
107107

108108
static bool sts_stepperBusy; // The stepper buffer has items and is in use.
109109

110-
111110
// Public methods
112111
static void init();
113112
static void startBlockProc(); // Set controller states to begin processing a block.
@@ -203,7 +202,7 @@ class FTMotion {
203202
#endif
204203

205204
// Private methods
206-
static uint32_t stepperCmdBuffItems();
205+
static int32_t stepperCmdBuffItems();
207206
static void loadBlockData(block_t *const current_block);
208207
static void makeVector();
209208
static void convertToSteps(const uint32_t idx);

Marlin/src/module/stepper.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3448,7 +3448,8 @@ void Stepper::report_positions() {
34483448
// Use one byte to restore one stepper command in the format:
34493449
// |X_step|X_direction|Y_step|Y_direction|Z_step|Z_direction|E_step|E_direction|
34503450
const ft_command_t command = ftMotion.stepperCmdBuff[ftMotion.stepperCmdBuff_consumeIdx];
3451-
if (++ftMotion.stepperCmdBuff_consumeIdx == (FTM_STEPPERCMD_BUFF_SIZE)) ftMotion.stepperCmdBuff_consumeIdx = 0U;
3451+
if (++ftMotion.stepperCmdBuff_consumeIdx == (FTM_STEPPERCMD_BUFF_SIZE))
3452+
ftMotion.stepperCmdBuff_consumeIdx = 0;
34523453

34533454
if (abort_current_block) return;
34543455

0 commit comments

Comments
 (0)