2016-04-27 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2018-03-10 12:12:57 +01:00
|
|
|
* endstops.h - manages endstops
|
2016-04-27 16:15:20 +02:00
|
|
|
*/
|
|
|
|
|
2018-03-10 12:12:57 +01:00
|
|
|
#ifndef __ENDSTOPS_H__
|
|
|
|
#define __ENDSTOPS_H__
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2017-12-05 08:07:11 +01:00
|
|
|
#include "MarlinConfig.h"
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2018-08-07 06:11:28 +02:00
|
|
|
#define VALIDATE_HOMING_ENDSTOPS
|
|
|
|
|
2018-05-20 17:59:58 +02:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
class Endstops {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-05-26 20:01:20 +02:00
|
|
|
static bool enabled, enabled_globally;
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2017-10-27 23:24:34 +02:00
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
|
2018-03-10 12:12:57 +01:00
|
|
|
typedef uint16_t esbits_t;
|
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
|
|
|
static float x_endstop_adj;
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
|
|
|
static float y_endstop_adj;
|
|
|
|
#endif
|
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
|
|
|
static float z_endstop_adj;
|
|
|
|
#endif
|
2016-04-27 16:15:20 +02:00
|
|
|
#else
|
2018-05-21 20:34:40 +02:00
|
|
|
typedef uint8_t esbits_t;
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
2018-03-10 12:12:57 +01:00
|
|
|
|
2018-05-21 20:34:40 +02:00
|
|
|
private:
|
|
|
|
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
|
2018-06-22 03:13:16 +02:00
|
|
|
|
2018-05-21 20:34:40 +02:00
|
|
|
#if ENABLED(ENDSTOP_NOISE_FILTER)
|
2018-06-22 03:13:16 +02:00
|
|
|
static esbits_t validated_live_state;
|
2018-05-21 20:34:40 +02:00
|
|
|
static uint8_t endstop_poll_count; // Countdown from threshold for polling
|
|
|
|
#endif
|
2016-07-19 15:31:09 +02:00
|
|
|
|
2018-05-21 20:34:40 +02:00
|
|
|
public:
|
2018-05-20 17:59:58 +02:00
|
|
|
Endstops() {};
|
2016-04-27 16:15:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the endstop pins
|
|
|
|
*/
|
2018-03-10 12:12:57 +01:00
|
|
|
static void init();
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2018-05-20 17:59:58 +02:00
|
|
|
/**
|
2018-06-22 03:13:16 +02:00
|
|
|
* Are endstops or the probe set to abort the move?
|
2018-05-20 17:59:58 +02:00
|
|
|
*/
|
2018-06-22 03:13:16 +02:00
|
|
|
FORCE_INLINE static bool abort_enabled() {
|
|
|
|
return (enabled
|
|
|
|
#if HAS_BED_PROBE
|
|
|
|
|| z_probe_enabled
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
}
|
2018-05-20 17:59:58 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Periodic call to poll endstops if required. Called from temperature ISR
|
|
|
|
*/
|
|
|
|
static void poll();
|
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
/**
|
2018-06-22 03:13:16 +02:00
|
|
|
* 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-04-27 16:15:20 +02:00
|
|
|
*/
|
2016-05-26 20:01:20 +02:00
|
|
|
static void update();
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2018-05-21 20:34:40 +02:00
|
|
|
/**
|
|
|
|
* Get Endstop hit state.
|
|
|
|
*/
|
|
|
|
FORCE_INLINE static uint8_t trigger_state() { return hit_state; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get current endstops state
|
|
|
|
*/
|
2018-06-02 02:00:59 +02:00
|
|
|
FORCE_INLINE static esbits_t state() {
|
|
|
|
return
|
|
|
|
#if ENABLED(ENDSTOP_NOISE_FILTER)
|
|
|
|
validated_live_state
|
|
|
|
#else
|
|
|
|
live_state
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
}
|
2018-05-21 20:34:40 +02:00
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
/**
|
2018-05-25 02:29:06 +02:00
|
|
|
* Report endstop hits to serial. Called from loop().
|
2016-04-27 16:15:20 +02:00
|
|
|
*/
|
2018-07-12 02:46:56 +02:00
|
|
|
static void event_handler();
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2016-04-27 23:46:24 +02:00
|
|
|
/**
|
|
|
|
* Report endstop positions in response to M119
|
|
|
|
*/
|
2016-05-26 20:01:20 +02:00
|
|
|
static void M119();
|
2016-04-27 23:46:24 +02:00
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
// Enable / disable endstop checking globally
|
2018-05-20 17:59:58 +02:00
|
|
|
static void enable_globally(const bool onoff=true);
|
2016-04-27 16:15:20 +02:00
|
|
|
|
|
|
|
// Enable / disable endstop checking
|
2018-05-20 17:59:58 +02:00
|
|
|
static void enable(const bool onoff=true);
|
2016-04-27 16:15:20 +02:00
|
|
|
|
|
|
|
// Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
|
2018-05-20 17:59:58 +02:00
|
|
|
static void not_homing();
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2018-08-07 06:11:28 +02:00
|
|
|
#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
|
2018-07-01 04:53:58 +02:00
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
// Clear endstops (i.e., they were hit intentionally) to suppress the report
|
2018-05-25 02:29:06 +02:00
|
|
|
FORCE_INLINE static void hit_on_purpose() { hit_state = 0; }
|
2016-04-27 16:15:20 +02:00
|
|
|
|
|
|
|
// Enable / disable endstop z-probe checking
|
2016-05-04 05:15:18 +02:00
|
|
|
#if HAS_BED_PROBE
|
2016-05-26 20:01:20 +02:00
|
|
|
static volatile bool z_probe_enabled;
|
2018-06-13 07:36:47 +02:00
|
|
|
static void enable_z_probe(const bool onoff=true);
|
2018-05-20 17:59:58 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Debugging of endstops
|
|
|
|
#if ENABLED(PINS_DEBUGGING)
|
|
|
|
static bool monitor_flag;
|
|
|
|
static void monitor();
|
|
|
|
static void run_monitor();
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
extern Endstops endstops;
|
|
|
|
|
2018-03-10 12:12:57 +01:00
|
|
|
#endif // __ENDSTOPS_H__
|