瀏覽代碼

Merge pull request #9130 from thinkyhead/bf2_tmc_followup

[2.0.x] More TMC followup
Scott Lahteine 7 年之前
父節點
當前提交
e654ea1e1a
No account linked to committer's email address

+ 2
- 1
.travis.yml 查看文件

@@ -28,7 +28,8 @@ before_install:
28 28
   - export PATH=${TRAVIS_BUILD_DIR}/buildroot/bin/:${PATH}
29 29
 
30 30
 install:
31
-  - pip install -U platformio
31
+  #- pip install -U platformio
32
+  - pip install -U https://github.com/platformio/platformio-core/archive/develop.zip
32 33
 
33 34
 before_script:
34 35
   # Update PlatformIO packages

+ 2
- 2
Marlin/src/HAL/HAL_DUE/usb/sd_mmc_spi_mem.cpp 查看文件

@@ -65,7 +65,7 @@ Ctrl_status sd_mmc_spi_usb_read_10(uint32_t addr, uint16_t nb_sector) {
65 65
   #ifdef DEBUG_MMC
66 66
     char buffer[80];
67 67
     sprintf(buffer, "SDRD: %d @ 0x%08x\n", nb_sector, addr);
68
-    MYSERIAL.print(buffer);
68
+    MYSERIAL0.print(buffer);
69 69
   #endif
70 70
 
71 71
   // Start reading
@@ -99,7 +99,7 @@ Ctrl_status sd_mmc_spi_usb_write_10(uint32_t addr, uint16_t nb_sector) {
99 99
   #ifdef DEBUG_MMC
100 100
     char buffer[80];
101 101
     sprintf(buffer, "SDWR: %d @ 0x%08x\n", nb_sector, addr);
102
-    MYSERIAL.print(buffer);
102
+    MYSERIAL0.print(buffer);
103 103
   #endif
104 104
 
105 105
   if (!card.getSd2Card().writeStart(addr, nb_sector))

+ 3
- 3
Marlin/src/core/serial.h 查看文件

@@ -67,13 +67,13 @@ enum DebugFlags {
67 67
   #ifdef USBCON
68 68
     #include <HardwareSerial.h>
69 69
     #if ENABLED(BLUETOOTH)
70
-      #define MYSERIAL bluetoothSerial
70
+      #define MYSERIAL0 bluetoothSerial
71 71
     #else
72
-      #define MYSERIAL Serial
72
+      #define MYSERIAL0 Serial
73 73
     #endif // BLUETOOTH
74 74
   #else
75 75
     #include "../HAL/HAL_AVR/MarlinSerial.h"
76
-    #define MYSERIAL customizedSerial
76
+    #define MYSERIAL0 customizedSerial
77 77
   #endif
78 78
 #elif defined(ARDUINO_ARCH_SAM)
79 79
   // To pull the Serial port definitions and overrides

+ 0
- 39
Marlin/src/feature/tmc_macros.h 查看文件

@@ -1,39 +0,0 @@
1
-/**
2
- * Marlin 3D Printer Firmware
3
- * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
- *
5
- * Based on Sprinter and grbl.
6
- * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
- *
8
- * This program is free software: you can redistribute it and/or modify
9
- * it under the terms of the GNU General Public License as published by
10
- * the Free Software Foundation, either version 3 of the License, or
11
- * (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
- * GNU General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
- *
21
- */
22
-#ifndef TMC_MACROS_H
23
-#define TMC_MACROS_H
24
-
25
-  // Trinamic Stepper Drivers
26
-  #define HAS_TRINAMIC (ENABLED(HAVE_TMC2130) || ENABLED(HAVE_TMC2208) || ENABLED(IS_TRAMS))
27
-  #define  X_IS_TRINAMIC (ENABLED( X_IS_TMC2130) || ENABLED( X_IS_TMC2208) || ENABLED(IS_TRAMS))
28
-  #define X2_IS_TRINAMIC (ENABLED(X2_IS_TMC2130) || ENABLED(X2_IS_TMC2208))
29
-  #define  Y_IS_TRINAMIC (ENABLED( Y_IS_TMC2130) || ENABLED( Y_IS_TMC2208) || ENABLED(IS_TRAMS))
30
-  #define Y2_IS_TRINAMIC (ENABLED(Y2_IS_TMC2130) || ENABLED(Y2_IS_TMC2208))
31
-  #define  Z_IS_TRINAMIC (ENABLED( Z_IS_TMC2130) || ENABLED( Z_IS_TMC2208) || ENABLED(IS_TRAMS))
32
-  #define Z2_IS_TRINAMIC (ENABLED(Z2_IS_TMC2130) || ENABLED(Z2_IS_TMC2208))
33
-  #define E0_IS_TRINAMIC (ENABLED(E0_IS_TMC2130) || ENABLED(E0_IS_TMC2208) || ENABLED(IS_TRAMS))
34
-  #define E1_IS_TRINAMIC (ENABLED(E1_IS_TMC2130) || ENABLED(E1_IS_TMC2208))
35
-  #define E2_IS_TRINAMIC (ENABLED(E2_IS_TMC2130) || ENABLED(E2_IS_TMC2208))
36
-  #define E3_IS_TRINAMIC (ENABLED(E3_IS_TMC2130) || ENABLED(E3_IS_TMC2208))
37
-  #define E4_IS_TRINAMIC (ENABLED(E4_IS_TMC2130) || ENABLED(E4_IS_TMC2208))
38
-
39
-#endif

+ 383
- 36
Marlin/src/feature/tmc_util.cpp 查看文件

@@ -32,6 +32,10 @@
32 32
 #include "../libs/duration_t.h"
33 33
 #include "../gcode/gcode.h"
34 34
 
35
+#if ENABLED(TMC_DEBUG)
36
+  #include "../module/planner.h"
37
+#endif
38
+
35 39
 bool report_tmc_status = false;
36 40
 char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1", "E2", "E3", "E4" };
37 41
 
@@ -51,7 +55,7 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
51 55
   };
52 56
   #if ENABLED(HAVE_TMC2130)
53 57
     static uint32_t get_pwm_scale(TMC2130Stepper &st) { return st.PWM_SCALE(); }
54
-    static uint8_t get_status_response(TMC2130Stepper &st) { return st.status_response&0xF; }
58
+    static uint8_t get_status_response(TMC2130Stepper &st) { return st.status_response & 0xF; }
55 59
     static TMC_driver_data get_driver_data(TMC2130Stepper &st) {
56 60
       constexpr uint32_t OTPW_bm = 0x4000000UL;
57 61
       constexpr uint8_t OTPW_bp = 26;
@@ -61,9 +65,9 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
61 65
       constexpr uint8_t DRIVER_ERROR_bp = 1;
62 66
       TMC_driver_data data;
63 67
       data.drv_status = st.DRV_STATUS();
64
-      data.is_otpw = (data.drv_status & OTPW_bm)>>OTPW_bp;
65
-      data.is_ot = (data.drv_status & OT_bm)>>OT_bp;
66
-      data.is_error = (st.status_response & DRIVER_ERROR_bm)>>DRIVER_ERROR_bp;
68
+      data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp;
69
+      data.is_ot = (data.drv_status & OT_bm) >> OT_bp;
70
+      data.is_error = (st.status_response & DRIVER_ERROR_bm) >> DRIVER_ERROR_bp;
67 71
       return data;
68 72
     }
69 73
   #endif
@@ -84,35 +88,35 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
84 88
       constexpr uint8_t OT_bp = 1;
85 89
       TMC_driver_data data;
86 90
       data.drv_status = st.DRV_STATUS();
87
-      data.is_otpw = (data.drv_status & OTPW_bm)>>OTPW_bp;
88
-      data.is_ot = (data.drv_status & OT_bm)>>OT_bp;
91
+      data.is_otpw = (data.drv_status & OTPW_bm) >> OTPW_bp;
92
+      data.is_ot = (data.drv_status & OT_bm) >> OT_bp;
89 93
       data.is_error = st.drv_err();
90 94
       return data;
91 95
     }
92 96
   #endif
93 97
 
94 98
   template<typename TMC>
95
-  uint8_t monitor_tmc_driver(TMC &st, const char axisID, uint8_t otpw_cnt) {
99
+  void monitor_tmc_driver(TMC &st, const char axisID, uint8_t &otpw_cnt) {
96 100
     TMC_driver_data data = get_driver_data(st);
97 101
 
98 102
     #if ENABLED(STOP_ON_ERROR)
99 103
       if (data.is_error) {
100 104
         SERIAL_EOL();
101 105
         SERIAL_ECHO(axisID);
102
-        SERIAL_ECHO(" driver error detected:");
103
-        if (data.is_ot) SERIAL_ECHO("\novertemperature");
104
-        if (st.s2ga()) SERIAL_ECHO("\nshort to ground (coil A)");
105
-        if (st.s2gb()) SERIAL_ECHO("\nshort to ground (coil B)");
106
+        SERIAL_ECHOPGM(" driver error detected:");
107
+        if (data.is_ot) SERIAL_ECHOPGM("\novertemperature");
108
+        if (st.s2ga()) SERIAL_ECHOPGM("\nshort to ground (coil A)");
109
+        if (st.s2gb()) SERIAL_ECHOPGM("\nshort to ground (coil B)");
106 110
         SERIAL_EOL();
107 111
         #if ENABLED(TMC_DEBUG)
108
-          _M122();
112
+          tmc_report_all();
109 113
         #endif
110 114
         kill(PSTR("Driver error"));
111 115
       }
112 116
     #endif
113 117
 
114 118
     // Report if a warning was triggered
115
-    if (data.is_otpw && otpw_cnt==0) {
119
+    if (data.is_otpw && otpw_cnt == 0) {
116 120
       char timestamp[10];
117 121
       duration_t elapsed = print_job_timer.duration();
118 122
       const bool has_days = (elapsed.value > 60*60*24L);
@@ -123,7 +127,7 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
123 127
       SERIAL_ECHO(axisID);
124 128
       SERIAL_ECHOPGM(" driver overtemperature warning! (");
125 129
       SERIAL_ECHO(st.getCurrent());
126
-      SERIAL_ECHOLN("mA)");
130
+      SERIAL_ECHOLNPGM("mA)");
127 131
     }
128 132
     #if CURRENT_STEP_DOWN > 0
129 133
       // Decrease current if is_otpw is true and driver is enabled and there's been more then 4 warnings
@@ -140,23 +144,21 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
140 144
       otpw_cnt++;
141 145
       st.flag_otpw = true;
142 146
     }
143
-    else if (otpw_cnt>0) otpw_cnt--;
147
+    else if (otpw_cnt > 0) otpw_cnt--;
144 148
 
145 149
     if (report_tmc_status) {
146 150
       const uint32_t pwm_scale = get_pwm_scale(st);
147 151
       SERIAL_ECHO(axisID);
148 152
       SERIAL_ECHOPAIR(":", pwm_scale);
149
-      SERIAL_ECHO(" |0b"); SERIAL_PRINT(get_status_response(st), BIN);
150
-      SERIAL_ECHO("| ");
151
-      if (data.is_error) SERIAL_ECHO('E');
152
-      else if (data.is_ot) SERIAL_ECHO('O');
153
-      else if (data.is_otpw) SERIAL_ECHO('W');
154
-      else if (otpw_cnt>0) SERIAL_PRINT(otpw_cnt, DEC);
155
-      else if (st.flag_otpw) SERIAL_ECHO('F');
156
-      SERIAL_ECHO("\t");
153
+      SERIAL_ECHOPGM(" |0b"); MYSERIAL0.print(get_status_response(st), BIN);
154
+      SERIAL_ECHOPGM("| ");
155
+      if (data.is_error) SERIAL_CHAR('E');
156
+      else if (data.is_ot) SERIAL_CHAR('O');
157
+      else if (data.is_otpw) SERIAL_CHAR('W');
158
+      else if (otpw_cnt > 0) SERIAL_PRINT(otpw_cnt, DEC);
159
+      else if (st.flag_otpw) SERIAL_CHAR('F');
160
+      SERIAL_CHAR('\t');
157 161
     }
158
-
159
-    return otpw_cnt;
160 162
   }
161 163
 
162 164
   #define HAS_HW_COMMS(ST) ENABLED(ST##_IS_TMC2130)|| (ENABLED(ST##_IS_TMC2208) && defined(ST##_HARDWARE_SERIAL))
@@ -167,47 +169,47 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
167 169
       next_cOT = millis() + 500;
168 170
       #if HAS_HW_COMMS(X) || ENABLED(IS_TRAMS)
169 171
         static uint8_t x_otpw_cnt = 0;
170
-        x_otpw_cnt = monitor_tmc_driver(stepperX, axis_codes[X_AXIS], x_otpw_cnt);
172
+        monitor_tmc_driver(stepperX, axis_codes[X_AXIS], x_otpw_cnt);
171 173
       #endif
172 174
       #if HAS_HW_COMMS(Y) || ENABLED(IS_TRAMS)
173 175
         static uint8_t y_otpw_cnt = 0;
174
-        y_otpw_cnt = monitor_tmc_driver(stepperY, axis_codes[Y_AXIS], y_otpw_cnt);
176
+        monitor_tmc_driver(stepperY, axis_codes[Y_AXIS], y_otpw_cnt);
175 177
       #endif
176 178
       #if HAS_HW_COMMS(Z) || ENABLED(IS_TRAMS)
177 179
         static uint8_t z_otpw_cnt = 0;
178
-        z_otpw_cnt = monitor_tmc_driver(stepperZ, axis_codes[Z_AXIS], z_otpw_cnt);
180
+        monitor_tmc_driver(stepperZ, axis_codes[Z_AXIS], z_otpw_cnt);
179 181
       #endif
180 182
       #if HAS_HW_COMMS(X2)
181 183
         static uint8_t x2_otpw_cnt = 0;
182
-        x2_otpw_cnt = monitor_tmc_driver(stepperX2, axis_codes[X_AXIS], x2_otpw_cnt);
184
+        monitor_tmc_driver(stepperX2, axis_codes[X_AXIS], x2_otpw_cnt);
183 185
       #endif
184 186
       #if HAS_HW_COMMS(Y2)
185 187
         static uint8_t y2_otpw_cnt = 0;
186
-        y2_otpw_cnt = monitor_tmc_driver(stepperY2, axis_codes[Y_AXIS], y2_otpw_cnt);
188
+        monitor_tmc_driver(stepperY2, axis_codes[Y_AXIS], y2_otpw_cnt);
187 189
       #endif
188 190
       #if HAS_HW_COMMS(Z2)
189 191
         static uint8_t z2_otpw_cnt = 0;
190
-        z2_otpw_cnt = monitor_tmc_driver(stepperZ2, axis_codes[Z_AXIS], z2_otpw_cnt);
192
+        monitor_tmc_driver(stepperZ2, axis_codes[Z_AXIS], z2_otpw_cnt);
191 193
       #endif
192 194
       #if HAS_HW_COMMS(E0) || ENABLED(IS_TRAMS)
193 195
         static uint8_t e0_otpw_cnt = 0;
194
-        e0_otpw_cnt = monitor_tmc_driver(stepperE0, axis_codes[E_AXIS], e0_otpw_cnt);
196
+        monitor_tmc_driver(stepperE0, axis_codes[E_AXIS], e0_otpw_cnt);
195 197
       #endif
196 198
       #if HAS_HW_COMMS(E1)
197 199
         static uint8_t e1_otpw_cnt = 0;
198
-        e1_otpw_cnt = monitor_tmc_driver(stepperE1, axis_codes[E_AXIS], e1_otpw_cnt);
200
+        monitor_tmc_driver(stepperE1, axis_codes[E_AXIS], e1_otpw_cnt);
199 201
       #endif
200 202
       #if HAS_HW_COMMS(E2)
201 203
         static uint8_t e2_otpw_cnt = 0;
202
-        e2_otpw_cnt = monitor_tmc_driver(stepperE2, axis_codes[E_AXIS], e2_otpw_cnt);
204
+        monitor_tmc_driver(stepperE2, axis_codes[E_AXIS], e2_otpw_cnt);
203 205
       #endif
204 206
       #if HAS_HW_COMMS(E3)
205 207
         static uint8_t e3_otpw_cnt = 0;
206
-        e3_otpw_cnt = monitor_tmc_driver(stepperE3, axis_codes[E_AXIS], e3_otpw_cnt);
208
+        monitor_tmc_driver(stepperE3, axis_codes[E_AXIS], e3_otpw_cnt);
207 209
       #endif
208 210
       #if HAS_HW_COMMS(E4)
209 211
         static uint8_t e4_otpw_cnt = 0;
210
-        e4_otpw_cnt = monitor_tmc_driver(stepperE4, axis_codes[E_AXIS], e4_otpw_cnt);
212
+        monitor_tmc_driver(stepperE4, axis_codes[E_AXIS], e4_otpw_cnt);
211 213
       #endif
212 214
 
213 215
       if (report_tmc_status) SERIAL_EOL();
@@ -216,4 +218,349 @@ char extended_axis_codes[11][3] = { "X", "X2", "Y", "Y2", "Z", "Z2", "E0", "E1",
216 218
 
217 219
 #endif // MONITOR_DRIVER_STATUS
218 220
 
221
+void _tmc_say_current(const char name[], const uint16_t curr) {
222
+  SERIAL_ECHO(name);
223
+  SERIAL_ECHOLNPAIR(" axis driver current: ", curr);
224
+}
225
+void _tmc_say_otpw(const char name[], const bool otpw) {
226
+  SERIAL_ECHO(name);
227
+  SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
228
+  serialprintPGM(otpw ? PSTR("true") : PSTR("false"));
229
+  SERIAL_EOL();
230
+}
231
+void _tmc_say_otpw_cleared(const char name[]) {
232
+  SERIAL_ECHO(name);
233
+  SERIAL_ECHOLNPGM(" prewarn flag cleared");
234
+}
235
+void _tmc_say_pwmthrs(const char name[], const uint32_t thrs) {
236
+  SERIAL_ECHO(name);
237
+  SERIAL_ECHOLNPAIR(" stealthChop max speed set to ", thrs);
238
+}
239
+void _tmc_say_sgt(const char name[], const uint32_t sgt) {
240
+  SERIAL_ECHO(name);
241
+  SERIAL_ECHOPGM(" driver homing sensitivity set to ");
242
+  MYSERIAL0.println(sgt, DEC);
243
+}
244
+
245
+#if ENABLED(TMC_DEBUG)
246
+
247
+  enum TMC_debug_enum {
248
+    TMC_CODES,
249
+    TMC_ENABLED,
250
+    TMC_CURRENT,
251
+    TMC_RMS_CURRENT,
252
+    TMC_MAX_CURRENT,
253
+    TMC_IRUN,
254
+    TMC_IHOLD,
255
+    TMC_CS_ACTUAL,
256
+    TMC_PWM_SCALE,
257
+    TMC_VSENSE,
258
+    TMC_STEALTHCHOP,
259
+    TMC_MICROSTEPS,
260
+    TMC_TSTEP,
261
+    TMC_TPWMTHRS,
262
+    TMC_TPWMTHRS_MMS,
263
+    TMC_OTPW,
264
+    TMC_OTPW_TRIGGERED,
265
+    TMC_TOFF,
266
+    TMC_TBL,
267
+    TMC_HEND,
268
+    TMC_HSTRT,
269
+    TMC_SGT
270
+  };
271
+  enum TMC_drv_status_enum {
272
+    TMC_DRV_CODES,
273
+    TMC_STST,
274
+    TMC_OLB,
275
+    TMC_OLA,
276
+    TMC_S2GB,
277
+    TMC_S2GA,
278
+    TMC_DRV_OTPW,
279
+    TMC_OT,
280
+    TMC_STALLGUARD,
281
+    TMC_DRV_CS_ACTUAL,
282
+    TMC_FSACTIVE,
283
+    TMC_SG_RESULT,
284
+    TMC_DRV_STATUS_HEX,
285
+    TMC_T157,
286
+    TMC_T150,
287
+    TMC_T143,
288
+    TMC_T120,
289
+    TMC_STEALTH,
290
+    TMC_S2VSB,
291
+    TMC_S2VSA
292
+  };
293
+  static void drv_status_print_hex(const char name[], const uint32_t drv_status) {
294
+    SERIAL_ECHO(name);
295
+    SERIAL_ECHOPGM(" = 0x");
296
+    for (int B = 24; B >= 8; B -= 8){
297
+      SERIAL_PRINT((drv_status >> (B + 4)) & 0xF, HEX);
298
+      SERIAL_PRINT((drv_status >> B) & 0xF, HEX);
299
+      SERIAL_CHAR(':');
300
+    }
301
+    SERIAL_PRINT((drv_status >> 4) & 0xF, HEX);
302
+    SERIAL_PRINT(drv_status & 0xF, HEX);
303
+    SERIAL_EOL();
304
+  }
305
+
306
+  #if ENABLED(HAVE_TMC2130)
307
+    static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
308
+      switch(i) {
309
+        case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
310
+        case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
311
+        case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
312
+        case TMC_STEALTHCHOP: serialprintPGM(st.stealthChop() ? PSTR("true") : PSTR("false")); break;
313
+        default: break;
314
+      }
315
+    }
316
+    static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
317
+      switch(i) {
318
+        case TMC_STALLGUARD: if (st.stallguard()) SERIAL_CHAR('X'); break;
319
+        case TMC_SG_RESULT:  SERIAL_PRINT(st.sg_result(), DEC);   break;
320
+        case TMC_FSACTIVE:   if (st.fsactive())   SERIAL_CHAR('X'); break;
321
+        default: break;
322
+      }
323
+    }
324
+  #endif
325
+  #if ENABLED(HAVE_TMC2208)
326
+    static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
327
+      switch(i) {
328
+        case TMC_TSTEP: { uint32_t data = 0; st.TSTEP(&data); MYSERIAL0.print(data); break; }
329
+        case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
330
+        case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
331
+        case TMC_S2VSA: if (st.s2vsa()) SERIAL_CHAR('X'); break;
332
+        case TMC_S2VSB: if (st.s2vsb()) SERIAL_CHAR('X'); break;
333
+        default: break;
334
+      }
335
+    }
336
+    static void tmc_parse_drv_status(TMC2208Stepper &st, const TMC_drv_status_enum i) {
337
+      switch(i) {
338
+        case TMC_T157: if (st.t157()) SERIAL_CHAR('X'); break;
339
+        case TMC_T150: if (st.t150()) SERIAL_CHAR('X'); break;
340
+        case TMC_T143: if (st.t143()) SERIAL_CHAR('X'); break;
341
+        case TMC_T120: if (st.t120()) SERIAL_CHAR('X'); break;
342
+        default: break;
343
+      }
344
+    }
345
+  #endif
346
+
347
+  template <typename TMC>
348
+  static void tmc_status(TMC &st, TMC_AxisEnum axis, const TMC_debug_enum i, const float spmm) {
349
+    SERIAL_ECHO('\t');
350
+    switch(i) {
351
+      case TMC_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
352
+      case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
353
+      case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
354
+      case TMC_RMS_CURRENT: MYSERIAL0.print(st.rms_current()); break;
355
+      case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current() * 1.41, 0); break;
356
+      case TMC_IRUN:
357
+        SERIAL_PRINT(st.irun(), DEC);
358
+        SERIAL_ECHOPGM("/31");
359
+        break;
360
+      case TMC_IHOLD:
361
+        SERIAL_PRINT(st.ihold(), DEC);
362
+        SERIAL_ECHOPGM("/31");
363
+        break;
364
+      case TMC_CS_ACTUAL:
365
+        SERIAL_PRINT(st.cs_actual(), DEC);
366
+        SERIAL_ECHOPGM("/31");
367
+        break;
368
+
369
+      case TMC_VSENSE: serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); break;
370
+
371
+      case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break;
372
+      case TMC_TPWMTHRS: {
373
+          uint32_t tpwmthrs_val = st.TPWMTHRS();
374
+          SERIAL_ECHO(tpwmthrs_val);
375
+        }
376
+        break;
377
+      case TMC_TPWMTHRS_MMS: {
378
+          uint32_t tpwmthrs_val = st.TPWMTHRS();
379
+          tpwmthrs_val ? SERIAL_ECHO(12650000UL * st.microsteps() / (256 * tpwmthrs_val * spmm)) : SERIAL_CHAR('-');
380
+        }
381
+        break;
382
+      case TMC_OTPW: serialprintPGM(st.otpw() ? PSTR("true") : PSTR("false")); break;
383
+      case TMC_OTPW_TRIGGERED: serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false")); break;
384
+      case TMC_TOFF: SERIAL_PRINT(st.toff(), DEC); break;
385
+      case TMC_TBL: SERIAL_PRINT(st.blank_time(), DEC); break;
386
+      case TMC_HEND: SERIAL_PRINT(st.hysterisis_end(), DEC); break;
387
+      case TMC_HSTRT: SERIAL_PRINT(st.hysterisis_start(), DEC); break;
388
+      default: tmc_status(st, i); break;
389
+    }
390
+  }
391
+
392
+  template <typename TMC>
393
+  static void tmc_parse_drv_status(TMC &st, TMC_AxisEnum axis, const TMC_drv_status_enum i) {
394
+    SERIAL_CHAR('\t');
395
+    switch(i) {
396
+      case TMC_DRV_CODES:     SERIAL_ECHO(extended_axis_codes[axis]);  break;
397
+      case TMC_STST:          if (st.stst())         SERIAL_CHAR('X'); break;
398
+      case TMC_OLB:           if (st.olb())          SERIAL_CHAR('X'); break;
399
+      case TMC_OLA:           if (st.ola())          SERIAL_CHAR('X'); break;
400
+      case TMC_S2GB:          if (st.s2gb())         SERIAL_CHAR('X'); break;
401
+      case TMC_S2GA:          if (st.s2ga())         SERIAL_CHAR('X'); break;
402
+      case TMC_DRV_OTPW:      if (st.otpw())         SERIAL_CHAR('X'); break;
403
+      case TMC_OT:            if (st.ot())           SERIAL_CHAR('X'); break;
404
+      case TMC_DRV_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC);       break;
405
+      case TMC_DRV_STATUS_HEX:drv_status_print_hex(extended_axis_codes[axis], st.DRV_STATUS()); break;
406
+      default: tmc_parse_drv_status(st, i); break;
407
+    }
408
+  }
409
+
410
+  static void tmc_debug_loop(const TMC_debug_enum i) {
411
+    #if X_IS_TRINAMIC
412
+      tmc_status(stepperX, TMC_X, i, planner.axis_steps_per_mm[X_AXIS]);
413
+    #endif
414
+    #if X2_IS_TRINAMIC
415
+      tmc_status(stepperX2, TMC_X2, i, planner.axis_steps_per_mm[X_AXIS]);
416
+    #endif
417
+
418
+    #if Y_IS_TRINAMIC
419
+      tmc_status(stepperY, TMC_Y, i, planner.axis_steps_per_mm[Y_AXIS]);
420
+    #endif
421
+    #if Y2_IS_TRINAMIC
422
+      tmc_status(stepperY2, TMC_Y2, i, planner.axis_steps_per_mm[Y_AXIS]);
423
+    #endif
424
+
425
+    #if Z_IS_TRINAMIC
426
+      tmc_status(stepperZ, TMC_Z, i, planner.axis_steps_per_mm[Z_AXIS]);
427
+    #endif
428
+    #if Z2_IS_TRINAMIC
429
+      tmc_status(stepperZ2, TMC_Z2, i, planner.axis_steps_per_mm[Z_AXIS]);
430
+    #endif
431
+
432
+    #if E0_IS_TRINAMIC
433
+      tmc_status(stepperE0, TMC_E0, i, planner.axis_steps_per_mm[E_AXIS]);
434
+    #endif
435
+    #if E1_IS_TRINAMIC
436
+      tmc_status(stepperE1, TMC_E1, i, planner.axis_steps_per_mm[E_AXIS+1]);
437
+    #endif
438
+    #if E2_IS_TRINAMIC
439
+      tmc_status(stepperE2, TMC_E2, i, planner.axis_steps_per_mm[E_AXIS+2]);
440
+    #endif
441
+    #if E3_IS_TRINAMIC
442
+      tmc_status(stepperE3, TMC_E3, i, planner.axis_steps_per_mm[E_AXIS+3]);
443
+    #endif
444
+    #if E4_IS_TRINAMIC
445
+      tmc_status(stepperE4, TMC_E4, i, planner.axis_steps_per_mm[E_AXIS+4]);
446
+    #endif
447
+
448
+    SERIAL_EOL();
449
+  }
450
+
451
+  static void drv_status_loop(const TMC_drv_status_enum i) {
452
+    #if X_IS_TRINAMIC
453
+      tmc_parse_drv_status(stepperX, TMC_X, i);
454
+    #endif
455
+    #if X2_IS_TRINAMIC
456
+      tmc_parse_drv_status(stepperX2, TMC_X2, i);
457
+    #endif
458
+
459
+    #if Y_IS_TRINAMIC
460
+      tmc_parse_drv_status(stepperY, TMC_Y, i);
461
+    #endif
462
+    #if Y2_IS_TRINAMIC
463
+      tmc_parse_drv_status(stepperY2, TMC_Y2, i);
464
+    #endif
465
+
466
+    #if Z_IS_TRINAMIC
467
+      tmc_parse_drv_status(stepperZ, TMC_Z, i);
468
+    #endif
469
+    #if Z2_IS_TRINAMIC
470
+      tmc_parse_drv_status(stepperZ2, TMC_Z2, i);
471
+    #endif
472
+
473
+    #if E0_IS_TRINAMIC
474
+      tmc_parse_drv_status(stepperE0, TMC_E0, i);
475
+    #endif
476
+    #if E1_IS_TRINAMIC
477
+      tmc_parse_drv_status(stepperE1, TMC_E1, i);
478
+    #endif
479
+    #if E2_IS_TRINAMIC
480
+      tmc_parse_drv_status(stepperE2, TMC_E2, i);
481
+    #endif
482
+    #if E3_IS_TRINAMIC
483
+      tmc_parse_drv_status(stepperE3, TMC_E3, i);
484
+    #endif
485
+    #if E4_IS_TRINAMIC
486
+      tmc_parse_drv_status(stepperE4, TMC_E4, i);
487
+    #endif
488
+
489
+    SERIAL_EOL();
490
+  }
491
+
492
+  /**
493
+   * M122 report functions
494
+   */
495
+  void tmc_set_report_status(const bool status) {
496
+    if ((report_tmc_status = status))
497
+      SERIAL_ECHOLNPGM("axis:pwm_scale |status_response|");
498
+  }
499
+
500
+  void tmc_report_all() {
501
+    #define TMC_REPORT(LABEL, ITEM) do{ SERIAL_ECHOPGM(LABEL);  tmc_debug_loop(ITEM); }while(0)
502
+    #define DRV_REPORT(LABEL, ITEM) do{ SERIAL_ECHOPGM(LABEL); drv_status_loop(ITEM); }while(0)
503
+    TMC_REPORT("\t",                 TMC_CODES);
504
+    TMC_REPORT("Enabled\t",          TMC_ENABLED);
505
+    TMC_REPORT("Set current",        TMC_CURRENT);
506
+    TMC_REPORT("RMS current",        TMC_RMS_CURRENT);
507
+    TMC_REPORT("MAX current",        TMC_MAX_CURRENT);
508
+    TMC_REPORT("Run current",        TMC_IRUN);
509
+    TMC_REPORT("Hold current",       TMC_IHOLD);
510
+    TMC_REPORT("CS actual\t",        TMC_CS_ACTUAL);
511
+    TMC_REPORT("PWM scale",          TMC_PWM_SCALE);
512
+    TMC_REPORT("vsense\t",           TMC_VSENSE);
513
+    TMC_REPORT("stealthChop",        TMC_STEALTHCHOP);
514
+    TMC_REPORT("msteps\t",           TMC_MICROSTEPS);
515
+    TMC_REPORT("tstep\t",            TMC_TSTEP);
516
+    TMC_REPORT("pwm\nthreshold\t",   TMC_TPWMTHRS);
517
+    TMC_REPORT("[mm/s]\t",           TMC_TPWMTHRS_MMS);
518
+    TMC_REPORT("OT prewarn",         TMC_OTPW);
519
+    TMC_REPORT("OT prewarn has\n"
520
+               "been triggered",     TMC_OTPW_TRIGGERED);
521
+    TMC_REPORT("off time\t",         TMC_TOFF);
522
+    TMC_REPORT("blank time",         TMC_TBL);
523
+    TMC_REPORT("hysterisis\n-end\t", TMC_HEND);
524
+    TMC_REPORT("-start\t",           TMC_HSTRT);
525
+    TMC_REPORT("Stallguard thrs",    TMC_SGT);
526
+
527
+    DRV_REPORT("DRVSTATUS",          TMC_DRV_CODES);
528
+    #if ENABLED(HAVE_TMC2130)
529
+      DRV_REPORT("stallguard\t",     TMC_STALLGUARD);
530
+      DRV_REPORT("sg_result\t",      TMC_SG_RESULT);
531
+      DRV_REPORT("fsactive\t",       TMC_FSACTIVE);
532
+    #endif
533
+    DRV_REPORT("stst\t",             TMC_STST);
534
+    DRV_REPORT("olb\t",              TMC_OLB);
535
+    DRV_REPORT("ola\t",              TMC_OLA);
536
+    DRV_REPORT("s2gb\t",             TMC_S2GB);
537
+    DRV_REPORT("s2ga\t",             TMC_S2GA);
538
+    DRV_REPORT("otpw\t",             TMC_DRV_OTPW);
539
+    DRV_REPORT("ot\t",               TMC_OT);
540
+    #if ENABLED(HAVE_TMC2208)
541
+      DRV_REPORT("157C\t",           TMC_T157);
542
+      DRV_REPORT("150C\t",           TMC_T150);
543
+      DRV_REPORT("143C\t",           TMC_T143);
544
+      DRV_REPORT("120C\t",           TMC_T120);
545
+      DRV_REPORT("s2vsa\t",          TMC_S2VSA);
546
+      DRV_REPORT("s2vsb\t",          TMC_S2VSB);
547
+    #endif
548
+    DRV_REPORT("Driver registers:",  TMC_DRV_STATUS_HEX);
549
+    SERIAL_EOL();
550
+  }
551
+
552
+#endif // TMC_DEBUG
553
+
554
+#if ENABLED(SENSORLESS_HOMING)
555
+
556
+  void tmc_sensorless_homing(TMC2130Stepper &st, bool enable/*=true*/) {
557
+    #if ENABLED(STEALTHCHOP)
558
+      st.coolstep_min_speed(enable ? 1024UL * 1024UL - 1UL : 0);
559
+      st.stealthChop(!enable);
560
+    #endif
561
+    st.diag1_stall(enable ? 1 : 0);
562
+  }
563
+
564
+#endif // SENSORLESS_HOMING
565
+
219 566
 #endif // HAS_TRINAMIC

