Prusa MINI Firmware overview
bltouch.h
Go to the documentation of this file.
1 /**
2  * Marlin 3D Printer Firmware
3  * Copyright (c) 2019 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 
24 #include "../inc/MarlinConfigPre.h"
25 
26 // BLTouch commands are sent as servo angles
27 typedef unsigned char BLTCommand;
28 
29 #define BLTOUCH_DEPLOY 10
30 #define BLTOUCH_SW_MODE 60
31 #define BLTOUCH_STOW 90
32 #define BLTOUCH_SELFTEST 120
33 #define BLTOUCH_MODE_STORE 130
34 #define BLTOUCH_5V_MODE 140
35 #define BLTOUCH_OD_MODE 150
36 #define BLTOUCH_RESET 160
37 
38 /**
39  * The following commands require different minimum delays.
40  *
41  * 500ms required for a reliable Reset.
42  *
43  * 750ms required for Deploy/Stow, otherwise the alarm state
44  * will not be seen until the following move command.
45  */
46 
47 #ifndef BLTOUCH_SET5V_DELAY
48  #define BLTOUCH_SET5V_DELAY 150
49 #endif
50 #ifndef BLTOUCH_SETOD_DELAY
51  #define BLTOUCH_SETOD_DELAY 150
52 #endif
53 #ifndef BLTOUCH_MODE_STORE_DELAY
54  #define BLTOUCH_MODE_STORE_DELAY 150
55 #endif
56 #ifndef BLTOUCH_DEPLOY_DELAY
57  #define BLTOUCH_DEPLOY_DELAY 750
58 #endif
59 #ifndef BLTOUCH_STOW_DELAY
60  #define BLTOUCH_STOW_DELAY 750
61 #endif
62 #ifndef BLTOUCH_RESET_DELAY
63  #define BLTOUCH_RESET_DELAY 500
64 #endif
65 
66 class BLTouch {
67 public:
68  static void init(const bool set_voltage=false);
69  static bool last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
70 
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 
76  // Native BLTouch commands ("Underscore"...), used in lcd menus and internally
78 
79  FORCE_INLINE static void _selftest() { command(BLTOUCH_SELFTEST, BLTOUCH_DELAY); }
80 
81  FORCE_INLINE static void _set_SW_mode() { command(BLTOUCH_SW_MODE, BLTOUCH_DELAY); }
82  FORCE_INLINE static void _reset_SW_mode() { if (triggered()) _stow(); else _deploy(); }
83 
87 
89  FORCE_INLINE static void _stow() { command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY); }
90 
91  FORCE_INLINE static void mode_conv_5V() { mode_conv_proc(true); }
92  FORCE_INLINE static void mode_conv_OD() { mode_conv_proc(false); }
93 
94 private:
95  FORCE_INLINE static bool _deploy_query_alarm() { return command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
96  FORCE_INLINE static bool _stow_query_alarm() { return command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY); }
97 
98  static void clear();
99  static bool command(const BLTCommand cmd, const millis_t &ms);
100  static bool triggered();
101  static bool deploy_proc();
102  static bool stow_proc();
103  static bool status_proc();
104  static void mode_conv_proc(const bool M5V);
105 };
106 
107 // Deploy/stow angles for use by servo.cpp / servo.h
108 #define BLTOUCH_ANGLES { BLTOUCH_DEPLOY, BLTOUCH_STOW }
109 
110 extern BLTouch bltouch;
BLTOUCH_DEPLOY_DELAY
#define BLTOUCH_DEPLOY_DELAY
Definition: bltouch.h:57
BLTouch::_reset
static FORCE_INLINE void _reset()
Definition: bltouch.h:77
BLTOUCH_STOW
#define BLTOUCH_STOW
Definition: bltouch.h:31
stop
void stop()
Definition: Marlin.cpp:783
BLTouch::_set_OD_mode
static FORCE_INLINE void _set_OD_mode()
Definition: bltouch.h:85
BLTOUCH_SELFTEST
#define BLTOUCH_SELFTEST
Definition: bltouch.h:32
BLTOUCH_MODE_STORE_DELAY
#define BLTOUCH_MODE_STORE_DELAY
Definition: bltouch.h:54
BLTOUCH_5V_MODE
#define BLTOUCH_5V_MODE
Definition: bltouch.h:34
DEBUG_ECHOLNPGM
#define DEBUG_ECHOLNPGM(...)
Definition: debug_out.h:79
_MAX
#define _MAX(V...)
Definition: macros.h:346
BLTouch::_mode_store
static FORCE_INLINE void _mode_store()
Definition: bltouch.h:86
BLTOUCH_SW_MODE
#define BLTOUCH_SW_MODE
Definition: bltouch.h:30
BLTOUCH_STOW_DELAY
#define BLTOUCH_STOW_DELAY
Definition: bltouch.h:60
BLTouch::_reset_SW_mode
static FORCE_INLINE void _reset_SW_mode()
Definition: bltouch.h:82
BLTouch::_set_5V_mode
static FORCE_INLINE void _set_5V_mode()
Definition: bltouch.h:84
DEBUG_ECHOLNPAIR
#define DEBUG_ECHOLNPAIR(...)
Definition: debug_out.h:82
BLTouch::_stow
static FORCE_INLINE void _stow()
Definition: bltouch.h:89
BLTouch::last_written_mode
static bool last_written_mode
Definition: bltouch.h:69
BLTouch::deploy
static FORCE_INLINE bool deploy()
Definition: bltouch.h:72
bltouch.h
BLTouch::_set_SW_mode
static FORCE_INLINE void _set_SW_mode()
Definition: bltouch.h:81
BLTOUCH_SET5V_DELAY
#define BLTOUCH_SET5V_DELAY
Definition: bltouch.h:48
MOVE_SERVO
#define MOVE_SERVO(I, P)
Definition: servo.h:93
BLTOUCH_RESET_DELAY
#define BLTOUCH_RESET_DELAY
Definition: bltouch.h:63
bltouch
BLTouch bltouch
FORCE_INLINE
#define FORCE_INLINE
Definition: macros.h:40
BLTouch::mode_conv_OD
static FORCE_INLINE void mode_conv_OD()
Definition: bltouch.h:92
BLTouch::mode_conv_5V
static FORCE_INLINE void mode_conv_5V()
Definition: bltouch.h:91
BLTOUCH_DEPLOY
#define BLTOUCH_DEPLOY
Definition: bltouch.h:29
Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
Definition: Configuration_A3ides_2209_MINI.h:759
BLTouch::_deploy
static FORCE_INLINE void _deploy()
Definition: bltouch.h:88
BLTouch::_selftest
static FORCE_INLINE void _selftest()
Definition: bltouch.h:79
Z_MIN_PROBE_ENDSTOP_INVERTING
#define Z_MIN_PROBE_ENDSTOP_INVERTING
Definition: Configuration_A3ides_2209_MINI.h:611
SERIAL_ECHOLNPAIR
#define SERIAL_ECHOLNPAIR(V...)
Definition: serial.h:144
BLTouch::init
static void init(const bool set_voltage=false)
SERIAL_ERROR_MSG
#define SERIAL_ERROR_MSG(S)
Definition: serial.h:184
Z_MIN_PROBE_PIN
#define Z_MIN_PROBE_PIN
Definition: pins_RAMPS_LINUX.h:86
DEBUGGING
#define DEBUGGING(F)
Definition: serial.h:47
Z_MIN_PIN
#define Z_MIN_PIN
Definition: pins_ESP32.h:47
BLTCommand
unsigned char BLTCommand
Definition: bltouch.h:27
safe_delay
void safe_delay(millis_t ms)
Definition: utility.cpp:28
BLTOUCH_RESET
#define BLTOUCH_RESET
Definition: bltouch.h:36
BLTouch
Definition: bltouch.h:66
BLTOUCH_SETOD_DELAY
#define BLTOUCH_SETOD_DELAY
Definition: bltouch.h:51
BLTOUCH_MODE_STORE
#define BLTOUCH_MODE_STORE
Definition: bltouch.h:33
READ
#define READ(IO)
Definition: fastio.h:95
MSG_STOP_BLTOUCH
#define MSG_STOP_BLTOUCH
Definition: language.h:255
BLTOUCH_OD_MODE
#define BLTOUCH_OD_MODE
Definition: bltouch.h:35
millis_t
uint32_t millis_t
Definition: millis_t.h:26
BLTouch::status
static FORCE_INLINE bool status()
Definition: bltouch.h:74
ENABLED
#define ENABLED(V...)
Definition: macros.h:177
Z_MIN_ENDSTOP_INVERTING
#define Z_MIN_ENDSTOP_INVERTING
Definition: Configuration_A3ides_2209_MINI.h:607
BLTouch::stow
static FORCE_INLINE bool stow()
Definition: bltouch.h:73