Browse Source

Move TMC2130 g-codes to cpp

Scott Lahteine 7 years ago
parent
commit
2e89685154

+ 4
- 17
Marlin/src/Marlin.cpp View File

95
   #include "HAL/HAL_endstop_interrupts.h"
95
   #include "HAL/HAL_endstop_interrupts.h"
96
 #endif
96
 #endif
97
 
97
 
98
+#if ENABLED(HAVE_TMC2130)
99
+  #include "feature/tmc2130.h"
100
+#endif
101
+
98
 #if ENABLED(SDSUPPORT)
102
 #if ENABLED(SDSUPPORT)
99
   CardReader card;
103
   CardReader card;
100
 #endif
104
 #endif
114
   #include "feature/bedlevel/bedlevel.h"
118
   #include "feature/bedlevel/bedlevel.h"
115
 #endif
119
 #endif
116
 
120
 
117
-#if ENABLED(SENSORLESS_HOMING)
118
-  #include "feature/tmc2130.h"
119
-#endif
120
-
121
 #if ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(PAUSE_PARK_NO_STEPPER_TIMEOUT)
121
 #if ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(PAUSE_PARK_NO_STEPPER_TIMEOUT)
122
   #include "feature/pause.h"
122
   #include "feature/pause.h"
123
 #endif
123
 #endif
359
   SYNC_PLAN_POSITION_KINEMATIC();
359
   SYNC_PLAN_POSITION_KINEMATIC();
360
 }
360
 }
361
 
361
 
362
-#if ENABLED(HAVE_TMC2130)
363
-  #include "feature/tmc2130.h"
364
-  #include "gcode/feature/trinamic/M906.h"
365
-  #include "gcode/feature/trinamic/M911.h"
366
-  #include "gcode/feature/trinamic/M912.h"
367
-  #if ENABLED(HYBRID_THRESHOLD)
368
-    #include "gcode/feature/trinamic/M913.h"
369
-  #endif
370
-  #if ENABLED(SENSORLESS_HOMING)
371
-    #include "gcode/feature/trinamic/M914.h"
372
-  #endif
373
-#endif
374
-
375
 #include "gcode/feature/digipot/M907.h"
362
 #include "gcode/feature/digipot/M907.h"
376
 
363
 
377
 #if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)
364
 #if HAS_DIGIPOTSS || ENABLED(DAC_STEPPER_CURRENT)

Marlin/src/gcode/feature/trinamic/M906.h → Marlin/src/gcode/feature/trinamic/M906.cpp View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-static void tmc2130_get_current(TMC2130Stepper &st, const char name) {
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(HAVE_TMC2130)
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/tmc2130.h"
29
+#include "../../../module/stepper_indirection.h"
30
+
31
+inline void tmc2130_get_current(TMC2130Stepper &st, const char name) {
24
   SERIAL_CHAR(name);
32
   SERIAL_CHAR(name);
25
   SERIAL_ECHOPGM(" axis driver current: ");
33
   SERIAL_ECHOPGM(" axis driver current: ");
26
   SERIAL_ECHOLN(st.getCurrent());
34
   SERIAL_ECHOLN(st.getCurrent());
27
 }
35
 }
28
-static void tmc2130_set_current(TMC2130Stepper &st, const char name, const int mA) {
36
+inline void tmc2130_set_current(TMC2130Stepper &st, const char name, const int mA) {
29
   st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
37
   st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
30
   tmc2130_get_current(st, name);
38
   tmc2130_get_current(st, name);
31
 }
39
 }
37
  * S1: Enable automatic current control
45
  * S1: Enable automatic current control
38
  * S0: Disable
46
  * S0: Disable
39
  */
47
  */
40
-void gcode_M906() {
48
+void GcodeSuite::M906() {
41
   uint16_t values[XYZE];
49
   uint16_t values[XYZE];
42
   LOOP_XYZE(i)
50
   LOOP_XYZE(i)
43
     values[i] = parser.intval(axis_codes[i]);
51
     values[i] = parser.intval(axis_codes[i]);
63
     if (parser.seen('S')) auto_current_control = parser.value_bool();
71
     if (parser.seen('S')) auto_current_control = parser.value_bool();
64
   #endif
72
   #endif
65
 }
73
 }
