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.

bltouch.h 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../inc/MarlinConfigPre.h"
  24. // BLTouch commands are sent as servo angles
  25. typedef unsigned char BLTCommand;
  26. #if ENABLED(CREALITY_TOUCH)
  27. #define STOW_ALARM false
  28. #define BLTOUCH_DEPLOY 170
  29. #define BLTOUCH_STOW 20
  30. #else
  31. #define STOW_ALARM true
  32. #define BLTOUCH_DEPLOY 10
  33. #define BLTOUCH_STOW 90
  34. #endif
  35. #define BLTOUCH_SW_MODE 60
  36. #define BLTOUCH_SELFTEST 120
  37. #define BLTOUCH_MODE_STORE 130
  38. #define BLTOUCH_5V_MODE 140
  39. #define BLTOUCH_OD_MODE 150
  40. #define BLTOUCH_RESET 160
  41. /**
  42. * The following commands require different minimum delays.
  43. *
  44. * 500ms required for a reliable Reset.
  45. *
  46. * 750ms required for Deploy/Stow, otherwise the alarm state
  47. * will not be seen until the following move command.
  48. */
  49. #ifndef BLTOUCH_SET5V_DELAY
  50. #define BLTOUCH_SET5V_DELAY 150
  51. #endif
  52. #ifndef BLTOUCH_SETOD_DELAY
  53. #define BLTOUCH_SETOD_DELAY 150
  54. #endif
  55. #ifndef BLTOUCH_MODE_STORE_DELAY
  56. #define BLTOUCH_MODE_STORE_DELAY 150
  57. #endif
  58. #ifndef BLTOUCH_DEPLOY_DELAY
  59. #define BLTOUCH_DEPLOY_DELAY 750
  60. #endif
  61. #ifndef BLTOUCH_STOW_DELAY
  62. #define BLTOUCH_STOW_DELAY 750
  63. #endif
  64. #ifndef BLTOUCH_RESET_DELAY
  65. #define BLTOUCH_RESET_DELAY 500
  66. #endif
  67. class BLTouch {
  68. public:
  69. static void init(const bool set_voltage=false);
  70. static bool last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
  71. // DEPLOY and STOW are wrapped for error handling - these are used by homing and by probing
  72. FORCE_INLINE static bool deploy() { return deploy_proc(); }
  73. FORCE_INLINE static bool stow() { return stow_proc(); }
  74. FORCE_INLINE static bool status() { return status_proc(); }
  75. // Native BLTouch commands ("Underscore"...), used in lcd menus and internally
  76. FORCE_INLINE static void _reset() { command(BLTOUCH_RESET, BLTOUCH_RESET_DELAY); }
  77. FORCE_INLINE static void _selftest() { command(BLTOUCH_SELFTEST, BLTOUCH_DELAY); }
  78. FORCE_INLINE static void _set_SW_mode() { command(BLTOUCH_SW_MODE, BLTOUCH_DELAY); }
  79. FORCE_INLINE static void _reset_SW_mode() { if (triggered()) _stow(); else _deploy(); }
  80. FORCE_INLINE static void _set_5V_mode() { command(BLTOUCH_5V_MODE, BLTOUCH_SET5V_DELAY); }
  81. FORCE_INLINE static void _set_OD_mode() { command(BLTOUCH_OD_MODE, BLTOUCH_SETOD_DELAY); }
  82. FORCE_INLINE static void _mode_store() { command(BLTOUCH_MODE_STORE, BLTOUCH_MODE_STORE_DELAY); }
  83. FORCE_INLINE static void _deploy() { command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
  84. FORCE_INLINE static void _stow() { command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY); }
  85. FORCE_INLINE static void mode_conv_5V() { mode_conv_proc(true); }
  86. FORCE_INLINE static void mode_conv_OD() { mode_conv_proc(false); }
  87. static bool triggered();
  88. private:
  89. FORCE_INLINE static bool _deploy_query_alarm() { return command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
  90. FORCE_INLINE static bool _stow_query_alarm() { return command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY) == STOW_ALARM; }
  91. static void clear();
  92. static bool command(const BLTCommand cmd, const millis_t &ms);
  93. static bool deploy_proc();
  94. static bool stow_proc();
  95. static bool status_proc();
  96. static void mode_conv_proc(const bool M5V);
  97. };
  98. extern BLTouch bltouch;