Browse Source

TMC2130 Library: @teemuatlut replaces @makertum

Scott Lahteine 7 years ago
parent
commit
45f949d833

+ 5
- 3
.travis.yml View File

@@ -47,8 +47,8 @@ install:
47 47
   # - sudo mv TMC26XStepper /usr/local/share/arduino/libraries/TMC26XStepper
48 48
   #
49 49
   # Install: TMC2130 Stepper Motor Controller library
50
-  - git clone https://github.com/MarlinFirmware/Trinamic_TMC2130.git
51
-  - sudo mv Trinamic_TMC2130/Trinamic_TMC2130 /usr/local/share/arduino/libraries/Trinamic_TMC2130
50
+  - git clone https://github.com/teemuatlut/TMC2130Stepper.git
51
+  - sudo mv TMC2130Stepper /usr/local/share/arduino/libraries/TMC2130Stepper
52 52
   #
53 53
 before_script:
54 54
   #
@@ -396,7 +396,9 @@ script:
396 396
   # TMC2130 Config
397 397
   #
398 398
   - restore_configs
399
-  - opt_enable_adv HAVE_TMC2130DRIVER X_IS_TMC2130 Y_IS_TMC2130 Z_IS_TMC2130 E0_IS_TMC2130
399
+  - opt_enable_adv HAVE_TMC2130 X_IS_TMC2130 Y_IS_TMC2130 Z_IS_TMC2130
400
+  - build_marlin
401
+  - opt_enable_adv AUTOMATIC_CURRENT_CONTROL STEALTHCHOP
400 402
   - build_marlin
401 403
   #
402 404
   # tvrrug Config need to check board type for sanguino atmega644p

+ 85
- 188
Marlin/Configuration_adv.h View File

@@ -761,14 +761,15 @@
761 761
                                                      // even if it takes longer than DEFAULT_STEPPER_DEACTIVE_TIME.
762 762
 #endif
763 763
 
764
-/******************************************************************************\
765
- * enable this section if you have TMC26X motor drivers.
766
- * you need to import the TMC26XStepper library into the Arduino IDE for this
767
- ******************************************************************************/
768
-
769 764
 // @section tmc
770 765
 
766
+/**
767
+ * Enable this section if you have TMC26X motor drivers.
768
+ * You will need to import the TMC26XStepper library into the Arduino IDE for this
769
+ * (https://github.com/trinamic/TMC26XStepper.git)
770
+ */
771 771
 //#define HAVE_TMCDRIVER
772
+
772 773
 #if ENABLED(HAVE_TMCDRIVER)
773 774
 
774 775
   //#define X_IS_TMC
@@ -826,23 +827,31 @@
826 827
 
827 828
 // @section TMC2130
828 829
 
829
-
830 830
 /**
831 831
  * Enable this for SilentStepStick Trinamic TMC2130 SPI-configurable stepper drivers.
832 832
  *
833
- * To use TMC2130 drivers in SPI mode, you'll also need the TMC2130 Arduino library
834
- * (https://github.com/makertum/Trinamic_TMC2130).
833
+ * You'll also need the TMC2130Stepper Arduino library
834
+ * (https://github.com/teemuatlut/TMC2130Stepper).
835 835
  *
836 836
  * To use TMC2130 stepper drivers in SPI mode connect your SPI2130 pins to
837 837
  * the hardware SPI interface on your board and define the required CS pins
838 838
  * in your `pins_MYBOARD.h` file. (e.g., RAMPS 1.4 uses AUX3 pins `X_CS_PIN 53`, `Y_CS_PIN 49`, etc.).
839 839
  */
840
+//#define HAVE_TMC2130
840 841
 
841
-//#define HAVE_TMC2130DRIVER
842
-
843
-#if ENABLED(HAVE_TMC2130DRIVER)
842
+#if ENABLED(HAVE_TMC2130)
843
+  #define STEALTHCHOP
844 844
 
845
-  //#define TMC2130_ADVANCED_CONFIGURATION
845
+  /**
846
+   * Let Marlin automatically control stepper current.
847
+   * This is still an experimental feature.
848
+   * Increase current every 5s by CURRENT_STEP until stepper temperature prewarn gets triggered,
849
+   * then decrease current by CURRENT_STEP until temperature prewarn is cleared.
850
+   * Adjusting starts from X/Y/Z/E_MAX_CURRENT but will not increase over AUTO_ADJUST_MAX
851
+   */ 
852
+  //#define AUTOMATIC_CURRENT_CONTROL
853
+  #define CURRENT_STEP          50  // [mA]
854
+  #define AUTO_ADJUST_MAX     1300  // [mA], 1300mA_rms = 1840mA_peak
846 855
 
847 856
   // CHOOSE YOUR MOTORS HERE, THIS IS MANDATORY
848 857
   //#define X_IS_TMC2130
@@ -856,182 +865,68 @@
856 865
   //#define E2_IS_TMC2130
857 866
   //#define E3_IS_TMC2130
858 867
 
