Browse Source

Move TMC2130 g-codes to cpp

pull/1/head
Scott Lahteine 7 years ago
parent
commit
2e89685154
  1. 21
      Marlin/src/Marlin.cpp
  2. 16
      Marlin/src/gcode/feature/trinamic/M906.cpp
  3. 14
      Marlin/src/gcode/feature/trinamic/M911.cpp
  4. 14
      Marlin/src/gcode/feature/trinamic/M912.cpp
  5. 17
      Marlin/src/gcode/feature/trinamic/M913.cpp
  6. 16
      Marlin/src/gcode/feature/trinamic/M914.cpp
  7. 31
      Marlin/src/gcode/gcode.cpp

21
Marlin/src/Marlin.cpp

@ -95,6 +95,10 @@
#include "HAL/HAL_endstop_interrupts.h" #include "HAL/HAL_endstop_interrupts.h"
#endif #endif
#if ENABLED(HAVE_TMC2130)
#include "feature/tmc2130.h"
#endif
#if ENABLED(SDSUPPORT) #if ENABLED(SDSUPPORT)
CardReader card; CardReader card;
#endif #endif
@ -114,10 +118,6 @@
#include "feature/bedlevel/bedlevel.h" #include "feature/bedlevel/bedlevel.h"
#endif #endif
#if ENABLED(SENSORLESS_HOMING)
#include "feature/tmc2130.h"
#endif
#if ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(PAUSE_PARK_NO_STEPPER_TIMEOUT) #if ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(PAUSE_PARK_NO_STEPPER_TIMEOUT)
#include "feature/pause.h" #include "feature/pause.h"
#endif #endif
@ -359,19 +359,6 @@ void quickstop_stepper() {
SYNC_PLAN_POSITION_KINEMATIC(); SYNC_PLAN_POSITION_KINEMATIC();
} }
#if ENABLED(HAVE_TMC2130)
#include "feature/tmc2130.h"
#include "gcode/feature/trinamic/M906.h"
#include "gcode/feature/trinamic/M911.h"
#include "gcode/feature/trinamic/M912.h"
#if ENABLED(HYBRID_THRESHOLD)
#include "gcode/feature/trinamic/M913.h"
#endif
#if ENABLED(SENSORLESS_HOMING)
#include "gcode/feature/trinamic/M914.h"
#endif
#endif
#include "gcode/feature/digipot/M907.h" #include "gcode/feature/digipot/M907.h"
#if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT) #if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)

16
Marlin/src/gcode/feature/trinamic/M906.h → Marlin/src/gcode/feature/trinamic/M906.cpp

