Skip to content

Commit 8d01c17

Browse files
thinkyheadLCh-77
authored andcommitted
♻️ More updates for multi-axis
1 parent b45b104 commit 8d01c17

File tree

8 files changed

+46
-51
lines changed

8 files changed

+46
-51
lines changed

Marlin/src/core/types.h

-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ enum AxisEnum : uint8_t {
181181
};
182182

183183
typedef IF<(NUM_AXIS_ENUMS > 8), uint16_t, uint8_t>::type axis_bits_t;
184-
typedef IF<(NUM_AXES > 8), uint16_t, uint8_t>::type linear_axis_bits_t;
185184

186185
//
187186
// Loop over axes

Marlin/src/gcode/control/M17_M18_M84.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "../gcode.h"
2424
#include "../../MarlinCore.h" // for stepper_inactive_time, disable_e_steppers
2525
#include "../../lcd/marlinui.h"
26+
#include "../../module/motion.h" // for e_axis_mask
2627
#include "../../module/stepper.h"
2728

2829
#if ENABLED(AUTO_BED_LEVELING_UBL)
@@ -43,7 +44,7 @@ inline stepper_flags_t selected_axis_bits() {
4344
selected.bits = _BV(INDEX_OF_AXIS(E_AXIS, e));
4445
}
4546
else
46-
selected.bits = selected.e_bits();
47+
selected.bits = e_axis_mask;
4748
}
4849
#endif
4950
selected.bits |= NUM_AXIS_GANG(

Marlin/src/gcode/feature/clean/G12.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@
4545
* X, Y, Z : Specify axes to move during cleaning. Default: ALL.
4646
*/
4747
void GcodeSuite::G12() {
48+
4849
// Don't allow nozzle cleaning without homing first
49-
if (homing_needed_error(linear_bits & ~TERN0(NOZZLE_CLEAN_NO_Z, Z_AXIS) & ~TERN0(NOZZLE_CLEAN_NO_Y, Y_AXIS)))
50-
return;
50+
constexpr main_axes_bits_t clean_axis_mask = main_axes_mask & ~TERN0(NOZZLE_CLEAN_NO_Z, Z_AXIS) & ~TERN0(NOZZLE_CLEAN_NO_Y, Y_AXIS);
51+
if (homing_needed_error(clean_axis_mask)) return;
5152

5253
#ifdef WIPE_SEQUENCE_COMMANDS
5354
if (!parser.seen_any()) {

Marlin/src/lcd/e3v2/marlinui/ui_status_480x272.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
8080
dwin_string.set();
8181
if (blink)
8282
dwin_string.add(value);
83-
else if (!TEST(axis_homed, axis))
83+
else if (!TEST(axes_homed, axis))
8484
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
85-
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axis_trusted, axis))
85+
else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axes_trusted, axis))
8686
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
8787
else
8888
dwin_string.add(value);
@@ -105,11 +105,11 @@ FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const
105105
if (blink)
106106
dwin_string.add(value);
107107
else {
108-
if (!TEST(axis_homed, axis))
108+
if (!TEST(axes_homed, axis))
109109
while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
110110
else {
111111
#if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
112-
if (!TEST(axis_trusted, axis))
112+
if (!TEST(axes_trusted, axis))
113113
dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
114114
else
115115
#endif

Marlin/src/module/motion.cpp

+6-17
Original file line numberDiff line numberDiff line change
@@ -1386,10 +1386,10 @@ void prepare_line_to_destination() {
13861386

13871387
#if HAS_ENDSTOPS
13881388

1389-
linear_axis_bits_t axis_homed, axis_trusted; // = 0
1389+
main_axes_bits_t axes_homed, axes_trusted; // = 0
13901390

1391-
linear_axis_bits_t axes_should_home(linear_axis_bits_t axis_bits/*=linear_bits*/) {
1392-
auto set_should = [](linear_axis_bits_t &b, AxisEnum a) {
1391+
main_axes_bits_t axes_should_home(main_axes_bits_t axis_bits/*=main_axes_mask*/) {
1392+
auto set_should = [](main_axes_bits_t &b, AxisEnum a) {
13931393
if (TEST(b, a) && TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(a))
13941394
CBI(b, a);
13951395
};
@@ -1402,23 +1402,12 @@ void prepare_line_to_destination() {
14021402
return axis_bits;
14031403
}
14041404

1405-
bool homing_needed_error(linear_axis_bits_t axis_bits/*=linear_bits*/) {
1405+
bool homing_needed_error(main_axes_bits_t axis_bits/*=main_axes_mask*/) {
14061406
if ((axis_bits = axes_should_home(axis_bits))) {
14071407
PGM_P home_first = GET_TEXT(MSG_HOME_FIRST);
14081408
char msg[30];
1409-
sprintf_P(msg, home_first,
1410-
NUM_AXIS_LIST(
1411-
TEST(axis_bits, X_AXIS) ? STR_A : "",
1412-
TEST(axis_bits, Y_AXIS) ? STR_B : "",
1413-
TEST(axis_bits, Z_AXIS) ? STR_C : "",
1414-
TEST(axis_bits, I_AXIS) ? STR_I : "",
1415-
TEST(axis_bits, J_AXIS) ? STR_J : "",
1416-
TEST(axis_bits, K_AXIS) ? STR_K : "",
1417-
TEST(axis_bits, U_AXIS) ? STR_U : "",
1418-
TEST(axis_bits, V_AXIS) ? STR_V : "",
1419-
TEST(axis_bits, W_AXIS) ? STR_W : ""
1420-
)
1421-
);
1409+
#define _AXIS_CHAR(N) TEST(axis_bits, _AXIS(N)) ? STR_##N : ""
1410+
sprintf_P(msg, home_first, MAPLIST(_AXIS_CHAR, MAIN_AXIS_NAMES));
14221411
SERIAL_ECHO_START();
14231412
SERIAL_ECHOLN(msg);
14241413
ui.set_status(msg);

Marlin/src/module/motion.h

+24-21
Original file line numberDiff line numberDiff line change
@@ -415,38 +415,41 @@ void restore_feedrate_and_scaling();
415415
/**
416416
* Homing and Trusted Axes
417417
*/
418-
typedef IF<(NUM_AXES > 8), uint16_t, uint8_t>::type linear_axis_bits_t;
419-
constexpr linear_axis_bits_t linear_bits = _BV(NUM_AXES) - 1;
418+
typedef IF<(NUM_AXES > 8), uint16_t, uint8_t>::type main_axes_bits_t;
419+
constexpr main_axes_bits_t main_axes_mask = _BV(NUM_AXES) - 1;
420+
421+
typedef IF<(NUM_AXES + EXTRUDERS > 8), uint16_t, uint8_t>::type e_axis_bits_t;
422+
constexpr e_axis_bits_t e_axis_mask = (_BV(EXTRUDERS) - 1) << NUM_AXES;
420423

421424
void set_axis_is_at_home(const AxisEnum axis);
422425

423426
#if HAS_ENDSTOPS
424427
/**
425-
* axis_homed
428+
* axes_homed
426429
* Flags that each linear axis was homed.
427430
* XYZ on cartesian, ABC on delta, ABZ on SCARA.
428431
*
429-
* axis_trusted
432+
* axes_trusted
430433
* Flags that the position is trusted in each linear axis. Set when homed.
431434
* Cleared whenever a stepper powers off, potentially losing its position.
432435
*/
433-
extern linear_axis_bits_t axis_homed, axis_trusted;
436+
extern main_axes_bits_t axes_homed, axes_trusted;
434437
void homeaxis(const AxisEnum axis);
435438
void set_axis_never_homed(const AxisEnum axis);
436-
linear_axis_bits_t axes_should_home(linear_axis_bits_t axis_bits=linear_bits);
437-
bool homing_needed_error(linear_axis_bits_t axis_bits=linear_bits);
438-
inline void set_axis_unhomed(const AxisEnum axis) { CBI(axis_homed, axis); }
439-
inline void set_axis_untrusted(const AxisEnum axis) { CBI(axis_trusted, axis); }
440-
inline void set_all_unhomed() { axis_homed = axis_trusted = 0; }
441-
inline void set_axis_homed(const AxisEnum axis) { SBI(axis_homed, axis); }
442-
inline void set_axis_trusted(const AxisEnum axis) { SBI(axis_trusted, axis); }
443-
inline void set_all_homed() { axis_homed = axis_trusted = linear_bits; }
439+
main_axes_bits_t axes_should_home(main_axes_bits_t axes_mask=main_axes_mask);
440+
bool homing_needed_error(main_axes_bits_t axes_mask=main_axes_mask);
441+
inline void set_axis_unhomed(const AxisEnum axis) { CBI(axes_homed, axis); }
442+
inline void set_axis_untrusted(const AxisEnum axis) { CBI(axes_trusted, axis); }
443+
inline void set_all_unhomed() { axes_homed = axes_trusted = 0; }
444+
inline void set_axis_homed(const AxisEnum axis) { SBI(axes_homed, axis); }
445+
inline void set_axis_trusted(const AxisEnum axis) { SBI(axes_trusted, axis); }
446+
inline void set_all_homed() { axes_homed = axes_trusted = main_axes_mask; }
444447
#else
445-
constexpr linear_axis_bits_t axis_homed = linear_bits, axis_trusted = linear_bits; // Zero-endstop machines are always homed and trusted
448+
constexpr main_axes_bits_t axes_homed = main_axes_mask, axes_trusted = main_axes_mask; // Zero-endstop machines are always homed and trusted
446449
inline void homeaxis(const AxisEnum axis) {}
447450
inline void set_axis_never_homed(const AxisEnum) {}
448-
inline linear_axis_bits_t axes_should_home(linear_axis_bits_t=linear_bits) { return 0; }
449-
inline bool homing_needed_error(linear_axis_bits_t=linear_bits) { return false; }
451+
inline main_axes_bits_t axes_should_home(main_axes_bits_t=main_axes_mask) { return 0; }
452+
inline bool homing_needed_error(main_axes_bits_t=main_axes_mask) { return false; }
450453
inline void set_axis_unhomed(const AxisEnum axis) {}
451454
inline void set_axis_untrusted(const AxisEnum axis) {}
452455
inline void set_all_unhomed() {}
@@ -455,13 +458,13 @@ void set_axis_is_at_home(const AxisEnum axis);
455458
inline void set_all_homed() {}
456459
#endif
457460

458-
inline bool axis_was_homed(const AxisEnum axis) { return TEST(axis_homed, axis); }
459-
inline bool axis_is_trusted(const AxisEnum axis) { return TEST(axis_trusted, axis); }
461+
inline bool axis_was_homed(const AxisEnum axis) { return TEST(axes_homed, axis); }
462+
inline bool axis_is_trusted(const AxisEnum axis) { return TEST(axes_trusted, axis); }
460463
inline bool axis_should_home(const AxisEnum axis) { return (axes_should_home() & _BV(axis)) != 0; }
461-
inline bool no_axes_homed() { return !axis_homed; }
462-
inline bool all_axes_homed() { return linear_bits == (axis_homed & linear_bits); }
464+
inline bool no_axes_homed() { return !axes_homed; }
465+
inline bool all_axes_homed() { return main_axes_mask == (axes_homed & main_axes_mask); }
463466
inline bool homing_needed() { return !all_axes_homed(); }
464-
inline bool all_axes_trusted() { return linear_bits == (axis_trusted & linear_bits); }
467+
inline bool all_axes_trusted() { return main_axes_mask == (axes_trusted & main_axes_mask); }
465468

466469
void home_if_needed(const bool keeplev=false);
467470

Marlin/src/module/probe.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,14 @@ xyz_pos_t Probe::offset; // Initialized by settings.load()
274274
#if ENABLED(PROBING_STEPPERS_OFF) && DISABLED(DELTA)
275275
static uint8_t old_trusted;
276276
if (dopause) {
277-
old_trusted = axis_trusted;
277+
old_trusted = axes_trusted;
278278
stepper.disable_axis(X_AXIS);
279279
stepper.disable_axis(Y_AXIS);
280280
}
281281
else {
282282
if (TEST(old_trusted, X_AXIS)) stepper.enable_axis(X_AXIS);
283283
if (TEST(old_trusted, Y_AXIS)) stepper.enable_axis(Y_AXIS);
284-
axis_trusted = old_trusted;
284+
axes_trusted = old_trusted;
285285
}
286286
#endif
287287
if (dopause) safe_delay(_MAX(DELAY_BEFORE_PROBING, 25));

Marlin/src/module/stepper.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,11 @@
246246
#define MIN_STEP_ISR_FREQUENCY (MAX_STEP_ISR_FREQUENCY_1X / 2)
247247

248248
#define ENABLE_COUNT (NUM_AXES + E_STEPPERS)
249-
typedef IF<(ENABLE_COUNT > 8), uint16_t, uint8_t>::type ena_mask_t;
249+
#if ENABLE_COUNT > 16
250+
typedef uint32_t ena_mask_t;
251+
#else
252+
typedef IF<(ENABLE_COUNT > 8), uint16_t, uint8_t>::type ena_mask_t;
253+
#endif
250254

251255
// Axis flags type, for enabled state or other simple state
252256
typedef struct {
@@ -259,8 +263,6 @@ typedef struct {
259263
#endif
260264
};
261265
};
262-
constexpr ena_mask_t linear_bits() { return _BV(NUM_AXES) - 1; }
263-
constexpr ena_mask_t e_bits() { return (_BV(EXTRUDERS) - 1) << NUM_AXES; }
264266
} stepper_flags_t;
265267

266268
// All the stepper enable pins

0 commit comments

Comments
 (0)