859
-  #if ENABLED(TMC2130_ADVANCED_CONFIGURATION)
860
-
861
-    // If you've enabled TMC2130_ADVANCED_CONFIGURATION, define global settings below.
862
-    // Enabled settings will be automatically applied to all axes specified above.
863
-    //
864
-    // Please read the TMC2130 datasheet:
865
-    // http://www.trinamic.com/_articles/products/integrated-circuits/tmc2130/_datasheet/TMC2130_datasheet.pdf
866
-    // All settings here have the same (sometimes cryptic) names as in the datasheet.
867
-    //
868
-    // The following, uncommented settings are only suggestion.
869
-
870
-    /* GENERAL CONFIGURATION */
871
-
872
-    //#define GLOBAL_EN_PWM_MODE        0
873
-    #define GLOBAL_I_SCALE_ANALOG     1 // [0,1] 0: Normal, 1: AIN
874
-    //#define GLOBAL_INTERNAL_RSENSE    0 // [0,1] 0: Normal, 1: Internal
875
-    #define GLOBAL_EN_PWM_MODE        0 // [0,1] 0: Normal, 1: stealthChop with velocity threshold
876
-    //#define GLOBAL_ENC_COMMUTATION    0 // [0,1]
877
-    #define GLOBAL_SHAFT              0 // [0,1] 0: normal, 1: invert
878
-    //#define GLOBAL_DIAG0_ERROR        0 // [0,1]
879
-    //#define GLOBAL_DIAG0_OTPW         0 // [0,1]
880
-    //#define GLOBAL_DIAG0_STALL        0 // [0,1]
881
-    //#define GLOBAL_DIAG1_STALL        0 // [0,1]
882
-    //#define GLOBAL_DIAG1_INDEX        0 // [0,1]
883
-    //#define GLOBAL_DIAG1_ONSTATE      0 // [0,1]
884
-    //#define GLOBAL_DIAG1_ONSTATE      0 // [0,1]
885
-    //#define GLOBAL_DIAG0_INT_PUSHPULL 0 // [0,1]
886
-    //#define GLOBAL_DIAG1_INT_PUSHPULL 0 // [0,1]
887
-    //#define GLOBAL_SMALL_HYSTERESIS   0 // [0,1]
888
-    //#define GLOBAL_STOP_ENABLE        0 // [0,1]
889
-    //#define GLOBAL_DIRECT_MODE        0 // [0,1]
890
-
891
-    /* VELOCITY-DEPENDENT DRIVE FEATURES */
892
-
893
-    #define GLOBAL_IHOLD             22 // [0-31] 0: min, 31: max
894
-    #define GLOBAL_IRUN              31 // [0-31] 0: min, 31: max
895
-    #define GLOBAL_IHOLDDELAY        15 // [0-15] 0: min, 15: about 4 seconds
896
-    //#define GLOBAL_TPOWERDOWN         0 // [0-255] 0: min, 255: about 4 seconds
897
-    //#define GLOBAL_TPWMTHRS           0 // [0-1048576] e.g. 20 corresponds with 2000 steps/s
898
-    //#define GLOBAL_TCOOLTHRS          0 // [0-1048576] e.g. 20 corresponds with 2000 steps/s
899
-    #define GLOBAL_THIGH             10 // [0-1048576] e.g. 20 corresponds with 2000 steps/s
900
-
901
-    /* SPI MODE CONFIGURATION */
902
-
903
-    //#define GLOBAL_XDIRECT            0
904
-
905
-    /* DCSTEP MINIMUM VELOCITY */
906
-
907
-    //#define GLOBAL_VDCMIN             0
908
-
909
-    /* MOTOR DRIVER CONFIGURATION*/
910
-
911
-    //#define GLOBAL_DEDGE              0
912
-    //#define GLOBAL_DISS2G             0
913
-    #define GLOBAL_INTPOL             1 // 0: off 1: 256 microstep interpolation
914
-    #define GLOBAL_MRES              16 // number of microsteps
915
-    #define GLOBAL_SYNC               1 // [0-15]
916
-    #define GLOBAL_VHIGHCHM           1 // [0,1] 0: normal, 1: high velocity stepper mode
917
-    #define GLOBAL_VHIGHFS            0 // [0,1] 0: normal, 1: switch to full steps for high velocities
918
-    // #define GLOBAL_VSENSE            0 // [0,1] 0: normal, 1: high sensitivity (not recommended)
919
-    #define GLOBAL_TBL                1 // 0-3: set comparator blank time to 16, 24, 36 or 54 clocks, 1 or 2 is recommended
920
-    #define GLOBAL_CHM                0 // [0,1] 0: spreadCycle, 1: Constant off time with fast decay time.
921
-    //#define GLOBAL_RNDTF              0
922
-    //#define GLOBAL_DISFDCC            0
923
-    //#define GLOBAL_FD                 0
924
-    //#define GLOBAL_HEND               0
925
-    //#define GLOBAL_HSTRT              0
926
-    #define GLOBAL_TOFF              10 // 0: driver disable, 1: use only with TBL>2, 2-15: off time setting during slow decay phase
927
-
928
-    //#define GLOBAL_SFILT              0
929
-    //#define GLOBAL_SGT                0
930
-    //#define GLOBAL_SEIMIN             0
931
-    //#define GLOBAL_SEDN               0
932
-    //#define GLOBAL_SEMAX              0
933
-    //#define GLOBAL_SEUP               0
934
-    //#define GLOBAL_SEMIN              0
935
-
936
-    //#define GLOBAL_DC_TIME            0
937
-    //#define GLOBAL_DC_SG              0
938
-
939
-    //#define GLOBAL_FREEWHEEL          0
940
-    //#define GLOBAL_PWM_SYMMETRIC      0
941
-    //#define GLOBAL_PWM_AUTOSCALE      0
942
-    //#define GLOBAL_PWM_FREQ           0
943
-    //#define GLOBAL_PWM_GRAD           0
944
-    //#define GLOBAL_PWM_AMPL           0
945
-
946
-    //#define GLOBAL_ENCM_CTRL          0
947
-
948
-  #else
949
-
950
-    #define X_IHOLD          31 // [0-31] 0: min, 31: max
951
-    #define X_IRUN           31 // [0-31] 0: min, 31: max
952
-    #define X_IHOLDDELAY     15 // [0-15] 0: min, 15: about 4 seconds
953
-    #define X_I_SCALE_ANALOG  1 // 0: Normal, 1: AIN
954
-    #define X_MRES           16 // number of microsteps
955
-    #define X_TBL             1 // 0-3: set comparator blank time to 16, 24, 36 or 54 clocks, 1 or 2 is recommended
956
-    #define X_TOFF            8 // 0: driver disable, 1: use only with TBL>2, 2-15: off time setting during slow decay phase
957
-
958
-    #define X2_IHOLD         31
959
-    #define X2_IRUN          31
960
-    #define X2_IHOLDDELAY    15
961
-    #define X2_I_SCALE_ANALOG 1
962
-    #define X2_MRES          16
963
-    #define X2_TBL            1
964
-    #define X2_TOFF           8
965
-
966
-    #define Y_IHOLD          31
967
-    #define Y_IRUN           31
968
-    #define Y_IHOLDDELAY     15
969
-    #define Y_I_SCALE_ANALOG  1
970
-    #define Y_MRES           16
971
-    #define Y_TBL             1
972
-    #define Y_TOFF            8
973
-
974
-    #define Y2_IHOLD         31
975
-    #define Y2_IRUN          31
976
-    #define Y2_IHOLDDELAY    15
977
-    #define Y2_I_SCALE_ANALOG 1
978
-    #define Y2_MRES          16
979
-    #define Y2_TBL            1
980
-    #define Y2_TOFF           8
981
-
982
-    #define Z_IHOLD          31
983
-    #define Z_IRUN           31
984
-    #define Z_IHOLDDELAY     15
985
-    #define Z_I_SCALE_ANALOG  1
986
-    #define Z_MRES           16
987
-    #define Z_TBL             1
988
-    #define Z_TOFF            8
989
-
990
-    #define Z2_IHOLD         31
991
-    #define Z2_IRUN          31
992
-    #define Z2_IHOLDDELAY    15
993
-    #define Z2_I_SCALE_ANALOG 1
994
-    #define Z2_MRES          16
995
-    #define Z2_TBL            1
996
-    #define Z2_TOFF           8
997
-
998
-    #define E0_IHOLD         31
999
-    #define E0_IRUN          31
1000
-    #define E0_IHOLDDELAY    15
1001
-    #define E0_I_SCALE_ANALOG 1
1002
-    #define E0_MRES          16
1003
-    #define E0_TBL            1
1004
-    #define E0_TOFF           8
1005
-
1006
-    #define E1_IHOLD         31
1007
-    #define E1_IRUN          31
1008
-    #define E1_IHOLDDELAY    15
1009
-    #define E1_I_SCALE_ANALOG 1
1010
-    #define E1_MRES          16
1011
-    #define E1_TBL            1
1012
-    #define E1_TOFF           8
1013
-
1014
-    #define E2_IHOLD         31
1015
-    #define E2_IRUN          31
1016
-    #define E2_IHOLDDELAY    15
1017
-    #define E2_I_SCALE_ANALOG 1
1018
-    #define E2_MRES          16
1019
-    #define E2_TBL            1
1020
-    #define E2_TOFF           8
1021
-
1022
-    #define E3_IHOLD         31
1023
-    #define E3_IRUN          31
1024
-    #define E3_IHOLDDELAY    15
1025
-    #define E3_I_SCALE_ANALOG 1
1026
-    #define E3_MRES          16
1027
-    #define E3_TBL            1
1028
-    #define E3_TOFF           8
1029
-
1030
-  #endif // TMC2130_ADVANCED_CONFIGURATION
1031
-
1032
-#endif // HAVE_TMC2130DRIVER
1033
-
1034
-// @section L6470
868
+  /**
869
+   * Stepper driver settings
870
+   */
871
+
872
+  #define R_SENSE           0.11  // R_sense resistor for SilentStepStick2130
873
+  #define HOLD_MULTIPLIER    0.5  // Scales down the holding current from run current
874
+  #define INTERPOLATE          1  // Interpolate X/Y/Z_MICROSTEPS to 256
875
+
876
+  #define X_MAX_CURRENT     1000  // rms current in mA
877
+  #define X_MICROSTEPS        16  // FULLSTEP..256
878
+  #define X_CHIP_SELECT       40  // Pin
879
+
880
+  #define Y_MAX_CURRENT     1000
881
+  #define Y_MICROSTEPS        16
882
+  #define Y_CHIP_SELECT       42
883
+
884
+  #define Z_MAX_CURRENT     1000
885
+  #define Z_MICROSTEPS        16
886
+  #define Z_CHIP_SELECT       65
887
+
888
+  //#define X2_MAX_CURRENT  1000
889
+  //#define X2_MICROSTEPS     16
890
+  //#define X2_CHIP_SELECT    -1
891
+
892
+  //#define Y2_MAX_CURRENT  1000
893
+  //#define Y2_MICROSTEPS     16
894
+  //#define Y2_CHIP_SELECT    -1
895
+
896
+  //#define Z2_MAX_CURRENT  1000
897
+  //#define Z2_MICROSTEPS     16
898
+  //#define Z2_CHIP_SELECT    -1
899
+
900
+  //#define E0_MAX_CURRENT  1000
901
+  //#define E0_MICROSTEPS     16
902
+  //#define E0_CHIP_SELECT    -1
903
+
904
+  //#define E1_MAX_CURRENT  1000
905
+  //#define E1_MICROSTEPS     16
906
+  //#define E1_CHIP_SELECT    -1
907
+
908
+  //#define E2_MAX_CURRENT  1000
909
+  //#define E2_MICROSTEPS     16
910
+  //#define E2_CHIP_SELECT    -1
911
+
912
+  //#define E3_MAX_CURRENT  1000
913
+  //#define E3_MICROSTEPS     16
914
+  //#define E3_CHIP_SELECT    -1
915
+
916
+  /**
917
+   * You can set your own advanced settings by filling in predefined functions.
918
+   * A list of available functions can be found on the library github page
919
+   * https://github.com/teemuatlut/TMC2130Stepper
920
+   *
921
+   * Example:
922
+   * #define TMC2130_ADV() { \
923
+   *   stepperX.diag0_temp_prewarn(1); \
924
+   *   stepperX.interpolate(0); \
925
+   * }
926
+   */
927
+  #define  TMC2130_ADV() {  }
928
+
929
+#endif // ENABLED(HAVE_TMC2130)
1035 930
 
1036 931
 /**
1037 932
  * Enable this section if you have L6470 motor drivers.
@@ -1039,6 +934,8 @@
1039 934
  * (https://github.com/ameyer/Arduino-L6470)
1040 935
  */
1041 936
 
937
+// @section l6470
938
+
1042 939
 //#define HAVE_L6470DRIVER
1043 940
 #if ENABLED(HAVE_L6470DRIVER)
1044 941
 

+ 2
- 2
Marlin/Marlin.ino View File

@@ -61,9 +61,9 @@
61 61
   #include <TMC26XStepper.h>
62 62
 #endif
63 63
 
64
-#if ENABLED(HAVE_TMC2130DRIVER)
64
+#if ENABLED(HAVE_TMC2130)
65 65
   #include <SPI.h>
66
-  #include <Trinamic_TMC2130.h>
66
+  #include <TMC2130Stepper.h>
67 67
 #endif
68 68
 
69 69
 #if ENABLED(HAVE_L6470DRIVER)

+ 176
- 60
Marlin/Marlin_main.cpp View File

@@ -189,10 +189,13 @@
189 189
  * M666 - Set delta endstop adjustment. (Requires DELTA)
190 190
  * M605 - Set dual x-carriage movement mode: "M605 S<mode> [X<x_offset>] [R<temp_offset>]". (Requires DUAL_X_CARRIAGE)
191 191
  * M851 - Set Z probe's Z offset in current units. (Negative = below the nozzle.)
192
+ * M906 - Set or get motor current in milliamps using axis codes X, Y, Z, E. Report values if no axis codes given. (Requires HAVE_TMC2130)
192 193
  * M907 - Set digital trimpot motor current using axis codes. (Requires a board with digital trimpots)
193 194
  * M908 - Control digital trimpot directly. (Requires DAC_STEPPER_CURRENT or DIGIPOTSS_PIN)
194 195
  * M909 - Print digipot/DAC current value. (Requires DAC_STEPPER_CURRENT)
195 196
  * M910 - Commit digipot/DAC value to external EEPROM via I2C. (Requires DAC_STEPPER_CURRENT)
197
+ * M911 - Report stepper driver overtemperature pre-warn condition. (Requires HAVE_TMC2130)
198
+ * M912 - Clear stepper driver overtemperature pre-warn condition flag. (Requires HAVE_TMC2130)
196 199
  * M350 - Set microstepping mode. (Requires digital microstepping pins.)
197 200
  * M351 - Toggle MS1 MS2 pins directly. (Requires digital microstepping pins.)
198 201
  *
@@ -6127,58 +6130,6 @@ inline void gcode_M120() { endstops.enable_globally(true); }
6127 6130
  */
6128 6131
 inline void gcode_M121() { endstops.enable_globally(false); }
6129 6132
 
6130
-#if ENABLED(HAVE_TMC2130DRIVER)
6131
-
6132
-  /**
6133
-   * M122: Output Trinamic TMC2130 status to serial output. Very bad formatting.
6134
-   */
6135
-
6136
-  static void tmc2130_report(Trinamic_TMC2130 &stepr, const char *name) {
6137
-    stepr.read_STAT();
6138
-    SERIAL_PROTOCOL(name);
6139
-    SERIAL_PROTOCOL(": ");
6140
-    stepr.isReset() ? SERIAL_PROTOCOLPGM("RESET ") : SERIAL_PROTOCOLPGM("----- ");
6141
-    stepr.isError() ? SERIAL_PROTOCOLPGM("ERROR ") : SERIAL_PROTOCOLPGM("----- ");
6142
-    stepr.isStallguard() ? SERIAL_PROTOCOLPGM("SLGRD ") : SERIAL_PROTOCOLPGM("----- ");
6143
-    stepr.isStandstill() ? SERIAL_PROTOCOLPGM("STILL ") : SERIAL_PROTOCOLPGM("----- ");
6144
-    SERIAL_PROTOCOLLN(stepr.debug());
6145
-  }
6146
-
6147
-  inline void gcode_M122() {
6148
-    SERIAL_PROTOCOLLNPGM("Reporting TMC2130 status");
6149
-    #if ENABLED(X_IS_TMC2130)
6150
-      tmc2130_report(stepperX, "X");
6151
-    #endif
6152
-    #if ENABLED(X2_IS_TMC2130)
6153
-      tmc2130_report(stepperX2, "X2");
6154
-    #endif
6155
-    #if ENABLED(Y_IS_TMC2130)
6156
-      tmc2130_report(stepperY, "Y");
6157
-    #endif
6158
-    #if ENABLED(Y2_IS_TMC2130)
6159
-      tmc2130_report(stepperY2, "Y2");
6160
-    #endif
6161
-    #if ENABLED(Z_IS_TMC2130)
6162
-      tmc2130_report(stepperZ, "Z");
6163
-    #endif
6164
-    #if ENABLED(Z2_IS_TMC2130)
6165
-      tmc2130_report(stepperZ2, "Z2");
6166
-    #endif
6167
-    #if ENABLED(E0_IS_TMC2130)
6168
-      tmc2130_report(stepperE0, "E0");
6169
-    #endif
6170
-    #if ENABLED(E1_IS_TMC2130)
6171
-      tmc2130_report(stepperE1, "E1");
6172
-    #endif
6173
-    #if ENABLED(E2_IS_TMC2130)
6174
-      tmc2130_report(stepperE2, "E2");
6175
-    #endif
6176
-    #if ENABLED(E3_IS_TMC2130)
6177
-      tmc2130_report(stepperE3, "E3");
6178
-    #endif
6179
-  }
6180
-#endif // HAVE_TMC2130DRIVER
6181
-
6182 6133
 #if ENABLED(BLINKM) || ENABLED(RGB_LED)