+ 22
- 32
Marlin/src/feature/tmc_util.h 查看文件

@@ -35,11 +35,19 @@ enum TMC_AxisEnum {
35 35
   TMC_E0, TMC_E1, TMC_E2, TMC_E3, TMC_E4
36 36
 };
37 37
 
38
+constexpr uint32_t _tmc_thrs(const uint16_t msteps, const int32_t thrs, const uint32_t spmm) {
39
+  return 12650000UL * msteps / (256 * thrs * spmm);
40
+}
41
+
42
+void _tmc_say_current(const char name[], const uint16_t curr);
43
+void _tmc_say_otpw(const char name[], const bool otpw);
44
+void _tmc_say_otpw_cleared(const char name[]);
45
+void _tmc_say_pwmthrs(const char name[], const uint32_t thrs);
46
+void _tmc_say_sgt(const char name[], const uint32_t sgt);
47
+
38 48
 template<typename TMC>
39 49
 void tmc_get_current(TMC &st, const char name[]) {
40
-  SERIAL_ECHO(name);
41
-  SERIAL_ECHOPGM(" axis driver current: ");
42
-  SERIAL_ECHOLN(st.getCurrent());
50
+  _tmc_say_current(name, st.getCurrent());
43 51
 }
44 52
 template<typename TMC>