74
+
75
+#endif // HAVE_TMC2130

Marlin/src/gcode/feature/trinamic/M911.h → Marlin/src/gcode/feature/trinamic/M911.cpp View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-static void tmc2130_report_otpw(TMC2130Stepper &st, const char name) {
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(HAVE_TMC2130)
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/tmc2130.h"
29
+#include "../../../module/stepper_indirection.h"
30
+
31
+inline void tmc2130_report_otpw(TMC2130Stepper &st, const char name) {
24
   SERIAL_CHAR(name);
32
   SERIAL_CHAR(name);
25
   SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
33
   SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
26
   serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
34
   serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
31
  * M911: Report TMC2130 stepper driver overtemperature pre-warn flag
39
  * M911: Report TMC2130 stepper driver overtemperature pre-warn flag
32
  * The flag is held by the library and persist until manually cleared by M912
40
  * The flag is held by the library and persist until manually cleared by M912
33
  */
41
  */
34
-void gcode_M911() {
42
+void GcodeSuite::M911() {
35
   const bool reportX = parser.seen('X'), reportY = parser.seen('Y'), reportZ = parser.seen('Z'), reportE = parser.seen('E'),
43
   const bool reportX = parser.seen('X'), reportY = parser.seen('Y'), reportZ = parser.seen('Z'), reportE = parser.seen('E'),
36
            reportAll = (!reportX && !reportY && !reportZ && !reportE) || (reportX && reportY && reportZ && reportE);
44
            reportAll = (!reportX && !reportY && !reportZ && !reportE) || (reportX && reportY && reportZ && reportE);
37
   #if ENABLED(X_IS_TMC2130)
45
   #if ENABLED(X_IS_TMC2130)
47
     if (reportE || reportAll) tmc2130_report_otpw(stepperE0, 'E');
55
     if (reportE || reportAll) tmc2130_report_otpw(stepperE0, 'E');
48
   #endif
56
   #endif
49
 }
57
 }
58
+
59
+#endif // HAVE_TMC2130

Marlin/src/gcode/feature/trinamic/M912.h → Marlin/src/gcode/feature/trinamic/M912.cpp View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-static void tmc2130_clear_otpw(TMC2130Stepper &st, const char name) {
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(HAVE_TMC2130)
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/tmc2130.h"
29
+#include "../../../module/stepper_indirection.h"
30
+
31
+inline void tmc2130_clear_otpw(TMC2130Stepper &st, const char name) {
24
   st.clear_otpw();
32
   st.clear_otpw();
25
   SERIAL_CHAR(name);
33
   SERIAL_CHAR(name);
26
   SERIAL_ECHOLNPGM(" prewarn flag cleared");
34
   SERIAL_ECHOLNPGM(" prewarn flag cleared");
29
 /**
37
 /**
30
  * M912: Clear TMC2130 stepper driver overtemperature pre-warn flag held by the library
38
  * M912: Clear TMC2130 stepper driver overtemperature pre-warn flag held by the library
31
  */
39
  */
32
-void gcode_M912() {
40
+void GcodeSuite::M912() {
33
   const bool clearX = parser.seen('X'), clearY = parser.seen('Y'), clearZ = parser.seen('Z'), clearE = parser.seen('E'),
41
   const bool clearX = parser.seen('X'), clearY = parser.seen('Y'), clearZ = parser.seen('Z'), clearE = parser.seen('E'),
34
            clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE);
42
            clearAll = (!clearX && !clearY && !clearZ && !clearE) || (clearX && clearY && clearZ && clearE);
35
   #if ENABLED(X_IS_TMC2130)
43
   #if ENABLED(X_IS_TMC2130)
45
     if (clearE || clearAll) tmc2130_clear_otpw(stepperE0, 'E');
53
     if (clearE || clearAll) tmc2130_clear_otpw(stepperE0, 'E');
46
   #endif
54
   #endif
47
 }
55
 }
56
+
57
+#endif // HAVE_TMC2130

Marlin/src/gcode/feature/trinamic/M913.h → Marlin/src/gcode/feature/trinamic/M913.cpp View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-static void tmc2130_get_pwmthrs(TMC2130Stepper &st, const char name, const uint16_t spmm) {
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(HAVE_TMC2130) && ENABLED(HYBRID_THRESHOLD)
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/tmc2130.h"
29
+#include "../../../module/planner.h"
30
+#include "../../../module/stepper_indirection.h"
31
+
32
+inline void tmc2130_get_pwmthrs(TMC2130Stepper &st, const char name, const uint16_t spmm) {
24
   SERIAL_CHAR(name);
33
   SERIAL_CHAR(name);
25
   SERIAL_ECHOPGM(" stealthChop max speed set to ");
34
   SERIAL_ECHOPGM(" stealthChop max speed set to ");
26
   SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.stealth_max_speed() * spmm));
35
   SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.stealth_max_speed() * spmm));
27
 }
