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.0KB

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