Skip to content

Commit 88715b5

Browse files
thinkyheadLCh-77
authored andcommitted
♻️ More updates for multi-axis
1 parent 28615d1 commit 88715b5

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
@@ -1382,10 +1382,10 @@ void prepare_line_to_destination() {
13821382

13831383
#if HAS_ENDSTOPS
13841384

1385-
linear_axis_bits_t axis_homed, axis_trusted; // = 0
1385+
main_axes_bits_t axes_homed, axes_trusted; // = 0
13861386

1387-
linear_axis_bits_t axes_should_home(linear_axis_bits_t axis_bits/*=linear_bits*/) {
1388-
auto set_should = [](linear_axis_bits_t &b, AxisEnum a) {
1387+
main_axes_bits_t axes_should_home(main_axes_bits_t axis_bits/*=main_axes_mask*/) {
1388+
auto set_should = [](main_axes_bits_t &b, AxisEnum a) {
13891389
if (TEST(b, a) && TERN(HOME_AFTER_DEACTIVATE, axis_is_trusted, axis_was_homed)(a))
13901390
CBI(b, a);
13911391
};
@@ -1398,23 +1398,12 @@ void prepare_line_to_destination() {
13981398
return axis_bits;
13991399
}
14001400

1401-
bool homing_needed_error(linear_axis_bits_t axis_bits/*=linear_bits*/) {
1401+
bool homing_needed_error(main_axes_bits_t axis_bits/*=main_axes_mask*/) {
14021402
if ((axis_bits = axes_should_home(axis_bits))) {
14031403
PGM_P home_first = GET_TEXT(MSG_HOME_FIRST);
14041404
char msg[30];
1405-
sprintf_P(msg, home_first,
1406-
NUM_AXIS_LIST(
1407-
TEST(axis_bits, X_AXIS) ? STR_A : "",
1408-
TEST(axis_bits, Y_AXIS) ? STR_B : "",
1409-
TEST(axis_bits, Z_AXIS) ? STR_C : "",
1410-
TEST(axis_bits, I_AXIS) ? STR_I : "",
1411-
TEST(axis_bits, J_AXIS) ? STR_J : "",
1412-
TEST(axis_bits, K_AXIS) ? STR_K : "",
1413-
TEST(axis_bits, U_AXIS) ? STR_U : "",
1414-
TEST(axis_bits, V_AXIS) ? STR_V : "",
1415-
TEST(axis_bits, W_AXIS) ? STR_W : ""
1416-
)
1417-
);
1405+
#define _AXIS_CHAR(N) TEST(axis_bits, _AXIS(N)) ? STR_##N : ""
1406+
sprintf_P(msg, home_first, MAPLIST(_AXIS_CHAR, MAIN_AXIS_NAMES));
14181407
SERIAL_ECHO_START();
14191408
SERIAL_ECHOLN(msg);
14201409
ui.set_status(msg);

Marlin/src/module/motion.h

+24-21
Original file line numberDiff line numberDiff line change
@@ -407,38 +407,41 @@ void restore_feedrate_and_scaling();
407407
/**
408408
* Homing and Trusted Axes
409409
*/
410-
typedef IF<(NUM_AXES > 8), uint16_t, uint8_t>::type linear_axis_bits_t;
411-
constexpr linear_axis_bits_t linear_bits = _BV(NUM_AXES) - 1;
410+
typedef IF<(NUM_AXES > 8), uint16_t, uint8_t>::type main_axes_bits_t;
411+
constexpr main_axes_bits_t main_axes_mask = _BV(NUM_AXES) - 1;
412+
413+
typedef IF<(NUM_AXES + EXTRUDERS > 8), uint16_t, uint8_t>::type e_axis_bits_t;
414+
constexpr e_axis_bits_t e_axis_mask = (_BV(EXTRUDERS) - 1) << NUM_AXES;
412415

413416
void set_axis_is_at_home(const AxisEnum axis);
414417

415418
#if HAS_ENDSTOPS
416419
/**
417-
* axis_homed
420+
* axes_homed
418421
* Flags that each linear axis was homed.
419422
* XYZ on cartesian, ABC on delta, ABZ on SCARA.
420423
*
421-
* axis_trusted
424+
* axes_trusted
422425
* Flags that the position is trusted in each linear axis. Set when homed.
423426
* Cleared whenever a stepper powers off, potentially losing its position.
424427
*/
425-
extern linear_axis_bits_t axis_homed, axis_trusted;
428+
extern main_axes_bits_t axes_homed, axes_trusted;
426429
void homeaxis(const AxisEnum axis);
427430
void set_axis_never_homed(const AxisEnum axis);
428-
linear_axis_bits_t axes_should_home(linear_axis_bits_t axis_bits=linear_bits);
429-
bool homing_needed_error(linear_axis_bits_t axis_bits=linear_bits);
430-
inline void set_axis_unhomed(const AxisEnum axis) { CBI(axis_homed, axis); }
431-
inline void set_axis_untrusted(const AxisEnum axis) { CBI(axis_trusted, axis); }
432-
inline void set_all_unhomed() { axis_homed = axis_trusted = 0; }
433-
inline void set_axis_homed(const AxisEnum axis) { SBI(axis_homed, axis); }
434-
inline void set_axis_trusted(const AxisEnum axis) { SBI(axis_trusted, axis); }
435-
inline void set_all_homed() { axis_homed = axis_trusted = linear_bits; }
431+
main_axes_bits_t axes_should_home(main_axes_bits_t axes_mask=main_axes_mask);
432+
bool homing_needed_error(main_axes_bits_t axes_mask=main_axes_mask);
433+
inline void set_axis_unhomed(const AxisEnum axis) { CBI(axes_homed, axis); }
434+
inline void set_axis_untrusted(const AxisEnum axis) { CBI(axes_trusted, axis); }
435+
inline void set_all_unhomed() { axes_homed = axes_trusted = 0; }
436+
inline void set_axis_homed(const AxisEnum axis) { SBI(axes_homed, axis); }
437+
inline void set_axis_trusted(const AxisEnum axis) { SBI(axes_trusted, axis); }
438+
inline void set_all_homed() { axes_homed = axes_trusted = main_axes_mask; }
436439
#else
437-
constexpr linear_axis_bits_t axis_homed = linear_bits, axis_trusted = linear_bits; // Zero-endstop machines are always homed and trusted
440+
constexpr main_axes_bits_t axes_homed = main_axes_mask, axes_trusted = main_axes_mask; // Zero-endstop machines are always homed and trusted
438441
inline void homeaxis(const AxisEnum axis) {}
439442
inline void set_axis_never_homed(const AxisEnum) {}
440-
inline linear_axis_bits_t axes_should_home(linear_axis_bits_t=linear_bits) { return 0; }
441-
inline bool homing_needed_error(linear_axis_bits_t=linear_bits) { return false; }
443+
inline main_axes_bits_t axes_should_home(main_axes_bits_t=main_axes_mask) { return 0; }
444+
inline bool homing_needed_error(main_axes_bits_t=main_axes_mask) { return false; }
442445
inline void set_axis_unhomed(const AxisEnum axis) {}
443446
inline void set_axis_untrusted(const AxisEnum axis) {}
444447
inline void set_all_unhomed() {}
@@ -447,13 +450,13 @@ void set_axis_is_at_home(const AxisEnum axis);
447450
inline void set_all_homed() {}
448451
#endif
449452

450-
inline bool axis_was_homed(const AxisEnum axis) { return TEST(axis_homed, axis); }
451-
inline bool axis_is_trusted(const AxisEnum axis) { return TEST(axis_trusted, axis); }
453+
inline bool axis_was_homed(const AxisEnum axis) { return TEST(axes_homed, axis); }
454+
inline bool axis_is_trusted(const AxisEnum axis) { return TEST(axes_trusted, axis); }
452455
inline bool axis_should_home(const AxisEnum axis) { return (axes_should_home() & _BV(axis)) != 0; }
453-
inline bool no_axes_homed() { return !axis_homed; }
454-
inline bool all_axes_homed() { return linear_bits == (axis_homed & linear_bits); }
456+
inline bool no_axes_homed() { return !axes_homed; }
457+
inline bool all_axes_homed() { return main_axes_mask == (axes_homed & main_axes_mask); }
455458
inline bool homing_needed() { return !all_axes_homed(); }
456-
inline bool all_axes_trusted() { return linear_bits == (axis_trusted & linear_bits); }
459+
inline bool all_axes_trusted() { return main_axes_mask == (axes_trusted & main_axes_mask); }
457460

458461
void home_if_needed(const bool keeplev=false);
459462

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)