6183 6134
 
6184 6135
   void set_led_color(const uint8_t r, const uint8_t g, const uint8_t b) {
@@ -7610,7 +7561,7 @@ inline void gcode_M503() {
7610 7561
     SERIAL_ECHOLNPAIR(MSG_DUPLICATION_MODE, extruder_duplication_enabled ? MSG_ON : MSG_OFF);
7611 7562
   }
7612 7563
 
7613
-#endif // M605
7564
+#endif // DUAL_NOZZLE_DUPLICATION_MODE
7614 7565
 
7615 7566
 #if ENABLED(LIN_ADVANCE)
7616 7567
   /**
@@ -7637,7 +7588,99 @@ inline void gcode_M503() {
7637 7588
       if (ratio) SERIAL_ECHOLN(ratio); else SERIAL_ECHOLNPGM("Automatic");
7638 7589
     }
7639 7590
   }
7640
-#endif
7591
+#endif // LIN_ADVANCE
7592
+
7593
+#if ENABLED(HAVE_TMC2130)
7594
+
7595
+  static void tmc2130_print_current(const int mA, const char name) {
7596
+    SERIAL_CHAR(name);
7597
+    SERIAL_ECHOPGM(" axis driver current: ");
7598
+    SERIAL_ECHOLN(mA);
7599
+  }
7600
+  static void tmc2130_set_current(const int mA, TMC2130Stepper &st, const char name) {
7601
+    tmc2130_print_current(mA, name);
7602
+    st.setCurrent(mA, 0.11, 0.5);
7603
+  }
7604
+  static void tmc2130_get_current(TMC2130Stepper &st, const char name) {
7605
+    tmc2130_print_current(st.getCurrent(), name);
7606
+  }
7607
+  static void tmc2130_report_otpw(TMC2130Stepper &st, const char name) {
7608
+    SERIAL_CHAR(name);
7609
+    SERIAL_ECHOPGM(" axis temperature prewarn triggered: ");
7610
+    serialprintPGM(st.getOTPW() ? PSTR("true") : PSTR("false"));
7611
+  }
7612
+  static void tmc2130_clear_otpw(TMC2130Stepper &st, const char name) {
7613
+    st.clear_otpw();
7614
+    SERIAL_CHAR(name);
7615
+    SERIAL_ECHOLNPGM(" prewarn flag cleared");
7616
+  }
7617
+
7618
+  /**
7619
+   * M906: Set motor current in milliamps using axis codes X, Y, Z, E
7620
+   *
7621
+   * Report driver currents when no axis specified
7622
+   */
7623
+  inline void gcode_M906() {
7624
+    uint16_t values[NUM_AXIS];
7625
+    LOOP_XYZE(i)
7626
+      values[i] = code_seen(axis_codes[i]) ? code_value_int() : 0;
7627
+
7628
+    #if ENABLED(X_IS_TMC2130)
7629
+      if (values[X_AXIS]) tmc2130_set_current(values[X_AXIS], stepperX, 'X');
7630
+      else tmc2130_get_current(stepperX, 'X');
7631
+    #endif
7632
+    #if ENABLED(Y_IS_TMC2130)
7633
+      if (values[Y_AXIS]) tmc2130_set_current(values[Y_AXIS], stepperY, 'Y');
7634
+      else tmc2130_get_current(stepperY, 'Y');
7635
+    #endif
7636
+    #if ENABLED(Z_IS_TMC2130)
7637
+      if (values[Z_AXIS]) tmc2130_set_current(values[Z_AXIS], stepperZ, 'Z');
7638
+      else tmc2130_get_current(stepperZ, 'Z');
7639
+    #endif
7640
+    #if ENABLED(E0_IS_TMC2130)
7641
+      if (values[E_AXIS]) tmc2130_set_current(values[E_AXIS], stepperE0, 'E');
7642
+      else tmc2130_get_current(stepperE0, 'E');
7643
+    #endif
7644
+  }
7645
+
7646
+  /**
7647
+   * M911: Report TMC2130 stepper driver overtemperature pre-warn flag
7648
+   * The flag is held by the library and persist until manually cleared by M912
7649
+   */
7650
+  inline void gcode_M911() {
7651
+    #if ENABLED(X_IS_TMC2130)
7652
+      tmc2130_report_otpw(stepperX, 'X');
7653
+    #endif
7654
+    #if ENABLED(Y_IS_TMC2130)
7655
+      tmc2130_report_otpw(stepperY, 'Y');
7656
+    #endif
7657
+    #if ENABLED(Z_IS_TMC2130)
7658
+      tmc2130_report_otpw(stepperZ, 'Z');
7659
+    #endif
7660
+    #if ENABLED(E0_IS_TMC2130)
7661
+      tmc2130_report_otpw(stepperE0, 'E');
7662
+    #endif
7663
+  }
7664
+
7665
+  /**
7666
+   * M912: Clear TMC2130 stepper driver overtemperature pre-warn flag held by the library
7667
+   */
7668
+  inline void gcode_M912() {
7669
+    #if ENABLED(X_IS_TMC2130)
7670
+      if (code_seen('X')) tmc2130_clear_otpw(stepperX, 'X');
7671
+    #endif
7672
+    #if ENABLED(Y_IS_TMC2130)
7673
+      if (code_seen('Y')) tmc2130_clear_otpw(stepperY, 'Y');
7674
+    #endif
7675
+    #if ENABLED(Z_IS_TMC2130)
7676
+      if (code_seen('Z')) tmc2130_clear_otpw(stepperZ, 'Z');
7677
+    #endif
7678
+    #if ENABLED(E0_IS_TMC2130)
7679
+      if (code_seen('E')) tmc2130_clear_otpw(stepperE0, 'E');
7680
+    #endif
7681
+  }
7682
+
7683
+#endif // HAVE_TMC2130
7641 7684
 
7642 7685
 /**
7643 7686
  * M907: Set digital trimpot motor current using axis codes X, Y, Z, E, B, S
@@ -8600,12 +8643,6 @@ void process_next_command() {
8600 8643
         gcode_M121();
8601 8644
         break;
8602 8645
 
8603
-      #if ENABLED(HAVE_TMC2130DRIVER)
8604
-        case 122: // M122: Diagnose, used to debug TMC2130
8605
-          gcode_M122();
8606
-          break;
8607
-      #endif
8608
-
8609 8646
       #if ENABLED(ULTIPANEL)
8610 8647
 
8611 8648
         case 145: // M145: Set material heatup parameters
@@ -8882,6 +8919,12 @@ void process_next_command() {
8882 8919
           break;
8883 8920
       #endif
8884 8921
 
8922
+      #if ENABLED(HAVE_TMC2130)
8923
+        case 906: // M906: Set motor current in milliamps using axis codes X, Y, Z, E
8924
+          gcode_M906();
8925
+          break;
8926
+      #endif
8927
+
8885 8928
       case 907: // M907: Set digital trimpot motor current using axis codes.
8886 8929
         gcode_M907();
8887 8930
         break;
@@ -8906,6 +8949,16 @@ void process_next_command() {
8906 8949
 
8907 8950
       #endif // HAS_DIGIPOTSS || DAC_STEPPER_CURRENT
8908 8951
 
8952
+      #if ENABLED(HAVE_TMC2130)
8953
+        case 911: // M911: Report TMC2130 prewarn triggered flags
8954
+          gcode_M911();
8955
+          break;
8956
+
8957
+        case 912: // M911: Clear TMC2130 prewarn triggered flags
8958
+          gcode_M912();
8959
+          break;
8960
+      #endif
8961
+
8909 8962
       #if HAS_MICROSTEPS
8910 8963
 
8911 8964
         case 350: // M350: Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers.
@@ -10169,6 +10222,65 @@ void disable_all_steppers() {
10169 10222
   disable_e3();
10170 10223
 }
10171 10224
 
10225
+#if ENABLED(AUTOMATIC_CURRENT_CONTROL)
10226
+
10227
+  void automatic_current_control(const TMC2130Stepper &st) {
10228
+    #if CURRENT_STEP > 0
10229
+      const bool is_otpw = st.checkOT(), // Check otpw even if we don't adjust. Allows for flag inspection.
10230
+                 is_otpw_triggered = st.getOTPW();
10231
+
10232
+      if (!is_otpw && !is_otpw_triggered) {
10233
+        // OTPW bit not triggered yet -> Increase current
10234
+        const uint16_t current = st.getCurrent() + CURRENT_STEP;
10235
+        if (current <= AUTO_ADJUST_MAX) st.SilentStepStick2130(current);
10236
+      }
10237
+      else if (is_otpw && is_otpw_triggered) {
10238
+        // OTPW bit triggered, triggered flag raised -> Decrease current
10239
+        st.SilentStepStick2130((float)st.getCurrent() - CURRENT_STEP);
10240
+      }
10241
+      // OTPW bit cleared (we've cooled down), triggered flag still raised until manually cleared -> Do nothing, we're good
10242
+    #endif
10243
+  }
10244
+
10245
+  void checkOverTemp() {
10246
+    static millis_t next_cOT = 0;
10247
+    if (ELAPSED(millis(), next_cOT)) {
10248
+      next_cOT = millis() + 5000;
10249
+      #if ENABLED(X_IS_TMC2130)
10250
+        automatic_current_control(stepperX);
10251
+      #endif
10252
+      #if ENABLED(Y_IS_TMC2130)
10253
+        automatic_current_control(stepperY);
10254
+      #endif
10255
+      #if ENABLED(Z_IS_TMC2130)
10256
+        automatic_current_control(stepperZ);
10257
+      #endif
10258
+      #if ENABLED(X2_IS_TMC2130)
10259
+        automatic_current_control(stepperX2);
10260
+      #endif
10261
+      #if ENABLED(Y2_IS_TMC2130)
10262
+        automatic_current_control(stepperY2);
10263
+      #endif
10264
+      #if ENABLED(Z2_IS_TMC2130)
10265
+        automatic_current_control(stepperZ2);
10266
+      #endif
10267
+      #if ENABLED(E0_IS_TMC2130)
10268
+        automatic_current_control(stepperE0);
10269
+      #endif
10270
+      #if ENABLED(E1_IS_TMC2130)
10271
+        automatic_current_control(stepperE1);
10272
+      #endif
10273
+      #if ENABLED(E2_IS_TMC2130)
10274
+        automatic_current_control(stepperE2);
10275
+      #endif
10276
+      #if ENABLED(E3_IS_TMC2130)
10277
+        automatic_current_control(stepperE3);
10278
+      #endif
10279
+    }
10280
+  }
10281
+
10282
+#endif // AUTOMATIC_CURRENT_CONTROL
10283
+
10172 10284
 /**
10173 10285
  * Manage several activities:
10174 10286
  *  - Check for Filament Runout
@@ -10360,6 +10472,10 @@ void manage_inactivity(bool ignore_stepper_queue/*=false*/) {
10360 10472
     handle_status_leds();
10361 10473
   #endif
10362 10474
 
10475
+  #if ENABLED(AUTOMATIC_CURRENT_CONTROL)
10476
+    checkOverTemp();
10477
+  #endif
10478
+
10363 10479
   planner.check_axes_activity();
10364 10480
 }
