Explorar el Código

More Trinamic cleanup

Scott Lahteine hace 6 años
padre
commit
b76344c080

+ 3
- 3
Marlin/src/feature/tmc_util.h Ver fichero

@@ -53,7 +53,7 @@ void tmc_get_current(TMC &st, const TMC_AxisEnum axis) {
53 53
   _tmc_say_current(axis, st.getCurrent());
54 54
 }
55 55
 template<typename TMC>
56
-void tmc_set_current(TMC &st, const TMC_AxisEnum axis, const int mA) {
56
+void tmc_set_current(TMC &st, const int mA) {
57 57
   st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
58 58
 }
59 59
 template<typename TMC>
@@ -70,7 +70,7 @@ void tmc_get_pwmthrs(TMC &st, const TMC_AxisEnum axis, const uint16_t spmm) {
70 70
   _tmc_say_pwmthrs(axis, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm));
71 71
 }
72 72
 template<typename TMC>
73
-void tmc_set_pwmthrs(TMC &st, const TMC_AxisEnum axis, const int32_t thrs, const uint32_t spmm) {
73
+void tmc_set_pwmthrs(TMC &st, const int32_t thrs, const uint32_t spmm) {
74 74
   st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
75 75
 }
76 76
 template<typename TMC>
@@ -78,7 +78,7 @@ void tmc_get_sgt(TMC &st, const TMC_AxisEnum axis) {
78 78
   _tmc_say_sgt(axis, st.sgt());
79 79
 }
80 80
 template<typename TMC>
81
-void tmc_set_sgt(TMC &st, const TMC_AxisEnum axis, const int8_t sgt_val) {
81
+void tmc_set_sgt(TMC &st, const int8_t sgt_val) {
82 82
   st.sgt(sgt_val);
83 83
 }
84 84
 

+ 1
- 1
Marlin/src/gcode/feature/trinamic/M906.cpp Ver fichero

@@ -34,7 +34,7 @@
34 34
  */
35 35
 void GcodeSuite::M906() {
36 36
   #define TMC_SAY_CURRENT(Q) tmc_get_current(stepper##Q, TMC_##Q)
37
-  #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, TMC_##Q, value)
37
+  #define TMC_SET_CURRENT(Q) tmc_set_current(stepper##Q, value)
38 38
 
39 39
   bool report = true;
40 40
   const uint8_t index = parser.byteval('I');

+ 74
- 52
Marlin/src/gcode/feature/trinamic/M911-M915.cpp Ver fichero

@@ -30,42 +30,48 @@
30 30
 #include "../../../module/planner.h"
31 31
 #include "../../queue.h"
32 32
 
33
+#define M91x_USE(A) (ENABLED(A##_IS_TMC2130) || (ENABLED(A##_IS_TMC2208) && PIN_EXISTS(A##_SERIAL_RX)))
34
+#define M91x_USE_X  (ENABLED(IS_TRAMS) || M91x_USE(X))
35
+#define M91x_USE_Y  (ENABLED(IS_TRAMS) || M91x_USE(Y))
36
+#define M91x_USE_Z  (ENABLED(IS_TRAMS) || M91x_USE(Z))
37
+#define M91x_USE_E0 (ENABLED(IS_TRAMS) || M91x_USE(E0))
38
+
33 39
 /**
34 40
  * M911: Report TMC stepper driver overtemperature pre-warn flag
35 41
  *       This flag is held by the library, persisting until cleared by M912
36 42
  */
37 43
 void GcodeSuite::M911() {
38
-  #if ENABLED(X_IS_TMC2130) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX)) || ENABLED(IS_TRAMS)
44
+  #if M91x_USE_X
39 45
     tmc_report_otpw(stepperX, TMC_X);
40 46
   #endif
41
-  #if ENABLED(X2_IS_TMC2130) || (ENABLED(X2_IS_TMC2208) && PIN_EXISTS(X2_SERIAL_RX))
47
+  #if M91x_USE(X2)
42 48
     tmc_report_otpw(stepperX2, TMC_X2);
43 49
   #endif
44
-  #if ENABLED(Y_IS_TMC2130) || (ENABLED(Y_IS_TMC2208) && PIN_EXISTS(Y_SERIAL_RX)) || ENABLED(IS_TRAMS)
50
+  #if M91x_USE_Y
45 51
     tmc_report_otpw(stepperY, TMC_Y);
46 52
   #endif
47
-  #if ENABLED(Y2_IS_TMC2130) || (ENABLED(Y2_IS_TMC2208) && PIN_EXISTS(Y2_SERIAL_RX))
53
+  #if M91x_USE(Y2)
48 54
     tmc_report_otpw(stepperY2, TMC_Y2);
49 55
   #endif
50
-  #if ENABLED(Z_IS_TMC2130) || (ENABLED(Z_IS_TMC2208) && PIN_EXISTS(Z_SERIAL_RX)) || ENABLED(IS_TRAMS)
56
+  #if M91x_USE_Z
51 57
     tmc_report_otpw(stepperZ, TMC_Z);
52 58
   #endif
53
-  #if ENABLED(Z2_IS_TMC2130) || (ENABLED(Z2_IS_TMC2208) && PIN_EXISTS(Z2_SERIAL_RX))
59
+  #if M91x_USE(Z2)
54 60
     tmc_report_otpw(stepperZ2, TMC_Z2);
55 61
   #endif
56
-  #if ENABLED(E0_IS_TMC2130) || (ENABLED(E0_IS_TMC2208) && PIN_EXISTS(E0_SERIAL_RX)) || ENABLED(IS_TRAMS)
62
+  #if M91x_USE_E0
57 63
     tmc_report_otpw(stepperE0, TMC_E0);
58 64
   #endif
59
-  #if ENABLED(E1_IS_TMC2130) || (ENABLED(E1_IS_TMC2208) && PIN_EXISTS(E1_SERIAL_RX))
65
+  #if M91x_USE(E1)
60 66
     tmc_report_otpw(stepperE1, TMC_E1);
61 67
   #endif
62
-  #if ENABLED(E2_IS_TMC2130) || (ENABLED(E2_IS_TMC2208) && PIN_EXISTS(E2_SERIAL_RX))
68
+  #if M91x_USE(E2)
63 69
     tmc_report_otpw(stepperE2, TMC_E2);
64 70
   #endif
65
-  #if ENABLED(E3_IS_TMC2130) || (ENABLED(E3_IS_TMC2208) && PIN_EXISTS(E3_SERIAL_RX))
71
+  #if M91x_USE(E3)
66 72
     tmc_report_otpw(stepperE3, TMC_E3);
67 73
   #endif
68
-  #if ENABLED(E4_IS_TMC2130) || (ENABLED(E4_IS_TMC2208) && PIN_EXISTS(E4_SERIAL_RX))
74
+  #if M91x_USE(E4)
69 75
     tmc_report_otpw(stepperE4, TMC_E4);
70 76
   #endif
71 77
 }
@@ -83,45 +89,61 @@ void GcodeSuite::M911() {
83 89
  *       M912 E1  ; clear E1 only
84 90
  */
85 91
 void GcodeSuite::M912() {
86
-  const bool hasX = parser.seen(axis_codes[X_AXIS]), hasY = parser.seen(axis_codes[Y_AXIS]),
87
-             hasZ = parser.seen(axis_codes[Z_AXIS]), hasE = parser.seen(axis_codes[E_AXIS]),
88
-             hasNone = !hasX && !hasY && !hasZ && !hasE;
89
-  const uint8_t xval = parser.byteval(axis_codes[X_AXIS], 10), yval = parser.byteval(axis_codes[Y_AXIS], 10),
90
-                zval = parser.byteval(axis_codes[Z_AXIS], 10), eval = parser.byteval(axis_codes[E_AXIS], 10);
92
+    const bool hasX = parser.seen(axis_codes[X_AXIS]),
93
+               hasY = parser.seen(axis_codes[Y_AXIS]),
94
+               hasZ = parser.seen(axis_codes[Z_AXIS]),
95
+               hasE = parser.seen(axis_codes[E_AXIS]),
96
+               hasNone = !hasX && !hasY && !hasZ && !hasE;
91 97
 
92
-  #if (ENABLED(X_IS_TMC2130) || (ENABLED(X_IS_TMC2208) && PIN_EXISTS(X_SERIAL_RX)) || ENABLED(IS_TRAMS))
93
-    if (hasNone || xval == 1 || (hasX && xval == 10)) tmc_clear_otpw(stepperX, TMC_X);
94
-  #endif
95
-  #if (ENABLED(X2_IS_TMC2130) || (ENABLED(X2_IS_TMC2208) && PIN_EXISTS(X2_SERIAL_RX)))
96
-    if (hasNone || xval == 2 || (hasX && xval == 10)) tmc_clear_otpw(stepperX2, TMC_X2);
97
-  #endif
98
-  #if (ENABLED(Y_IS_TMC2130) || (ENABLED(Y_IS_TMC2208) && PIN_EXISTS(Y_SERIAL_RX)) || ENABLED(IS_TRAMS))
99
-    if (hasNone || yval == 1 || (hasY && yval == 10)) tmc_clear_otpw(stepperY, TMC_Y);
100
-  #endif
101
-  #if (ENABLED(Y2_IS_TMC2130) || (ENABLED(Y2_IS_TMC2208) && PIN_EXISTS(Y2_SERIAL_RX)))
102
-    if (hasNone || yval == 2 || (hasY && yval == 10)) tmc_clear_otpw(stepperY2, TMC_Y2);
103
-  #endif
104
-  #if (ENABLED(Z_IS_TMC2130) || (ENABLED(Z_IS_TMC2208) && PIN_EXISTS(Z_SERIAL_RX)) || ENABLED(IS_TRAMS))
105
-    if (hasNone || zval == 1 || (hasZ && zval == 10)) tmc_clear_otpw(stepperZ, TMC_Z);
106
-  #endif
107
-  #if (ENABLED(Z2_IS_TMC2130) || (ENABLED(Z2_IS_TMC2208) && PIN_EXISTS(Z2_SERIAL_RX)))
108
-    if (hasNone || zval == 2 || (hasZ && zval == 10)) tmc_clear_otpw(stepperZ2, TMC_Z2);
109
-  #endif
110
-  #if (ENABLED(E0_IS_TMC2130) || (ENABLED(E0_IS_TMC2208) && PIN_EXISTS(E0_SERIAL_RX)) || ENABLED(IS_TRAMS))
111
-    if (hasNone || eval == 0 || (hasE && eval == 10)) tmc_clear_otpw(stepperE0, TMC_E0);
112
-  #endif
113
-  #if E_STEPPERS > 1 && (ENABLED(E1_IS_TMC2130) || (ENABLED(E1_IS_TMC2208) && PIN_EXISTS(E1_SERIAL_RX)))
114
-    if (hasNone || eval == 1 || (hasE && eval == 10)) tmc_clear_otpw(stepperE1, TMC_E1);
115
-  #endif
116
-  #if E_STEPPERS > 2 && (ENABLED(E2_IS_TMC2130) || (ENABLED(E2_IS_TMC2208) && PIN_EXISTS(E2_SERIAL_RX)))
117
-    if (hasNone || eval == 2 || (hasE && eval == 10)) tmc_clear_otpw(stepperE2, TMC_E2);
118
-  #endif
119
-  #if E_STEPPERS > 3 && (ENABLED(E3_IS_TMC2130) || (ENABLED(E3_IS_TMC2208) && PIN_EXISTS(E3_SERIAL_RX)))
120
-    if (hasNone || eval == 3 || (hasE && eval == 10)) tmc_clear_otpw(stepperE3, TMC_E3);
121
-  #endif
122
-  #if E_STEPPERS > 4 && (ENABLED(E4_IS_TMC2130) || (ENABLED(E4_IS_TMC2208) && PIN_EXISTS(E4_SERIAL_RX)))
123
-    if (hasNone || eval == 4 || (hasE && eval == 10)) tmc_clear_otpw(stepperE4, TMC_E4);
124
-  #endif
98
+    #if M91x_USE_X || M91x_USE(X2)
99
+      const uint8_t xval = parser.byteval(axis_codes[X_AXIS], 10);
100
+      #if M91x_USE_X
101
+        if (hasNone || xval == 1 || (hasX && xval == 10)) tmc_clear_otpw(stepperX, TMC_X);
102
+      #endif
103
+      #if M91x_USE(X2)
104
+        if (hasNone || xval == 2 || (hasX && xval == 10)) tmc_clear_otpw(stepperX2, TMC_X2);
105
+      #endif
106
+    #endif
107
+
108
+    #define M91x_USE_Y (M91x_USE(Y) || ENABLED(IS_TRAMS))
109
+    #if M91x_USE_Y || M91x_USE(Y2)
110
+      const uint8_t yval = parser.byteval(axis_codes[Y_AXIS], 10);
111
+      #if M91x_USE_Y
112
+        if (hasNone || yval == 1 || (hasY && yval == 10)) tmc_clear_otpw(stepperY, TMC_Y);
113
+      #endif
114
+      #if M91x_USE(Y2)
115
+        if (hasNone || yval == 2 || (hasY && yval == 10)) tmc_clear_otpw(stepperY2, TMC_Y2);
116
+      #endif
117
+    #endif
118
+
119
+    #define M91x_USE_Z (M91x_USE(Z) || ENABLED(IS_TRAMS))
120
+    #if M91x_USE_Z || M91x_USE(Z2)
121
+      const uint8_t zval = parser.byteval(axis_codes[Z_AXIS], 10);
122
+      #if M91x_USE_Z
123
+        if (hasNone || zval == 1 || (hasZ && zval == 10)) tmc_clear_otpw(stepperZ, TMC_Z);
124
+      #endif
125
+      #if M91x_USE(Z2)
126
+        if (hasNone || zval == 2 || (hasZ && zval == 10)) tmc_clear_otpw(stepperZ2, TMC_Z2);
127
+      #endif
128
+    #endif
129
+
130
+    const uint8_t eval = parser.byteval(axis_codes[E_AXIS], 10);
131
+
132
+    #if M91x_USE_E0
133
+      if (hasNone || eval == 0 || (hasE && eval == 10)) tmc_clear_otpw(stepperE0, TMC_E0);
134
+    #endif
135
+    #if E_STEPPERS > 1 && M91x_USE(E1)
136
+      if (hasNone || eval == 1 || (hasE && eval == 10)) tmc_clear_otpw(stepperE1, TMC_E1);
137
+    #endif
138
+    #if E_STEPPERS > 2 && M91x_USE(E2)
139
+      if (hasNone || eval == 2 || (hasE && eval == 10)) tmc_clear_otpw(stepperE2, TMC_E2);
140
+    #endif
141
+    #if E_STEPPERS > 3 && M91x_USE(E3)
142
+      if (hasNone || eval == 3 || (hasE && eval == 10)) tmc_clear_otpw(stepperE3, TMC_E3);
143
+    #endif
144
+    #if E_STEPPERS > 4 && M91x_USE(E4)
145
+      if (hasNone || eval == 4 || (hasE && eval == 10)) tmc_clear_otpw(stepperE4, TMC_E4);
146
+    #endif
125 147
 }
126 148
 
127 149
 /**
@@ -130,9 +152,9 @@ void GcodeSuite::M912() {
130 152
 #if ENABLED(HYBRID_THRESHOLD)
131 153
   void GcodeSuite::M913() {
132 154
     #define TMC_SAY_PWMTHRS(P,Q) tmc_get_pwmthrs(stepper##Q, TMC_##Q, planner.axis_steps_per_mm[P##_AXIS])
133
-    #define TMC_SET_PWMTHRS(P,Q) tmc_set_pwmthrs(stepper##Q, TMC_##Q, value, planner.axis_steps_per_mm[P##_AXIS])
155
+    #define TMC_SET_PWMTHRS(P,Q) tmc_set_pwmthrs(stepper##Q, value, planner.axis_steps_per_mm[P##_AXIS])
134 156
     #define TMC_SAY_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_get_pwmthrs(stepperE##E, TMC_E##E, planner.axis_steps_per_mm[E_AXIS_N]); }while(0)
135
-    #define TMC_SET_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_set_pwmthrs(stepperE##E, TMC_E##E, value, planner.axis_steps_per_mm[E_AXIS_N]); }while(0)
157
+    #define TMC_SET_PWMTHRS_E(E) do{ const uint8_t extruder = E; tmc_set_pwmthrs(stepperE##E, value, planner.axis_steps_per_mm[E_AXIS_N]); }while(0)
136 158
 
137 159
     bool report = true;
138 160
     const uint8_t index = parser.byteval('I');
@@ -238,7 +260,7 @@ void GcodeSuite::M912() {
238 260
 #if ENABLED(SENSORLESS_HOMING)
239 261
   void GcodeSuite::M914() {
240 262
     #define TMC_SAY_SGT(Q) tmc_get_sgt(stepper##Q, TMC_##Q)
241
-    #define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, TMC_##Q, value)
263
+    #define TMC_SET_SGT(Q) tmc_set_sgt(stepper##Q, value)
242 264
 
243 265
     bool report = true;
244 266
     const uint8_t index = parser.byteval('I');

+ 1
- 1
Marlin/src/module/configuration_store.cpp Ver fichero

@@ -1326,7 +1326,7 @@ void MarlinSettings::postprocess() {
1326 1326
       #endif
1327 1327
 
1328 1328
       #if ENABLED(HYBRID_THRESHOLD)
1329
-        #define TMC_SET_PWMTHRS(P,Q) tmc_set_pwmthrs(stepper##Q, TMC_##Q, tmc_hybrid_threshold[TMC_##Q], planner.axis_steps_per_mm[P##_AXIS])
1329
+        #define TMC_SET_PWMTHRS(P,Q) tmc_set_pwmthrs(stepper##Q, tmc_hybrid_threshold[TMC_##Q], planner.axis_steps_per_mm[P##_AXIS])
1330 1330
         uint32_t tmc_hybrid_threshold[TMC_AXES];
1331 1331
         EEPROM_READ(tmc_hybrid_threshold);
1332 1332
         if (!validating) {

+ 4
- 3
Marlin/src/module/stepper_indirection.cpp Ver fichero

@@ -184,6 +184,10 @@
184 184
   // Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
185 185
   // https://www.trinamic.com/products/integrated-circuits/details/tmc2130/
186 186
   void tmc2130_init(TMC2130Stepper &st, const uint16_t mA, const uint16_t microsteps, const uint32_t thrs, const float spmm) {
187
+    #if DISABLED(STEALTHCHOP) || DISABLED(HYBRID_THRESHOLD)
188
+      UNUSED(thrs);
189
+      UNUSED(spmm);
190
+    #endif
187 191
     st.begin();
188 192
     st.setCurrent(mA, R_SENSE, HOLD_MULTIPLIER);
189 193
     st.microsteps(microsteps);
@@ -201,9 +205,6 @@
201 205
       st.stealthChop(1);
202 206
       #if ENABLED(HYBRID_THRESHOLD)
203 207
         st.stealth_max_speed(12650000UL*microsteps/(256*thrs*spmm));
204
-      #else
205
-        UNUSED(thrs);
206
-        UNUSED(spmm);
207 208
       #endif
208 209
     #elif ENABLED(SENSORLESS_HOMING)
209 210
       st.coolstep_min_speed(1024UL * 1024UL - 1UL);

Loading…
Cancelar
Guardar