From f164a8afa04630706028952a8b7c70e118223c53 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Fri, 28 Jul 2023 16:59:48 +0200 Subject: [PATCH] Enforce specific ErrorCodes bitmask values --- src/logic/command_base.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/logic/command_base.cpp b/src/logic/command_base.cpp index e8e2a00..b44bfd3 100644 --- a/src/logic/command_base.cpp +++ b/src/logic/command_base.cpp @@ -44,6 +44,11 @@ static ErrorCode TMC2130ToErrorCode(const hal::tmc2130::ErrorFlags &ef) { } ErrorCode __attribute__((noinline)) AddErrorAxisBit(ErrorCode ec, uint8_t axis) { + // From now on, we rely on specific ErrorCode bitmask values - that allowed some important optimizations. + // In case someone fiddles with the bits, the build must fail. + static_assert((uint16_t)ErrorCode::TMC_PULLEY_BIT == 0x0040); + static_assert((uint16_t)ErrorCode::TMC_SELECTOR_BIT == 0x0080); + static_assert((uint16_t)ErrorCode::TMC_IDLER_BIT == 0x0100); return ec |= (ErrorCode::TMC_PULLEY_BIT << axis); }