From a17153f877725b81b5a8668a7b5e418fb5a18f39 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Sat, 19 Nov 2022 17:11:51 +0100 Subject: [PATCH] Make TMC mask more readable --- Firmware/mmu2.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Firmware/mmu2.cpp b/Firmware/mmu2.cpp index 632419b95..d405da2e5 100644 --- a/Firmware/mmu2.cpp +++ b/Firmware/mmu2.cpp @@ -918,7 +918,17 @@ void MMU2::ReportError(ErrorCode ec, ErrorSource res) { IncrementMMUFails(); // check if it is a "power" failure - we consider TMC-related errors as power failures - if( (uint16_t)ec & 0x7e00 ){ // @@TODO can be optimized to uint8_t operation + static constexpr uint16_t tmcMask = + ( (uint16_t)ErrorCode::TMC_IOIN_MISMATCH + | (uint16_t)ErrorCode::TMC_RESET + | (uint16_t)ErrorCode::TMC_UNDERVOLTAGE_ON_CHARGE_PUMP + | (uint16_t)ErrorCode::TMC_SHORT_TO_GROUND + | (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_WARN + | (uint16_t)ErrorCode::TMC_OVER_TEMPERATURE_ERROR + | (uint16_t)ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION ) & 0x7fffU; // skip the top bit + static_assert(tmcMask == 0x7e00); // just make sure we fail compilation if any of the TMC error codes change + + if ((uint16_t)ec & tmcMask) { // @@TODO can be optimized to uint8_t operation // TMC-related errors are from 0x8200 higher IncrementTMCFailures(); }