Skip to content

Commit

Permalink
use _MAX and other style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Jan 5, 2024
1 parent e92d929 commit ccf4ef8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
35 changes: 19 additions & 16 deletions Marlin/src/module/ft_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ FTMotion ftMotion;
ft_config_t FTMotion::cfg;
bool FTMotion::busy; // = false
ft_command_t FTMotion::stepperCmdBuff[FTM_STEPPERCMD_BUFF_SIZE] = {0U}; // Stepper commands buffer.
uint32_t FTMotion::stepperCmdBuff_produceIdx = 0, // Index of next stepper command write to the buffer.
FTMotion::stepperCmdBuff_consumeIdx = 0; // Index of next stepper command read from the buffer.
int32_t FTMotion::stepperCmdBuff_produceIdx = 0, // Index of next stepper command write to the buffer.
FTMotion::stepperCmdBuff_consumeIdx = 0; // Index of next stepper command read from the buffer.

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

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

#if DISABLED(FTM_UNIFIED_BWS)
constexpr uint32_t last_batchIdx = (FTM_WINDOW_SIZE) - (FTM_BATCH_SIZE);
#endif
constexpr uint32_t last_batchIdx = TERN(FTM_UNIFIED_BWS, 0, (FTM_WINDOW_SIZE) - (FTM_BATCH_SIZE));

//-----------------------------------------------------------------
// Function definitions.
Expand All @@ -149,12 +147,16 @@ void FTMotion::runoutBlock() {
ratio.reset();

max_intervals = cfg.modeHasShaper() ? shaper_intervals : 0;
if (max_intervals <= TERN(FTM_UNIFIED_BWS, FTM_BW_SIZE, min_max_intervals - (FTM_BATCH_SIZE))) max_intervals = min_max_intervals;
#if DISABLED(FTM_UNIFIED_BWS)
max_intervals += FTM_WINDOW_SIZE - ((FTM_BATCH_SIZE > last_batchIdx)? 0:makeVector_batchIdx);
#else
max_intervals += FTM_BW_SIZE - makeVector_batchIdx;
#endif
if (max_intervals <= TERN(FTM_UNIFIED_BWS, FTM_BW_SIZE, min_max_intervals - (FTM_BATCH_SIZE)))
max_intervals = min_max_intervals;

max_intervals += (
#if ENABLED(FTM_UNIFIED_BWS)
FTM_BW_SIZE - makeVector_batchIdx
#else
FTM_WINDOW_SIZE - ((last_batchIdx < (FTM_BATCH_SIZE)) ? 0 : makeVector_batchIdx)
#endif
);
blockProcRdy = blockDataIsRunout = true;
runoutEna = blockProcDn = false;
}
Expand Down Expand Up @@ -457,7 +459,7 @@ void FTMotion::reset() {
endPosn_prevBlock.reset();

makeVector_idx = makeVector_idx_z1 = 0;
makeVector_batchIdx = TERN(FTM_UNIFIED_BWS, 0, (FTM_BATCH_SIZE > last_batchIdx)? FTM_BATCH_SIZE:last_batchIdx);
makeVector_batchIdx = TERN(FTM_UNIFIED_BWS, 0, _MAX(last_batchIdx, FTM_BATCH_SIZE));

steps.reset();
interpIdx = interpIdx_z1 = 0;
Expand All @@ -472,10 +474,11 @@ void FTMotion::reset() {
}

// Private functions.

// Auxiliary function to get number of step commands in the buffer.
uint32_t FTMotion::stepperCmdBuffItems() {
const uint32_t udiff = stepperCmdBuff_produceIdx - stepperCmdBuff_consumeIdx;
return stepperCmdBuff_produceIdx < stepperCmdBuff_consumeIdx ? (FTM_STEPPERCMD_BUFF_SIZE) + udiff : udiff;
int32_t FTMotion::stepperCmdBuffItems() {
const int32_t udiff = stepperCmdBuff_produceIdx - stepperCmdBuff_consumeIdx;
return (udiff < 0) ? udiff + (FTM_STEPPERCMD_BUFF_SIZE) : udiff;
}

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

// Filled up the queue with regular and shaped steps
if (++makeVector_batchIdx == TERN(FTM_UNIFIED_BWS, FTM_BW_SIZE, FTM_WINDOW_SIZE)) {
makeVector_batchIdx = TERN(FTM_UNIFIED_BWS, 0, last_batchIdx);
makeVector_batchIdx = last_batchIdx;
batchRdy = true;
}

Expand Down
7 changes: 3 additions & 4 deletions Marlin/src/module/ft_motion.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ class FTMotion {
}

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

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


// Public methods
static void init();
static void startBlockProc(); // Set controller states to begin processing a block.
Expand Down Expand Up @@ -203,7 +202,7 @@ class FTMotion {
#endif

// Private methods
static uint32_t stepperCmdBuffItems();
static int32_t stepperCmdBuffItems();
static void loadBlockData(block_t *const current_block);
static void makeVector();
static void convertToSteps(const uint32_t idx);
Expand Down
3 changes: 2 additions & 1 deletion Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3448,7 +3448,8 @@ void Stepper::report_positions() {
// Use one byte to restore one stepper command in the format:
// |X_step|X_direction|Y_step|Y_direction|Z_step|Z_direction|E_step|E_direction|
const ft_command_t command = ftMotion.stepperCmdBuff[ftMotion.stepperCmdBuff_consumeIdx];
if (++ftMotion.stepperCmdBuff_consumeIdx == (FTM_STEPPERCMD_BUFF_SIZE)) ftMotion.stepperCmdBuff_consumeIdx = 0U;
if (++ftMotion.stepperCmdBuff_consumeIdx == (FTM_STEPPERCMD_BUFF_SIZE))
ftMotion.stepperCmdBuff_consumeIdx = 0;

if (abort_current_block) return;

Expand Down

0 comments on commit ccf4ef8

Please sign in to comment.