@@ -95,7 +95,7 @@ class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
9595 TMC (CS, RS, pinMOSI, pinMISO, pinSCK)
9696 {}
9797 TMCMarlin (const uint16_t CS, const float RS, const uint16_t pinMOSI, const uint16_t pinMISO, const uint16_t pinSCK, const uint8_t axis_chain_index) :
98- TMC (CS, RS, pinMOSI, pinMISO, pinSCK, axis_chain_index)
98+ TMC (CS, RS, pinMOSI, pinMISO, pinSCK, axis_chain_index)
9999 {}
100100 uint16_t rms_current () { return TMC::rms_current (); }
101101 void rms_current (uint16_t mA ) {
@@ -124,7 +124,7 @@ class TMCMarlin : public TMC, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
124124
125125 #if ENABLED(HYBRID_THRESHOLD)
126126 uint32_t get_pwm_thrs () {
127- return _tmc_thrs (this ->microsteps (), this -> TPWMTHRS (), planner.settings .axis_steps_per_mm [AXIS_ID]);
127+ return _tmc_thrs (this ->microsteps (), TMC:: TPWMTHRS (), planner.settings .axis_steps_per_mm [AXIS_ID]);
128128 }
129129 void set_pwm_thrs (const uint32_t thrs) {
130130 TMC::TPWMTHRS (_tmc_thrs (this ->microsteps (), thrs, planner.settings .axis_steps_per_mm [AXIS_ID]));
@@ -197,7 +197,7 @@ class TMCMarlin<TMC2208Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
197197
198198 #if ENABLED(HYBRID_THRESHOLD)
199199 uint32_t get_pwm_thrs () {
200- return _tmc_thrs (this ->microsteps (), this -> TPWMTHRS (), planner.settings .axis_steps_per_mm [AXIS_ID]);
200+ return _tmc_thrs (this ->microsteps (), TMC2208Stepper:: TPWMTHRS (), planner.settings .axis_steps_per_mm [AXIS_ID]);
201201 }
202202 void set_pwm_thrs (const uint32_t thrs) {
203203 TMC2208Stepper::TPWMTHRS (_tmc_thrs (this ->microsteps (), thrs, planner.settings .axis_steps_per_mm [AXIS_ID]));
@@ -249,13 +249,14 @@ class TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
249249
250250 #if ENABLED(HYBRID_THRESHOLD)
251251 uint32_t get_pwm_thrs () {
252- return _tmc_thrs (this ->microsteps (), this -> TPWMTHRS (), planner.settings .axis_steps_per_mm [AXIS_ID]);
252+ return _tmc_thrs (this ->microsteps (), TMC2209Stepper:: TPWMTHRS (), planner.settings .axis_steps_per_mm [AXIS_ID]);
253253 }
254254 void set_pwm_thrs (const uint32_t thrs) {
255255 TMC2209Stepper::TPWMTHRS (_tmc_thrs (this ->microsteps (), thrs, planner.settings .axis_steps_per_mm [AXIS_ID]));
256256 TERN_ (HAS_MARLINUI_MENU, this ->stored .hybrid_thrs = thrs);
257257 }
258258 #endif
259+
259260 #if USE_SENSORLESS
260261 int16_t homing_threshold () { return TMC2209Stepper::SGTHRS (); }
261262 void homing_threshold (int16_t sgt_val) {
@@ -278,6 +279,74 @@ class TMCMarlin<TMC2209Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC220
278279 sgt_max = 255 ;
279280};
280281
282+ template <char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
283+ class TMCMarlin <TMC2240Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC2240Stepper, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
284+ public:
285+ TMCMarlin (const uint16_t cs_pin, const uint8_t axis_chain_index) :
286+ TMC2240Stepper (cs_pin, axis_chain_index)
287+ {}
288+ TMCMarlin (const uint16_t CS, const uint16_t pinMOSI, const uint16_t pinMISO, const uint16_t pinSCK, const uint8_t axis_chain_index) :
289+ TMC2240Stepper (CS, pinMOSI, pinMISO, pinSCK, axis_chain_index )
290+ {}
291+
292+ // uint8_t get_address() { return slave_address; }
293+ uint16_t get_microstep_counter () { return microsteps (); }
294+
295+ uint16_t rms_current () { return TMC2240Stepper::rms_current (); }
296+ void rms_current (const uint16_t mA ) {
297+ this ->val_mA = mA ;
298+ TMC2240Stepper::rms_current (mA );
299+ }
300+ void rms_current (const uint16_t mA , const float mult) {
301+ this ->val_mA = mA ;
302+ TMC2240Stepper::rms_current (mA , mult);
303+ }
304+
305+ #if HAS_STEALTHCHOP
306+ bool get_stealthChop () { return this ->en_pwm_mode (); }
307+ bool get_stored_stealthChop () { return this ->stored .stealthChop_enabled ; }
308+ void refresh_stepping_mode () { this ->en_pwm_mode (this ->stored .stealthChop_enabled ); }
309+ void set_stealthChop (const bool stch) { this ->stored .stealthChop_enabled = stch; refresh_stepping_mode (); }
310+ bool toggle_stepping_mode () { set_stealthChop (!this ->stored .stealthChop_enabled ); return get_stealthChop (); }
311+ #endif
312+
313+ void set_chopper_times (const chopper_timing_t &ct) {
314+ TMC2240Stepper::toff (ct.toff );
315+ TMC2240Stepper::hysteresis_end (ct.hend );
316+ TMC2240Stepper::hysteresis_start (ct.hstrt );
317+ }
318+
319+ #if ENABLED(HYBRID_THRESHOLD)
320+ uint32_t get_pwm_thrs () {
321+ return _tmc_thrs (this ->microsteps (), TMC2240Stepper::TPWMTHRS (), planner.settings .axis_steps_per_mm [AXIS_ID]);
322+ }
323+ void set_pwm_thrs (const uint32_t thrs) {
324+ TMC2240Stepper::TPWMTHRS (_tmc_thrs (this ->microsteps (), thrs, planner.settings .axis_steps_per_mm [AXIS_ID]));
325+ TERN_ (HAS_MARLINUI_MENU, this ->stored .hybrid_thrs = thrs);
326+ }
327+ #endif
328+
329+ #if USE_SENSORLESS
330+ int16_t homing_threshold () { return TMC2240Stepper::sgt (); }
331+ void homing_threshold (int16_t sgt_val) {
332+ sgt_val = (int16_t )constrain (sgt_val, sgt_min, sgt_max);
333+ TMC2240Stepper::sgt (sgt_val);
334+ TERN_ (HAS_MARLINUI_MENU, this ->stored .homing_thrs = sgt_val);
335+ }
336+ #endif
337+
338+ void refresh_stepper_current () { rms_current (this ->val_mA ); }
339+ #if ENABLED(HYBRID_THRESHOLD)
340+ void refresh_hybrid_thrs () { set_pwm_thrs (this ->stored .hybrid_thrs ); }
341+ #endif
342+ #if USE_SENSORLESS
343+ void refresh_homing_thrs () { homing_threshold (this ->stored .homing_thrs ); }
344+ #endif
345+
346+ static constexpr int8_t sgt_min = -64 ,
347+ sgt_max = 63 ;
348+ };
349+
281350template <char AXIS_LETTER, char DRIVER_ID, AxisEnum AXIS_ID>
282351class TMCMarlin <TMC2660Stepper, AXIS_LETTER, DRIVER_ID, AXIS_ID> : public TMC2660Stepper, public TMCStorage<AXIS_LETTER, DRIVER_ID> {
283352 public:
0 commit comments