36
 }
28
-static void tmc2130_set_pwmthrs(TMC2130Stepper &st, const char name, const int32_t thrs, const uint32_t spmm) {
37
+inline void tmc2130_set_pwmthrs(TMC2130Stepper &st, const char name, const int32_t thrs, const uint32_t spmm) {
29
   st.stealth_max_speed(12650000UL * st.microsteps() / (256 * thrs * spmm));
38
   st.stealth_max_speed(12650000UL * st.microsteps() / (256 * thrs * spmm));
30
   tmc2130_get_pwmthrs(st, name, spmm);
39
   tmc2130_get_pwmthrs(st, name, spmm);
31
 }
40
 }
33
 /**
42
 /**
34
  * M913: Set HYBRID_THRESHOLD speed.
43
  * M913: Set HYBRID_THRESHOLD speed.
35
  */
44
  */
36
-void gcode_M913() {
45
+void GcodeSuite::M913() {
37
   uint16_t values[XYZE];
46
   uint16_t values[XYZE];
38
   LOOP_XYZE(i)
47
   LOOP_XYZE(i)
39
     values[i] = parser.intval(axis_codes[i]);
48
     values[i] = parser.intval(axis_codes[i]);
55
     else tmc2130_get_pwmthrs(stepperE0, 'E', planner.axis_steps_per_mm[E_AXIS]);
64
     else tmc2130_get_pwmthrs(stepperE0, 'E', planner.axis_steps_per_mm[E_AXIS]);
56
   #endif
65
   #endif
57
 }
66
 }
67
+
68
+#endif // HAVE_TMC2130 && HYBRID_THRESHOLD

Marlin/src/gcode/feature/trinamic/M914.h → Marlin/src/gcode/feature/trinamic/M914.cpp View File

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
-static void tmc2130_get_sgt(TMC2130Stepper &st, const char name) {
23
+#include "../../../inc/MarlinConfig.h"
24
+
25
+#if ENABLED(HAVE_TMC2130) && ENABLED(SENSORLESS_HOMING)
26
+
27
+#include "../../gcode.h"
28
+#include "../../../feature/tmc2130.h"
29
+#include "../../../module/stepper_indirection.h"
30
+
31
+inline void tmc2130_get_sgt(TMC2130Stepper &st, const char name) {
24
   SERIAL_CHAR(name);
32
   SERIAL_CHAR(name);
25
   SERIAL_ECHOPGM(" driver homing sensitivity set to ");
33
   SERIAL_ECHOPGM(" driver homing sensitivity set to ");
26
   SERIAL_ECHOLN(st.sgt());
34
   SERIAL_ECHOLN(st.sgt());
27
 }
35
 }
28
-static void tmc2130_set_sgt(TMC2130Stepper &st, const char name, const int8_t sgt_val) {
36
+inline void tmc2130_set_sgt(TMC2130Stepper &st, const char name, const int8_t sgt_val) {
29
   st.sgt(sgt_val);
37
   st.sgt(sgt_val);
30
   tmc2130_get_sgt(st, name);
38
   tmc2130_get_sgt(st, name);
31
 }
39
 }
