|
@ -28,24 +28,52 @@ |
|
|
#include "../inc/MarlinConfig.h" |
|
|
#include "../inc/MarlinConfig.h" |
|
|
#include <stdint.h> |
|
|
#include <stdint.h> |
|
|
|
|
|
|
|
|
|
|
|
#define __ES_ITEM(N) N, |
|
|
|
|
|
#define _ES_ITEM(K,N) TERN_(K,DEFER4(__ES_ITEM)(N)) |
|
|
|
|
|
|
|
|
enum EndstopEnum : char { |
|
|
enum EndstopEnum : char { |
|
|
X_MIN, Y_MIN, Z_MIN, Z_MIN_PROBE, |
|
|
_ES_ITEM(HAS_X_MIN, X_MIN) |
|
|
X_MAX, Y_MAX, Z_MAX, |
|
|
_ES_ITEM(HAS_X_MAX, X_MAX) |
|
|
X2_MIN, X2_MAX, |
|
|
_ES_ITEM(HAS_Y_MIN, Y_MIN) |
|
|
Y2_MIN, Y2_MAX, |
|
|
_ES_ITEM(HAS_Y_MAX, Y_MAX) |
|
|
Z2_MIN, Z2_MAX, |
|
|
_ES_ITEM(HAS_Z_MIN, Z_MIN) |
|
|
Z3_MIN, Z3_MAX, |
|
|
_ES_ITEM(HAS_Z_MAX, Z_MAX) |
|
|
Z4_MIN, Z4_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 X_ENDSTOP (x_home_dir(active_extruder) < 0 ? X_MIN : X_MAX) |
|
|
#define Y_ENDSTOP (Y_HOME_DIR < 0 ? Y_MIN : Y_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) |
|
|
#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 { |
|
|
class Endstops { |
|
|
public: |
|
|
public: |
|
|
#if HAS_EXTRA_ENDSTOPS |
|
|
|
|
|
typedef uint16_t esbits_t; |
|
|
typedef IF<(NUM_ENDSTOP_STATES > 8), uint16_t, uint8_t>::type endstop_mask_t; |
|
|
|
|
|
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS) |
|
|
#if ENABLED(X_DUAL_ENDSTOPS) |
|
|
static float x2_endstop_adj; |
|
|
static float x2_endstop_adj; |
|
|
#endif |
|
|
#endif |
|
@ -61,17 +89,14 @@ class Endstops { |
|
|
#if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4 |
|
|
#if ENABLED(Z_MULTI_ENDSTOPS) && NUM_Z_STEPPER_DRIVERS >= 4 |
|
|
static float z4_endstop_adj; |
|
|
static float z4_endstop_adj; |
|
|
#endif |
|
|
#endif |
|
|
#else |
|
|
|
|
|
typedef uint8_t esbits_t; |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
static bool enabled, enabled_globally; |
|
|
static bool enabled, enabled_globally; |
|
|
static esbits_t live_state; |
|
|
static endstop_mask_t live_state; |
|
|
static volatile uint8_t hit_state; // Use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT index
|
|
|
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 |
|
|
#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
|
|
|
static uint8_t endstop_poll_count; // Countdown from threshold for polling
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
@ -107,12 +132,12 @@ class Endstops { |
|
|
/**
|
|
|
/**
|
|
|
* Get Endstop hit state. |
|
|
* 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 |
|
|
* Get current endstops state |
|
|
*/ |
|
|
*/ |
|
|
FORCE_INLINE static esbits_t state() { |
|
|
FORCE_INLINE static endstop_mask_t state() { |
|
|
return |
|
|
return |
|
|
#if ENDSTOP_NOISE_THRESHOLD |
|
|
#if ENDSTOP_NOISE_THRESHOLD |
|
|
validated_live_state |
|
|
validated_live_state |
|
|