My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

endstops.h 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * endstops.h - manages endstops
  24. */
  25. #ifndef __ENDSTOPS_H__
  26. #define __ENDSTOPS_H__
  27. #include "../inc/MarlinConfig.h"
  28. #include <stdint.h>
  29. #define VALIDATE_HOMING_ENDSTOPS
  30. enum EndstopEnum : char {
  31. X_MIN,
  32. Y_MIN,
  33. Z_MIN,
  34. Z_MIN_PROBE,
  35. X_MAX,
  36. Y_MAX,
  37. Z_MAX,
  38. X2_MIN,
  39. X2_MAX,
  40. Y2_MIN,
  41. Y2_MAX,
  42. Z2_MIN,
  43. Z2_MAX
  44. };
  45. class Endstops {
  46. public:
  47. static bool enabled, enabled_globally;
  48. #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS)
  49. typedef uint16_t esbits_t;
  50. #if ENABLED(X_DUAL_ENDSTOPS)
  51. static float x_endstop_adj;
  52. #endif
  53. #if ENABLED(Y_DUAL_ENDSTOPS)
  54. static float y_endstop_adj;
  55. #endif
  56. #if ENABLED(Z_DUAL_ENDSTOPS)
  57. static float z_endstop_adj;
  58. #endif
  59. #else
  60. typedef uint8_t esbits_t;
  61. #endif
  62. private:
  63. static esbits_t live_state;
  64. static volatile uint8_t hit_state; // Use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT index
  65. #if ENABLED(ENDSTOP_NOISE_FILTER)
  66. static esbits_t validated_live_state;
  67. static uint8_t endstop_poll_count; // Countdown from threshold for polling
  68. #endif
  69. public:
  70. Endstops() {};
  71. /**
  72. * Initialize the endstop pins
  73. */
  74. static void init();
  75. /**
  76. * Are endstops or the probe set to abort the move?
  77. */
  78. FORCE_INLINE static bool abort_enabled() {
  79. return (enabled
  80. #if HAS_BED_PROBE
  81. || z_probe_enabled
  82. #endif
  83. );
  84. }
  85. /**
  86. * Periodic call to poll endstops if required. Called from temperature ISR
  87. */
  88. static void poll();
  89. /**
  90. * Update endstops bits from the pins. Apply filtering to get a verified state.
  91. * If abort_enabled() and moving towards a triggered switch, abort the current move.
  92. * Called from ISR contexts.
  93. */
  94. static void update();
  95. /**
  96. * Get Endstop hit state.
  97. */
  98. FORCE_INLINE static uint8_t trigger_state() { return hit_state; }
  99. /**
  100. * Get current endstops state
  101. */
  102. FORCE_INLINE static esbits_t state() {
  103. return
  104. #if ENABLED(ENDSTOP_NOISE_FILTER)
  105. validated_live_state
  106. #else
  107. live_state
  108. #endif
  109. ;
  110. }
  111. /**
  112. * Report endstop hits to serial. Called from loop().
  113. */
  114. static void event_handler();
  115. /**
  116. * Report endstop positions in response to M119
  117. */
  118. static void M119();
  119. // Enable / disable endstop checking globally
  120. static void enable_globally(const bool onoff=true);
  121. // Enable / disable endstop checking
  122. static void enable(const bool onoff=true);
  123. // Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
  124. static void not_homing();
  125. #if ENABLED(VALIDATE_HOMING_ENDSTOPS)
  126. // If the last move failed to trigger an endstop, call kill
  127. static void validate_homing_move();
  128. #else
  129. FORCE_INLINE static void validate_homing_move() { hit_on_purpose(); }
  130. #endif
  131. // Clear endstops (i.e., they were hit intentionally) to suppress the report
  132. FORCE_INLINE static void hit_on_purpose() { hit_state = 0; }
  133. // Enable / disable endstop z-probe checking
  134. #if HAS_BED_PROBE
  135. static volatile bool z_probe_enabled;
  136. static void enable_z_probe(const bool onoff=true);
  137. #endif
  138. // Debugging of endstops
  139. #if ENABLED(PINS_DEBUGGING)
  140. static bool monitor_flag;
  141. static void monitor();
  142. static void run_monitor();
  143. #endif
  144. };
  145. extern Endstops endstops;
  146. #endif // __ENDSTOPS_H__