🧑💻 MAP macro for axis lists, etc. (#24191)
This commit is contained in:
committed by
Scott Lahteine
parent
ecfe7b6400
commit
3c482a9ba1
@ -738,10 +738,12 @@ void restore_feedrate_and_scaling() {
|
||||
#if HAS_SOFTWARE_ENDSTOPS
|
||||
|
||||
// Software Endstops are based on the configured limits.
|
||||
#define _AMIN(A) A##_MIN_POS
|
||||
#define _AMAX(A) A##_MAX_POS
|
||||
soft_endstops_t soft_endstop = {
|
||||
true, false,
|
||||
NUM_AXIS_ARRAY(X_MIN_POS, Y_MIN_POS, Z_MIN_POS, I_MIN_POS, J_MIN_POS, K_MIN_POS, U_MIN_POS, V_MIN_POS, W_MIN_POS),
|
||||
NUM_AXIS_ARRAY(X_MAX_BED, Y_MAX_BED, Z_MAX_POS, I_MAX_POS, J_MAX_POS, K_MAX_POS, U_MAX_POS, V_MAX_POS, W_MAX_POS)
|
||||
{ MAPLIST(_AMIN, MAIN_AXIS_NAMES) },
|
||||
{ MAPLIST(_AMAX, MAIN_AXIS_NAMES) },
|
||||
};
|
||||
|
||||
/**
|
||||
@ -1888,17 +1890,8 @@ void prepare_line_to_destination() {
|
||||
|| TERN0(A##_HOME_TO_MIN, A##_MIN_PIN > -1) \
|
||||
|| TERN0(A##_HOME_TO_MAX, A##_MAX_PIN > -1) \
|
||||
))
|
||||
if (NUM_AXIS_GANG(
|
||||
!_CAN_HOME(X),
|
||||
&& !_CAN_HOME(Y),
|
||||
&& !_CAN_HOME(Z),
|
||||
&& !_CAN_HOME(I),
|
||||
&& !_CAN_HOME(J),
|
||||
&& !_CAN_HOME(K),
|
||||
&& !_CAN_HOME(U),
|
||||
&& !_CAN_HOME(V),
|
||||
&& !_CAN_HOME(W))
|
||||
) return;
|
||||
#define _ANDCANT(N) && !_CAN_HOME(N)
|
||||
if (true MAIN_AXIS_MAP(_ANDCANT)) return;
|
||||
#endif
|
||||
|
||||
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(">>> homeaxis(", AS_CHAR(AXIS_CHAR(axis)), ")");
|
||||
|
@ -180,9 +180,9 @@
|
||||
#define _EN_ITEM(N) , E##N
|
||||
#define _EN1_ITEM(N) , E##N:1
|
||||
|
||||
typedef struct { uint16_t NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint16_t;
|
||||
typedef struct { uint32_t NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint32_t;
|
||||
typedef struct { int16_t NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4; } mot_stepper_int16_t;
|
||||
typedef struct { uint16_t MAIN_AXIS_NAMES, X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint16_t;
|
||||
typedef struct { uint32_t MAIN_AXIS_NAMES, X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } per_stepper_uint32_t;
|
||||
typedef struct { int16_t MAIN_AXIS_NAMES, X2, Y2, Z2, Z3, Z4; } mot_stepper_int16_t;
|
||||
typedef struct { bool NUM_AXIS_LIST(X:1, Y:1, Z:1, I:1, J:1, K:1, U:1, V:1, W:1), X2:1, Y2:1, Z2:1, Z3:1, Z4:1 REPEAT(E_STEPPERS, _EN1_ITEM); } per_stepper_bool_t;
|
||||
|
||||
#undef _EN_ITEM
|
||||
|
@ -498,11 +498,7 @@ xyze_int8_t Stepper::count_direction{0};
|
||||
void Stepper::enable_axis(const AxisEnum axis) {
|
||||
#define _CASE_ENABLE(N) case N##_AXIS: ENABLE_AXIS_##N(); break;
|
||||
switch (axis) {
|
||||
NUM_AXIS_CODE(
|
||||
_CASE_ENABLE(X), _CASE_ENABLE(Y), _CASE_ENABLE(Z),
|
||||
_CASE_ENABLE(I), _CASE_ENABLE(J), _CASE_ENABLE(K),
|
||||
_CASE_ENABLE(U), _CASE_ENABLE(V), _CASE_ENABLE(W)
|
||||
);
|
||||
MAIN_AXIS_MAP(_CASE_ENABLE)
|
||||
default: break;
|
||||
}
|
||||
mark_axis_enabled(axis);
|
||||
@ -518,11 +514,7 @@ bool Stepper::disable_axis(const AxisEnum axis) {
|
||||
if (can_disable) {
|
||||
#define _CASE_DISABLE(N) case N##_AXIS: DISABLE_AXIS_##N(); break;
|
||||
switch (axis) {
|
||||
NUM_AXIS_CODE(
|
||||
_CASE_DISABLE(X), _CASE_DISABLE(Y), _CASE_DISABLE(Z),
|
||||
_CASE_DISABLE(I), _CASE_DISABLE(J), _CASE_DISABLE(K),
|
||||
_CASE_DISABLE(U), _CASE_DISABLE(V), _CASE_DISABLE(W)
|
||||
);
|
||||
MAIN_AXIS_MAP(_CASE_DISABLE)
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
@ -493,7 +493,7 @@ enum StealthIndex : uint8_t {
|
||||
#endif
|
||||
|
||||
#define _EN_ITEM(N) , E##N
|
||||
enum TMCAxis : uint8_t { NUM_AXIS_LIST(X, Y, Z, I, J, K, U, V, W), X2, Y2, Z2, Z3, Z4 REPEAT(EXTRUDERS, _EN_ITEM), TOTAL };
|
||||
enum TMCAxis : uint8_t { MAIN_AXIS_NAMES, X2, Y2, Z2, Z3, Z4 REPEAT(EXTRUDERS, _EN_ITEM), TOTAL };
|
||||
#undef _EN_ITEM
|
||||
|
||||
void tmc_serial_begin() {
|
||||
@ -1023,18 +1023,16 @@ void reset_trinamic_drivers() {
|
||||
// 2. For each axis in use, static_assert using a constexpr function, which counts the
|
||||
// number of matching/conflicting axis. If the value is not exactly 1, fail.
|
||||
|
||||
#define ALL_AXIS_NAMES X, X2, Y, Y2, Z, Z2, Z3, Z4, I, J, K, U, V, W, E0, E1, E2, E3, E4, E5, E6, E7
|
||||
|
||||
#if ANY_AXIS_HAS(HW_SERIAL)
|
||||
// Hardware serial names are compared as strings, since actually resolving them cannot occur in a constexpr.
|
||||
// Using a fixed-length character array for the port name allows this to be constexpr compatible.
|
||||
struct SanityHwSerialDetails { const char port[20]; uint32_t address; };
|
||||
#define TMC_HW_DETAIL_ARGS(A) TERN(A##_HAS_HW_SERIAL, STRINGIFY(A##_HARDWARE_SERIAL), ""), TERN0(A##_HAS_HW_SERIAL, A##_SLAVE_ADDRESS)
|
||||
#define TMC_HW_DETAIL(A) { TMC_HW_DETAIL_ARGS(A) }
|
||||
#define TMC_HW_DETAIL(A) { TMC_HW_DETAIL_ARGS(A) },
|
||||
constexpr SanityHwSerialDetails sanity_tmc_hw_details[] = {
|
||||
TMC_HW_DETAIL(X), TMC_HW_DETAIL(X2),
|
||||
TMC_HW_DETAIL(Y), TMC_HW_DETAIL(Y2),
|
||||
TMC_HW_DETAIL(Z), TMC_HW_DETAIL(Z2), TMC_HW_DETAIL(Z3), TMC_HW_DETAIL(Z4),
|
||||
TMC_HW_DETAIL(I), TMC_HW_DETAIL(J), TMC_HW_DETAIL(K), TMC_HW_DETAIL(U), TMC_HW_DETAIL(V), TMC_HW_DETAIL(W),
|
||||
TMC_HW_DETAIL(E0), TMC_HW_DETAIL(E1), TMC_HW_DETAIL(E2), TMC_HW_DETAIL(E3), TMC_HW_DETAIL(E4), TMC_HW_DETAIL(E5), TMC_HW_DETAIL(E6), TMC_HW_DETAIL(E7)
|
||||
MAP(TMC_HW_DETAIL, ALL_AXIS_NAMES)
|
||||
};
|
||||
|
||||
// constexpr compatible string comparison
|
||||
@ -1053,23 +1051,15 @@ void reset_trinamic_drivers() {
|
||||
|
||||
#define TMC_HWSERIAL_CONFLICT_MSG(A) STRINGIFY(A) "_SLAVE_ADDRESS conflicts with another driver using the same " STRINGIFY(A) "_HARDWARE_SERIAL"
|
||||
#define SA_NO_TMC_HW_C(A) static_assert(1 >= count_tmc_hw_serial_matches(TMC_HW_DETAIL_ARGS(A), 0, COUNT(sanity_tmc_hw_details)), TMC_HWSERIAL_CONFLICT_MSG(A));
|
||||
SA_NO_TMC_HW_C(X); SA_NO_TMC_HW_C(X2);
|
||||
SA_NO_TMC_HW_C(Y); SA_NO_TMC_HW_C(Y2);
|
||||
SA_NO_TMC_HW_C(Z); SA_NO_TMC_HW_C(Z2); SA_NO_TMC_HW_C(Z3); SA_NO_TMC_HW_C(Z4);
|
||||
SA_NO_TMC_HW_C(I); SA_NO_TMC_HW_C(J); SA_NO_TMC_HW_C(K); SA_NO_TMC_HW_C(U); SA_NO_TMC_HW_C(V); SA_NO_TMC_HW_C(W);
|
||||
SA_NO_TMC_HW_C(E0); SA_NO_TMC_HW_C(E1); SA_NO_TMC_HW_C(E2); SA_NO_TMC_HW_C(E3); SA_NO_TMC_HW_C(E4); SA_NO_TMC_HW_C(E5); SA_NO_TMC_HW_C(E6); SA_NO_TMC_HW_C(E7);
|
||||
MAP(SA_NO_TMC_HW_C, ALL_AXIS_NAMES)
|
||||
#endif
|
||||
|
||||
#if ANY_AXIS_HAS(SW_SERIAL)
|
||||
struct SanitySwSerialDetails { int32_t txpin; int32_t rxpin; uint32_t address; };
|
||||
#define TMC_SW_DETAIL_ARGS(A) TERN(A##_HAS_SW_SERIAL, A##_SERIAL_TX_PIN, -1), TERN(A##_HAS_SW_SERIAL, A##_SERIAL_RX_PIN, -1), TERN0(A##_HAS_SW_SERIAL, A##_SLAVE_ADDRESS)
|
||||
#define TMC_SW_DETAIL(A) TMC_SW_DETAIL_ARGS(A)
|
||||
#define TMC_SW_DETAIL(A) TMC_SW_DETAIL_ARGS(A),
|
||||
constexpr SanitySwSerialDetails sanity_tmc_sw_details[] = {
|
||||
TMC_SW_DETAIL(X), TMC_SW_DETAIL(X2),
|
||||
TMC_SW_DETAIL(Y), TMC_SW_DETAIL(Y2),
|
||||
TMC_SW_DETAIL(Z), TMC_SW_DETAIL(Z2), TMC_SW_DETAIL(Z3), TMC_SW_DETAIL(Z4),
|
||||
TMC_SW_DETAIL(I), TMC_SW_DETAIL(J), TMC_SW_DETAIL(K), TMC_SW_DETAIL(U), TMC_SW_DETAIL(V), TMC_SW_DETAIL(W),
|
||||
TMC_SW_DETAIL(E0), TMC_SW_DETAIL(E1), TMC_SW_DETAIL(E2), TMC_SW_DETAIL(E3), TMC_SW_DETAIL(E4), TMC_SW_DETAIL(E5), TMC_SW_DETAIL(E6), TMC_SW_DETAIL(E7)
|
||||
MAP(TMC_SW_DETAIL, ALL_AXIS_NAMES)
|
||||
};
|
||||
|
||||
constexpr bool sc_sw_done(size_t start, size_t end) { return start == end; }
|
||||
@ -1083,11 +1073,7 @@ void reset_trinamic_drivers() {
|
||||
|
||||
#define TMC_SWSERIAL_CONFLICT_MSG(A) STRINGIFY(A) "_SLAVE_ADDRESS conflicts with another driver using the same " STRINGIFY(A) "_SERIAL_RX_PIN or " STRINGIFY(A) "_SERIAL_TX_PIN"
|
||||
#define SA_NO_TMC_SW_C(A) static_assert(1 >= count_tmc_sw_serial_matches(TMC_SW_DETAIL_ARGS(A), 0, COUNT(sanity_tmc_sw_details)), TMC_SWSERIAL_CONFLICT_MSG(A));
|
||||
SA_NO_TMC_SW_C(X); SA_NO_TMC_SW_C(X2);
|
||||
SA_NO_TMC_SW_C(Y); SA_NO_TMC_SW_C(Y2);
|
||||
SA_NO_TMC_SW_C(Z); SA_NO_TMC_SW_C(Z2); SA_NO_TMC_SW_C(Z3); SA_NO_TMC_SW_C(Z4);
|
||||
SA_NO_TMC_SW_C(I); SA_NO_TMC_SW_C(J); SA_NO_TMC_SW_C(K); SA_NO_TMC_SW_C(U); SA_NO_TMC_SW_C(V); SA_NO_TMC_SW_C(W);
|
||||
SA_NO_TMC_SW_C(E0); SA_NO_TMC_SW_C(E1); SA_NO_TMC_SW_C(E2); SA_NO_TMC_SW_C(E3); SA_NO_TMC_SW_C(E4); SA_NO_TMC_SW_C(E5); SA_NO_TMC_SW_C(E6); SA_NO_TMC_SW_C(E7);
|
||||
MAP(SA_NO_TMC_SW_C, ALL_AXIS_NAMES)
|
||||
#endif
|
||||
|
||||
#endif // HAS_TRINAMIC_CONFIG
|
||||
|
Reference in New Issue
Block a user