From db279967da7a8c07bfed564640de95665ddf2fe2 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 27 Oct 2025 20:55:28 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=92=BB=20Simpler=20t?= =?UTF-8?q?ype=20conversion=20(defer!)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Marlin/src/core/types.h | 61 +++++++---------------------------- Marlin/src/module/stepper.cpp | 2 +- 2 files changed, 13 insertions(+), 50 deletions(-) diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h index d20a23aba3..cac42da06e 100644 --- a/Marlin/src/core/types.h +++ b/Marlin/src/core/types.h @@ -549,21 +549,12 @@ struct XYval { // Explicit copy and copies with conversion FI constexpr XYval copy() const { return *this; } FI constexpr XYval ABS() const { return { T(_ABS(x)), T(_ABS(y)) }; } + FI constexpr XYval asInt16() const { return { int16_t(x), int16_t(y) }; } + FI constexpr XYval asInt32() const { return { int32_t(x), int32_t(y) }; } FI constexpr XYval ROUNDL() const { return { int32_t(LROUND(x)), int32_t(LROUND(y)) }; } + FI constexpr XYval asFloat() const { return { static_cast(x), static_cast(y) }; } FI constexpr XYval reciprocal() const { return { _RECIP(x), _RECIP(y) }; } - // Conversion to other types - template - constexpr XYval as() const { - return XYval{ static_cast(x), static_cast(y) }; - } - FI constexpr XYval asInt16() const { return as(); } - FI constexpr XYval asInt32() const { return as(); } - FI constexpr XYval asUInt32() const { return as(); } - FI constexpr XYval asInt64() const { return as(); } - FI constexpr XYval asUInt64() const { return as(); } - FI constexpr XYval asFloat() const { return as(); } - // Marlin workspace shifting is done with G92 and M206 FI XYval asLogical() const { XYval o = asFloat(); toLogical(o); return o; } FI XYval asNative() const { XYval o = asFloat(); toNative(o); return o; } @@ -715,27 +706,12 @@ struct XYZval { // Explicit copy and copies with conversion FI constexpr XYZval copy() const { XYZval o = *this; return o; } FI constexpr XYZval ABS() const { return NUM_AXIS_ARRAY(T(_ABS(x)), T(_ABS(y)), T(_ABS(z)), T(_ABS(i)), T(_ABS(j)), T(_ABS(k)), T(_ABS(u)), T(_ABS(v)), T(_ABS(w))); } + FI constexpr XYZval asInt16() const { return NUM_AXIS_ARRAY(int16_t(x), int16_t(y), int16_t(z), int16_t(i), int16_t(j), int16_t(k), int16_t(u), int16_t(v), int16_t(w)); } + FI constexpr XYZval asInt32() const { return NUM_AXIS_ARRAY(int32_t(x), int32_t(y), int32_t(z), int32_t(i), int32_t(j), int32_t(k), int32_t(u), int32_t(v), int32_t(w)); } FI constexpr XYZval ROUNDL() const { return NUM_AXIS_ARRAY(int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(i)), int32_t(LROUND(j)), int32_t(LROUND(k)), int32_t(LROUND(u)), int32_t(LROUND(v)), int32_t(LROUND(w))); } + FI constexpr XYZval asFloat() const { return NUM_AXIS_ARRAY(static_cast(x), static_cast(y), static_cast(z), static_cast(i), static_cast(j), static_cast(k), static_cast(u), static_cast(v), static_cast(w)); } FI constexpr XYZval reciprocal() const { return NUM_AXIS_ARRAY(_RECIP(x), _RECIP(y), _RECIP(z), _RECIP(i), _RECIP(j), _RECIP(k), _RECIP(u), _RECIP(v), _RECIP(w)); } - // Conversion to other types - template - constexpr XYZval as() const { - return XYZval{ - NUM_AXIS_LIST( - static_cast(x), static_cast(y), static_cast(z), - static_cast(i), static_cast(j), static_cast(k), - static_cast(u), static_cast(v), static_cast(w) - ) - }; - } - FI constexpr XYZval asInt16() const { return as(); } - FI constexpr XYZval asInt32() const { return as(); } - FI constexpr XYZval asUInt32() const { return as(); } - FI constexpr XYZval asInt64() const { return as(); } - FI constexpr XYZval asUInt64() const { return as(); } - FI constexpr XYZval asFloat() const { return as(); } - // Marlin workspace shifting is done with G92 and M206 FI XYZval asLogical() const { XYZval o = asFloat(); toLogical(o); return o; } FI XYZval asNative() const { XYZval o = asFloat(); toNative(o); return o; } @@ -885,28 +861,15 @@ struct XYZEval { // Explicit copy and copies with conversion FI constexpr XYZEval copy() const { XYZEval v = *this; return v; } FI constexpr XYZEval ABS() const { return LOGICAL_AXIS_ARRAY(T(_ABS(e)), T(_ABS(x)), T(_ABS(y)), T(_ABS(z)), T(_ABS(i)), T(_ABS(j)), T(_ABS(k)), T(_ABS(u)), T(_ABS(v)), T(_ABS(w))); } + FI constexpr XYZEval asInt16() const { return LOGICAL_AXIS_ARRAY(int16_t(e), int16_t(x), int16_t(y), int16_t(z), int16_t(i), int16_t(j), int16_t(k), int16_t(u), int16_t(v), int16_t(w)); } + FI constexpr XYZEval asInt32() const { return LOGICAL_AXIS_ARRAY(int32_t(e), int32_t(x), int32_t(y), int32_t(z), int32_t(i), int32_t(j), int32_t(k), int32_t(u), int32_t(v), int32_t(w)); } + FI constexpr XYZEval asUInt32() const { return LOGICAL_AXIS_ARRAY(uint32_t(e), uint32_t(x), uint32_t(y), uint32_t(z), uint32_t(i), uint32_t(j), uint32_t(k), uint32_t(u), uint32_t(v), uint32_t(w)); } + FI constexpr XYZEval asInt64() const { return LOGICAL_AXIS_ARRAY(int64_t(e), int64_t(x), int64_t(y), int64_t(z), int64_t(i), int64_t(j), int64_t(k), int64_t(u), int64_t(v), int64_t(w)); } + FI constexpr XYZEval asUInt64() const { return LOGICAL_AXIS_ARRAY(uint64_t(e), uint64_t(x), uint64_t(y), uint64_t(z), uint64_t(i), uint64_t(j), uint64_t(k), uint64_t(u), uint64_t(v), uint64_t(w)); } FI constexpr XYZEval ROUNDL() const { return LOGICAL_AXIS_ARRAY(int32_t(LROUND(e)), int32_t(LROUND(x)), int32_t(LROUND(y)), int32_t(LROUND(z)), int32_t(LROUND(i)), int32_t(LROUND(j)), int32_t(LROUND(k)), int32_t(LROUND(u)), int32_t(LROUND(v)), int32_t(LROUND(w))); } + FI constexpr XYZEval asFloat() const { return LOGICAL_AXIS_ARRAY(static_cast(e), static_cast(x), static_cast(y), static_cast(z), static_cast(i), static_cast(j), static_cast(k), static_cast(u), static_cast(v), static_cast(w)); } FI constexpr XYZEval reciprocal() const { return LOGICAL_AXIS_ARRAY(_RECIP(e), _RECIP(x), _RECIP(y), _RECIP(z), _RECIP(i), _RECIP(j), _RECIP(k), _RECIP(u), _RECIP(v), _RECIP(w)); } - // Conversion to other types - template - constexpr XYZEval as() const { - return XYZEval{ - LOGICAL_AXIS_LIST( - static_cast(e), - static_cast(x), static_cast(y), static_cast(z), - static_cast(i), static_cast(j), static_cast(k), - static_cast(u), static_cast(v), static_cast(w) - ) - }; - } - FI constexpr XYZEval asInt16() const { return as(); } - FI constexpr XYZEval asInt32() const { return as(); } - FI constexpr XYZEval asUInt32() const { return as(); } - FI constexpr XYZEval asInt64() const { return as(); } - FI constexpr XYZEval asUInt64() const { return as(); } - FI constexpr XYZEval asFloat() const { return as(); } - // Marlin workspace shifting is done with G92 and M206 FI XYZEval asLogical() const { XYZEval o = asFloat(); toLogical(o); return o; } FI XYZEval asNative() const { XYZEval o = asFloat(); toNative(o); return o; } diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index a16d1e72e3..3025cb83bd 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -2699,7 +2699,7 @@ hal_timer_t Stepper::block_phase_isr() { TERN_(HAS_ROUGH_LIN_ADVANCE, la_delta_error = delta_error); // Calculate Bresenham dividends and divisors - advance_dividend = current_block->steps << 1; // narrowing conversion + advance_dividend = (current_block->steps << 1).asInt32(); advance_divisor = step_event_count << 1; #if ENABLED(INPUT_SHAPING_X)