Migrate to a new TMC library (#11943)
This commit is contained in:
committed by
Scott Lahteine
parent
2abf3d258d
commit
c3229e1b34
@ -33,7 +33,7 @@
|
||||
* Report driver currents when no axis specified
|
||||
*/
|
||||
void GcodeSuite::M906() {
|
||||
#define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q, TMC_##Q)
|
||||
#define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q)
|
||||
#define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, value)
|
||||
|
||||
bool report = true;
|
||||
|
@ -33,135 +33,137 @@
|
||||
#define M91x_USE(ST) (AXIS_DRIVER_TYPE(ST, TMC2130) || (AXIS_DRIVER_TYPE(ST, TMC2208) && PIN_EXISTS(ST##_SERIAL_RX)))
|
||||
#define M91x_USE_E(N) (E_STEPPERS > N && M91x_USE(E##N))
|
||||
|
||||
/**
|
||||
* M911: Report TMC stepper driver overtemperature pre-warn flag
|
||||
* This flag is held by the library, persisting until cleared by M912
|
||||
*/
|
||||
void GcodeSuite::M911() {
|
||||
#if M91x_USE(X)
|
||||
tmc_report_otpw(stepperX, TMC_X);
|
||||
#endif
|
||||
#if M91x_USE(X2)
|
||||
tmc_report_otpw(stepperX2, TMC_X2);
|
||||
#endif
|
||||
#if M91x_USE(Y)
|
||||
tmc_report_otpw(stepperY, TMC_Y);
|
||||
#endif
|
||||
#if M91x_USE(Y2)
|
||||
tmc_report_otpw(stepperY2, TMC_Y2);
|
||||
#endif
|
||||
#if M91x_USE(Z)
|
||||
tmc_report_otpw(stepperZ, TMC_Z);
|
||||
#endif
|
||||
#if M91x_USE(Z2)
|
||||
tmc_report_otpw(stepperZ2, TMC_Z2);
|
||||
#endif
|
||||
#if M91x_USE(Z3)
|
||||
tmc_report_otpw(stepperZ3, TMC_Z3);
|
||||
#endif
|
||||
#if M91x_USE_E(0)
|
||||
tmc_report_otpw(stepperE0, TMC_E0);
|
||||
#endif
|
||||
#if M91x_USE_E(1)
|
||||
tmc_report_otpw(stepperE1, TMC_E1);
|
||||
#endif
|
||||
#if M91x_USE_E(2)
|
||||
tmc_report_otpw(stepperE2, TMC_E2);
|
||||
#endif
|
||||
#if M91x_USE_E(3)
|
||||
tmc_report_otpw(stepperE3, TMC_E3);
|
||||
#endif
|
||||
#if M91x_USE_E(4)
|
||||
tmc_report_otpw(stepperE4, TMC_E4);
|
||||
#endif
|
||||
#if M91x_USE_E(5)
|
||||
tmc_report_otpw(stepperE5, TMC_E5);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library
|
||||
* Specify one or more axes with X, Y, Z, X1, Y1, Z1, X2, Y2, Z2, Z3 and E[index].
|
||||
* If no axes are given, clear all.
|
||||
*
|
||||
* Examples:
|
||||
* M912 X ; clear X and X2
|
||||
* M912 X1 ; clear X1 only
|
||||
* M912 X2 ; clear X2 only
|
||||
* M912 X E ; clear X, X2, and all E
|
||||
* M912 E1 ; clear E1 only
|
||||
*/
|
||||
void GcodeSuite::M912() {
|
||||
const bool hasX = parser.seen(axis_codes[X_AXIS]),
|
||||
hasY = parser.seen(axis_codes[Y_AXIS]),
|
||||
hasZ = parser.seen(axis_codes[Z_AXIS]),
|
||||
hasE = parser.seen(axis_codes[E_AXIS]),
|
||||
hasNone = !hasX && !hasY && !hasZ && !hasE;
|
||||
|
||||
#if M91x_USE(X) || M91x_USE(X2)
|
||||
const int8_t xval = int8_t(parser.byteval(axis_codes[X_AXIS], 0xFF));
|
||||
#if M91x_USE(X)
|
||||
if (hasNone || xval == 1 || (hasX && xval < 0)) tmc_clear_otpw(stepperX, TMC_X);
|
||||
#endif
|
||||
#if M91x_USE(X2)
|
||||
if (hasNone || xval == 2 || (hasX && xval < 0)) tmc_clear_otpw(stepperX2, TMC_X2);
|
||||
#endif
|
||||
#if ENABLED(MONITOR_DRIVER_STATUS)
|
||||
/**
|
||||
* M911: Report TMC stepper driver overtemperature pre-warn flag
|
||||
* This flag is held by the library, persisting until cleared by M912
|
||||
*/
|
||||
void GcodeSuite::M911() {
|
||||
#if M91x_USE(X)
|
||||
tmc_report_otpw(stepperX);
|
||||
#endif
|
||||
|
||||
#if M91x_USE(Y) || M91x_USE(Y2)
|
||||
const int8_t yval = int8_t(parser.byteval(axis_codes[Y_AXIS], 0xFF));
|
||||
#if M91x_USE(Y)
|
||||
if (hasNone || yval == 1 || (hasY && yval < 0)) tmc_clear_otpw(stepperY, TMC_Y);
|
||||
#endif
|
||||
#if M91x_USE(Y2)
|
||||
if (hasNone || yval == 2 || (hasY && yval < 0)) tmc_clear_otpw(stepperY2, TMC_Y2);
|
||||
#endif
|
||||
#if M91x_USE(X2)
|
||||
tmc_report_otpw(stepperX2);
|
||||
#endif
|
||||
|
||||
#if M91x_USE(Z) || M91x_USE(Z2) || M91x_USE(Z3)
|
||||
const int8_t zval = int8_t(parser.byteval(axis_codes[Z_AXIS], 0xFF));
|
||||
#if M91x_USE(Z)
|
||||
if (hasNone || zval == 1 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ, TMC_Z);
|
||||
#endif
|
||||
#if M91x_USE(Z2)
|
||||
if (hasNone || zval == 2 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ2, TMC_Z2);
|
||||
#endif
|
||||
#if M91x_USE(Z3)
|
||||
if (hasNone || zval == 3 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ3, TMC_Z3);
|
||||
#endif
|
||||
#if M91x_USE(Y)
|
||||
tmc_report_otpw(stepperY);
|
||||
#endif
|
||||
|
||||
#if M91x_USE_E(0) || M91x_USE_E(1) || M91x_USE_E(2) || M91x_USE_E(3) || M91x_USE_E(4) || M91x_USE_E(5)
|
||||
const uint8_t eval = int8_t(parser.byteval(axis_codes[E_AXIS], 0xFF));
|
||||
#if M91x_USE_E(0)
|
||||
if (hasNone || eval == 0 || (hasE && eval < 0)) tmc_clear_otpw(stepperE0, TMC_E0);
|
||||
#endif
|
||||
#if M91x_USE_E(1)
|
||||
if (hasNone || eval == 1 || (hasE && eval < 0)) tmc_clear_otpw(stepperE1, TMC_E1);
|
||||
#endif
|
||||
#if M91x_USE_E(2)
|
||||
if (hasNone || eval == 2 || (hasE && eval < 0)) tmc_clear_otpw(stepperE2, TMC_E2);
|
||||
#endif
|
||||
#if M91x_USE_E(3)
|
||||
if (hasNone || eval == 3 || (hasE && eval < 0)) tmc_clear_otpw(stepperE3, TMC_E3);
|
||||
#endif
|
||||
#if M91x_USE_E(4)
|
||||
if (hasNone || eval == 4 || (hasE && eval < 0)) tmc_clear_otpw(stepperE4, TMC_E4);
|
||||
#endif
|
||||
#if M91x_USE_E(5)
|
||||
if (hasNone || eval == 5 || (hasE && eval < 0)) tmc_clear_otpw(stepperE5, TMC_E5);
|
||||
#endif
|
||||
#if M91x_USE(Y2)
|
||||
tmc_report_otpw(stepperY2);
|
||||
#endif
|
||||
}
|
||||
#if M91x_USE(Z)
|
||||
tmc_report_otpw(stepperZ);
|
||||
#endif
|
||||
#if M91x_USE(Z2)
|
||||
tmc_report_otpw(stepperZ2);
|
||||
#endif
|
||||
#if M91x_USE(Z3)
|
||||
tmc_report_otpw(stepperZ3);
|
||||
#endif
|
||||
#if M91x_USE_E(0)
|
||||
tmc_report_otpw(stepperE0);
|
||||
#endif
|
||||
#if M91x_USE_E(1)
|
||||
tmc_report_otpw(stepperE1);
|
||||
#endif
|
||||
#if M91x_USE_E(2)
|
||||
tmc_report_otpw(stepperE2);
|
||||
#endif
|
||||
#if M91x_USE_E(3)
|
||||
tmc_report_otpw(stepperE3);
|
||||
#endif
|
||||
#if M91x_USE_E(4)
|
||||
tmc_report_otpw(stepperE4);
|
||||
#endif
|
||||
#if M91x_USE_E(5)
|
||||
tmc_report_otpw(stepperE5);
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* M912: Clear TMC stepper driver overtemperature pre-warn flag held by the library
|
||||
* Specify one or more axes with X, Y, Z, X1, Y1, Z1, X2, Y2, Z2, Z3 and E[index].
|
||||
* If no axes are given, clear all.
|
||||
*
|
||||
* Examples:
|
||||
* M912 X ; clear X and X2
|
||||
* M912 X1 ; clear X1 only
|
||||
* M912 X2 ; clear X2 only
|
||||
* M912 X E ; clear X, X2, and all E
|
||||
* M912 E1 ; clear E1 only
|
||||
*/
|
||||
void GcodeSuite::M912() {
|
||||
const bool hasX = parser.seen(axis_codes[X_AXIS]),
|
||||
hasY = parser.seen(axis_codes[Y_AXIS]),
|
||||
hasZ = parser.seen(axis_codes[Z_AXIS]),
|
||||
hasE = parser.seen(axis_codes[E_AXIS]),
|
||||
hasNone = !hasX && !hasY && !hasZ && !hasE;
|
||||
|
||||
#if M91x_USE(X) || M91x_USE(X2)
|
||||
const int8_t xval = int8_t(parser.byteval(axis_codes[X_AXIS], 0xFF));
|
||||
#if M91x_USE(X)
|
||||
if (hasNone || xval == 1 || (hasX && xval < 0)) tmc_clear_otpw(stepperX);
|
||||
#endif
|
||||
#if M91x_USE(X2)
|
||||
if (hasNone || xval == 2 || (hasX && xval < 0)) tmc_clear_otpw(stepperX2);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if M91x_USE(Y) || M91x_USE(Y2)
|
||||
const int8_t yval = int8_t(parser.byteval(axis_codes[Y_AXIS], 0xFF));
|
||||
#if M91x_USE(Y)
|
||||
if (hasNone || yval == 1 || (hasY && yval < 0)) tmc_clear_otpw(stepperY);
|
||||
#endif
|
||||
#if M91x_USE(Y2)
|
||||
if (hasNone || yval == 2 || (hasY && yval < 0)) tmc_clear_otpw(stepperY2);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if M91x_USE(Z) || M91x_USE(Z2) || M91x_USE(Z3)
|
||||
const int8_t zval = int8_t(parser.byteval(axis_codes[Z_AXIS], 0xFF));
|
||||
#if M91x_USE(Z)
|
||||
if (hasNone || zval == 1 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ);
|
||||
#endif
|
||||
#if M91x_USE(Z2)
|
||||
if (hasNone || zval == 2 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ2);
|
||||
#endif
|
||||
#if M91x_USE(Z3)
|
||||
if (hasNone || zval == 3 || (hasZ && zval < 0)) tmc_clear_otpw(stepperZ3);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if M91x_USE_E(0) || M91x_USE_E(1) || M91x_USE_E(2) || M91x_USE_E(3) || M91x_USE_E(4) || M91x_USE_E(5)
|
||||
const int8_t eval = int8_t(parser.byteval(axis_codes[E_AXIS], 0xFF));
|
||||
#if M91x_USE_E(0)
|
||||
if (hasNone || eval == 0 || (hasE && eval < 0)) tmc_clear_otpw(stepperE0);
|
||||
#endif
|
||||
#if M91x_USE_E(1)
|
||||
if (hasNone || eval == 1 || (hasE && eval < 0)) tmc_clear_otpw(stepperE1);
|
||||
#endif
|
||||
#if M91x_USE_E(2)
|
||||
if (hasNone || eval == 2 || (hasE && eval < 0)) tmc_clear_otpw(stepperE2);
|
||||
#endif
|
||||
#if M91x_USE_E(3)
|
||||
if (hasNone || eval == 3 || (hasE && eval < 0)) tmc_clear_otpw(stepperE3);
|
||||
#endif
|
||||
#if M91x_USE_E(4)
|
||||
if (hasNone || eval == 4 || (hasE && eval < 0)) tmc_clear_otpw(stepperE4);
|
||||
#endif
|
||||
#if M91x_USE_E(5)
|
||||
if (hasNone || eval == 5 || (hasE && eval < 0)) tmc_clear_otpw(stepperE5);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* M913: Set HYBRID_THRESHOLD speed.
|
||||
*/
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
void GcodeSuite::M913() {
|
||||
#define TMC_SAY_PWMTHRS(A,Q) tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[_AXIS(A)])
|
||||
#define TMC_SAY_PWMTHRS(A,Q) tmc_get_pwmthrs(stepper##Q, planner.axis_steps_per_mm[_AXIS(A)])
|
||||
#define TMC_SET_PWMTHRS(A,Q) tmc_set_pwmthrs(stepper##Q, value, planner.axis_steps_per_mm[_AXIS(A)])
|
||||
#define TMC_SAY_PWMTHRS_E(E) do{ constexpr uint8_t extruder = E; tmc_get_pwmthrs(stepperE##E, TMC_E##E, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }while(0)
|
||||
#define TMC_SAY_PWMTHRS_E(E) do{ constexpr uint8_t extruder = E; tmc_get_pwmthrs(stepperE##E, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }while(0)
|
||||
#define TMC_SET_PWMTHRS_E(E) do{ constexpr uint8_t extruder = E; tmc_set_pwmthrs(stepperE##E, value, planner.axis_steps_per_mm[E_AXIS_N]); UNUSED(extruder); }while(0)
|
||||
|
||||
bool report = true;
|
||||
@ -271,7 +273,7 @@ void GcodeSuite::M912() {
|
||||
*/
|
||||
#if USE_SENSORLESS
|
||||
void GcodeSuite::M914() {
|
||||
#define TMC_SAY_SGT(Q) tmc_get_sgt(stepper##Q, TMC_##Q)
|
||||
#define TMC_SAY_SGT(Q) tmc_get_sgt(stepper##Q)
|
||||
#define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, value)
|
||||
|
||||
bool report = true;
|
||||
@ -362,16 +364,16 @@ void GcodeSuite::M912() {
|
||||
}
|
||||
|
||||
#if AXIS_IS_TMC(Z)
|
||||
const uint16_t Z_current_1 = stepperZ.getCurrent();
|
||||
stepperZ.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
|
||||
const uint16_t Z_current_1 = stepperZ.getMilliamps();
|
||||
stepperZ.rms_current(_rms);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(Z2)
|
||||
const uint16_t Z2_current_1 = stepperZ2.getCurrent();
|
||||
stepperZ2.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
|
||||
const uint16_t Z2_current_1 = stepperZ2.getMilliamps();
|
||||
stepperZ2.rms_current(_rms);
|
||||
#endif
|
||||
#if Z3_IS_TRINAMIC
|
||||
const uint16_t Z3_current_1 = stepperZ3.getCurrent();
|
||||
stepperZ3.setCurrent(_rms, R_SENSE, HOLD_MULTIPLIER);
|
||||
#if AXIS_IS_TMC(Z3)
|
||||
const uint16_t Z3_current_1 = stepperZ3.getMilliamps();
|
||||
stepperZ3.rms_current(_rms);
|
||||
#endif
|
||||
|
||||
SERIAL_ECHOPAIR("\nCalibration current: Z", _rms);
|
||||
@ -381,13 +383,13 @@ void GcodeSuite::M912() {
|
||||
do_blocking_move_to_z(Z_MAX_POS+_z);
|
||||
|
||||
#if AXIS_IS_TMC(Z)
|
||||
stepperZ.setCurrent(Z_current_1, R_SENSE, HOLD_MULTIPLIER);
|
||||
stepperZ.rms_current(Z_current_1);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(Z2)
|
||||
stepperZ2.setCurrent(Z2_current_1, R_SENSE, HOLD_MULTIPLIER);
|
||||
stepperZ2.rms_current(Z2_current_1);
|
||||
#endif
|
||||
#if AXIS_IS_TMC(Z3)
|
||||
stepperZ3.setCurrent(Z3_current_1, R_SENSE, HOLD_MULTIPLIER);
|
||||
stepperZ3.rms_current(Z3_current_1);
|
||||
#endif
|
||||
|
||||
do_blocking_move_to_z(Z_MAX_POS);
|
||||
|
@ -632,8 +632,10 @@ void GcodeSuite::process_parsed_command(
|
||||
case 122: M122(); break;
|
||||
#endif
|
||||
case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E
|
||||
case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags
|
||||
case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags
|
||||
#if ENABLED(MONITOR_DRIVER_STATUS)
|
||||
case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags
|
||||
case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags
|
||||
#endif
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed.
|
||||
#endif
|
||||
|
@ -775,8 +775,10 @@ private:
|
||||
static void M122();
|
||||
#endif
|
||||
static void M906();
|
||||
static void M911();
|
||||
static void M912();
|
||||
#if ENABLED(MONITOR_DRIVER_STATUS)
|
||||
static void M911();
|
||||
static void M912();
|
||||
#endif
|
||||
#if ENABLED(HYBRID_THRESHOLD)
|
||||
static void M913();
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user