33
 /**
41
 /**
34
  * M914: Set SENSORLESS_HOMING sensitivity.
42
  * M914: Set SENSORLESS_HOMING sensitivity.
35
  */
43
  */
36
-void gcode_M914() {
44
+void GcodeSuite::M914() {
37
   #if ENABLED(X_IS_TMC2130)
45
   #if ENABLED(X_IS_TMC2130)
38
     if (parser.seen(axis_codes[X_AXIS])) tmc2130_set_sgt(stepperX, 'X', parser.value_int());
46
     if (parser.seen(axis_codes[X_AXIS])) tmc2130_set_sgt(stepperX, 'X', parser.value_int());
39
     else tmc2130_get_sgt(stepperX, 'X');
47
     else tmc2130_get_sgt(stepperX, 'X');
43
     else tmc2130_get_sgt(stepperY, 'Y');
51
     else tmc2130_get_sgt(stepperY, 'Y');
44
   #endif
52
   #endif
45
 }
53
 }
54
+
55
+#endif // HAVE_TMC2130 && SENSORLESS_HOMING

+ 5
- 26
Marlin/src/gcode/gcode.cpp View File

122
 extern void gcode_M350();
122
 extern void gcode_M350();
123
 extern void gcode_M351();
123
 extern void gcode_M351();
124
 extern void gcode_M355();
124
 extern void gcode_M355();
125
-extern void gcode_M906();
126
-extern void gcode_M911();
127
-extern void gcode_M912();
128
-extern void gcode_M913();
129
-extern void gcode_M914();
130
 extern void gcode_M907();
125
 extern void gcode_M907();
131
 extern void gcode_M908();
126
 extern void gcode_M908();
132
 extern void gcode_M909();
127
 extern void gcode_M909();
660
         case 900: M900(); break;  // M900: Set advance K factor.
655
         case 900: M900(); break;  // M900: Set advance K factor.
661
       #endif
656
       #endif
662
 
657
 
663
-      #if ENABLED(HAVE_TMC2130)
664
-        case 906: // M906: Set motor current in milliamps using axis codes X, Y, Z, E
665
-          gcode_M906();
666
-          break;
667
-      #endif
668
-
669
       case 907: // M907: Set digital trimpot motor current using axis codes.
658
       case 907: // M907: Set digital trimpot motor current using axis codes.
670
         gcode_M907();
659
         gcode_M907();
671
         break;
660
         break;
691
       #endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT
680
       #endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT
692
 
681
 
693
       #if ENABLED(HAVE_TMC2130)
682
       #if ENABLED(HAVE_TMC2130)
694
-        case 911: // M911: Report TMC2130 prewarn triggered flags
695
-          gcode_M911();
696
-          break;
697
-
698
-        case 912: // M911: Clear TMC2130 prewarn triggered flags
699
-          gcode_M912();
700
-          break;
701
-
683
+        case 906: M906(); break;    // M906: Set motor current in milliamps using axis codes X, Y, Z, E
684
+        case 911: M911(); break;    // M911: Report TMC2130 prewarn triggered flags
685
+        case 912: M912(); break;    // M912: Clear TMC2130 prewarn triggered flags
702
         #if ENABLED(HYBRID_THRESHOLD)
686
         #if ENABLED(HYBRID_THRESHOLD)
703
-          case 913: // M913: Set HYBRID_THRESHOLD speed.
704
-            gcode_M913();
705
-            break;
687
+          case 913: M913(); break;  // M913: Set HYBRID_THRESHOLD speed.
706
         #endif
688
         #endif
707
-
708
         #if ENABLED(SENSORLESS_HOMING)
689
         #if ENABLED(SENSORLESS_HOMING)
709
-          case 914: // M914: Set SENSORLESS_HOMING sensitivity.
710
-            gcode_M914();
711
-            break;
690
+          case 914: M914(); break;  // M914: Set SENSORLESS_HOMING sensitivity.
712
         #endif
691
         #endif
713
       #endif
692
       #endif
714
 
693
 

Loading…
Cancel
Save