♻️ Minimize endstop bits
This commit is contained in:
committed by
Scott Lahteine
parent
046bac6769
commit
894c954e8f
@ -28,50 +28,75 @@
|
||||
#include "../inc/MarlinConfig.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#define __ES_ITEM(N) N,
|
||||
#define _ES_ITEM(K,N) TERN_(K,DEFER4(__ES_ITEM)(N))
|
||||
|
||||
enum EndstopEnum : char {
|
||||
X_MIN, Y_MIN, Z_MIN, Z_MIN_PROBE,
|
||||
X_MAX, Y_MAX, Z_MAX,
|
||||
X2_MIN, X2_MAX,
|
||||
Y2_MIN, Y2_MAX,
|
||||
Z2_MIN, Z2_MAX,
|
||||
Z3_MIN, Z3_MAX,
|
||||
Z4_MIN, Z4_MAX
|
||||
_ES_ITEM(HAS_X_MIN, X_MIN)
|
||||
_ES_ITEM(HAS_X_MAX, X_MAX)
|
||||
_ES_ITEM(HAS_Y_MIN, Y_MIN)
|
||||
_ES_ITEM(HAS_Y_MAX, Y_MAX)
|
||||
_ES_ITEM(HAS_Z_MIN, Z_MIN)
|
||||
_ES_ITEM(HAS_Z_MAX, Z_MAX)
|
||||
#if ENABLED(X_DUAL_ENDSTOPS)
|
||||
_ES_ITEM(HAS_X_MIN, X2_MIN)
|
||||
_ES_ITEM(HAS_X_MAX, X2_MAX)
|
||||
#endif
|
||||
#if ENABLED(Y_DUAL_ENDSTOPS)
|
||||
_ES_ITEM(HAS_Y_MIN, Y2_MIN)
|
||||
_ES_ITEM(HAS_Y_MAX, Y2_MAX)
|
||||
#endif
|
||||
#if ENABLED(Z_MULTI_ENDSTOPS)
|
||||
_ES_ITEM(HAS_Z_MIN, Z2_MIN)
|
||||
_ES_ITEM(HAS_Z_MAX, Z2_MAX)
|
||||
#if NUM_Z_STEPPER_DRIVERS >= 3
|
||||
_ES_ITEM(HAS_Z_MIN, Z3_MIN)
|
||||
_ES_ITEM(HAS_Z_MAX, Z3_MAX)
|
||||
#endif
|
||||
#if NUM_Z_STEPPER_DRIVERS >= 4
|
||||
_ES_ITEM(HAS_Z_MIN, Z4_MIN)
|
||||
_ES_ITEM(HAS_Z_MAX, Z4_MAX)
|
||||
#endif
|
||||
#endif
|
||||
_ES_ITEM(HAS_Z_MIN_PROBE_PIN, Z_MIN_PROBE)
|
||||
NUM_ENDSTOP_STATES
|
||||
};
|
||||
|
||||
#define X_ENDSTOP (x_home_dir(active_extruder) < 0 ? X_MIN : X_MAX)
|
||||
#define Y_ENDSTOP (Y_HOME_DIR < 0 ? Y_MIN : Y_MAX)
|
||||
#define Z_ENDSTOP (Z_HOME_DIR < 0 ? TERN(HOMING_Z_WITH_PROBE, Z_MIN, Z_MIN_PROBE) : Z_MAX)
|
||||
|
||||
#undef __ES_ITEM
|
||||
#undef _ES_ITEM
|
||||
|
||||
class Endstops {
|
||||
public:
|
||||
#if HAS_EXTRA_ENDSTOPS
|
||||
typedef uint16_t esbits_t;
|
||||
#if ENABLED(X_DUAL_ENDSTOPS)
|
||||
static float x2_endstop_adj;
|
||||
#endif
|
||||
#if ENABLED(Y_DUAL_ENDSTOPS)
|
||||
static float y2_endstop_adj;
|
||||
#endif
|
||||
#if ENABLED(Z_MULTI_ENDSTOPS)
|
||||
static float z2_endstop_adj;
|
||||
#endif
|
||||
#if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3
|
||||
static float z3_endstop_adj;
|
||||
#endif
|
||||
#if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4
|
||||
static float z4_endstop_adj;
|
||||
#endif
|
||||
#else
|
||||
typedef uint8_t esbits_t;
|
||||
|
||||
typedef IF<(NUM_ENDSTOP_STATES > 8), uint16_t, uint8_t>::type endstop_mask_t;
|
||||
|
||||
#if ENABLED(X_DUAL_ENDSTOPS)
|
||||
static float x2_endstop_adj;
|
||||
#endif
|
||||
#if ENABLED(Y_DUAL_ENDSTOPS)
|
||||
static float y2_endstop_adj;
|
||||
#endif
|
||||
#if ENABLED(Z_MULTI_ENDSTOPS)
|
||||
static float z2_endstop_adj;
|
||||
#endif
|
||||
#if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 3
|
||||
static float z3_endstop_adj;
|
||||
#endif
|
||||
#if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4
|
||||
static float z4_endstop_adj;
|
||||
#endif
|
||||
|
||||
private:
|
||||
static bool enabled, enabled_globally;
|
||||
static esbits_t live_state;
|
||||
static volatile uint8_t hit_state; // Use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT index
|
||||
static endstop_mask_t live_state;
|
||||
static volatile endstop_mask_t hit_state; // Use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT index
|
||||
|
||||
#if ENDSTOP_NOISE_THRESHOLD
|
||||
static esbits_t validated_live_state;
|
||||
static endstop_mask_t validated_live_state;
|
||||
static uint8_t endstop_poll_count; // Countdown from threshold for polling
|
||||
#endif
|
||||
|
||||
@ -107,12 +132,12 @@ class Endstops {
|
||||
/**
|
||||
* Get Endstop hit state.
|
||||
*/
|
||||
FORCE_INLINE static uint8_t trigger_state() { return hit_state; }
|
||||
FORCE_INLINE static endstop_mask_t trigger_state() { return hit_state; }
|
||||
|
||||
/**
|
||||
* Get current endstops state
|
||||
*/
|
||||
FORCE_INLINE static esbits_t state() {
|
||||
FORCE_INLINE static endstop_mask_t state() {
|
||||
return
|
||||
#if ENDSTOP_NOISE_THRESHOLD
|
||||
validated_live_state
|
||||
|
Reference in New Issue
Block a user