From 15ce5d06127553050d20f1e92cca8b67bdbddf66 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 30 Mar 2025 23:30:31 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=F0=9F=A9=B9=20Misc.=20code=20corre?= =?UTF-8?q?ctions,=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/gcode/feature/digipot/M907-M910.cpp | 29 ++++++++++++++----- Marlin/src/inc/Conditionals-6-type.h | 2 +- Marlin/src/inc/SanityCheck.h | 8 ++--- Marlin/src/module/stepper.cpp | 2 +- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/Marlin/src/gcode/feature/digipot/M907-M910.cpp b/Marlin/src/gcode/feature/digipot/M907-M910.cpp index ab1c316705..b1bd9b4f95 100644 --- a/Marlin/src/gcode/feature/digipot/M907-M910.cpp +++ b/Marlin/src/gcode/feature/digipot/M907-M910.cpp @@ -51,10 +51,25 @@ void GcodeSuite::M907() { if (!parser.seen("BS" STR_AXES_LOGICAL)) return M907_report(); - if (parser.seenval('S')) for (uint8_t i = 0; i < MOTOR_CURRENT_COUNT; ++i) stepper.set_digipot_current(i, parser.value_int()); - LOOP_LOGICAL_AXES(i) if (parser.seenval(IAXIS_CHAR(i))) stepper.set_digipot_current(i, parser.value_int()); // X Y Z (I J K U V W) E (map to drivers according to DIGIPOT_CHANNELS. Default with NUM_AXES 3: map X Y Z E to X Y Z E0) - // Additional extruders use B,C. - // TODO: Change these parameters because 'E' is used and D should be reserved for debugging. B? + // S - Set current in mA for all axes + if (parser.seenval('S')) + for (uint8_t i = 0; i < MOTOR_CURRENT_COUNT; ++i) + stepper.set_digipot_current(i, parser.value_int()); + + // X Y Z (I J K U V W) E (map to drivers according to DIGIPOT_CHANNELS. + // Default with NUM_AXES 3: map X Y Z E to X Y Z E0) + LOOP_LOGICAL_AXES(i) + if (parser.seenval(IAXIS_CHAR(i))) + stepper.set_digipot_current(i, parser.value_int()); + + /** + * Additional extruders use B,C in this legacy protocol + * TODO: Update to allow for an index with X, Y, Z, E axis to isolate a single stepper + * and use configured axis names instead of IJKUVW. i.e., Match the behavior of + * other G-codes that set stepper-specific parameters. If necessary deprecate G-codes. + * Bonus Points: Standardize a method that all G-codes can use to refer to one or + * more steppers/drivers and apply to various G-codes. + */ #if E_STEPPERS >= 2 if (parser.seenval('B')) stepper.set_digipot_current(E_AXIS + 1, parser.value_int()); #if E_STEPPERS >= 3 @@ -72,14 +87,12 @@ void GcodeSuite::M907() { if (!parser.seen("S" #if HAS_X_Y_XY_I_J_K_U_V_W - "XY" SECONDARY_AXIS_GANG("I", "J", "K", "U", "V", "W") + NUM_AXIS_GANG("X", "Y",, "I", "J", "K", "U", "V", "W") #endif #if PIN_EXISTS(MOTOR_CURRENT_PWM_Z) "Z" #endif - #if HAS_MOTOR_CURRENT_PWM_E - "E" - #endif + TERN_(HAS_MOTOR_CURRENT_PWM_E, "E") )) return M907_report(); if (parser.seenval('S')) for (uint8_t a = 0; a < MOTOR_CURRENT_COUNT; ++a) stepper.set_digipot_current(a, parser.value_int()); diff --git a/Marlin/src/inc/Conditionals-6-type.h b/Marlin/src/inc/Conditionals-6-type.h index bd8e3b78b4..9f0c0c3564 100644 --- a/Marlin/src/inc/Conditionals-6-type.h +++ b/Marlin/src/inc/Conditionals-6-type.h @@ -38,7 +38,7 @@ #endif // If an axis's Homing Current differs from standard current... -#define HAS_HOME_CURRENT(N) (N##_CURRENT_HOME > 0 && N##_CURRENT_HOME != N##_CURRENT) +#define HAS_HOME_CURRENT(N) TERN0(EDITABLE_HOMING_CURRENT, N##_IS_TRINAMIC && N##_HOME_DIR != 0) || (N##_CURRENT_HOME > 0 && N##_CURRENT_HOME != N##_CURRENT) #if HAS_HOME_CURRENT(X) #define X_HAS_HOME_CURRENT 1 #endif diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 1a86bb37de..62e16b0156 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1890,7 +1890,7 @@ static_assert(NUM_SERVOS <= NUM_SERVO_PLUGS, "NUM_SERVOS (or some servo index) i /** * ULTIPANEL encoder */ -#if IS_ULTIPANEL && NONE(IS_NEWPANEL, SR_LCD_2W_NL) && !PIN_EXISTS(SHIFT_CLK) +#if IS_ULTIPANEL && NONE(HAS_ROTARY_ENCODER, SR_LCD_2W_NL, SR_LCD_3W_NL) && !PIN_EXISTS(SHIFT_CLK) #error "ULTIPANEL controllers require some kind of encoder." #endif @@ -4041,11 +4041,11 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive." #elif _PIN_CONFLICT(CONTROLLERFAN) #error "SPINDLE_LASER_PWM_PIN conflicts with CONTROLLERFAN_PIN." #elif _PIN_CONFLICT(MOTOR_CURRENT_PWM_XY) - #error "SPINDLE_LASER_PWM_PIN conflicts with MOTOR_CURRENT_PWM_XY." + #error "SPINDLE_LASER_PWM_PIN conflicts with MOTOR_CURRENT_PWM_XY_PIN." #elif _PIN_CONFLICT(MOTOR_CURRENT_PWM_Z) - #error "SPINDLE_LASER_PWM_PIN conflicts with MOTOR_CURRENT_PWM_Z." + #error "SPINDLE_LASER_PWM_PIN conflicts with MOTOR_CURRENT_PWM_Z_PIN." #elif _PIN_CONFLICT(MOTOR_CURRENT_PWM_E) - #error "SPINDLE_LASER_PWM_PIN conflicts with MOTOR_CURRENT_PWM_E." + #error "SPINDLE_LASER_PWM_PIN conflicts with MOTOR_CURRENT_PWM_E_PIN." #endif #endif #undef _PIN_CONFLICT diff --git a/Marlin/src/module/stepper.cpp b/Marlin/src/module/stepper.cpp index f55465ea56..3ee2d6e91c 100644 --- a/Marlin/src/module/stepper.cpp +++ b/Marlin/src/module/stepper.cpp @@ -3673,7 +3673,7 @@ void Stepper::report_positions() { #if HAS_MOTOR_CURRENT_SPI || HAS_MOTOR_CURRENT_PWM void Stepper::set_digipot_current(const uint8_t driver, const int16_t current) { - if (WITHIN(driver, 0, MOTOR_CURRENT_COUNT - 1)) + if (WITHIN(driver, 0, COUNT(motor_current_setting) - 1)) motor_current_setting[driver] = current; // update motor_current_setting if (!initialized) return;