♻️ Refactor Linear / Logical / Distinct Axes (#21953)

* More patches supporting EXTRUDERS 0
* Extend types in prep for more axes
This commit is contained in:
Scott Lahteine
2021-05-24 16:38:57 -05:00
committed by Scott Lahteine
parent f5f999d7bf
commit 4194cdda5b
43 changed files with 1142 additions and 788 deletions

View File

@ -537,12 +537,12 @@
* E_STEPPERS - Number of actual E stepper motors
* E_MANUAL - Number of E steppers for LCD move options
*/
#if EXTRUDERS
#define HAS_EXTRUDERS 1
#if EXTRUDERS > 1
#define HAS_MULTI_EXTRUDER 1
#endif
#define E_AXIS_N(E) AxisEnum(E_AXIS + E_INDEX_N(E))
#else
#undef EXTRUDERS
#define EXTRUDERS 0
@ -551,6 +551,7 @@
#undef SWITCHING_NOZZLE
#undef MIXING_EXTRUDER
#undef HOTEND_IDLE_TIMEOUT
#undef DISABLE_E
#endif
#if ENABLED(SWITCHING_EXTRUDER) // One stepper for every two EXTRUDERS
@ -604,6 +605,50 @@
#define E_MANUAL EXTRUDERS
#endif
/**
* Number of Linear Axes (e.g., XYZ)
* All the logical axes except for the tool (E) axis
*/
#ifndef LINEAR_AXES
#define LINEAR_AXES XYZ
#endif
/**
* Number of Logical Axes (e.g., XYZE)
* All the logical axes that can be commanded directly by G-code.
* Delta maps stepper-specific values to ABC steppers.
*/
#if HAS_EXTRUDERS
#define LOGICAL_AXES INCREMENT(LINEAR_AXES)
#else
#define LOGICAL_AXES LINEAR_AXES
#endif
/**
* DISTINCT_E_FACTORS is set to give extruders (some) individual settings.
*
* DISTINCT_AXES is the number of distinct addressable axes (not steppers).
* Includes all linear axes plus all distinguished extruders.
* The default behavior is to treat all extruders as a single E axis
* with shared motion and temperature settings.
*
* DISTINCT_E is the number of distinguished extruders. By default this
* well be 1 which indicates all extruders share the same settings.
*
* E_INDEX_N(E) should be used to get the E index of any item that might be
* distinguished.
*/
#if ENABLED(DISTINCT_E_FACTORS) && E_STEPPERS > 1
#define DISTINCT_AXES (LINEAR_AXES + E_STEPPERS)
#define DISTINCT_E E_STEPPERS
#define E_INDEX_N(E) (E)
#else
#undef DISTINCT_E_FACTORS
#define DISTINCT_AXES LOGICAL_AXES
#define DISTINCT_E 1
#define E_INDEX_N(E) 0
#endif
#if HOTENDS
#define HAS_HOTEND 1
#ifndef HOTEND_OVERSHOOT
@ -624,10 +669,6 @@
#define ARRAY_BY_HOTENDS(V...) ARRAY_N(HOTENDS, V)
#define ARRAY_BY_HOTENDS1(v1) ARRAY_N_1(HOTENDS, v1)
#if ENABLED(SWITCHING_EXTRUDER) && (DISABLED(SWITCHING_NOZZLE) || SWITCHING_EXTRUDER_SERVO_NR != SWITCHING_NOZZLE_SERVO_NR)
#define DO_SWITCH_EXTRUDER 1
#endif
/**
* Default hotend offsets, if not defined
*/
@ -653,40 +694,11 @@
#undef SINGLENOZZLE_STANDBY_FAN
#endif
/**
* Number of Linear Axes (e.g., XYZ)
* All the logical axes except for the tool (E) axis
*/
#ifndef LINEAR_AXES
#define LINEAR_AXES XYZ
// Switching extruder has its own servo?
#if ENABLED(SWITCHING_EXTRUDER) && (DISABLED(SWITCHING_NOZZLE) || SWITCHING_EXTRUDER_SERVO_NR != SWITCHING_NOZZLE_SERVO_NR)
#define DO_SWITCH_EXTRUDER 1
#endif
/**
* Number of Logical Axes (e.g., XYZE)
* All the logical axes that can be commanded directly by G-code.
* Delta maps stepper-specific values to ABC steppers.
*/
#if HAS_EXTRUDERS
#define LOGICAL_AXES INCREMENT(LINEAR_AXES)
#else
#define LOGICAL_AXES LINEAR_AXES
#endif
/**
* DISTINCT_E_FACTORS affects whether Extruders use different settings
*/
#if ENABLED(DISTINCT_E_FACTORS) && E_STEPPERS > 1
#define DISTINCT_E E_STEPPERS
#define DISTINCT_AXES (LINEAR_AXES + E_STEPPERS)
#define E_INDEX_N(E) (E)
#else
#undef DISTINCT_E_FACTORS
#define DISTINCT_E 1
#define DISTINCT_AXES LOGICAL_AXES
#define E_INDEX_N(E) 0
#endif
#define E_AXIS_N(E) AxisEnum(E_AXIS + E_INDEX_N(E))
/**
* The BLTouch Probe emulates a servo probe
* and uses "special" angles for its state.
@ -726,6 +738,9 @@
#define HAS_BED_PROBE 1
#endif
/**
* Fill in undefined Filament Sensor options
*/
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
#if NUM_RUNOUT_SENSORS >= 1
#ifndef FIL_RUNOUT1_STATE
@ -834,6 +849,9 @@
#define Z_HOME_TO_MIN 1
#endif
/**
* Conditionals based on the type of Bed Probe
*/
#if HAS_BED_PROBE
#if DISABLED(NOZZLE_AS_PROBE)
#define HAS_PROBE_XY_OFFSET 1
@ -868,7 +886,7 @@
#endif
/**
* Set granular options based on the specific type of leveling
* Conditionals based on the type of Bed Leveling
*/
#if ENABLED(AUTO_BED_LEVELING_UBL)
#undef LCD_BED_LEVELING

View File

@ -103,6 +103,9 @@
#undef THERMAL_PROTECTION_PERIOD
#undef WATCH_TEMP_PERIOD
#undef SHOW_TEMP_ADC_VALUES
#undef LCD_SHOW_E_TOTAL
#undef MANUAL_E_MOVES_RELATIVE
#undef STEALTHCHOP_E
#endif
#if TEMP_SENSOR_BED == 0
@ -482,6 +485,23 @@
#endif
#endif
// Remove unused STEALTHCHOP flags
#if LINEAR_AXES < 6
#undef STEALTHCHOP_K
#if LINEAR_AXES < 5
#undef STEALTHCHOP_J
#if LINEAR_AXES < 4
#undef STEALTHCHOP_I
#if LINEAR_AXES < 3
#undef STEALTHCHOP_Z
#if LINEAR_AXES < 2
#undef STEALTHCHOP_Y
#endif
#endif
#endif
#endif
#endif
//
// SD Card connection methods
// Defined here so pins and sanity checks can use them

View File

@ -1563,133 +1563,137 @@
#endif
// Extruder steppers and solenoids
#if PIN_EXISTS(E0_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E0))
#define HAS_E0_ENABLE 1
#endif
#if PIN_EXISTS(E0_DIR)
#define HAS_E0_DIR 1
#endif
#if PIN_EXISTS(E0_STEP)
#define HAS_E0_STEP 1
#endif
#if PIN_EXISTS(E0_MS1)
#define HAS_E0_MS_PINS 1
#endif
#if PIN_EXISTS(SOL0)
#define HAS_SOLENOID_0 1
#endif
#if HAS_EXTRUDERS
#if PIN_EXISTS(E1_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E1))
#define HAS_E1_ENABLE 1
#endif
#if PIN_EXISTS(E1_DIR)
#define HAS_E1_DIR 1
#endif
#if PIN_EXISTS(E1_STEP)
#define HAS_E1_STEP 1
#endif
#if PIN_EXISTS(E1_MS1)
#define HAS_E1_MS_PINS 1
#endif
#if PIN_EXISTS(SOL1)
#define HAS_SOLENOID_1 1
#endif
#if PIN_EXISTS(E0_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E0))
#define HAS_E0_ENABLE 1
#endif
#if PIN_EXISTS(E0_DIR)
#define HAS_E0_DIR 1
#endif
#if PIN_EXISTS(E0_STEP)
#define HAS_E0_STEP 1
#endif
#if PIN_EXISTS(E0_MS1)
#define HAS_E0_MS_PINS 1
#endif
#if PIN_EXISTS(SOL0)
#define HAS_SOLENOID_0 1
#endif
#if PIN_EXISTS(E2_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E2))
#define HAS_E2_ENABLE 1
#endif
#if PIN_EXISTS(E2_DIR)
#define HAS_E2_DIR 1
#endif
#if PIN_EXISTS(E2_STEP)
#define HAS_E2_STEP 1
#endif
#if PIN_EXISTS(E2_MS1)
#define HAS_E2_MS_PINS 1
#endif
#if PIN_EXISTS(SOL2)
#define HAS_SOLENOID_2 1
#endif
#if PIN_EXISTS(E1_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E1))
#define HAS_E1_ENABLE 1
#endif
#if PIN_EXISTS(E1_DIR)
#define HAS_E1_DIR 1
#endif
#if PIN_EXISTS(E1_STEP)
#define HAS_E1_STEP 1
#endif
#if PIN_EXISTS(E1_MS1)
#define HAS_E1_MS_PINS 1
#endif
#if PIN_EXISTS(SOL1)
#define HAS_SOLENOID_1 1
#endif
#if PIN_EXISTS(E3_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E3))
#define HAS_E3_ENABLE 1
#endif
#if PIN_EXISTS(E3_DIR)
#define HAS_E3_DIR 1
#endif
#if PIN_EXISTS(E3_STEP)
#define HAS_E3_STEP 1
#endif
#if PIN_EXISTS(E3_MS1)
#define HAS_E3_MS_PINS 1
#endif
#if PIN_EXISTS(SOL3)
#define HAS_SOLENOID_3 1
#endif
#if PIN_EXISTS(E2_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E2))
#define HAS_E2_ENABLE 1
#endif
#if PIN_EXISTS(E2_DIR)
#define HAS_E2_DIR 1
#endif
#if PIN_EXISTS(E2_STEP)
#define HAS_E2_STEP 1
#endif
#if PIN_EXISTS(E2_MS1)
#define HAS_E2_MS_PINS 1
#endif
#if PIN_EXISTS(SOL2)
#define HAS_SOLENOID_2 1
#endif
#if PIN_EXISTS(E4_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E4))
#define HAS_E4_ENABLE 1
#endif
#if PIN_EXISTS(E4_DIR)
#define HAS_E4_DIR 1
#endif
#if PIN_EXISTS(E4_STEP)
#define HAS_E4_STEP 1
#endif
#if PIN_EXISTS(E4_MS1)
#define HAS_E4_MS_PINS 1
#endif
#if PIN_EXISTS(SOL4)
#define HAS_SOLENOID_4 1
#endif
#if PIN_EXISTS(E3_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E3))
#define HAS_E3_ENABLE 1
#endif
#if PIN_EXISTS(E3_DIR)
#define HAS_E3_DIR 1
#endif
#if PIN_EXISTS(E3_STEP)
#define HAS_E3_STEP 1
#endif
#if PIN_EXISTS(E3_MS1)
#define HAS_E3_MS_PINS 1
#endif
#if PIN_EXISTS(SOL3)
#define HAS_SOLENOID_3 1
#endif
#if PIN_EXISTS(E5_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E5))
#define HAS_E5_ENABLE 1
#endif
#if PIN_EXISTS(E5_DIR)
#define HAS_E5_DIR 1
#endif
#if PIN_EXISTS(E5_STEP)
#define HAS_E5_STEP 1
#endif
#if PIN_EXISTS(E5_MS1)
#define HAS_E5_MS_PINS 1
#endif
#if PIN_EXISTS(SOL5)
#define HAS_SOLENOID_5 1
#endif
#if PIN_EXISTS(E4_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E4))
#define HAS_E4_ENABLE 1
#endif
#if PIN_EXISTS(E4_DIR)
#define HAS_E4_DIR 1
#endif
#if PIN_EXISTS(E4_STEP)
#define HAS_E4_STEP 1
#endif
#if PIN_EXISTS(E4_MS1)
#define HAS_E4_MS_PINS 1
#endif
#if PIN_EXISTS(SOL4)
#define HAS_SOLENOID_4 1
#endif
#if PIN_EXISTS(E6_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E6))
#define HAS_E6_ENABLE 1
#endif
#if PIN_EXISTS(E6_DIR)
#define HAS_E6_DIR 1
#endif
#if PIN_EXISTS(E6_STEP)
#define HAS_E6_STEP 1
#endif
#if PIN_EXISTS(E6_MS1)
#define HAS_E6_MS_PINS 1
#endif
#if PIN_EXISTS(SOL6)
#define HAS_SOLENOID_6 1
#endif
#if PIN_EXISTS(E5_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E5))
#define HAS_E5_ENABLE 1
#endif
#if PIN_EXISTS(E5_DIR)
#define HAS_E5_DIR 1
#endif
#if PIN_EXISTS(E5_STEP)
#define HAS_E5_STEP 1
#endif
#if PIN_EXISTS(E5_MS1)
#define HAS_E5_MS_PINS 1
#endif
#if PIN_EXISTS(SOL5)
#define HAS_SOLENOID_5 1
#endif
#if PIN_EXISTS(E7_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E7))
#define HAS_E7_ENABLE 1
#endif
#if PIN_EXISTS(E7_DIR)
#define HAS_E7_DIR 1
#endif
#if PIN_EXISTS(E7_STEP)
#define HAS_E7_STEP 1
#endif
#if PIN_EXISTS(E7_MS1)
#define HAS_E7_MS_PINS 1
#endif
#if PIN_EXISTS(SOL7)
#define HAS_SOLENOID_7 1
#endif
#if PIN_EXISTS(E6_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E6))
#define HAS_E6_ENABLE 1
#endif
#if PIN_EXISTS(E6_DIR)
#define HAS_E6_DIR 1
#endif
#if PIN_EXISTS(E6_STEP)
#define HAS_E6_STEP 1
#endif
#if PIN_EXISTS(E6_MS1)
#define HAS_E6_MS_PINS 1
#endif
#if PIN_EXISTS(SOL6)
#define HAS_SOLENOID_6 1
#endif
#if PIN_EXISTS(E7_ENABLE) || (ENABLED(SOFTWARE_DRIVER_ENABLE) && AXIS_IS_TMC(E7))
#define HAS_E7_ENABLE 1
#endif
#if PIN_EXISTS(E7_DIR)
#define HAS_E7_DIR 1
#endif
#if PIN_EXISTS(E7_STEP)
#define HAS_E7_STEP 1
#endif
#if PIN_EXISTS(E7_MS1)
#define HAS_E7_MS_PINS 1
#endif
#if PIN_EXISTS(SOL7)
#define HAS_SOLENOID_7 1
#endif
#endif // HAS_EXTRUDERS
//
// Trinamic Stepper Drivers
@ -2348,7 +2352,10 @@
#if PIN_EXISTS(DIGIPOTSS)
#define HAS_MOTOR_CURRENT_SPI 1
#endif
#if ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_Z, MOTOR_CURRENT_PWM_E)
#if HAS_EXTRUDERS && PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#define HAS_MOTOR_CURRENT_PWM_E 1
#endif
#if HAS_MOTOR_CURRENT_PWM_E || ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_Z)
#define HAS_MOTOR_CURRENT_PWM 1
#endif

View File

@ -1600,11 +1600,12 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
* Homing
*/
constexpr float hbm[] = HOMING_BUMP_MM;
static_assert(COUNT(hbm) == XYZ, "HOMING_BUMP_MM requires X, Y, and Z elements.");
static_assert(hbm[X_AXIS] >= 0, "HOMING_BUMP_MM.X must be greater than or equal to 0.");
static_assert(hbm[Y_AXIS] >= 0, "HOMING_BUMP_MM.Y must be greater than or equal to 0.");
static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal to 0.");
static_assert(COUNT(hbm) == LINEAR_AXES, "HOMING_BUMP_MM requires one element per linear axis.");
LINEAR_AXIS_CODE(
static_assert(hbm[X_AXIS] >= 0, "HOMING_BUMP_MM.X must be greater than or equal to 0."),
static_assert(hbm[Y_AXIS] >= 0, "HOMING_BUMP_MM.Y must be greater than or equal to 0."),
static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal to 0.")
);
#if ENABLED(CODEPENDENT_XY_HOMING)
#if ENABLED(QUICK_HOME)
#error "QUICK_HOME is incompatible with CODEPENDENT_XY_HOMING."
@ -1983,12 +1984,16 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
#error "HEATER_0_PIN not defined for this board."
#elif !ANY_PIN(TEMP_0, MAX6675_SS)
#error "TEMP_0_PIN or MAX6675_SS not defined for this board."
#elif ((defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)) && !PINS_EXIST(E0_STEP, E0_DIR))
#error "E0_STEP_PIN or E0_DIR_PIN not defined for this board."
#elif ( !(defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)) && (!PINS_EXIST(E0_STEP, E0_DIR) || !HAS_E0_ENABLE))
#error "E0_STEP_PIN, E0_DIR_PIN, or E0_ENABLE_PIN not defined for this board."
#elif EXTRUDERS && TEMP_SENSOR_0 == 0
#error "TEMP_SENSOR_0 is required if there are any extruders."
#endif
#if HAS_EXTRUDERS
#if ((defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)) && !PINS_EXIST(E0_STEP, E0_DIR))
#error "E0_STEP_PIN or E0_DIR_PIN not defined for this board."
#elif ( !(defined(__AVR_ATmega644P__) || defined(__AVR_ATmega1284P__)) && (!PINS_EXIST(E0_STEP, E0_DIR) || !HAS_E0_ENABLE))
#error "E0_STEP_PIN, E0_DIR_PIN, or E0_ENABLE_PIN not defined for this board."
#elif EXTRUDERS && TEMP_SENSOR_0 == 0
#error "TEMP_SENSOR_0 is required if there are any extruders."
#endif
#endif
/**