10365 10481
 

+ 214
- 8
Marlin/configuration_store.cpp View File

@@ -36,13 +36,13 @@
36 36
  *
37 37
  */
38 38
 
39
-#define EEPROM_VERSION "V29"
39
+#define EEPROM_VERSION "V30"
40 40
 
41 41
 // Change EEPROM version if these are changed:
42 42
 #define EEPROM_OFFSET 100
43 43
 
44 44
 /**
45
- * V29 EEPROM Layout:
45
+ * V30 EEPROM Layout:
46 46
  *
47 47
  *  100  Version                                   (char x4)
48 48
  *  104  EEPROM Checksum                           (uint16_t)
@@ -128,8 +128,20 @@
128 128
  *  509  M200 D    volumetric_enabled               (bool)
129 129
  *  510  M200 T D  filament_size                    (float x4) (T0..3)
130 130
  *
131
- *  526                                Minimum end-point
132
- * 1847 (526 + 36 + 9 + 288 + 988)     Maximum end-point
131
+ * TMC2130:                                         20 bytes
132
+ *  526  M906 X    TMC2130  X-stepper current       (uint16_t)
133
+ *  528  M906 Y    TMC2130  Y-stepper current       (uint16_t)
134
+ *  530  M906 Z    TMC2130  Z-stepper current       (uint16_t)
135
+ *  532  M906 X2   TMC2130 X2-stepper current       (uint16_t)
136
+ *  534  M906 Y2   TMC2130 Y2-stepper current       (uint16_t)
137
+ *  536  M906 Z2   TMC2130 Z2-stepper current       (uint16_t)
138
+ *  538  M906 E0   TMC2130 E0-stepper current       (uint16_t)
139
+ *  540  M906 E1   TMC2130 E1-stepper current       (uint16_t)
140
+ *  542  M906 E2   TMC2130 E2-stepper current       (uint16_t)
141
+ *  544  M906 E3   TMC2130 E3-stepper current       (uint16_t)
142
+ *
143
+ *  546                                Minimum end-point
144
+ * 1867 (546 + 36 + 9 + 288 + 988)     Maximum end-point
133 145
  *
134 146
  */
135 147
 #include "Marlin.h"
@@ -144,6 +156,10 @@
144 156
   #include "mesh_bed_leveling.h"
145 157
 #endif
146 158
 
159
+#if ENABLED(HAVE_TMC2130)
160
+  #include "stepper_indirection.h"
161
+#endif
162
+
147 163
 #if ENABLED(ABL_BILINEAR_SUBDIVISION)
148 164
   extern void bed_level_virt_interpolate();
149 165
 #endif
@@ -432,10 +448,78 @@ void Config_Postprocess() {
432 448
       EEPROM_WRITE(dummy);
433 449
     }
434 450
 