45 53
 void tmc_set_current(TMC &st, const char name[], const int mA) {
@@ -48,33 +56,25 @@ void tmc_set_current(TMC &st, const char name[], const int mA) {
48 56
 }
49 57
 template<typename TMC>
50 58
 void tmc_report_otpw(TMC &st, const char name[]) {
51
-  SERIAL_ECHO(name);
52
-  SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
53
-  serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
54
-  SERIAL_EOL();
59
+  _tmc_say_otpw(name, st.getOTPW());
55 60
 }
56 61
 template<typename TMC>
57 62
 void tmc_clear_otpw(TMC &st, const char name[]) {
58 63
   st.clear_otpw();
59
-  SERIAL_ECHO(name);
60
-  SERIAL_ECHOLNPGM(" prewarn flag cleared");
64
+  _tmc_say_otpw_cleared(name);
61 65
 }
62 66
 template<typename TMC>
63 67
 void tmc_get_pwmthrs(TMC &st, const char name[], const uint16_t spmm) {
64
-  SERIAL_ECHO(name);
65
-  SERIAL_ECHOPGM(" stealthChop max speed set to ");
66
-  SERIAL_ECHOLN(12650000UL * st.microsteps() / (256 * st.TPWMTHRS() * spmm));
68
+  _tmc_say_pwmthrs(name, _tmc_thrs(st.microsteps(), st.TPWMTHRS(), spmm));
67 69
 }
68 70
 template<typename TMC>
69 71
 void tmc_set_pwmthrs(TMC &st, const char name[], const int32_t thrs, const uint32_t spmm) {
70
-  st.TPWMTHRS(12650000UL * st.microsteps() / (256 * thrs * spmm));
72
+  st.TPWMTHRS(_tmc_thrs(st.microsteps(), thrs, spmm));
71 73
   tmc_get_pwmthrs(st, name, spmm);
72 74
 }
73 75
 template<typename TMC>
74 76
 void tmc_get_sgt(TMC &st, const char name[]) {
75
-  SERIAL_ECHO(name);
76
-  SERIAL_ECHOPGM(" driver homing sensitivity set to ");
77
-  MYSERIAL.println(st.sgt(), DEC);
77
+  _tmc_say_sgt(name, st.sgt());
78 78
 }
79 79
 template<typename TMC>
80 80
 void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val) {
@@ -82,9 +82,13 @@ void tmc_set_sgt(TMC &st, const char name[], const int8_t sgt_val) {
82 82
   tmc_get_sgt(st, name);
83 83
 }
84 84
 
85
-void _M122();
86 85
 void monitor_tmc_driver();
87 86
 
87
+#if ENABLED(TMC_DEBUG)
88
+  void tmc_set_report_status(const bool status);
89
+  void tmc_report_all();
90
+#endif
91
+
88 92
 /**
89 93
  * TMC2130 specific sensorless homing using stallGuard2.
90 94
  * stallGuard2 only works when in spreadCycle mode.
@@ -93,21 +97,7 @@ void monitor_tmc_driver();
93 97
  * Defined here because of limitations with templates and headers.
94 98
  */
95 99
 #if ENABLED(SENSORLESS_HOMING)
96
-  template<typename TMC>
97
-  void tmc_sensorless_homing(TMC &st, bool enable=true) {
98
-    #if ENABLED(STEALTHCHOP)
99
-      if (enable) {
100
-        st.coolstep_min_speed(1024UL * 1024UL - 1UL);
101
-        st.stealthChop(0);
102
-      }
103
-      else {
104
-        st.coolstep_min_speed(0);
105
-        st.stealthChop(1);
106
-      }
107
-    #endif
108
-
109
-    st.diag1_stall(enable ? 1 : 0);
110
-  }
100
+  void tmc_sensorless_homing(TMC2130Stepper &st, bool enable=true);
111 101
 #endif
112 102
 
113 103
 #endif // _TMC_UTIL_H_

+ 8
- 307
Marlin/src/gcode/feature/trinamic/M122.cpp 查看文件

@@ -26,314 +26,15 @@
26 26
 
27 27
 #include "../../gcode.h"
28 28
 #include "../../../feature/tmc_util.h"
29
-#include "../../../module/stepper_indirection.h"
30
-#include "../../../module/planner.h"
31 29
 
32
-enum TMC_debug_enum {
33
-  TMC_CODES,
34
-  TMC_ENABLED,
35
-  TMC_CURRENT,
36
-  TMC_RMS_CURRENT,
37
-  TMC_MAX_CURRENT,
38
-  TMC_IRUN,
39
-  TMC_IHOLD,
40
-  TMC_CS_ACTUAL,
41
-  TMC_PWM_SCALE,
42
-  TMC_VSENSE,
43
-  TMC_STEALTHCHOP,
44
-  TMC_MICROSTEPS,
45
-  TMC_TSTEP,
46
-  TMC_TPWMTHRS,
47
-  TMC_TPWMTHRS_MMS,
48
-  TMC_OTPW,
49
-  TMC_OTPW_TRIGGERED,
50
-  TMC_TOFF,
51
-  TMC_TBL,
52
-  TMC_HEND,
53
-  TMC_HSTRT,
54
-  TMC_SGT
55
-};
56
-enum TMC_drv_status_enum {
57
-  TMC_DRV_CODES,
58
-  TMC_STST,
59
-  TMC_OLB,
60
-  TMC_OLA,
61
-  TMC_S2GB,
62
-  TMC_S2GA,
63
-  TMC_DRV_OTPW,
64
-  TMC_OT,
65
-  TMC_STALLGUARD,
66
-  TMC_DRV_CS_ACTUAL,
67
-  TMC_FSACTIVE,
68
-  TMC_SG_RESULT,
69
-  TMC_DRV_STATUS_HEX,
70
-  TMC_T157,
71
-  TMC_T150,
72
-  TMC_T143,
73
-  TMC_T120,
74
-  TMC_STEALTH,
75
-  TMC_S2VSB,
76
-  TMC_S2VSA
77
-};
78
-static void drv_status_print_hex(const char name[], const uint32_t drv_status) {
79
-  SERIAL_ECHO(name);
80
-  SERIAL_ECHOPGM(" = 0x");
81
-  for(int B=24; B>=8; B-=8){
82
-    SERIAL_PRINT((drv_status>>(B+4))&0xF, HEX);
83
-    SERIAL_PRINT((drv_status>>B)&0xF, HEX);
84
-    SERIAL_CHAR(':');
85
-  }
86
-  SERIAL_PRINT((drv_status>>4)&0xF, HEX);
87
-  SERIAL_PRINT((drv_status)&0xF, HEX);
88
-  SERIAL_EOL();
89
-}
90
-
91
-#if ENABLED(HAVE_TMC2130)
92
-  static void tmc_status(TMC2130Stepper &st, const TMC_debug_enum i) {
93
-    switch(i) {
94
-      case TMC_PWM_SCALE: SERIAL_PRINT(st.PWM_SCALE(), DEC); break;
95
-      case TMC_TSTEP: SERIAL_ECHO(st.TSTEP()); break;
96
-      case TMC_SGT: SERIAL_PRINT(st.sgt(), DEC); break;
97
-      case TMC_STEALTHCHOP: serialprintPGM(st.stealthChop() ? PSTR("true") : PSTR("false")); break;
98
-      default: break;
99
-    }
100
-  }
101
-  static void tmc_parse_drv_status(TMC2130Stepper &st, const TMC_drv_status_enum i) {
102
-    switch(i) {
103
-      case TMC_STALLGUARD: if (st.stallguard()) SERIAL_ECHOPGM("X"); break;
104
-      case TMC_SG_RESULT:  SERIAL_PRINT(st.sg_result(), DEC);      break;
105
-      case TMC_FSACTIVE:   if (st.fsactive())   SERIAL_ECHOPGM("X"); break;
106
-      default: break;
107
-    }
108
-  }
109
-#endif
110
-#if ENABLED(HAVE_TMC2208)
111
-  static void tmc_status(TMC2208Stepper &st, const TMC_debug_enum i) {
112
-    switch(i) {
113
-      case TMC_TSTEP: {
114
-          uint32_t data = 0;
115
-          st.TSTEP(&data);
116
-          SERIAL_PROTOCOL(data);
117
-          break;
118
-        }
119
-      case TMC_PWM_SCALE: SERIAL_PRINT(st.pwm_scale_sum(), DEC); break;
120
-      case TMC_STEALTHCHOP: serialprintPGM(st.stealth() ? PSTR("true") : PSTR("false")); break;
121
-      case TMC_S2VSA: if (st.s2vsa()) SERIAL_ECHOPGM("X"); break;
122
-      case TMC_S2VSB: if (st.s2vsb()) SERIAL_ECHOPGM("X"); break;
123
-      default: break;
124
-    }
125
-  }
126
-  static void tmc_parse_drv_status(TMC2208Stepper &st, const TMC_drv_status_enum i) {
127
-    switch(i) {
128
-      case TMC_T157: if (st.t157()) SERIAL_ECHOPGM("X"); break;
129
-      case TMC_T150: if (st.t150()) SERIAL_ECHOPGM("X"); break;
130
-      case TMC_T143: if (st.t143()) SERIAL_ECHOPGM("X"); break;
131
-      case TMC_T120: if (st.t120()) SERIAL_ECHOPGM("X"); break;
132
-      default: break;
133
-    }
134
-  }
135
-#endif
136
-template <typename TMC>
137
-static void tmc_status(TMC &st, TMC_AxisEnum axis, const TMC_debug_enum i, const float spmm) {
138
-  SERIAL_ECHO('\t');
139
-  switch(i) {
140
-    case TMC_CODES: SERIAL_ECHO(extended_axis_codes[axis]); break;
141
-    case TMC_ENABLED: serialprintPGM(st.isEnabled() ? PSTR("true") : PSTR("false")); break;
142
-    case TMC_CURRENT: SERIAL_ECHO(st.getCurrent()); break;
143
-    case TMC_RMS_CURRENT: SERIAL_PROTOCOL(st.rms_current()); break;
144
-    case TMC_MAX_CURRENT: SERIAL_PRINT((float)st.rms_current()*1.41, 0); break;
145
-    case TMC_IRUN:
146
-      SERIAL_PRINT(st.irun(), DEC);
147
-      SERIAL_ECHOPGM("/31");
148
-      break;
149
-    case TMC_IHOLD:
150
-      SERIAL_PRINT(st.ihold(), DEC);
151
-      SERIAL_ECHOPGM("/31");
152
-      break;
153
-    case TMC_CS_ACTUAL:
154
-      SERIAL_PRINT(st.cs_actual(), DEC);
155
-      SERIAL_ECHOPGM("/31");
156
-      break;
157
-
158
-    case TMC_VSENSE: serialprintPGM(st.vsense() ? PSTR("1=.18") : PSTR("0=.325")); break;
159
-
160
-    case TMC_MICROSTEPS: SERIAL_ECHO(st.microsteps()); break;
161
-    case TMC_TPWMTHRS: {
162
-        uint32_t tpwmthrs_val = st.TPWMTHRS();
163
-        SERIAL_ECHO(tpwmthrs_val);
164
-      }
165
-      break;
166
-    case TMC_TPWMTHRS_MMS: {
167
-        uint32_t tpwmthrs_val = st.TPWMTHRS();
168
-        tpwmthrs_val ? SERIAL_ECHO(12650000UL * st.microsteps() / (256 * tpwmthrs_val * spmm)) : SERIAL_ECHO('-');
169
-      }
170
-      break;
171
-    case TMC_OTPW: serialprintPGM(st.otpw() ? PSTR("true") : PSTR("false")); break;
172
-    case TMC_OTPW_TRIGGERED: serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false")); break;
173
-    case TMC_TOFF: SERIAL_PRINT(st.toff(), DEC); break;
174
-    case TMC_TBL: SERIAL_PRINT(st.blank_time(), DEC); break;
175
-    case TMC_HEND: SERIAL_PRINT(st.hysterisis_end(), DEC); break;
176
-    case TMC_HSTRT: SERIAL_PRINT(st.hysterisis_start(), DEC); break;
177
-    default: tmc_status(st, i); break;
178
-  }
179
-}
180
-template <typename TMC>
181
-static void tmc_parse_drv_status(TMC &st, TMC_AxisEnum axis, const TMC_drv_status_enum i) {
182
-  SERIAL_ECHOPGM("\t");
183
-  switch(i) {
184
-    case TMC_DRV_CODES:     SERIAL_ECHO(extended_axis_codes[axis]);  break;
185
-    case TMC_STST:          if (st.stst())         SERIAL_ECHOPGM("X"); break;
186
-    case TMC_OLB:           if (st.olb())          SERIAL_ECHOPGM("X"); break;
187
-    case TMC_OLA:           if (st.ola())          SERIAL_ECHOPGM("X"); break;
188
-    case TMC_S2GB:          if (st.s2gb())         SERIAL_ECHOPGM("X"); break;
189
-    case TMC_S2GA:          if (st.s2ga())         SERIAL_ECHOPGM("X"); break;
190
-    case TMC_DRV_OTPW:      if (st.otpw())         SERIAL_ECHOPGM("X"); break;
191
-    case TMC_OT:            if (st.ot())           SERIAL_ECHOPGM("X"); break;
192
-    case TMC_DRV_CS_ACTUAL: SERIAL_PRINT(st.cs_actual(), DEC);        break;
193
-    case TMC_DRV_STATUS_HEX:drv_status_print_hex(extended_axis_codes[axis], st.DRV_STATUS()); break;
194
-    default: tmc_parse_drv_status(st, i); break;
195
-  }
196
-}
197
-
198
-static void tmc_debug_loop(const TMC_debug_enum i) {
199
-  #if X_IS_TRINAMIC
200
-    tmc_status(stepperX, TMC_X, i, planner.axis_steps_per_mm[X_AXIS]);
201
-  #endif
202
-  #if X2_IS_TRINAMIC
203
-    tmc_status(stepperX2, TMC_X2, i, planner.axis_steps_per_mm[X_AXIS]);
204
-  #endif
205
-
206
-  #if Y_IS_TRINAMIC
207
-    tmc_status(stepperY, TMC_Y, i, planner.axis_steps_per_mm[Y_AXIS]);
208
-  #endif
209
-  #if Y2_IS_TRINAMIC
210
-    tmc_status(stepperY2, TMC_Y2, i, planner.axis_steps_per_mm[Y_AXIS]);
211
-  #endif
212
-
213
-  #if Z_IS_TRINAMIC
214
-    tmc_status(stepperZ, TMC_Z, i, planner.axis_steps_per_mm[Z_AXIS]);
215
-  #endif
216
-  #if Z2_IS_TRINAMIC
217
-    tmc_status(stepperZ2, TMC_Z2, i, planner.axis_steps_per_mm[Z_AXIS]);
218
-  #endif
219
-
220
-  #if E0_IS_TRINAMIC
221
-    tmc_status(stepperE0, TMC_E0, i, planner.axis_steps_per_mm[E_AXIS]);
222
-  #endif
223
-  #if E1_IS_TRINAMIC
224
-    tmc_status(stepperE1, TMC_E1, i, planner.axis_steps_per_mm[E_AXIS+1]);
225
-  #endif
226
-  #if E2_IS_TRINAMIC
227
-    tmc_status(stepperE2, TMC_E2, i, planner.axis_steps_per_mm[E_AXIS+2]);
228
-  #endif
229
-  #if E3_IS_TRINAMIC
230
-    tmc_status(stepperE3, TMC_E3, i, planner.axis_steps_per_mm[E_AXIS+3]);
231
-  #endif
232
-  #if E4_IS_TRINAMIC
233
-    tmc_status(stepperE4, TMC_E4, i, planner.axis_steps_per_mm[E_AXIS+4]);
234
-  #endif
235
-
236
-  SERIAL_EOL();
237
-}
238
-
239
-static void drv_status_loop(const TMC_drv_status_enum i) {
240
-  #if X_IS_TRINAMIC
241
-    tmc_parse_drv_status(stepperX, TMC_X, i);
242
-  #endif
243
-  #if X2_IS_TRINAMIC
244
-    tmc_parse_drv_status(stepperX2, TMC_X2, i);
245
-  #endif
246
-
247
-  #if Y_IS_TRINAMIC
248
-    tmc_parse_drv_status(stepperY, TMC_Y, i);
249
-  #endif
250
-  #if Y2_IS_TRINAMIC
251
-    tmc_parse_drv_status(stepperY2, TMC_Y2, i);
252
-  #endif
253
-
254
-  #if Z_IS_TRINAMIC
255
-    tmc_parse_drv_status(stepperZ, TMC_Z, i);
256
-  #endif
257
-  #if Z2_IS_TRINAMIC
258
-    tmc_parse_drv_status(stepperZ2, TMC_Z2, i);
259
-  #endif
260
-
261
-  #if E0_IS_TRINAMIC
262
-    tmc_parse_drv_status(stepperE0, TMC_E0, i);
263
-  #endif
264
-  #if E1_IS_TRINAMIC
265
-    tmc_parse_drv_status(stepperE1, TMC_E1, i);
266
-  #endif
267
-  #if E2_IS_TRINAMIC
268
-    tmc_parse_drv_status(stepperE2, TMC_E2, i);
269
-  #endif
270
-  #if E3_IS_TRINAMIC
271
-    tmc_parse_drv_status(stepperE3, TMC_E3, i);
272
-  #endif
273
-  #if E4_IS_TRINAMIC
274
-    tmc_parse_drv_status(stepperE4, TMC_E4, i);
275
-  #endif
276
-
277
-  SERIAL_EOL();
278
-}
279
-
280
-void _M122() {
281
-  if (parser.seen('S')) {
282
-    if (parser.value_bool()) {
283
-      SERIAL_ECHOLNPGM("axis:pwm_scale |status_response|");
284
-      report_tmc_status = true;
285
-    } else
286
-      report_tmc_status = false;
287
-  } else {
288
-    SERIAL_ECHOPGM("\t");                 tmc_debug_loop(TMC_CODES);
289
-    SERIAL_ECHOPGM("Enabled\t");          tmc_debug_loop(TMC_ENABLED);
290
-    SERIAL_ECHOPGM("Set current");        tmc_debug_loop(TMC_CURRENT);
291
-    SERIAL_ECHOPGM("RMS current");        tmc_debug_loop(TMC_RMS_CURRENT);
292
-    SERIAL_ECHOPGM("MAX current");        tmc_debug_loop(TMC_MAX_CURRENT);
293
-    SERIAL_ECHOPGM("Run current");        tmc_debug_loop(TMC_IRUN);
294
-    SERIAL_ECHOPGM("Hold current");       tmc_debug_loop(TMC_IHOLD);
295
-    SERIAL_ECHOPGM("CS actual\t");        tmc_debug_loop(TMC_CS_ACTUAL);
296
-    SERIAL_ECHOPGM("PWM scale");          tmc_debug_loop(TMC_PWM_SCALE);
297
-    SERIAL_ECHOPGM("vsense\t");           tmc_debug_loop(TMC_VSENSE);
298
-    SERIAL_ECHOPGM("stealthChop");        tmc_debug_loop(TMC_STEALTHCHOP);
299
-    SERIAL_ECHOPGM("msteps\t");           tmc_debug_loop(TMC_MICROSTEPS);
300
-    SERIAL_ECHOPGM("tstep\t");            tmc_debug_loop(TMC_TSTEP);
301
-    SERIAL_ECHOPGM("pwm\nthreshold\t");   tmc_debug_loop(TMC_TPWMTHRS);
302
-    SERIAL_ECHOPGM("[mm/s]\t");           tmc_debug_loop(TMC_TPWMTHRS_MMS);
303
-    SERIAL_ECHOPGM("OT prewarn");         tmc_debug_loop(TMC_OTPW);
304
-    SERIAL_ECHOPGM("OT prewarn has\nbeen triggered"); tmc_debug_loop(TMC_OTPW_TRIGGERED);
305
-    SERIAL_ECHOPGM("off time\t");         tmc_debug_loop(TMC_TOFF);
306
-    SERIAL_ECHOPGM("blank time");         tmc_debug_loop(TMC_TBL);
307
-    SERIAL_ECHOPGM("hysterisis\n-end\t"); tmc_debug_loop(TMC_HEND);
308
-    SERIAL_ECHOPGM("-start\t");           tmc_debug_loop(TMC_HSTRT);
309
-    SERIAL_ECHOPGM("Stallguard thrs");    tmc_debug_loop(TMC_SGT);
310
-
311
-    SERIAL_ECHOPGM("DRVSTATUS");          drv_status_loop(TMC_DRV_CODES);
312
-    #if ENABLED(HAVE_TMC2130)
313
-      SERIAL_ECHOPGM("stallguard\t");     drv_status_loop(TMC_STALLGUARD);
314
-      SERIAL_ECHOPGM("sg_result\t");      drv_status_loop(TMC_SG_RESULT);
315
-      SERIAL_ECHOPGM("fsactive\t");       drv_status_loop(TMC_FSACTIVE);
316
-    #endif
317
-    SERIAL_ECHOPGM("stst\t");             drv_status_loop(TMC_STST);
318
-    SERIAL_ECHOPGM("olb\t");              drv_status_loop(TMC_OLB);
319
-    SERIAL_ECHOPGM("ola\t");              drv_status_loop(TMC_OLA);
320
-    SERIAL_ECHOPGM("s2gb\t");             drv_status_loop(TMC_S2GB);
321
-    SERIAL_ECHOPGM("s2ga\t");             drv_status_loop(TMC_S2GA);
322
-    SERIAL_ECHOPGM("otpw\t");             drv_status_loop(TMC_DRV_OTPW);
323
-    SERIAL_ECHOPGM("ot\t");               drv_status_loop(TMC_OT);
324
-    #if ENABLED(HAVE_TMC2208)
325
-      SERIAL_ECHOPGM("157C\t");           drv_status_loop(TMC_T157);
326
-      SERIAL_ECHOPGM("150C\t");           drv_status_loop(TMC_T150);
327
-      SERIAL_ECHOPGM("143C\t");           drv_status_loop(TMC_T143);
328
-      SERIAL_ECHOPGM("120C\t");           drv_status_loop(TMC_T120);
329
-      SERIAL_ECHOPGM("s2vsa\t");          drv_status_loop(TMC_S2VSA);
330
-      SERIAL_ECHOPGM("s2vsb\t");          drv_status_loop(TMC_S2VSB);
331
-    #endif
332
-    SERIAL_ECHOLNPGM("Driver registers:");drv_status_loop(TMC_DRV_STATUS_HEX);
333
-  }
30
+/**
31
+ * M122: Debug TMC drivers
32
+ */
33
+void GcodeSuite::M122() {
34
+  if (parser.seen('S')) 
35
+    tmc_set_report_status(parser.value_bool());
36
+  else
37
+    tmc_report_all();
334 38
 }
335 39
 
336
-// We need to call M122 from monitor_tmc_driver() as well but GcodeSuite::M122 is private.
337
-void GcodeSuite::M122() { _M122(); }
338
-
339 40
 #endif // TMC_DEBUG

+ 16
- 26
Marlin/src/gcode/feature/trinamic/M906.cpp 查看文件

@@ -27,7 +27,6 @@
27 27
 #include "../../gcode.h"
28 28
 #include "../../../feature/tmc_util.h"
29 29
 #include "../../../module/stepper_indirection.h"
30
-#include "../../../module/planner.h"
31 30
 
32 31
 /**
33 32
  * M906: Set motor current in milliamps using axis codes X, Y, Z, E
@@ -35,54 +34,45 @@
35 34
  */
36 35
 void GcodeSuite::M906() {
37 36
   uint16_t values[XYZE];
38
-  LOOP_XYZE(i)
39
-    values[i] = parser.intval(axis_codes[i]);
37
+  LOOP_XYZE(i) values[i] = parser.intval(axis_codes[i]);
38
+
39
+  #define TMC_SET_GET_CURRENT(P,Q) do { \
40
+    if (values[P##_AXIS]) tmc_set_current(stepper##Q, extended_axis_codes[TMC_##Q], values[P##_AXIS]); \
41
+    else tmc_get_current(stepper##Q, extended_axis_codes[TMC_##Q]); } while(0)
40 42
 
41 43
   #if X_IS_TRINAMIC
42
-    if (values[X_AXIS]) tmc_set_current(stepperX, extended_axis_codes[TMC_X], values[X_AXIS]);
43
-    else tmc_get_current(stepperX, extended_axis_codes[TMC_X]);
44
+    TMC_SET_GET_CURRENT(X,X);
44 45
   #endif
45 46
   #if X2_IS_TRINAMIC
46
-    if (values[X_AXIS]) tmc_set_current(stepperX2, extended_axis_codes[TMC_X2], values[X_AXIS]);
47
-    else tmc_get_current(stepperX2, extended_axis_codes[TMC_X2]);
47
+    TMC_SET_GET_CURRENT(X,X2);
48 48
   #endif
49 49
   #if Y_IS_TRINAMIC
50
-    if (values[Y_AXIS]) tmc_set_current(stepperY, extended_axis_codes[TMC_Y], values[Y_AXIS]);
51
-    else tmc_get_current(stepperY, extended_axis_codes[TMC_Y]);
50
+    TMC_SET_GET_CURRENT(Y,Y);
52 51
   #endif
53 52
   #if Y2_IS_TRINAMIC
54
-    if (values[Y_AXIS]) tmc_set_current(stepperY2, extended_axis_codes[TMC_Y2], values[Y_AXIS]);
55
-    else tmc_get_current(stepperY2, extended_axis_codes[TMC_Y2]);
53
+    TMC_SET_GET_CURRENT(Y,Y2);
56 54
   #endif
57 55
   #if Z_IS_TRINAMIC
58
-    if (values[Z_AXIS]) tmc_set_current(stepperZ, extended_axis_codes[TMC_Z], values[Z_AXIS]);
59
-    else tmc_get_current(stepperZ, extended_axis_codes[TMC_Z]);
56
+    TMC_SET_GET_CURRENT(Z,Z);
60 57
   #endif
61 58
   #if Z2_IS_TRINAMIC
62
-    if (values[Z_AXIS]) tmc_set_current(stepperZ2, extended_axis_codes[TMC_Z2], values[Z_AXIS]);
63
-    else tmc_get_current(stepperZ2, extended_axis_codes[TMC_Z2]);
59
+    TMC_SET_GET_CURRENT(Z,Z2);
64 60
   #endif
65 61
   #if E0_IS_TRINAMIC
66
-    if (values[E_AXIS]) tmc_set_current(stepperE0, extended_axis_codes[TMC_E0], values[E_AXIS]);
67
-    else tmc_get_current(stepperE0, extended_axis_codes[TMC_E0]);
62
+    TMC_SET_GET_CURRENT(E,E0);
68 63
   #endif
69 64
   #if E1_IS_TRINAMIC
70
-    if (values[E_AXIS]) tmc_set_current(stepperE1, extended_axis_codes[TMC_E1], values[E_AXIS]);
71
-    else tmc_get_current(stepperE1, extended_axis_codes[TMC_E1]);
65
+    TMC_SET_GET_CURRENT(E,E1);
72 66
   #endif
73 67
   #if E2_IS_TRINAMIC
74
-    if (values[E_AXIS]) tmc_set_current(stepperE2, extended_axis_codes[TMC_E2], values[E_AXIS]);
75
-    else tmc_get_current(stepperE2, extended_axis_codes[TMC_E2]);
68
+    TMC_SET_GET_CURRENT(E,E2);
76 69
   #endif
77 70
   #if E3_IS_TRINAMIC
78
-    if (values[E_AXIS]) tmc_set_current(stepperE3, extended_axis_codes[TMC_E3], values[E_AXIS]);
79
-    else tmc_get_current(stepperE3, extended_axis_codes[TMC_E3]);
71
+    TMC_SET_GET_CURRENT(E,E3);
80 72
   #endif
81 73
   #if E4_IS_TRINAMIC
82
-    if (values[E_AXIS]) tmc_set_current(stepperE4, extended_axis_codes[TMC_E4], values[E_AXIS]);
83
-    else tmc_get_current(stepperE4, extended_axis_codes[TMC_E4]);
74
+    TMC_SET_GET_CURRENT(E,E4);
84 75
   #endif
85
-
86 76
 }
87 77
 
88 78
 #endif // HAS_TRINAMIC

+ 24
- 35
Marlin/src/gcode/feature/trinamic/M911-M915.cpp 查看文件

@@ -81,55 +81,44 @@ void GcodeSuite::M912() {
81 81
 #if ENABLED(HYBRID_THRESHOLD)
82 82
   void GcodeSuite::M913() {
83 83
     uint16_t values[XYZE];
84
-    LOOP_XYZE(i)
85
-      values[i] = parser.intval(axis_codes[i]);
84
+    LOOP_XYZE(i) values[i] = parser.intval(axis_codes[i]);
85
+
86
+    #define TMC_SET_GET_PWMTHRS(P,Q) do { \
87
+      if (values[P##_AXIS]) tmc_set_pwmthrs(stepper##Q, extended_axis_codes[TMC_##Q], values[P##_AXIS], planner.axis_steps_per_mm[P##_AXIS]); \
88
+      else tmc_get_pwmthrs(stepper##Q, extended_axis_codes[TMC_##Q], planner.axis_steps_per_mm[P##_AXIS]); } while(0)
86 89
 
87 90
     #if X_IS_TRINAMIC
88
-      if (values[X_AXIS]) tmc_set_pwmthrs(stepperX, extended_axis_codes[TMC_X], values[X_AXIS], planner.axis_steps_per_mm[X_AXIS]);
89
-      else tmc_get_pwmthrs(stepperX, extended_axis_codes[TMC_X], planner.axis_steps_per_mm[X_AXIS]);
91
+      TMC_SET_GET_PWMTHRS(X,X);
90 92
     #endif
91 93
     #if X2_IS_TRINAMIC
92
-      if (values[X_AXIS]) tmc_set_pwmthrs(stepperX2, extended_axis_codes[TMC_X2], values[X_AXIS], planner.axis_steps_per_mm[X_AXIS]);
93
-      else tmc_get_pwmthrs(stepperX, extended_axis_codes[TMC_X2], planner.axis_steps_per_mm[X_AXIS]);
94
+      TMC_SET_GET_PWMTHRS(X,X2);
94 95
     #endif
95
-
96 96
     #if Y_IS_TRINAMIC
97
-      if (values[Y_AXIS]) tmc_set_pwmthrs(stepperY, extended_axis_codes[TMC_Y], values[Y_AXIS], planner.axis_steps_per_mm[Y_AXIS]);
98
-      else tmc_get_pwmthrs(stepperY, extended_axis_codes[TMC_Y], planner.axis_steps_per_mm[Y_AXIS]);
97
+      TMC_SET_GET_PWMTHRS(Y,Y);
99 98
     #endif
100 99
     #if Y2_IS_TRINAMIC
101
-      if (values[Y_AXIS]) tmc_set_pwmthrs(stepperY2, extended_axis_codes[TMC_Y2], values[Y_AXIS], planner.axis_steps_per_mm[Y_AXIS]);
102
-      else tmc_get_pwmthrs(stepperY, extended_axis_codes[TMC_Y2], planner.axis_steps_per_mm[Y_AXIS]);
100
+      TMC_SET_GET_PWMTHRS(Y,Y2);
103 101
     #endif
104
-
105 102
     #if Z_IS_TRINAMIC
106
-      if (values[Z_AXIS]) tmc_set_pwmthrs(stepperZ, extended_axis_codes[TMC_Z], values[Z_AXIS], planner.axis_steps_per_mm[Z_AXIS]);
107
-      else tmc_get_pwmthrs(stepperZ, extended_axis_codes[TMC_Z], planner.axis_steps_per_mm[Z_AXIS]);
103
+      TMC_SET_GET_PWMTHRS(Z,Z);
108 104
     #endif
109 105
     #if Z2_IS_TRINAMIC
110
-      if (values[Z_AXIS]) tmc_set_pwmthrs(stepperZ2, extended_axis_codes[TMC_Z2], values[Z_AXIS], planner.axis_steps_per_mm[Z_AXIS]);
111
-      else tmc_get_pwmthrs(stepperZ, extended_axis_codes[TMC_Z2], planner.axis_steps_per_mm[Z_AXIS]);
106
+      TMC_SET_GET_PWMTHRS(Z,Z2);
112 107
     #endif
113
-
114 108
     #if E0_IS_TRINAMIC
115
-      if (values[E_AXIS]) tmc_set_pwmthrs(stepperE0, extended_axis_codes[TMC_E0], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
116
-      else tmc_get_pwmthrs(stepperE0, extended_axis_codes[TMC_E0], planner.axis_steps_per_mm[E_AXIS]);
109
+      TMC_SET_GET_PWMTHRS(E,E0);
117 110
     #endif
118 111
     #if E1_IS_TRINAMIC
119
-      if (values[E_AXIS]) tmc_set_pwmthrs(stepperE1, extended_axis_codes[TMC_E1], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
120
-      else tmc_get_pwmthrs(stepperE1, extended_axis_codes[TMC_E1], planner.axis_steps_per_mm[E_AXIS]);
112
+      TMC_SET_GET_PWMTHRS(E,E1);
121 113
     #endif
122 114
     #if E2_IS_TRINAMIC
123
-      if (values[E_AXIS]) tmc_set_pwmthrs(stepperE2, extended_axis_codes[TMC_E2], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
124
-      else tmc_get_pwmthrs(stepperE2, extended_axis_codes[TMC_E2], planner.axis_steps_per_mm[E_AXIS]);
115
+      TMC_SET_GET_PWMTHRS(E,E2);
125 116
     #endif
126 117
     #if E3_IS_TRINAMIC
127
-      if (values[E_AXIS]) tmc_set_pwmthrs(stepperE3, extended_axis_codes[TMC_E3], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
128
-      else tmc_get_pwmthrs(stepperE3, extended_axis_codes[TMC_E3], planner.axis_steps_per_mm[E_AXIS]);
118
+      TMC_SET_GET_PWMTHRS(E,E3);
129 119
     #endif
130 120
     #if E4_IS_TRINAMIC
131
-      if (values[E_AXIS]) tmc_set_pwmthrs(stepperE4, extended_axis_codes[TMC_E4], values[E_AXIS], planner.axis_steps_per_mm[E_AXIS]);
132
-      else tmc_get_pwmthrs(stepperE4, extended_axis_codes[TMC_E4], planner.axis_steps_per_mm[E_AXIS]);
121
+      TMC_SET_GET_PWMTHRS(E,E4);
133 122
     #endif
134 123
   }
135 124
 #endif // HYBRID_THRESHOLD
@@ -139,21 +128,21 @@ void GcodeSuite::M912() {
139 128
  */
140 129
 #if ENABLED(SENSORLESS_HOMING)
141 130
   void GcodeSuite::M914() {
131
+    #define TMC_SET_GET_SGT(P,Q) do { \
132
+      if (parser.seen(axis_codes[P##_AXIS])) tmc_set_sgt(stepper##Q, extended_axis_codes[TMC_##Q], parser.value_int()); \
133
+      else tmc_get_sgt(stepper##Q, extended_axis_codes[TMC_##Q]); } while(0)
134
+
142 135
     #if ENABLED(X_IS_TMC2130) || ENABLED(IS_TRAMS)
143
-      if (parser.seen(axis_codes[X_AXIS])) tmc_set_sgt(stepperX, extended_axis_codes[TMC_X], parser.value_int());
144
-      else tmc_get_sgt(stepperX, extended_axis_codes[TMC_X]);
136
+      TMC_SET_GET_SGT(X,X);
145 137
     #endif
146 138
     #if ENABLED(X2_IS_TMC2130)
147
-      if (parser.seen(axis_codes[X_AXIS])) tmc_set_sgt(stepperX2, extended_axis_codes[TMC_X2], parser.value_int());
148
-      else tmc_get_sgt(stepperX2, extended_axis_codes[TMC_X2]);
139
+      TMC_SET_GET_SGT(X,X2);
149 140
     #endif
150 141
     #if ENABLED(Y_IS_TMC2130) || ENABLED(IS_TRAMS)
151
-      if (parser.seen(axis_codes[Y_AXIS])) tmc_set_sgt(stepperY, extended_axis_codes[TMC_Y], parser.value_int());
152
-      else tmc_get_sgt(stepperY, extended_axis_codes[TMC_Y]);
142
+      TMC_SET_GET_SGT(Y,Y);
153 143
     #endif
154 144
     #if ENABLED(Y2_IS_TMC2130)
155
-      if (parser.seen(axis_codes[Y_AXIS])) tmc_set_sgt(stepperY2, extended_axis_codes[TMC_Y2], parser.value_int());
156
-      else tmc_get_sgt(stepperY2, extended_axis_codes[TMC_Y2]);
145
+      TMC_SET_GET_SGT(Y,Y2);
157 146
     #endif
158 147
   }
159 148
 #endif // SENSORLESS_HOMING

+ 14
- 0
Marlin/src/inc/Conditionals_post.h 查看文件

@@ -679,6 +679,20 @@
679 679
 #define HAS_E4_MICROSTEPS (PIN_EXISTS(E4_MS1))
680 680
 #define HAS_SOLENOID_4    (PIN_EXISTS(SOL4))
681 681
 
682
+// Trinamic Stepper Drivers
683
+#define HAS_TRINAMIC (ENABLED(HAVE_TMC2130) || ENABLED(HAVE_TMC2208) || ENABLED(IS_TRAMS))
684
+#define  X_IS_TRINAMIC (ENABLED( X_IS_TMC2130) || ENABLED( X_IS_TMC2208) || ENABLED(IS_TRAMS))
685
+#define X2_IS_TRINAMIC (ENABLED(X2_IS_TMC2130) || ENABLED(X2_IS_TMC2208))
686
+#define  Y_IS_TRINAMIC (ENABLED( Y_IS_TMC2130) || ENABLED( Y_IS_TMC2208) || ENABLED(IS_TRAMS))
687
+#define Y2_IS_TRINAMIC (ENABLED(Y2_IS_TMC2130) || ENABLED(Y2_IS_TMC2208))
688
+#define  Z_IS_TRINAMIC (ENABLED( Z_IS_TMC2130) || ENABLED( Z_IS_TMC2208) || ENABLED(IS_TRAMS))
689
+#define Z2_IS_TRINAMIC (ENABLED(Z2_IS_TMC2130) || ENABLED(Z2_IS_TMC2208))
690
+#define E0_IS_TRINAMIC (ENABLED(E0_IS_TMC2130) || ENABLED(E0_IS_TMC2208) || ENABLED(IS_TRAMS))
691
+#define E1_IS_TRINAMIC (ENABLED(E1_IS_TMC2130) || ENABLED(E1_IS_TMC2208))
692
+#define E2_IS_TRINAMIC (ENABLED(E2_IS_TMC2130) || ENABLED(E2_IS_TMC2208))
693
+#define E3_IS_TRINAMIC (ENABLED(E3_IS_TMC2130) || ENABLED(E3_IS_TMC2208))
694
+#define E4_IS_TRINAMIC (ENABLED(E4_IS_TMC2130) || ENABLED(E4_IS_TMC2208))
695
+
682 696
 // Endstops and bed probe
683 697
 #define HAS_X_MIN (PIN_EXISTS(X_MIN) && !IS_X2_ENDSTOP(X,MIN) && !IS_Y2_ENDSTOP(X,MIN) && !IS_Z2_OR_PROBE(X,MIN))
684 698
 #define HAS_X_MAX (PIN_EXISTS(X_MAX) && !IS_X2_ENDSTOP(X,MAX) && !IS_Y2_ENDSTOP(X,MAX) && !IS_Z2_OR_PROBE(X,MAX))

+ 0
- 1
Marlin/src/inc/MarlinConfigPre.h 查看文件

@@ -28,7 +28,6 @@
28 28
 #include "Version.h"
29 29
 #include "../../Configuration.h"
30 30
 #include "Conditionals_LCD.h"
31
-#include "../feature/tmc_macros.h"
32 31
 #include "../../Configuration_adv.h"
33 32
 #include "Conditionals_adv.h"
34 33
 

+ 0
- 2
Marlin/src/inc/SanityCheck.h 查看文件

@@ -1491,8 +1491,6 @@ static_assert(1 >= 0
1491 1491
   #error "Enable STEALTHCHOP to use HYBRID_THRESHOLD."
1492 1492
 #endif
1493 1493
 
1494
-#include "../feature/tmc_macros.h"
1495
-
1496 1494
 #if ENABLED(TMC_Z_CALIBRATION) && !Z_IS_TRINAMIC && !Z2_IS_TRINAMIC
1497 1495
   #error "TMC_Z_CALIBRATION requires at least one TMC driver on Z axis"
1498 1496
 #endif

Loading…
取消
儲存