This repository has been archived on 2022-01-28. You can view files and clone it, but cannot push or open issues or pull requests.
Marlin-Artillery-M600/Marlin/src/module/endstops.h

193 lines
5 KiB
C
Raw Normal View History

/**
* Marlin 3D Printer Firmware
2019-06-28 06:57:50 +02:00
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
*
* Based on Sprinter and grbl.
2019-06-28 06:57:50 +02:00
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#pragma once
/**
2018-03-10 12:56:04 +01:00
* endstops.h - manages endstops
*/
2017-09-18 12:55:09 +02:00
#include "../inc/MarlinConfig.h"
#include <stdint.h>
2018-03-07 05:35:22 +01:00
enum EndstopEnum : char {
2019-07-24 08:52:36 +02:00
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
2017-09-18 12:55:09 +02:00
};
class Endstops {
public:
2019-02-06 11:59:22 +01:00
#if HAS_EXTRA_ENDSTOPS
2017-09-18 12:55:09 +02:00
typedef uint16_t esbits_t;
2018-03-10 12:56:04 +01:00
#if ENABLED(X_DUAL_ENDSTOPS)
static float x2_endstop_adj;
2018-03-10 12:56:04 +01:00
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
static float y2_endstop_adj;
2018-03-10 12:56:04 +01:00
#endif
#if Z_MULTI_ENDSTOPS
static float z2_endstop_adj;
#endif
#if ENABLED(Z_TRIPLE_ENDSTOPS)
static float z3_endstop_adj;
2018-03-10 12:56:04 +01:00
#endif
#else
typedef uint8_t esbits_t;
#endif
2017-09-18 12:55:09 +02:00
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
#if ENDSTOP_NOISE_THRESHOLD
static esbits_t validated_live_state;
static uint8_t endstop_poll_count; // Countdown from threshold for polling
#endif
public:
Endstops() {};
/**
* Initialize the endstop pins
*/
2017-09-06 13:28:32 +02:00
static void init();
/**
* Are endstops or the probe set to abort the move?
*/
FORCE_INLINE static bool abort_enabled() {
return (enabled
#if HAS_BED_PROBE
|| z_probe_enabled
#endif
);
}
static inline bool global_enabled() { return enabled_globally; }
/**
* Periodic call to poll endstops if required. Called from temperature ISR
*/
static void poll();
/**
* Update endstops bits from the pins. Apply filtering to get a verified state.
* If abort_enabled() and moving towards a triggered switch, abort the current move.
* Called from ISR contexts.
*/
2016-05-26 20:01:20 +02:00
static void update();
/**
* Get Endstop hit state.
*/
FORCE_INLINE static uint8_t trigger_state() { return hit_state; }
/**
* Get current endstops state
*/
FORCE_INLINE static esbits_t state() {
return
#if ENDSTOP_NOISE_THRESHOLD
validated_live_state
#else
live_state
#endif
;
}
/**
2018-05-25 02:28:15 +02:00
* Report endstop hits to serial. Called from loop().
*/
static void event_handler();
2016-04-27 23:46:24 +02:00
/**
2019-10-30 21:07:24 +01:00
* Report endstop states in response to M119
2016-04-27 23:46:24 +02:00
*/
2019-10-30 21:07:24 +01:00
static void report_states();
2016-04-27 23:46:24 +02:00
// Enable / disable endstop checking globally
static void enable_globally(const bool onoff=true);
// Enable / disable endstop checking
static void enable(const bool onoff=true);
// Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
static void not_homing();
#if ENABLED(VALIDATE_HOMING_ENDSTOPS)
// If the last move failed to trigger an endstop, call kill
static void validate_homing_move();
#else
FORCE_INLINE static void validate_homing_move() { hit_on_purpose(); }
#endif
// Clear endstops (i.e., they were hit intentionally) to suppress the report
2018-05-25 02:28:15 +02:00
FORCE_INLINE static void hit_on_purpose() { hit_state = 0; }
// Enable / disable endstop z-probe checking
#if HAS_BED_PROBE
2016-05-26 20:01:20 +02:00
static volatile bool z_probe_enabled;
static void enable_z_probe(const bool onoff=true);
#endif
2016-04-28 11:15:53 +02:00
static void resync();
2017-09-18 12:55:09 +02:00
// Debugging of endstops
#if ENABLED(PINS_DEBUGGING)
static bool monitor_flag;
static void monitor();
static void run_monitor();
2017-09-18 12:55:09 +02:00
#endif
#if ENABLED(SPI_ENDSTOPS)
typedef struct {
union {
bool any;
struct { bool x:1, y:1, z:1; };
};
} tmc_spi_homing_t;
static tmc_spi_homing_t tmc_spi_homing;
static void clear_endstop_state();
static bool tmc_spi_homing_check();
#endif
};
extern Endstops endstops;
/**
* A class to save and change the endstop state,
* then restore it when it goes out of scope.
*/
class TemporaryGlobalEndstopsState {
bool saved;
public:
TemporaryGlobalEndstopsState(const bool enable) : saved(endstops.global_enabled()) {
endstops.enable_globally(enable);
}
~TemporaryGlobalEndstopsState() { endstops.enable_globally(saved); }
};