optimisation: Add << operator to ErrorCode

Change in memory:
Flash: -54 bytes
SRAM: 0 bytes
pull/288/head
Guðni Már Gilbert 2023-07-23 16:15:55 +00:00 committed by DRracer
parent 35a89d2452
commit 5293547094
3 changed files with 19 additions and 32 deletions

View File

@ -17,6 +17,10 @@ inline ErrorCode &operator|=(ErrorCode &a, ErrorCode b) {
return a = (ErrorCode)((uint16_t)a | (uint16_t)b); return a = (ErrorCode)((uint16_t)a | (uint16_t)b);
} }
inline ErrorCode operator<<(ErrorCode a, uint8_t b) {
return a = (ErrorCode)((uint16_t)a << (uint16_t)b);
}
static ErrorCode TMC2130ToErrorCode(const hal::tmc2130::ErrorFlags &ef) { static ErrorCode TMC2130ToErrorCode(const hal::tmc2130::ErrorFlags &ef) {
ErrorCode e = ErrorCode::RUNNING; ErrorCode e = ErrorCode::RUNNING;
@ -39,21 +43,8 @@ static ErrorCode TMC2130ToErrorCode(const hal::tmc2130::ErrorFlags &ef) {
return e; return e;
} }
static ErrorCode __attribute__((noinline)) AddErrorAxisBit(ErrorCode ec, uint8_t tmcIndex) { ErrorCode __attribute__((noinline)) AddErrorAxisBit(ErrorCode ec, uint8_t axis) {
switch (tmcIndex) { return ec |= (ErrorCode::TMC_PULLEY_BIT << axis);
case config::Axis::Pulley:
ec |= ErrorCode::TMC_PULLEY_BIT;
break;
case config::Axis::Selector:
ec |= ErrorCode::TMC_SELECTOR_BIT;
break;
case config::Axis::Idler:
ec |= ErrorCode::TMC_IDLER_BIT;
break;
default:
break;
}
return ec;
} }
ErrorCode CheckMovable(const mm::MovableBase &m) { ErrorCode CheckMovable(const mm::MovableBase &m) {

View File

@ -14,6 +14,10 @@ class MovableBase;
/// The logic namespace handles the application logic on top of the modules. /// The logic namespace handles the application logic on top of the modules.
namespace logic { namespace logic {
/// Bitwise OR (ErrorCode::TMC_PULLEY_BIT << axis) into ec
/// where axis ranges from 0 to 2
ErrorCode AddErrorAxisBit(ErrorCode ec, uint8_t axis);
/// @brief Base class defining common API for high-level operations/commands/state machines /// @brief Base class defining common API for high-level operations/commands/state machines
/// ///
/// Which state machines are high-level? Those which are being initiated either by a command over the serial line or from a button /// Which state machines are high-level? Those which are being initiated either by a command over the serial line or from a button

View File

@ -1,5 +1,7 @@
/// @file hw_sanity.cpp /// @file hw_sanity.cpp
#include <string.h>
#include "hw_sanity.h" #include "hw_sanity.h"
#include "command_base.h"
#include "../modules/globals.h" #include "../modules/globals.h"
#include "../modules/motion.h" #include "../modules/motion.h"
#include "../modules/leds.h" #include "../modules/leds.h"
@ -26,9 +28,7 @@ bool HWSanity::Reset(uint8_t param) {
state = ProgressCode::HWTestBegin; state = ProgressCode::HWTestBegin;
error = ErrorCode::RUNNING; error = ErrorCode::RUNNING;
axis = config::Axis::Idler; axis = config::Axis::Idler;
fault_masks[0] = 0; memset(fault_masks, 0, sizeof(fault_masks));
fault_masks[1] = 0;
fault_masks[2] = 0;
return true; return true;
} }
@ -140,20 +140,12 @@ bool HWSanity::StepInner() {
// error, display it and return the code. // error, display it and return the code.
state = ProgressCode::ErrHwTestFailed; state = ProgressCode::ErrHwTestFailed;
error = ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION; error = ErrorCode::MMU_SOLDERING_NEEDS_ATTENTION;
uint8_t mask = fault_masks[Axis::Idler]; for (uint8_t axis = 0; axis < 3; axis++) {
if (mask) { const uint8_t mask = fault_masks[axis];
error |= ErrorCode::TMC_IDLER_BIT; if (mask) {
SetFaultDisplay(0, mask); error = logic::AddErrorAxisBit(error, axis);
} SetFaultDisplay(axis, mask);
mask = fault_masks[Axis::Pulley]; }
if (mask) {
error |= ErrorCode::TMC_PULLEY_BIT;
SetFaultDisplay(2, mask);
}
mask = fault_masks[Axis::Selector];
if (mask) {
error |= ErrorCode::TMC_SELECTOR_BIT;
SetFaultDisplay(1, mask);
} }
ml::leds.SetMode(3, ml::red, ml::off); ml::leds.SetMode(3, ml::red, ml::off);
ml::leds.SetMode(3, ml::green, ml::off); ml::leds.SetMode(3, ml::green, ml::off);