Skip to content

Commit

Permalink
🔧 Undef motor current PWM for unused axes
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 12, 2024
1 parent dabcea9 commit 08fe8a3
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Marlin/src/HAL/DUE/fastio/G2_PWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#else
#define G2_PWM_Z 0
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#if HAS_MOTOR_CURRENT_PWM_E
#define G2_PWM_E 1
#else
#define G2_PWM_E 0
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/gcode/feature/digipot/M907-M910.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void GcodeSuite::M907() {
#define HAS_X_Y_XY_I_J_K_U_V_W 1
#endif

#if HAS_X_Y_XY_I_J_K_U_V_W || ANY_PIN(MOTOR_CURRENT_PWM_E, MOTOR_CURRENT_PWM_Z)
#if HAS_X_Y_XY_I_J_K_U_V_W || HAS_MOTOR_CURRENT_PWM_E || PIN_EXISTS(MOTOR_CURRENT_PWM_Z)

if (!parser.seen("S"
#if HAS_X_Y_XY_I_J_K_U_V_W
Expand All @@ -77,7 +77,7 @@ void GcodeSuite::M907() {
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
"Z"
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#if HAS_MOTOR_CURRENT_PWM_E
"E"
#endif
)) return M907_report();
Expand All @@ -94,7 +94,7 @@ void GcodeSuite::M907() {
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
if (parser.seenval('Z')) stepper.set_digipot_current(1, parser.value_int());
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#if HAS_MOTOR_CURRENT_PWM_E
if (parser.seenval('E')) stepper.set_digipot_current(2, parser.value_int());
#endif

Expand Down Expand Up @@ -133,7 +133,7 @@ void GcodeSuite::M907() {
SERIAL_ECHOLNPGM_P( // PWM-based has 3 values:
PSTR(" M907 X"), stepper.motor_current_setting[0] // X, Y, (I, J, K, U, V, W)
, SP_Z_STR, stepper.motor_current_setting[1] // Z
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#if HAS_MOTOR_CURRENT_PWM_E
, SP_E_STR, stepper.motor_current_setting[2] // E
#endif
);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2814,7 +2814,7 @@
#if PIN_EXISTS(DIGIPOTSS)
#define HAS_MOTOR_CURRENT_SPI 1
#endif
#if HAS_EXTRUDERS && PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#if ANY_PIN(MOTOR_CURRENT_PWM_E, MOTOR_CURRENT_PWM_E0, MOTOR_CURRENT_PWM_E1)
#define HAS_MOTOR_CURRENT_PWM_E 1
#endif
#if HAS_MOTOR_CURRENT_PWM_E || ANY_PIN(MOTOR_CURRENT_PWM_X, MOTOR_CURRENT_PWM_Y, MOTOR_CURRENT_PWM_XY, MOTOR_CURRENT_PWM_Z, MOTOR_CURRENT_PWM_I, MOTOR_CURRENT_PWM_J, MOTOR_CURRENT_PWM_K, MOTOR_CURRENT_PWM_U, MOTOR_CURRENT_PWM_V, MOTOR_CURRENT_PWM_W)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void menu_backlash();
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
EDIT_CURRENT_PWM(STR_C, 1);
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#if HAS_MOTOR_CURRENT_PWM_E
EDIT_CURRENT_PWM(STR_E, 2);
#endif
END_MENU();
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/module/stepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3906,7 +3906,7 @@ void Stepper::report_positions() {
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
case 1:
#endif
#if ANY_PIN(MOTOR_CURRENT_PWM_E, MOTOR_CURRENT_PWM_E0, MOTOR_CURRENT_PWM_E1)
#if HAS_MOTOR_CURRENT_PWM_E
case 2:
#endif
set_digipot_current(i, motor_current_setting[i]);
Expand Down Expand Up @@ -3973,7 +3973,7 @@ void Stepper::report_positions() {
#endif
break;
case 2:
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#if HAS_MOTOR_CURRENT_PWM_E
_WRITE_CURRENT_PWM(E);
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E0)
Expand Down Expand Up @@ -4036,7 +4036,7 @@ void Stepper::report_positions() {
#if PIN_EXISTS(MOTOR_CURRENT_PWM_Z)
INIT_CURRENT_PWM(Z);
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E)
#if HAS_MOTOR_CURRENT_PWM_E
INIT_CURRENT_PWM(E);
#endif
#if PIN_EXISTS(MOTOR_CURRENT_PWM_E0)
Expand Down
40 changes: 40 additions & 0 deletions Marlin/src/pins/pins_postprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -1736,3 +1736,43 @@
#define NEOPIXEL_PIN BOARD_NEOPIXEL_PIN
#endif
#endif

// Undefine motor PWM pins for nonexistent axes since the existence of a MOTOR_CURRENT_PWM_*_PIN implies its standard use.
// TODO: Allow remapping (e.g., E => Z2). Spec G-codes to use logical axis with index (e.g., to set Z2: Mxxx Z P1 Snnn).
#if !HAS_X_AXIS
#undef MOTOR_CURRENT_PWM_X_PIN
#endif
#if !HAS_Y_AXIS
#undef MOTOR_CURRENT_PWM_Y_PIN
#endif
#if !HAS_X_AXIS && !HAS_Y_AXIS
#undef MOTOR_CURRENT_PWM_XY_PIN
#endif
#if !HAS_Z_AXIS
#undef MOTOR_CURRENT_PWM_Z_PIN
#endif
#if !HAS_I_AXIS
#undef MOTOR_CURRENT_PWM_I_PIN
#endif
#if !HAS_J_AXIS
#undef MOTOR_CURRENT_PWM_J_PIN
#endif
#if !HAS_K_AXIS
#undef MOTOR_CURRENT_PWM_K_PIN
#endif
#if !HAS_U_AXIS
#undef MOTOR_CURRENT_PWM_U_PIN
#endif
#if !HAS_V_AXIS
#undef MOTOR_CURRENT_PWM_V_PIN
#endif
#if !HAS_W_AXIS
#undef MOTOR_CURRENT_PWM_W_PIN
#endif
#if !HAS_EXTRUDERS
#undef MOTOR_CURRENT_PWM_E_PIN
#undef MOTOR_CURRENT_PWM_E0_PIN // Archim 1.0
#undef MOTOR_CURRENT_PWM_E1_PIN // Kept in sync with E0
#elif !HAS_MULTI_EXTRUDER
#undef MOTOR_CURRENT_PWM_E1_PIN
#endif

0 comments on commit 08fe8a3

Please sign in to comment.