451
+    // Save TCM2130 Configuration, and placeholder values
452
+    uint16_t val;
453
+    #if ENABLED(HAVE_TMC2130)
454
+      #if ENABLED(X_IS_TMC2130)
455
+        val = stepperX.getCurrent();
456
+      #else
457
+        val = 0;
458
+      #endif
459
+      EEPROM_WRITE(val);
460
+      #if ENABLED(Y_IS_TMC2130)
461
+        val = stepperY.getCurrent();
462
+      #else
463
+        val = 0;
464
+      #endif
465
+      EEPROM_WRITE(val);
466
+      #if ENABLED(Z_IS_TMC2130)
467
+        val = stepperZ.getCurrent();
468
+      #else
469
+        val = 0;
470
+      #endif
471
+      EEPROM_WRITE(val);
472
+      #if ENABLED(X2_IS_TMC2130)
473
+        val = stepperX2.getCurrent();
474
+      #else
475
+        val = 0;
476
+      #endif
477
+      EEPROM_WRITE(val);
478
+      #if ENABLED(Y2_IS_TMC2130)
479
+        val = stepperY2.getCurrent();
480
+      #else
481
+        val = 0;
482
+      #endif
483
+      EEPROM_WRITE(val);
484
+      #if ENABLED(Z2_IS_TMC2130)
485
+        val = stepperZ2.getCurrent();
486
+      #else
487
+        val = 0;
488
+      #endif
489
+      EEPROM_WRITE(val);
490
+      #if ENABLED(E0_IS_TMC2130)
491
+        val = stepperE0.getCurrent();
492
+      #else
493
+        val = 0;
494
+      #endif
495
+      EEPROM_WRITE(val);
496
+      #if ENABLED(E1_IS_TMC2130)
497
+        val = stepperE1.getCurrent();
498
+      #else
499
+        val = 0;
500
+      #endif
501
+      EEPROM_WRITE(val);
502
+      #if ENABLED(E2_IS_TMC2130)
503
+        val = stepperE2.getCurrent();
504
+      #else
505
+        val = 0;
506
+      #endif
507
+      EEPROM_WRITE(val);
508
+      #if ENABLED(E3_IS_TMC2130)
509
+        val = stepperE3.getCurrent();
510
+      #else
511
+        val = 0;
512
+      #endif
513
+      EEPROM_WRITE(val);
514
+    #else
515
+      val = 0;
516
+      for (uint8_t q = 0; q < 10; ++q) EEPROM_WRITE(val);
517
+    #endif
518
+
435 519
     if (!eeprom_write_error) {
436 520
 
437
-      uint16_t final_checksum = eeprom_checksum,
438
-               eeprom_size = eeprom_index;
521
+      const uint16_t final_checksum = eeprom_checksum,
522
+                     eeprom_size = eeprom_index;
439 523
 
440 524
       // Write the EEPROM header
441 525
       eeprom_index = EEPROM_OFFSET;
@@ -684,6 +768,52 @@ void Config_Postprocess() {
684 768
         if (q < COUNT(filament_size)) filament_size[q] = dummy;
685 769
       }
686 770
 
771
+      uint16_t val;
772
+      #if ENABLED(HAVE_TMC2130)
773
+        EEPROM_READ(val);
774
+        #if ENABLED(X_IS_TMC2130)
775
+          stepperX.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
776
+        #endif
777
+        EEPROM_READ(val);
778
+        #if ENABLED(Y_IS_TMC2130)
779
+          stepperY.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
780
+        #endif
781
+        EEPROM_READ(val);
782
+        #if ENABLED(Z_IS_TMC2130)
783
+          stepperZ.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
784
+        #endif
785
+        EEPROM_READ(val);
786
+        #if ENABLED(X2_IS_TMC2130)
787
+          stepperX2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
788
+        #endif
789
+        EEPROM_READ(val);
790
+        #if ENABLED(Y2_IS_TMC2130)
791
+          stepperY2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
792
+        #endif
793
+        EEPROM_READ(val);
794
+        #if ENABLED(Z2_IS_TMC2130)
795
+          stepperZ2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
796
+        #endif
797
+        EEPROM_READ(val);
798
+        #if ENABLED(E0_IS_TMC2130)
799
+          stepperE0.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
800
+        #endif
801
+        EEPROM_READ(val);
802
+        #if ENABLED(E1_IS_TMC2130)
803
+          stepperE1.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
804
+        #endif
805
+        EEPROM_READ(val);
806
+        #if ENABLED(E2_IS_TMC2130)
807
+          stepperE2.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
808
+        #endif
809
+        EEPROM_READ(val);
810
+        #if ENABLED(E3_IS_TMC2130)
811
+          stepperE3.setCurrent(val, R_SENSE, HOLD_MULTIPLIER);
812
+        #endif
813
+      #else
814
+        for (uint8_t q = 0; q < 10; q++) EEPROM_READ(val);
815
+      #endif
816
+
687 817
       if (eeprom_checksum == stored_checksum) {
688 818
         if (eeprom_read_error)
689 819
           Config_ResetDefault();
@@ -852,6 +982,39 @@ void Config_ResetDefault() {
852 982
     #endif
853 983
   );
854 984
 
985
+  #if ENABLED(HAVE_TMC2130)
986
+    #if ENABLED(X_IS_TMC2130)
987
+      stepperX.setCurrent(X_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
988
+    #endif
989
+    #if ENABLED(Y_IS_TMC2130)
990
+      stepperY.setCurrent(Y_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
991
+    #endif
992
+    #if ENABLED(Z_IS_TMC2130)
993
+      stepperZ.setCurrent(Z_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
994
+    #endif
995
+    #if ENABLED(X2_IS_TMC2130)
996
+      stepperX2.setCurrent(X2_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
997
+    #endif
998
+    #if ENABLED(Y2_IS_TMC2130)
999
+      stepperY2.setCurrent(Y2_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1000
+    #endif
1001
+    #if ENABLED(Z2_IS_TMC2130)
1002
+      stepperZ2.setCurrent(Z2_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1003
+    #endif
1004
+    #if ENABLED(E0_IS_TMC2130)
1005
+      stepperE0.setCurrent(E0_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1006
+    #endif
1007
+    #if ENABLED(E1_IS_TMC2130)
1008
+      stepperE1.setCurrent(E1_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1009
+    #endif
1010
+    #if ENABLED(E2_IS_TMC2130)
1011
+      stepperE2.setCurrent(E2_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1012
+    #endif
1013
+    #if ENABLED(E3_IS_TMC2130)
1014
+      stepperE3.setCurrent(E3_MAX_CURRENT, R_SENSE, HOLD_MULTIPLIER);
1015
+    #endif
1016
+  #endif
1017
+
855 1018
   Config_Postprocess();
856 1019
 
857 1020
   SERIAL_ECHO_START;
@@ -1184,14 +1347,57 @@ void Config_ResetDefault() {
1184 1347
      * Auto Bed Leveling
1185 1348
      */
1186 1349
     #if HAS_BED_PROBE
1350
+      CONFIG_ECHO_START;
1187 1351
       if (!forReplay) {
1188
-        CONFIG_ECHO_START;
1189 1352
         SERIAL_ECHOLNPGM("Z-Probe Offset (mm):");
1353
+        CONFIG_ECHO_START;
1190 1354
       }
1191
-      CONFIG_ECHO_START;
1192 1355
       SERIAL_ECHOPAIR("  M851 Z", zprobe_zoffset);
1193 1356
       SERIAL_EOL;
1194 1357
     #endif
1358
+
1359
+    /**
1360
+     * TMC2130 stepper driver current
1361
+     */
1362
+    #if ENABLED(HAVE_TMC2130)
1363
+      CONFIG_ECHO_START;
1364
+      if (!forReplay) {
1365
+        SERIAL_ECHOLNPGM("Stepper driver current:");
1366
+        CONFIG_ECHO_START;
1367
+      }
1368
+      SERIAL_ECHO("  M906");
1369
+      #if ENABLED(X_IS_TMC2130)
1370
+        SERIAL_ECHOPAIR(" X", stepperX.getCurrent());
1371
+      #endif
1372
+      #if ENABLED(Y_IS_TMC2130)
1373
+        SERIAL_ECHOPAIR(" Y", stepperY.getCurrent());
1374
+      #endif
1375
+      #if ENABLED(Z_IS_TMC2130)
1376
+        SERIAL_ECHOPAIR(" Z", stepperZ.getCurrent());
1377
+      #endif
1378
+      #if ENABLED(X2_IS_TMC2130)
1379
+        SERIAL_ECHOPAIR(" X2", stepperX2.getCurrent());
1380
+      #endif
1381
+      #if ENABLED(Y2_IS_TMC2130)
1382
+        SERIAL_ECHOPAIR(" Y2", stepperY2.getCurrent());
1383
+      #endif
1384
+      #if ENABLED(Z2_IS_TMC2130)
1385
+        SERIAL_ECHOPAIR(" Z2", stepperZ2.getCurrent());
1386
+      #endif
1387
+      #if ENABLED(E0_IS_TMC2130)
1388
+        SERIAL_ECHOPAIR(" E0", stepperE0.getCurrent());
1389
+      #endif
1390
+      #if ENABLED(E1_IS_TMC2130)
1391
+        SERIAL_ECHOPAIR(" E1", stepperE1.getCurrent());
1392
+      #endif
1393
+      #if ENABLED(E2_IS_TMC2130)
1394
+        SERIAL_ECHOPAIR(" E2", stepperE2.getCurrent());
1395
+      #endif
1396
+      #if ENABLED(E3_IS_TMC2130)
1397
+        SERIAL_ECHOPAIR(" E3", stepperE3.getCurrent());
1398
+      #endif
1399
+      SERIAL_EOL;
1400
+    #endif
1195 1401
   }
1196 1402
 
1197 1403
 #endif // !DISABLE_M503

+ 1
- 1
Marlin/stepper.cpp View File

@@ -894,7 +894,7 @@ void Stepper::init() {
894 894
   #endif
895 895
 
896 896
   // Init TMC2130 Steppers
897
-  #if ENABLED(HAVE_TMC2130DRIVER)
897
+  #if ENABLED(HAVE_TMC2130)
898 898
     tmc2130_init();
899 899
   #endif
900 900
 

+ 75
- 403
Marlin/stepper_indirection.cpp View File

@@ -21,25 +21,15 @@
21 21
  */
22 22
 
23 23
 /**
24
-  stepper_indirection.c - stepper motor driver indirection
25
-  to allow some stepper functions to be done via SPI/I2c instead of direct pin manipulation
26
-  Part of Marlin
27
-
28
-  Copyright (c) 2015 Dominik Wenger
29
-
30
-  Marlin is free software: you can redistribute it and/or modify
31
-  it under the terms of the GNU General Public License as published by
32
-  the Free Software Foundation, either version 3 of the License, or
33
-  (at your option) any later version.
34
-
35
-  Marlin is distributed in the hope that it will be useful,
36
-  but WITHOUT ANY WARRANTY; without even the implied warranty of
37
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38
-  GNU General Public License for more details.
39
-
40
-  You should have received a copy of the GNU General Public License
41
-  along with Marlin.  If not, see <http://www.gnu.org/licenses/>.
42
-*/
24
+ * stepper_indirection.cpp
25
+ *
26
+ * Stepper motor driver indirection to allow some stepper functions to
27
+ * be done via SPI/I2c instead of direct pin manipulation.
28
+ *
29
+ * Part of Marlin
30
+ *
31
+ * Copyright (c) 2015 Dominik Wenger
32
+ */
43 33
 
44 34
 #include "stepper_indirection.h"
45 35
 
@@ -53,41 +43,43 @@
53 43
   #include <SPI.h>
54 44
   #include <TMC26XStepper.h>
55 45
 
46
+  #define _TMC_DEFINE(ST) TMC26XStepper stepper##ST(200, ST##_ENABLE_PIN, ST##_STEP_PIN, ST##_DIR_PIN, ST##_MAX_CURRENT, ST##_SENSE_RESISTOR)
47
+
56 48
   #if ENABLED(X_IS_TMC)
57
-    TMC26XStepper stepperX(200, X_ENABLE_PIN, X_STEP_PIN, X_DIR_PIN, X_MAX_CURRENT, X_SENSE_RESISTOR);
49
+    _TMC_DEFINE(X);
58 50
   #endif
59 51
   #if ENABLED(X2_IS_TMC)
60
-    TMC26XStepper stepperX2(200, X2_ENABLE_PIN, X2_STEP_PIN, X2_DIR_PIN, X2_MAX_CURRENT, X2_SENSE_RESISTOR);
52
+    _TMC_DEFINE(X2);
61 53
   #endif
62 54
   #if ENABLED(Y_IS_TMC)
63
-    TMC26XStepper stepperY(200, Y_ENABLE_PIN, Y_STEP_PIN, Y_DIR_PIN, Y_MAX_CURRENT, Y_SENSE_RESISTOR);
55
+    _TMC_DEFINE(Y);
64 56
   #endif
65 57
   #if ENABLED(Y2_IS_TMC)
66
-    TMC26XStepper stepperY2(200, Y2_ENABLE_PIN, Y2_STEP_PIN, Y2_DIR_PIN, Y2_MAX_CURRENT, Y2_SENSE_RESISTOR);
58
+    _TMC_DEFINE(Y2);
67 59
   #endif
68 60
   #if ENABLED(Z_IS_TMC)
69
-    TMC26XStepper stepperZ(200, Z_ENABLE_PIN, Z_STEP_PIN, Z_DIR_PIN, Z_MAX_CURRENT, Z_SENSE_RESISTOR);
61
+    _TMC_DEFINE(Z);
70 62
   #endif
71 63
   #if ENABLED(Z2_IS_TMC)
72
-    TMC26XStepper stepperZ2(200, Z2_ENABLE_PIN, Z2_STEP_PIN, Z2_DIR_PIN, Z2_MAX_CURRENT, Z2_SENSE_RESISTOR);
64
+    _TMC_DEFINE(Z2);
73 65
   #endif
74 66
   #if ENABLED(E0_IS_TMC)
75
-    TMC26XStepper stepperE0(200, E0_ENABLE_PIN, E0_STEP_PIN, E0_DIR_PIN, E0_MAX_CURRENT, E0_SENSE_RESISTOR);
67
+    _TMC_DEFINE(E0);
76 68
   #endif
77 69
   #if ENABLED(E1_IS_TMC)
78
-    TMC26XStepper stepperE1(200, E1_ENABLE_PIN, E1_STEP_PIN, E1_DIR_PIN, E1_MAX_CURRENT, E1_SENSE_RESISTOR);
70
+    _TMC_DEFINE(E1);
79 71
   #endif
80 72
   #if ENABLED(E2_IS_TMC)
81
-    TMC26XStepper stepperE2(200, E2_ENABLE_PIN, E2_STEP_PIN, E2_DIR_PIN, E2_MAX_CURRENT, E2_SENSE_RESISTOR);
73
+    _TMC_DEFINE(E2);
82 74
   #endif
83 75
   #if ENABLED(E3_IS_TMC)
84
-    TMC26XStepper stepperE3(200, E3_ENABLE_PIN, E3_STEP_PIN, E3_DIR_PIN, E3_MAX_CURRENT, E3_SENSE_RESISTOR);
76
+    _TMC_DEFINE(E3);
85 77
   #endif
86 78
 
87 79
   #define _TMC_INIT(A) do{ \
88 80
     stepper##A.setMicrosteps(A##_MICROSTEPS); \
89 81
     stepper##A.start(); \
90
-  } while(0)
82
+  }while(0)
91 83
 
92 84
   void tmc_init() {
93 85
     #if ENABLED(X_IS_TMC)
@@ -127,394 +119,70 @@
127 119
 //
128 120
 // TMC2130 Driver objects and inits
129 121
 //
130
-#if ENABLED(HAVE_TMC2130DRIVER)
122
+#if ENABLED(HAVE_TMC2130)
131 123
 
132 124
   #include <SPI.h>
133
-  #include <Trinamic_TMC2130.h>
134
-
135
-  #if ENABLED(TMC2130_ADVANCED_CONFIGURATION)
125
+  #include <TMC2130Stepper.h>
136 126
 
137
-    #ifdef GLOBAL_I_SCALE_ANALOG
138
-      #define _2130_set_I_scale_analog(A) stepper##A.set_I_scale_analog(GLOBAL_I_SCALE_ANALOG)
139
-    #else
140
-      #define _2130_set_I_scale_analog(A) NOOP
141
-    #endif
142
-    #ifdef GLOBAL_INTERNAL_RSENSE
143
-      #define _2130_set_internal_Rsense(A) stepper##A.set_internal_Rsense(GLOBAL_INTERNAL_RSENSE)
144
-    #else
145
-      #define _2130_set_internal_Rsense(A) NOOP
146
-    #endif
147
-    #ifdef GLOBAL_EN_PWM_MODE
148
-      #define _2130_set_en_pwm_mode(A) stepper##A.set_en_pwm_mode(GLOBAL_EN_PWM_MODE)
149
-    #else
150
-      #define _2130_set_en_pwm_mode(A) NOOP
151
-    #endif
152
-    #ifdef GLOBAL_ENC_COMMUTATION
153
-      #define _2130_set_enc_commutation(A) stepper##A.set_enc_commutation(GLOBAL_ENC_COMMUTATION)
154
-    #else
155
-      #define _2130_set_enc_commutation(A) NOOP
156
-    #endif
157
-    #ifdef GLOBAL_SHAFT
158
-      #define _2130_set_shaft(A) stepper##A.set_shaft(GLOBAL_SHAFT)
159
-    #else
160
-      #define _2130_set_shaft(A) NOOP
161
-    #endif
162
-    #ifdef GLOBAL_DIAG0_ERROR
163
-      #define _2130_set_diag0_error(A) stepper##A.set_diag0_error(GLOBAL_DIAG0_ERROR)
164
-    #else
165
-      #define _2130_set_diag0_error(A) NOOP
166
-    #endif
167
-    #ifdef GLOBAL_DIAG0_OTPW
168
-      #define _2130_set_diag0_otpw(A) stepper##A.set_diag0_otpw(GLOBAL_DIAG0_OTPW)
169
-    #else
170
-      #define _2130_set_diag0_otpw(A) NOOP
171
-    #endif
172
-    #ifdef GLOBAL_DIAG0_STALL
173
-      #define _2130_set_diag0_stall(A) stepper##A.set_diag0_stall(GLOBAL_DIAG0_STALL)
174
-    #else
175
-      #define _2130_set_diag0_stall(A) NOOP
176
-    #endif
177
-    #ifdef GLOBAL_DIAG1_STALL
178
-      #define _2130_set_diag1_stall(A) stepper##A.set_diag1_stall(GLOBAL_DIAG1_STALL)
179
-    #else
180
-      #define _2130_set_diag1_stall(A) NOOP
181
-    #endif
182
-    #ifdef GLOBAL_DIAG1_INDEX
183
-      #define _2130_set_diag1_index(A) stepper##A.set_diag1_index(GLOBAL_DIAG1_INDEX)
184
-    #else
185
-      #define _2130_set_diag1_index(A) NOOP
186
-    #endif
187
-    #ifdef GLOBAL_DIAG1_ONSTATE
188
-      #define _2130_set_diag1_onstate(A) stepper##A.set_diag1_onstate(GLOBAL_DIAG1_ONSTATE)
189
-    #else
190
-      #define _2130_set_diag1_onstate(A) NOOP
191
-    #endif
192
-    #ifdef GLOBAL_DIAG1_ONSTATE
193
-      #define _2130_set_diag1_steps_skipped(A) stepper##A.set_diag1_steps_skipped(GLOBAL_DIAG1_ONSTATE)
194
-    #else
195
-      #define _2130_set_diag1_steps_skipped(A) NOOP
196
-    #endif
197
-    #ifdef GLOBAL_DIAG0_INT_PUSHPULL
198
-      #define _2130_set_diag0_int_pushpull(A) stepper##A.set_diag0_int_pushpull(GLOBAL_DIAG0_INT_PUSHPULL)
199
-    #else
200
-      #define _2130_set_diag0_int_pushpull(A) NOOP
201
-    #endif
202
-    #ifdef GLOBAL_DIAG1_INT_PUSHPULL
203
-      #define _2130_set_diag1_int_pushpull(A) stepper##A.set_diag1_int_pushpull(GLOBAL_DIAG1_INT_PUSHPULL)
204
-    #else
205
-      #define _2130_set_diag1_int_pushpull(A) NOOP
206
-    #endif
207
-    #ifdef GLOBAL_SMALL_HYSTERESIS
208
-      #define _2130_set_small_hysteresis(A) stepper##A.set_small_hysteresis(GLOBAL_SMALL_HYSTERESIS)
209
-    #else
210
-      #define _2130_set_small_hysteresis(A) NOOP
211
-    #endif
212
-    #ifdef GLOBAL_STOP_ENABLE
213
-      #define _2130_set_stop_enable(A) stepper##A.set_stop_enable(GLOBAL_STOP_ENABLE)
214
-    #else
215
-      #define _2130_set_stop_enable(A) NOOP
216
-    #endif
217
-    #ifdef GLOBAL_DIRECT_MODE
218
-      #define _2130_set_direct_mode(A) stepper##A.set_direct_mode(GLOBAL_DIRECT_MODE)
219
-    #else
220
-      #define _2130_set_direct_mode(A) NOOP
221
-    #endif
222
-    #if defined(GLOBAL_IHOLD) && defined(GLOBAL_IRUN) && defined(GLOBAL_IHOLDDELAY)
223
-      #define _2130_set_IHOLD_IRUN(A) stepper##A.set_IHOLD_IRUN(GLOBAL_IHOLD, GLOBAL_IRUN, GLOBAL_IHOLDDELAY)
224
-    #else
225
-      #define _2130_set_IHOLD_IRUN(A) NOOP
226
-    #endif
227
-    #ifdef GLOBAL_TPOWERDOWN
228
-      #define _2130_set_TPOWERDOWN(A) stepper##A.set_TPOWERDOWN(GLOBAL_TPOWERDOWN)
229
-    #else
230
-      #define _2130_set_TPOWERDOWN(A) NOOP
231
-    #endif
232
-    #ifdef GLOBAL_TPWMTHRS
233
-      #define _2130_set_TPWMTHRS(A) stepper##A.set_TPWMTHRS(GLOBAL_TPWMTHRS)
234
-    #else
235
-      #define _2130_set_TPWMTHRS(A) NOOP
236
-    #endif
237
-    #ifdef GLOBAL_TCOOLTHRS
238
-      #define _2130_set_TCOOLTHRS(A) stepper##A.set_TCOOLTHRS(GLOBAL_TCOOLTHRS)
239
-    #else
240
-      #define _2130_set_TCOOLTHRS(A) NOOP
241
-    #endif
242
-    #ifdef GLOBAL_THIGH
243
-      #define _2130_set_THIGH(A) stepper##A.set_THIGH(GLOBAL_THIGH)
244
-    #else
245
-      #define _2130_set_THIGH(A) NOOP
246
-    #endif
247
-    #ifdef GLOBAL_XDIRECT
248
-      #define _2130_set_XDIRECT(A) stepper##A.set_XDIRECT(GLOBAL_XDIRECT)
249
-    #else
250
-      #define _2130_set_XDIRECT(A) NOOP
251
-    #endif
252
-    #ifdef GLOBAL_VDCMIN
253
-      #define _2130_set_VDCMIN(A) stepper##A.set_VDCMIN(GLOBAL_VDCMIN)
254
-    #else
255
-      #define _2130_set_VDCMIN(A) NOOP
256
-    #endif
257
-    #ifdef GLOBAL_DEDGE
258
-      #define _2130_set_dedge(A) stepper##A.set_dedge(GLOBAL_DEDGE)
259
-    #else
260
-      #define _2130_set_dedge(A) NOOP
261
-    #endif
262
-    #ifdef GLOBAL_DISS2G
263
-      #define _2130_set_diss2g(A) stepper##A.set_diss2g(GLOBAL_DISS2G)
264
-    #else
265
-      #define _2130_set_diss2g(A) NOOP
266
-    #endif
267
-    #ifdef GLOBAL_INTPOL
268
-      #define _2130_set_intpol(A) stepper##A.set_intpol(GLOBAL_INTPOL)
269
-    #else
270
-      #define _2130_set_intpol(A) NOOP
271
-    #endif
272
-    #ifdef GLOBAL_MRES
273
-      #define _2130_set_mres(A) stepper##A.set_mres(GLOBAL_MRES)
274
-    #else
275
-      #define _2130_set_mres(A) NOOP
276
-    #endif
277
-    #ifdef GLOBAL_SYNC
278
-      #define _2130_set_sync(A) stepper##A.set_sync(GLOBAL_SYNC)
279
-    #else
280
-      #define _2130_set_sync(A) NOOP
281
-    #endif
282
-    #ifdef GLOBAL_VHIGHCHM
283
-      #define _2130_set_vhighchm(A) stepper##A.set_vhighchm(GLOBAL_VHIGHCHM)
284
-    #else
285
-      #define _2130_set_vhighchm(A) NOOP
286
-    #endif
287
-    #ifdef GLOBAL_VHIGHFS
288
-      #define _2130_set_vhighfs(A) stepper##A.set_vhighfs(GLOBAL_VHIGHFS)
289
-    #else
290
-      #define _2130_set_vhighfs(A) NOOP
291
-    #endif
292
-    #ifdef GLOBAL_VSENSE
293
-      #define _2130_set_vsense(A) stepper##A.set_vsense(GLOBAL_VSENSE)
294
-    #else
295
-      #define _2130_set_vsense(A) NOOP
296
-    #endif
297
-    #ifdef GLOBAL_TBL
298
-      #define _2130_set_tbl(A) stepper##A.set_tbl(GLOBAL_TBL)
299
-    #else
300
-      #define _2130_set_tbl(A) NOOP
301
-    #endif
302
-    #ifdef GLOBAL_CHM
303
-      #define _2130_set_chm(A) stepper##A.set_chm(GLOBAL_CHM)
304
-    #else
305
-      #define _2130_set_chm(A) NOOP
306
-    #endif
307
-    #ifdef GLOBAL_RNDTF
308
-      #define _2130_set_rndtf(A) stepper##A.set_rndtf(GLOBAL_RNDTF)
309
-    #else
310
-      #define _2130_set_rndtf(A) NOOP
311
-    #endif
312
-    #ifdef GLOBAL_DISFDCC
313
-      #define _2130_set_disfdcc(A) stepper##A.set_disfdcc(GLOBAL_DISFDCC)
314
-    #else
315
-      #define _2130_set_disfdcc(A) NOOP
316
-    #endif
317
-    #ifdef GLOBAL_FD
318
-      #define _2130_set_fd(A) stepper##A.set_fd(GLOBAL_FD)
319
-    #else
320
-      #define _2130_set_fd(A) NOOP
321
-    #endif
322
-    #ifdef GLOBAL_HEND
323
-      #define _2130_set_hend(A) stepper##A.set_hend(GLOBAL_HEND)
324
-    #else
325
-      #define _2130_set_hend(A) NOOP
326
-    #endif
327
-    #ifdef GLOBAL_HSTRT
328
-      #define _2130_set_hstrt(A) stepper##A.set_hstrt(GLOBAL_HSTRT)
329
-    #else
330
-      #define _2130_set_hstrt(A) NOOP
331
-    #endif
332
-    #ifdef GLOBAL_TOFF
333
-      #define _2130_set_toff(A) stepper##A.set_toff(GLOBAL_TOFF)
334
-    #else
335
-      #define _2130_set_toff(A) NOOP
336
-    #endif
337
-    #ifdef GLOBAL_SFILT
338
-      #define _2130_set_sfilt(A) stepper##A.set_sfilt(GLOBAL_SFILT)
339
-    #else
340
-      #define _2130_set_sfilt(A) NOOP
341
-    #endif
342
-    #ifdef GLOBAL_SGT
343
-      #define _2130_set_sgt(A) stepper##A.set_sgt(GLOBAL_SGT)
344
-    #else
345
-      #define _2130_set_sgt(A) NOOP
346
-    #endif
347
-    #ifdef GLOBAL_SEIMIN
348
-      #define _2130_set_seimin(A) stepper##A.set_seimin(GLOBAL_SEIMIN)
349
-    #else
350
-      #define _2130_set_seimin(A) NOOP
351
-    #endif
352
-    #ifdef GLOBAL_SEDN
353
-      #define _2130_set_sedn(A) stepper##A.set_sedn(GLOBAL_SEDN)
354
-    #else
355
-      #define _2130_set_sedn(A) NOOP
356
-    #endif
357
-    #ifdef GLOBAL_SEMAX
358
-      #define _2130_set_semax(A) stepper##A.set_semax(GLOBAL_SEMAX)
359
-    #else
360
-      #define _2130_set_semax(A) NOOP
361
-    #endif
362
-    #ifdef GLOBAL_SEUP
363
-      #define _2130_set_seup(A) stepper##A.set_seup(GLOBAL_SEUP)
364
-    #else
365
-      #define _2130_set_seup(A) NOOP
366
-    #endif
367
-    #ifdef GLOBAL_SEMIN
368
-      #define _2130_set_semin(A) stepper##A.set_semin(GLOBAL_SEMIN)
369
-    #else
370
-      #define _2130_set_semin(A) NOOP
371
-    #endif
372
-    #if defined(GLOBAL_DC_TIME) && defined(GLOBAL_DC_SG)
373
-      #define _2130_set_DCCTRL(A) stepper##A.set_DCCTRL(GLOBAL_DC_TIME, GLOBAL_DC_SG)
374
-    #else
375
-      #define _2130_set_DCCTRL(A) NOOP
376
-    #endif
377
-    #ifdef GLOBAL_FREEWHEEL
378
-      #define _2130_set_freewheel(A) stepper##A.set_freewheel(GLOBAL_FREEWHEEL)
379
-    #else
380
-      #define _2130_set_freewheel(A) NOOP
381
-    #endif
382
-    #ifdef GLOBAL_PWM_SYMMETRIC
383
-      #define _2130_set_pwm_symmetric(A) stepper##A.set_pwm_symmetric(GLOBAL_PWM_SYMMETRIC)
384
-    #else
385
-      #define _2130_set_pwm_symmetric(A) NOOP
386
-    #endif
387
-    #ifdef GLOBAL_PWM_AUTOSCALE
388
-      #define _2130_set_pwm_autoscale(A) stepper##A.set_pwm_autoscale(GLOBAL_PWM_AUTOSCALE)
389
-    #else
390
-      #define _2130_set_pwm_autoscale(A) NOOP
391
-    #endif
392
-    #ifdef GLOBAL_PWM_FREQ
393
-      #define _2130_set_pwm_freq(A) stepper##A.set_pwm_freq(GLOBAL_PWM_FREQ)
394
-    #else
395
-      #define _2130_set_pwm_freq(A) NOOP
396
-    #endif
397
-    #ifdef GLOBAL_PWM_GRAD
398
-      #define _2130_set_PWM_GRAD(A) stepper##A.set_PWM_GRAD(GLOBAL_PWM_GRAD)
399
-    #else
400
-      #define _2130_set_PWM_GRAD(A) NOOP
401
-    #endif
402
-    #ifdef GLOBAL_PWM_AMPL
403
-      #define _2130_set_PWM_AMPL(A) stepper##A.set_PWM_AMPL(GLOBAL_PWM_AMPL)
404
-    #else
405
-      #define _2130_set_PWM_AMPL(A) NOOP
406
-    #endif
407
-    #ifdef GLOBAL_ENCM_CTRL
408
-      #define _2130_set_ENCM_CTRL(A) stepper##A.set_ENCM_CTRL(GLOBAL_ENCM_CTRL)
409
-    #else
410
-      #define _2130_set_ENCM_CTRL(A) NOOP
411
-    #endif
412
-
413
-    #define _TMC2130_INIT(A) do{ \
414
-      stepper##A.init(); \
415
-      _2130_set_I_scale_analog(A); \
416
-      _2130_set_internal_Rsense(A); \
417
-      _2130_set_en_pwm_mode(A); \
418
-      _2130_set_enc_commutation(A); \
419
-      _2130_set_shaft(A); \
420
-      _2130_set_diag0_error(A); \
421
-      _2130_set_diag0_otpw(A); \
422
-      _2130_set_diag0_stall(A); \
423
-      _2130_set_diag1_stall(A); \
424
-      _2130_set_diag1_index(A); \
425
-      _2130_set_diag1_onstate(A); \
426
-      _2130_set_diag1_steps_skipped(A); \
427
-      _2130_set_diag0_int_pushpull(A); \
428
-      _2130_set_diag1_int_pushpull(A); \
429
-      _2130_set_small_hysteresis(A); \
430
-      _2130_set_stop_enable(A); \
431
-      _2130_set_direct_mode(A); \
432
-      _2130_set_IHOLD_IRUN(A); \
433
-      _2130_set_TPOWERDOWN(A); \
434
-      _2130_set_TPWMTHRS(A); \
435
-      _2130_set_TCOOLTHRS(A); \
436
-      _2130_set_THIGH(A); \
437
-      _2130_set_XDIRECT(A); \
438
-      _2130_set_VDCMIN(A); \
439
-      _2130_set_dedge(A); \
440
-      _2130_set_diss2g(A); \
441
-      _2130_set_intpol(A); \
442
-      _2130_set_mres(A); \
443
-      _2130_set_sync(A); \
444
-      _2130_set_vhighchm(A); \
445
-      _2130_set_vhighfs(A); \
446
-      _2130_set_vsense(A); \
447
-      _2130_set_tbl(A); \
448
-      _2130_set_chm(A); \
449
-      _2130_set_rndtf(A); \
450
-      _2130_set_disfdcc(A); \
451
-      _2130_set_fd(A); \
452
-      _2130_set_hend(A); \
453
-      _2130_set_hstrt(A); \
454
-      _2130_set_toff(A); \
455
-      _2130_set_sfilt(A); \
456
-      _2130_set_sgt(A); \
457
-      _2130_set_seimin(A); \
458
-      _2130_set_sedn(A); \
459
-      _2130_set_semax(A); \
460
-      _2130_set_seup(A); \
461
-      _2130_set_semin(A); \
462
-      _2130_set_DCCTRL(A); \
463
-      _2130_set_freewheel(A); \
464
-      _2130_set_pwm_symmetric(A); \
465
-      _2130_set_pwm_autoscale(A); \
466
-      _2130_set_pwm_freq(A); \
467
-      _2130_set_PWM_GRAD(A); \
468
-      _2130_set_PWM_AMPL(A); \
469
-      _2130_set_ENCM_CTRL(A); \
470
-    } while(0)
471
-
472
-  #else // !TMC2130_ADVANCED_CONFIGURATION
127
+  #define _TMC2130_DEFINE(ST) TMC2130Stepper stepper##ST(ST##_ENABLE_PIN, ST##_DIR_PIN, ST##_STEP_PIN, ST##_CHIP_SELECT)
473 128
 
474
-    #define _TMC2130_INIT(A) do{ \
475
-      stepper##A.init(); \
476
-      stepper##A.set_mres(A##_MRES); \
477
-      stepper##A.set_IHOLD_IRUN(A##_IHOLD, A##_IRUN, A##_IHOLDDELAY); \
478
-      stepper##A.set_I_scale_analog(A##_I_SCALE_ANALOG); \
479
-      stepper##A.set_tbl(A##_TBL); \
480
-      stepper##A.set_toff(A##_TOFF); \
481
-    } while(0)
482
-
483
-  #endif // TMC2130_ADVANCED_CONFIGURATION
484
-
485
-  // Stepper objects of TMC2310 steppers used
129
+  // Stepper objects of TMC2130 steppers used
486 130
   #if ENABLED(X_IS_TMC2130)
487
-    Trinamic_TMC2130 stepperX(X_CS_PIN);
131
+    _TMC2130_DEFINE(X);
488 132
   #endif
489 133
   #if ENABLED(X2_IS_TMC2130)
490
-    Trinamic_TMC2130 stepperX2(X2_CS_PIN);
134
+    _TMC2130_DEFINE(X2);
491 135
   #endif
492 136
   #if ENABLED(Y_IS_TMC2130)
493
-    Trinamic_TMC2130 stepperY(Y_CS_PIN);
137
+    _TMC2130_DEFINE(Y);
494 138
   #endif
495 139
   #if ENABLED(Y2_IS_TMC2130)
496
-    Trinamic_TMC2130 stepperY2(Y2_CS_PINR);
140
+    _TMC2130_DEFINE(Y2);
497 141
   #endif
498 142
   #if ENABLED(Z_IS_TMC2130)
499
-    Trinamic_TMC2130 stepperZ(Z_CS_PIN);
143
+    _TMC2130_DEFINE(Z);
500 144
   #endif
501 145
   #if ENABLED(Z2_IS_TMC2130)
502
-    Trinamic_TMC2130 stepperZ2(Z2_CS_PIN);
146
+    _TMC2130_DEFINE(Z2);
503 147
   #endif
504 148
   #if ENABLED(E0_IS_TMC2130)
505
-    Trinamic_TMC2130 stepperE0(E0_CS_PIN);
149
+    _TMC2130_DEFINE(E0);
506 150
   #endif
507 151
   #if ENABLED(E1_IS_TMC2130)
508
-    Trinamic_TMC2130 stepperE1(E1_CS_PIN);
152
+    _TMC2130_DEFINE(E1);
509 153
   #endif
510 154
   #if ENABLED(E2_IS_TMC2130)
511
-    Trinamic_TMC2130 stepperE2(E2_CS_PIN);
155
+    _TMC2130_DEFINE(E2);
512 156
   #endif
513 157
   #if ENABLED(E3_IS_TMC2130)
514
-    Trinamic_TMC2130 stepperE3(E3_CS_PIN);
158
+    _TMC2130_DEFINE(E3);
515 159
   #endif
516 160
 
161
+  // Use internal reference voltage for current calculations. This is the default.
162
+  // Following values from Trinamic's spreadsheet with values for a NEMA17 (42BYGHW609)
163
+  void tmc2130_init(TMC2130Stepper &st, const uint16_t max_current, const uint16_t microsteps) {
164
+    st.begin();
165
+    st.setCurrent(st.getCurrent(), R_SENSE, HOLD_MULTIPLIER);
166
+    st.microsteps(microsteps);
167
+    st.blank_time(24);
168
+    st.off_time(8);
169
+    st.interpolate(INTERPOLATE);
170
+    #if ENABLED(STEALTHCHOP)
171
+      st.stealthChop(1);
172
+    #endif
173
+    #if ENABLED(SENSORLESS_HOMING)
174
+      st.coolstep_min_speed(1048575);
175
+      st.sg_stall_value(STALL_THRESHOLD);
176
+      st.sg_filter(1);
177
+      st.diag1_stall(1);
178
+      st.diag1_active_high(1);
179
+    #endif
180
+  }
181
+
182
+  #define _TMC2130_INIT(ST) tmc2130_init(stepper##ST, ST##_MAX_CURRENT, ST##_MICROSTEPS)
183
+
517 184
   void tmc2130_init() {
185
+    delay(500); // Let power stabilize before configuring the steppers
518 186
     #if ENABLED(X_IS_TMC2130)
519 187
       _TMC2130_INIT(X);
520 188
     #endif
@@ -545,9 +213,11 @@
545 213
     #if ENABLED(E3_IS_TMC2130)
546 214
       _TMC2130_INIT(E3);
547 215
     #endif
216
+
217
+    TMC2130_ADV()
548 218
   }
219
+#endif // HAVE_TMC2130
549 220
 
550
-#endif // HAVE_TMC2130DRIVER
551 221
 
552 222
 //
553 223
 // L6470 Driver objects and inits
@@ -557,36 +227,38 @@
557 227
   #include <SPI.h>
558 228
   #include <L6470.h>
559 229
 
230
+  #define _L6470_DEFINE(ST) L6470 stepper##ST(ST##_ENABLE_PIN)
231
+
560 232
   // L6470 Stepper objects
561 233
   #if ENABLED(X_IS_L6470)
562
-    L6470 stepperX(X_ENABLE_PIN);
234
+    _L6470_DEFINE(X);
563 235
   #endif
564 236
   #if ENABLED(X2_IS_L6470)
565
-    L6470 stepperX2(X2_ENABLE_PIN);
237
+    _L6470_DEFINE(X2);
566 238
   #endif
567 239
   #if ENABLED(Y_IS_L6470)
568
-    L6470 stepperY(Y_ENABLE_PIN);
240
+    _L6470_DEFINE(Y);
569 241
   #endif
570 242
   #if ENABLED(Y2_IS_L6470)
571
-    L6470 stepperY2(Y2_ENABLE_PIN);
243
+    _L6470_DEFINE(Y2);
572 244
   #endif
573 245
   #if ENABLED(Z_IS_L6470)
574
-    L6470 stepperZ(Z_ENABLE_PIN);
246
+    _L6470_DEFINE(Z);
575 247
   #endif
576 248
   #if ENABLED(Z2_IS_L6470)
577
-    L6470 stepperZ2(Z2_ENABLE_PIN);
249
+    _L6470_DEFINE(Z2);
578 250
   #endif
579 251
   #if ENABLED(E0_IS_L6470)
580
-    L6470 stepperE0(E0_ENABLE_PIN);
252
+    _L6470_DEFINE(E0);
581 253
   #endif
582 254
   #if ENABLED(E1_IS_L6470)
583
-    L6470 stepperE1(E1_ENABLE_PIN);
255
+    _L6470_DEFINE(E1);
584 256
   #endif
585 257
   #if ENABLED(E2_IS_L6470)
586
-    L6470 stepperE2(E2_ENABLE_PIN);
258
+    _L6470_DEFINE(E2);
587 259
   #endif
588 260
   #if ENABLED(E3_IS_L6470)
589
-    L6470 stepperE3(E3_ENABLE_PIN);
261
+    _L6470_DEFINE(E3);
590 262
   #endif
591 263
 
592 264
   #define _L6470_INIT(A) do{ \

+ 22
- 24
Marlin/stepper_indirection.h View File

@@ -53,10 +53,8 @@
53 53
   void tmc_init();
54 54
 #endif
55 55
 
56
-// TMC130 drivers have STEP/DIR/ENABLE on normal pins
57
-#if ENABLED(HAVE_TMC2130DRIVER)
58
-  #include <SPI.h>
59
-  #include <Trinamic_TMC2130.h>
56
+#if ENABLED(HAVE_TMC2130)
57
+  #include <TMC2130Stepper.h>
60 58
   void tmc2130_init();
61 59
 #endif
62 60
 
@@ -83,8 +81,8 @@
83 81
     #define X_ENABLE_WRITE(STATE) stepperX.setEnabled(STATE)
84 82
     #define X_ENABLE_READ stepperX.isEnabled()
85 83
   #else
86
-    #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(X_IS_TMC2130)
87
-      extern Trinamic_TMC2130 stepperX;
84
+    #if ENABLED(HAVE_TMC2130) && ENABLED(X_IS_TMC2130)
85
+      extern TMC2130Stepper stepperX;
88 86
     #endif
89 87
     #define X_ENABLE_INIT SET_OUTPUT(X_ENABLE_PIN)
90 88
     #define X_ENABLE_WRITE(STATE) WRITE(X_ENABLE_PIN,STATE)
@@ -114,8 +112,8 @@
114 112
     #define Y_ENABLE_WRITE(STATE) stepperY.setEnabled(STATE)
115 113
     #define Y_ENABLE_READ stepperY.isEnabled()
116 114
   #else
117
-    #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(Y_IS_TMC2130)
118
-      extern Trinamic_TMC2130 stepperY;
115
+    #if ENABLED(HAVE_TMC2130) && ENABLED(Y_IS_TMC2130)
116
+      extern TMC2130Stepper stepperY;
119 117
     #endif
120 118
     #define Y_ENABLE_INIT SET_OUTPUT(Y_ENABLE_PIN)
121 119
     #define Y_ENABLE_WRITE(STATE) WRITE(Y_ENABLE_PIN,STATE)
@@ -145,8 +143,8 @@
145 143
     #define Z_ENABLE_WRITE(STATE) stepperZ.setEnabled(STATE)
146 144
     #define Z_ENABLE_READ stepperZ.isEnabled()
147 145
   #else
148
-    #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(Z_IS_TMC2130)
149
-      extern Trinamic_TMC2130 stepperZ;
146
+    #if ENABLED(HAVE_TMC2130) && ENABLED(Z_IS_TMC2130)
147
+      extern TMC2130Stepper stepperZ;
150 148
     #endif
151 149
     #define Z_ENABLE_INIT SET_OUTPUT(Z_ENABLE_PIN)
152 150
     #define Z_ENABLE_WRITE(STATE) WRITE(Z_ENABLE_PIN,STATE)
@@ -177,8 +175,8 @@
177 175
       #define X2_ENABLE_WRITE(STATE) stepperX2.setEnabled(STATE)
178 176
       #define X2_ENABLE_READ stepperX2.isEnabled()
179 177
     #else
180
-      #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(X2_IS_TMC2130)
181
-        extern Trinamic_TMC2130 stepperX2;
178
+      #if ENABLED(HAVE_TMC2130) && ENABLED(X2_IS_TMC2130)
179
+        extern TMC2130Stepper stepperX2;
182 180
       #endif
183 181
       #define X2_ENABLE_INIT SET_OUTPUT(X2_ENABLE_PIN)
184 182
       #define X2_ENABLE_WRITE(STATE) WRITE(X2_ENABLE_PIN,STATE)
@@ -210,8 +208,8 @@
210 208
       #define Y2_ENABLE_WRITE(STATE) stepperY2.setEnabled(STATE)
211 209
       #define Y2_ENABLE_READ stepperY2.isEnabled()
212 210
     #else
213
-      #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(Y2_IS_TMC2130)
214
-        extern Trinamic_TMC2130 stepperY2;
211
+      #if ENABLED(HAVE_TMC2130) && ENABLED(Y2_IS_TMC2130)
212
+        extern TMC2130Stepper stepperY2;
215 213
       #endif
216 214
       #define Y2_ENABLE_INIT SET_OUTPUT(Y2_ENABLE_PIN)
217 215
       #define Y2_ENABLE_WRITE(STATE) WRITE(Y2_ENABLE_PIN,STATE)
@@ -243,8 +241,8 @@
243 241
       #define Z2_ENABLE_WRITE(STATE) stepperZ2.setEnabled(STATE)
244 242
       #define Z2_ENABLE_READ stepperZ2.isEnabled()
245 243
     #else
246
-      #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(Z2_IS_TMC2130)
247
-        extern Trinamic_TMC2130 stepperZ2;
244
+      #if ENABLED(HAVE_TMC2130) && ENABLED(Z2_IS_TMC2130)
245
+        extern TMC2130Stepper stepperZ2;
248 246
       #endif
249 247
       #define Z2_ENABLE_INIT SET_OUTPUT(Z2_ENABLE_PIN)
250 248
       #define Z2_ENABLE_WRITE(STATE) WRITE(Z2_ENABLE_PIN,STATE)
@@ -275,8 +273,8 @@
275 273
     #define E0_ENABLE_WRITE(STATE) stepperE0.setEnabled(STATE)
276 274
     #define E0_ENABLE_READ stepperE0.isEnabled()
277 275
   #else
278
-    #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(E0_IS_TMC2130)
279
-      extern Trinamic_TMC2130 stepperE0;
276
+    #if ENABLED(HAVE_TMC2130) && ENABLED(E0_IS_TMC2130)
277
+      extern TMC2130Stepper stepperE0;
280 278
     #endif
281 279
     #define E0_ENABLE_INIT SET_OUTPUT(E0_ENABLE_PIN)
282 280
     #define E0_ENABLE_WRITE(STATE) WRITE(E0_ENABLE_PIN,STATE)
@@ -306,8 +304,8 @@
306 304
     #define E1_ENABLE_WRITE(STATE) stepperE1.setEnabled(STATE)
307 305
     #define E1_ENABLE_READ stepperE1.isEnabled()
308 306
   #else
309
-    #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(E1_IS_TMC2130)
310
-      extern Trinamic_TMC2130 stepperE1;
307
+    #if ENABLED(HAVE_TMC2130) && ENABLED(E1_IS_TMC2130)
308
+      extern TMC2130Stepper stepperE1;
311 309
     #endif
312 310
     #define E1_ENABLE_INIT SET_OUTPUT(E1_ENABLE_PIN)
313 311
     #define E1_ENABLE_WRITE(STATE) WRITE(E1_ENABLE_PIN,STATE)
@@ -337,8 +335,8 @@
337 335
     #define E2_ENABLE_WRITE(STATE) stepperE2.setEnabled(STATE)
338 336
     #define E2_ENABLE_READ stepperE2.isEnabled()
339 337
   #else
340
-    #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(E2_IS_TMC2130)
341
-      extern Trinamic_TMC2130 stepperE2;
338
+    #if ENABLED(HAVE_TMC2130) && ENABLED(E2_IS_TMC2130)
339
+      extern TMC2130Stepper stepperE2;
342 340
     #endif
343 341
     #define E2_ENABLE_INIT SET_OUTPUT(E2_ENABLE_PIN)
344 342
     #define E2_ENABLE_WRITE(STATE) WRITE(E2_ENABLE_PIN,STATE)
@@ -368,8 +366,8 @@
368 366
     #define E3_ENABLE_WRITE(STATE) stepperE3.setEnabled(STATE)
369 367
     #define E3_ENABLE_READ stepperE3.isEnabled()
370 368
   #else
371
-    #if ENABLED(HAVE_TMC2130DRIVER) && ENABLED(E3_IS_TMC2130)
372
-      extern Trinamic_TMC2130 stepperE3;
369
+    #if ENABLED(HAVE_TMC2130) && ENABLED(E3_IS_TMC2130)
370
+      extern TMC2130Stepper stepperE3;
373 371
     #endif
374 372
     #define E3_ENABLE_INIT SET_OUTPUT(E3_ENABLE_PIN)
375 373
     #define E3_ENABLE_WRITE(STATE) WRITE(E3_ENABLE_PIN,STATE)

Loading…
Cancel
Save