@ -20,12 +20,20 @@
* *
*/ */
static void tmc2130_get_current(TMC2130Stepper &st, const char name) { #include "../../../inc/MarlinConfig.h"
#if ENABLED(HAVE_TMC2130)
#include "../../gcode.h"
#include "../../../feature/tmc2130.h"
#include "../../../module/stepper_indirection.h"
inline void tmc2130_get_current(TMC2130Stepper &st, const char name) {
SERIAL_CHAR(name); SERIAL_CHAR(name);
SERIAL_ECHOPGM(" axis driver current: "); SERIAL_ECHOPGM(" axis driver current: ");
SERIAL_ECHOLN(st.getCurrent()); SERIAL_ECHOLN(st.getCurrent());
} }
static void tmc2130_set_current(TMC2130Stepper &st, const char name, const int mA) { inline void tmc2130_set_current(TMC2130Stepper &st, const char name, const int mA) {
st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER); st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
tmc2130_get_current(st, name); tmc2130_get_current(st, name);
} }
@ -37,7 +45,7 @@ static void tmc2130_set_current(TMC2130Stepper &st, const char name, const int m
* S1: Enable automatic current control * S1: Enable automatic current control
* S0: Disable * S0: Disable
*/ */
void gcode_M906() { void GcodeSuite::M906() {
uint16_t values[XYZE]; uint16_t values[XYZE];
LOOP_XYZE(i) LOOP_XYZE(i)
values[i] = parser.intval(axis_codes[i]); values[i] = parser.intval(axis_codes[i]);
@ -63,3 +71,5 @@ void gcode_M906() {
if (parser.seen('S')) auto_current_control = parser.value_bool(); if (parser.seen('S')) auto_current_control = parser.value_bool();
#endif #endif
} }
#endif // HAVE_TMC2130

14
Marlin/src/gcode/feature/trinamic/M911.h → Marlin/src/gcode/feature/trinamic/M911.cpp

@ -20,7 +20,15 @@
* *
*/ */
static void tmc2130_report_otpw(TMC2130Stepper &st, const char name) { #include "../../../inc/MarlinConfig.h"
#if ENABLED(HAVE_TMC2130)
#include "../../gcode.h"
#include "../../../feature/tmc2130.h"
#include "../../../module/stepper_indirection.h"
inline void tmc2130_report_otpw(TMC2130Stepper &st, const char name) {
SERIAL_CHAR(name); SERIAL_CHAR(name);
SERIAL_ECHOPGM(" axis temperature prewarn triggered: "); SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false")); serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
@ -31,7 +39,7 @@ static void tmc2130_report_otpw(TMC2130Stepper &st, const char name) {
* M911: Report TMC2130 stepper driver overtemperature pre-warn flag * M911: Report TMC2130 stepper driver overtemperature pre-warn flag
* The flag is held by the library and persist until manually cleared by M912 * The flag is held by the library and persist until manually cleared by M912
*/ */
void gcode_M911() { void GcodeSuite::M911() {
const bool reportX = parser.seen('X'), reportY = parser.seen('Y'), reportZ = parser.seen('Z'), reportE = parser.seen('E'), const bool reportX = parser.seen('X'), reportY = parser.seen('Y'), reportZ = parser.seen('Z'), reportE = parser.seen('E'),
reportAll = (!reportX && !reportY && !reportZ && !reportE) || (reportX && reportY && reportZ && reportE); reportAll = (!reportX && !reportY && !reportZ && !reportE) || (reportX && reportY && reportZ && reportE);
#if ENABLED(X_IS_TMC2130) #if ENABLED(X_IS_TMC2130)
@ -47,3 +55,5 @@ void gcode_M911() {
if (reportE || reportAll) tmc2130_report_otpw(stepperE0, 'E'); if (reportE || reportAll) tmc2130_report_otpw(stepperE0, 'E');
#endif #endif
} }
#endif // HAVE_TMC2130

14
Marlin/src/gcode/feature/trinamic/M912.h → Marlin/src/gcode/feature/trinamic/M912.cpp

@ -20,7 +20,15 @@
* *
*/ */
static void tmc2130_clear_otpw(TMC2130Stepper &st, const char name) { #include "../../../inc/MarlinConfig.h"
#if ENABLED(HAVE_TMC2130)
#include "../../gcode.h"
#include "../../../feature/tmc2130.h"
#include "../../../module/stepper_indirection.h"
inline void tmc2130_clear_otpw(TMC2130Stepper &st, const char name) {
st.clear_otpw(); st.clear_otpw();
SERIAL_CHAR(name); SERIAL_CHAR(name);
SERIAL_ECHOLNPGM(" prewarn flag cleared"); SERIAL_ECHOLNPGM(" prewarn flag cleared");
@ -29,7 +37,7 @@ static void tmc2130_clear_otpw(TMC2130Stepper &st, const char name) {
/** /**
* M912: Clear TMC2130 stepper driver overtemperature pre-warn flag held by the library * M912: Clear TMC2130 stepper driver overtemperature pre-warn flag held by the library
*/ */
void gcode_M912() { void GcodeSuite::M912() {
const bool clearX = parser.seen('X'), clearY = parser.seen('Y'), clearZ = parser.seen('Z'), clearE = parser.seen('E'), const bool clearX = parser.seen('X'), clearY = parser.seen('Y'), clearZ = parser.seen('Z'), clearE = parser.seen('E'),
clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE); clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE);
#if ENABLED(X_IS_TMC2130) #if ENABLED(X_IS_TMC2130)
@ -45,3 +53,5 @@ void gcode_M912() {
if (clearE || clearAll) tmc2130_clear_otpw(stepperE0, 'E'); if (clearE || clearAll) tmc2130_clear_otpw(stepperE0, 'E');
#endif #endif
} }
#endif // HAVE_TMC2130

17
Marlin/src/gcode/feature/trinamic/M913.h → Marlin/src/gcode/feature/trinamic/M913.cpp

@ -20,12 +20,21 @@
* *
*/ */
static void tmc2130_get_pwmthrs(TMC2130Stepper &st, const char name, const uint16_t spmm) { #include "../../../inc/MarlinConfig.h"
#if ENABLED(HAVE_TMC2130) && ENABLED(HYBRID_THRESHOLD)
#include "../../gcode.h"
#include "../../../feature/tmc2130.h"
#include "../../../module/planner.h"
#include "../../../module/stepper_indirection.h"
inline void tmc2130_get_pwmthrs(TMC2130Stepper &st, const char name, const uint16_t spmm) {
SERIAL_CHAR(name); SERIAL_CHAR(name);
SERIAL_ECHOPGM(" stealthChop max speed set to "); SERIAL_ECHOPGM(" stealthChop max speed set to ");
SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.stealth_max_speed() * spmm)); SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.stealth_max_speed() * spmm));
} }
static void tmc2130_set_pwmthrs(TMC2130Stepper &st, const char name, const int32_t thrs, const uint32_t spmm) { inline void tmc2130_set_pwmthrs(TMC2130Stepper &st, const char name, const int32_t thrs, const uint32_t spmm) {
st.stealth_max_speed(12650000UL * st.microsteps() / (256 * thrs * spmm)); st.stealth_max_speed(12650000UL * st.microsteps() / (256 * thrs * spmm));
tmc2130_get_pwmthrs(st, name, spmm); tmc2130_get_pwmthrs(st, name, spmm);
} }
@ -33,7 +42,7 @@ static void tmc2130_set_pwmthrs(TMC2130Stepper &st, const char name, const int32
/** /**
* M913: Set HYBRID_THRESHOLD speed. * M913: Set HYBRID_THRESHOLD speed.
*/ */
void gcode_M913() { void GcodeSuite::M913() {
uint16_t values[XYZE]; uint16_t values[XYZE];
LOOP_XYZE(i) LOOP_XYZE(i)
values[i] = parser.intval(axis_codes[i]); values[i] = parser.intval(axis_codes[i]);
@ -55,3 +64,5 @@ void gcode_M913() {
else tmc2130_get_pwmthrs(stepperE0, 'E', planner.axis_steps_per_mm[E_AXIS]); else tmc2130_get_pwmthrs(stepperE0, 'E', planner.axis_steps_per_mm[E_AXIS]);
#endif #endif
} }
#endif // HAVE_TMC2130 && HYBRID_THRESHOLD

16
Marlin/src/gcode/feature/trinamic/M914.h → Marlin/src/gcode/feature/trinamic/M914.cpp

@ -20,12 +20,20 @@
* *
*/ */
static void tmc2130_get_sgt(TMC2130Stepper &st, const char name) { #include "../../../inc/MarlinConfig.h"
#if ENABLED(HAVE_TMC2130) && ENABLED(SENSORLESS_HOMING)
#include "../../gcode.h"
#include "../../../feature/tmc2130.h"
#include "../../../module/stepper_indirection.h"
inline void tmc2130_get_sgt(TMC2130Stepper &st, const char name) {
SERIAL_CHAR(name); SERIAL_CHAR(name);
SERIAL_ECHOPGM(" driver homing sensitivity set to "); SERIAL_ECHOPGM(" driver homing sensitivity set to ");
SERIAL_ECHOLN(st.sgt()); SERIAL_ECHOLN(st.sgt());
} }
static void tmc2130_set_sgt(TMC2130Stepper &st, const char name, const int8_t sgt_val) { inline void tmc2130_set_sgt(TMC2130Stepper &st, const char name, const int8_t sgt_val) {
st.sgt(sgt_val); st.sgt(sgt_val);
tmc2130_get_sgt(st, name); tmc2130_get_sgt(st, name);
} }
@ -33,7 +41,7 @@ static void tmc2130_set_sgt(TMC2130Stepper &st, const char name, const int8_t sg
/** /**
* M914: Set SENSORLESS_HOMING sensitivity. * M914: Set SENSORLESS_HOMING sensitivity.
*/ */
void gcode_M914() { void GcodeSuite::M914() {
#if ENABLED(X_IS_TMC2130) #if ENABLED(X_IS_TMC2130)
if (parser.seen(axis_codes[X_AXIS])) tmc2130_set_sgt(stepperX, 'X', parser.value_int()); if (parser.seen(axis_codes[X_AXIS])) tmc2130_set_sgt(stepperX, 'X', parser.value_int());
else tmc2130_get_sgt(stepperX, 'X'); else tmc2130_get_sgt(stepperX, 'X');
@ -43,3 +51,5 @@ void gcode_M914() {
else tmc2130_get_sgt(stepperY, 'Y'); else tmc2130_get_sgt(stepperY, 'Y');
#endif #endif
} }
#endif // HAVE_TMC2130 && SENSORLESS_HOMING

31
Marlin/src/gcode/gcode.cpp

@ -122,11 +122,6 @@ extern void gcode_M165();
extern void gcode_M350(); extern void gcode_M350();
extern void gcode_M351(); extern void gcode_M351();
extern void gcode_M355(); extern void gcode_M355();
extern void gcode_M906();
extern void gcode_M911();
extern void gcode_M912();
extern void gcode_M913();
extern void gcode_M914();
extern void gcode_M907(); extern void gcode_M907();
extern void gcode_M908(); extern void gcode_M908();
extern void gcode_M909(); extern void gcode_M909();
@ -660,12 +655,6 @@ void GcodeSuite::process_next_command() {
case 900: M900(); break; // M900: Set advance K factor. case 900: M900(); break; // M900: Set advance K factor.
#endif #endif
#if ENABLED(HAVE_TMC2130)
case 906: // M906: Set motor current in milliamps using axis codes X, Y, Z, E
gcode_M906();
break;
#endif
case 907: // M907: Set digital trimpot motor current using axis codes. case 907: // M907: Set digital trimpot motor current using axis codes.
gcode_M907(); gcode_M907();
break; break;
@ -691,24 +680,14 @@ void GcodeSuite::process_next_command() {
#endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT #endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT
#if ENABLED(HAVE_TMC2130) #if ENABLED(HAVE_TMC2130)
case 911: // M911: Report TMC2130 prewarn triggered flags case 906: M906(); break; // M906: Set motor current in milliamps using axis codes X, Y, Z, E
gcode_M911(); case 911: M911(); break; // M911: Report TMC2130 prewarn triggered flags
break; case 912: M912(); break; // M912: Clear TMC2130 prewarn triggered flags
case 912: // M911: Clear TMC2130 prewarn triggered flags
gcode_M912();
break;
#if ENABLED(HYBRID_THRESHOLD) #if ENABLED(HYBRID_THRESHOLD)
case 913: // M913: Set HYBRID_THRESHOLD speed. case 913: M913(); break; // M913: Set HYBRID_THRESHOLD speed.
gcode_M913();
break;
#endif #endif
#if ENABLED(SENSORLESS_HOMING) #if ENABLED(SENSORLESS_HOMING)
case 914: // M914: Set SENSORLESS_HOMING sensitivity. case 914: M914(); break; // M914: Set SENSORLESS_HOMING sensitivity.
gcode_M914();
break;
#endif #endif
#endif #endif

Loading…
Cancel
Save