TMC5160 Driver
API reference
Loading...
Searching...
No Matches
tmc51x0.hpp
Go to the documentation of this file.
1
6#pragma once
7#include <cstdint>
8#include <string>
9
12#include "tmc51x0_result.hpp"
13#include "tmc51x0_types.hpp"
14#include "tmc51x0_version.h"
15
16namespace tmc51x0 {
17
119template <typename CommType> class TMC51x0 {
120public:
121 //================================================================================
122 // @name Core Initialization and Management
123 // @{
124 //================================================================================
125
151 explicit TMC51x0(CommType &comm, uint8_t daisy_chain_position = 0,
152 uint8_t uart_node_address = 0) noexcept
153 : comm_(comm), daisy_chain_position_(daisy_chain_position),
154 uart_node_address_(uart_node_address & 0xFF) {}
155
159 ~TMC51x0() noexcept {
160 // Disable motor on destruction
161 if (initialized_) {
162 motorControl.Disable();
163 }
164 }
165
170 [[nodiscard]] CommType &GetComm() noexcept { return comm_; }
171
203 bool verbose = true) noexcept;
204
209 uint32_t power_off_ms{20};
210 uint32_t power_on_settle_ms{20};
211 bool reinitialize{true};
212 bool prefer_power_cycle{true};
213 bool uart_assume_accessible_at_0{true};
216 bool verbose{true};
218 };
219
238
250 [[nodiscard]] DriverConfig GetDriverConfig() const noexcept {
251 return driver_config_;
252 }
253
266 [[nodiscard]] DriverConfig GetDriverConfig(bool &initialized) const noexcept {
267 initialized = initialized_;
268 return driver_config_;
269 }
270
271 // NOTE: Heap-heavy string diagnostics are intentionally only available when
272 // debug logging is enabled. For embedded targets, prefer LogConfigSummary()
273 // and friends (which can be compiled out).
274#ifndef TMC51X0_DISABLE_DEBUG_LOGGING
287 [[nodiscard]] std::string GetDriverConfigString() const noexcept;
288#endif // TMC51X0_DISABLE_DEBUG_LOGGING
289
290#ifndef TMC51X0_DISABLE_DEBUG_LOGGING
302 void LogConfigSummary(const DriverConfig &cfg, const char *tag = "TMC5160",
303 LogLevel lvl = LogLevel::Info) noexcept;
304
316 void LogDerivedInitSummary(const char *tag = "TMC5160",
317 LogLevel lvl = LogLevel::Info) noexcept;
318
332 void LogLiveStatusReport(const char *tag = "TMC5160",
333 LogLevel lvl = LogLevel::Info) noexcept;
334#endif // TMC51X0_DISABLE_DEBUG_LOGGING
335
358
366 [[nodiscard]] MotorCurrentDebugInfo GetMotorCurrentDebugInfo() const noexcept;
367
368 // @}
369
370 //================================================================================
371 // @name Subsystem Interfaces
372 // @{
373 //================================================================================
374
375 //================================================================================
376 //================================================================================
377 // RAMP CONTROL STRUCT
378 //================================================================================
379 //================================================================================
380
388 struct RampControl {
393 explicit RampControl(TMC51x0 &driver) noexcept : driver_(driver) {}
394
401
407
412 Result<bool> IsPositionReached() noexcept;
413
418 Result<bool> IsVelocityReached() noexcept;
419
425 Result<bool> IsStandstill() noexcept;
426
444 Result<void> SetTargetPosition(float value, Unit unit) noexcept;
445
461 Result<void> MoveRelative(float offset, Unit unit) noexcept;
462
476 Result<float> GetCurrentPosition(Unit unit) noexcept;
477
483 Result<float> GetTargetPosition(Unit unit) noexcept;
484
492 Result<int32_t> GetCurrentPositionMicrosteps() noexcept;
493
498 Result<int32_t> GetTargetPositionMicrosteps() noexcept;
499
507 Result<void> SetCurrentPosition(float value, Unit unit,
508 bool update_encoder = false) noexcept;
509
516 Result<void> SetMaxSpeed(float value, Unit unit) noexcept;
517
524 Result<void> SetAcceleration(float value, Unit unit) noexcept;
525
533 Result<void> SetAccelerations(float accel_val, float decel_val,
534 Unit unit) noexcept;
535
545 Result<void> SetDeceleration(float value, Unit unit) noexcept;
546
555 Result<void> SetRampSpeeds(float start_speed, float stop_speed,
556 float transition_speed, Unit unit) noexcept;
557
564 Result<float> GetCurrentSpeed(Unit unit) noexcept;
565
571 Result<bool> IsTargetReached() noexcept;
572
578 Result<bool> IsTargetVelocityReached() noexcept;
579
586 Result<void> Stop() noexcept;
587
599 Result<void> SetPowerDownDelay(uint8_t tpowerdown) noexcept;
600
617 Result<void> SetPowerDownDelayMs(float delay_ms) noexcept;
618
630 Result<void> SetZeroWaitTime(uint16_t tzerowait) noexcept;
631
652 Result<void> SetZeroWaitTimeMs(float delay_ms) noexcept;
653
662 Result<void> ConfigureRamp(const RampConfig &config) noexcept;
663
672 Result<void> SetFirstAcceleration(float a1, Unit unit) noexcept;
673
685 Result<void> SetFinalDeceleration(float d1, Unit unit) noexcept;
686
687 private:
688 TMC51x0 &driver_;
689
690 // Internal helper methods (used by unit-aware public methods)
699 Result<void> SetTargetPosition(int32_t position) noexcept;
700 Result<void> SetCurrentPosition(int32_t position,
701 bool update_encoder = false) noexcept;
702 } rampControl{*this};
703
704 //================================================================================
705 //================================================================================
706 // SWITCHES STRUCT
707 //================================================================================
708 //================================================================================
717 struct Switches {
718 explicit Switches(TMC51x0 &driver) noexcept : driver_(driver) {}
719
735
741
751
761
767 Result<void> SetLeftSwitchStopEnable(bool enable) noexcept;
768
774 Result<void> SetRightSwitchStopEnable(bool enable) noexcept;
775
782
789
799 Result<void> SetStopMode(ReferenceStopMode stop_mode) noexcept;
800
811 Result<bool> GetReferenceSwitchStatus(bool &right_active,
812 bool &left_enabled,
813 bool &right_enabled) noexcept;
814
824 Result<float> GetLatchedPosition(Unit unit) noexcept;
825
826 private:
828 } switches{*this};
829
830 //================================================================================
831 //================================================================================
832 // EVENTS STRUCT
833 //================================================================================
834 //================================================================================
839 struct Events {
840 explicit Events(TMC51x0 &driver) noexcept : driver_(driver) {}
841
851 Result<void> SetXCompare(float position, Unit unit) noexcept;
852
861 Result<float> GetXCompare(Unit unit) const noexcept;
862
868 Result<void> ClearRampStatus(uint32_t bits_to_clear) noexcept;
869
870 private:
872 } events{*this};
873
874 //================================================================================
875 //================================================================================
876 // MOTOR CONTROL STRUCT
877 //================================================================================
878 //================================================================================
879
892 explicit MotorControl(TMC51x0 &driver) noexcept : driver_(driver) {}
893
899
904 Result<void> Disable() noexcept;
905
912 Result<void> SetCurrent(uint8_t irun, uint8_t ihold) noexcept;
913
919 Result<void> ConfigureChopper(const ChopperConfig &config) noexcept;
920
935 Result<void> SetMicrostepResolution(
937 const MicrostepChangeOptions &opts = MicrostepChangeOptions{}) noexcept;
938
945
955 Result<void> ConfigureMotorCurrent(const MotorSpec &motor_spec) noexcept;
956
962 Result<void> SetGlobalScaler(uint16_t scaler) noexcept;
963
970
976 Result<void> ConfigureCoolStep(const CoolStepConfig &config) noexcept;
977
983 Result<void> ConfigureDcStep(const DcStepConfig &config) noexcept;
984
991 Result<void> SetMicrostepLookupTable(uint8_t index,
992 uint32_t value) noexcept;
993
1005 Result<void> SetMicrostepLookupTableSegmentation(
1006 uint8_t width_sel_0, uint8_t width_sel_1, uint8_t width_sel_2,
1007 uint8_t width_sel_3, uint8_t lut_seg_start1, uint8_t lut_seg_start2,
1008 uint8_t lut_seg_start3) noexcept;
1009
1015 Result<void> SetMicrostepLookupTableStart(uint16_t start_current) noexcept;
1016
1034 Result<void> ConfigureMicrostepLutPreset(MicrostepLutPreset preset) noexcept;
1035
1056 Result<void> ConfigureMicrostepLutCustom(
1057 const uint32_t lut[8], uint8_t w0, uint8_t w1, uint8_t w2, uint8_t w3,
1058 uint8_t x1, uint8_t x2, uint8_t x3, uint8_t start_sin,
1059 uint8_t start_sin90) noexcept;
1060
1070 Result<void> SetupMotorFromSpec(
1071 const MotorSpec &motor_spec,
1072 const MechanicalSystem *mechanical_system = nullptr) noexcept;
1073
1079 Result<void> ConfigureGlobalConfig(const GlobalConfig &config) noexcept;
1080
1086 Result<void> SetStealthChopEnabled(bool enabled) noexcept;
1087
1093 Result<ChopperConfig> GetChopperConfig() noexcept;
1094
1100 Result<bool> IsEnabled() noexcept;
1101
1107 Result<bool> IsStealthChopEnabled() noexcept;
1108
1117 Result<bool> IsStealthChopCalibrated() noexcept;
1118
1127 Result<Diag0Config> GetDiag0Config() noexcept;
1128
1137 Result<void> SetDiag0Config(const Diag0Config &config) noexcept;
1138
1147 Result<Diag1Config> GetDiag1Config() noexcept;
1148
1160 Result<void> SetDiag1Config(const Diag1Config &config) noexcept;
1161
1188 Result<void> SetCoilCurrents(int16_t coil_a, int16_t coil_b) noexcept;
1189
1216 Result<void> SetIholdDelayMs(float total_delay_ms) noexcept;
1217
1218 private:
1219 TMC51x0 &driver_;
1220 } motorControl{*this};
1221
1222 //================================================================================
1223 //================================================================================
1224 // THRESHOLDS STRUCT
1225 //================================================================================
1226 //================================================================================
1234 struct Thresholds {
1235 explicit Thresholds(TMC51x0 &driver) noexcept : driver_(driver) {}
1236
1244
1251
1258 Result<void> SetTcoolthrs(float threshold, Unit unit) noexcept;
1259
1265 Result<float> GetTcoolthrs(Unit unit) const noexcept;
1266
1273 Result<void> SetHighSpeedThreshold(float value, Unit unit) noexcept;
1274
1288 Result<void> SetDcStepVelocityThreshold(float value, Unit unit) noexcept;
1289
1299
1304 uint32_t GetVdcminRegisterValue() const noexcept;
1305
1314 Result<void> SetModeChangeSpeeds(float pwm_thrs, float cool_thrs,
1315 float high_thrs, Unit unit) noexcept;
1316
1321 uint32_t GetTpwmthrsRegisterValue() const noexcept;
1322
1327 uint32_t GetTcoolthrsRegisterValue() const noexcept;
1328
1335 uint32_t GetThighRegisterValue() const noexcept;
1336
1337 //==========================================================================
1338 // StealthChop/SpreadCycle Transition Hysteresis
1339 //==========================================================================
1340
1366 Result<void> SetModeHysteresis(float lower_speed, float upper_speed,
1367 Unit unit) noexcept;
1368
1382 Result<void> UpdateModeHysteresis() noexcept;
1383
1391 Result<void> DisableModeHysteresis() noexcept;
1392
1397 bool IsModeHysteresisEnabled() const noexcept;
1398
1399 private:
1400 TMC51x0 &driver_;
1401
1402 // Hysteresis state tracking (internal units: TSTEP register values)
1403 // Note: TSTEP is inverse of velocity (lower TSTEP = higher speed)
1404 uint32_t hysteresis_to_spreadcycle_tstep_{0}; // Switch to SpreadCycle when TSTEP < this (higher velocity)
1405 uint32_t hysteresis_to_stealthchop_tstep_{0}; // Switch to StealthChop when TSTEP > this (lower velocity)
1406 bool hysteresis_enabled_{false};
1407 } thresholds{*this};
1408
1409 //================================================================================
1410 //================================================================================
1411 // POWER STAGE STRUCT
1412 //================================================================================
1413 //================================================================================
1421 struct PowerStage {
1422 explicit PowerStage(TMC51x0 &driver) noexcept : driver_(driver) {}
1423
1430
1437
1446 Result<void> SetShortProtectionLevels(uint8_t s2vs_level, uint8_t s2g_level,
1447 uint8_t shortfilter,
1448 uint8_t shortdelay) noexcept;
1449
1450 private:
1452 } powerStage{*this};
1453
1454 //================================================================================
1455 //================================================================================
1456 // COMMUNICATION STRUCT
1457 //================================================================================
1458 //================================================================================
1459
1472 explicit Communication(TMC51x0 &driver) noexcept : driver_(driver) {}
1473
1496 Result<void> SetClkFreq(uint32_t frequency_hz) noexcept {
1497 return driver_.comm_.SetClkFreq(frequency_hz);
1498 }
1499
1533
1553 uint8_t send_delay = 0) noexcept;
1554
1570 void SetDaisyChainPosition(uint8_t position) noexcept {
1571 driver_.daisy_chain_position_ = position;
1572 }
1573
1579 [[nodiscard]] uint8_t GetDaisyChainPosition() const noexcept {
1580 return driver_.daisy_chain_position_;
1581 }
1582
1598 void SetUartNodeAddress(uint8_t address) noexcept {
1599 driver_.uart_node_address_ =
1600 address & 0xFF; // Address range is 0-254 (8-bit)
1601 }
1602
1607 [[nodiscard]] uint8_t GetUartNodeAddress() const noexcept {
1608 return driver_.uart_node_address_;
1609 }
1610
1611 private:
1613 } communication{*this};
1614
1615 //================================================================================
1616 //================================================================================
1617 // IO / PINS STRUCT
1618 //================================================================================
1619 //================================================================================
1627 struct Io {
1628 explicit Io(TMC51x0 &driver) noexcept : driver_(driver) {}
1629
1666
1678
1683 Result<InputStatus> ReadInputStatus() noexcept;
1684
1689 Result<uint8_t> ReadIcVersion() noexcept;
1690
1695 Result<uint32_t> ReadGpioPins() noexcept;
1696
1703 Result<void> SetSdoCfg0Polarity(bool polarity) noexcept;
1704
1705 private:
1706 TMC51x0 &driver_;
1707 } io{*this};
1708
1709 //================================================================================
1710 //================================================================================
1711 // ENCODER STRUCT
1712 //================================================================================
1713 //================================================================================
1714
1721 struct Encoder {
1726 explicit Encoder(TMC51x0 &driver) noexcept : driver_(driver) {}
1727
1740 Result<void> Configure(const EncoderConfig &config) noexcept;
1741
1750
1759 Result<void>
1760 SetNChannelActiveLevel(ReferenceSwitchActiveLevel active_level) noexcept;
1761
1770 Result<void>
1771 SetNChannelSensitivity(EncoderNSensitivity sensitivity) noexcept;
1772
1780 Result<void> SetClearMode(EncoderClearMode clear_mode) noexcept;
1781
1789 Result<void> SetPrescalerMode(EncoderPrescalerMode prescaler_mode) noexcept;
1790
1804 Result<void> SetLatchXactualEnabled(bool enable) noexcept;
1805
1810 Result<bool> IsLatchXactualEnabled() noexcept;
1811
1819 Result<int32_t> GetPosition() noexcept;
1820
1828 Result<void> SetResolution(int32_t motor_steps, int32_t enc_resolution,
1829 bool inverted = false) noexcept;
1830
1836 Result<void> SetAllowedDeviation(int32_t steps) noexcept;
1837
1847 Result<bool> IsNEventDetected() noexcept;
1848
1855 Result<void> ClearNEventFlag() noexcept;
1856
1866 Result<int32_t> GetLatchedPosition() noexcept;
1867
1868 //==========================================================================
1869 // Encoder Deviation Detection
1870 //==========================================================================
1871
1891 Result<bool> IsDeviationWarning() noexcept;
1892
1903 Result<void> ClearDeviationWarning() noexcept;
1904
1905 private:
1906 TMC51x0 &driver_;
1907 } encoder{*this};
1908
1909 //================================================================================
1910 //================================================================================
1911 // STATUS STRUCT
1912 //================================================================================
1913 //================================================================================
1914
1921 struct Status {
1926 explicit Status(TMC51x0 &driver) noexcept : driver_(driver) {}
1927
1933
1942 Result<bool> GetGlobalStatus(bool &drv_err, bool &uv_cp) noexcept;
1943
1959 Result<void> ClearGlobalStatus(bool clear_reset = true,
1960 bool clear_drv_err = true,
1961 bool clear_uv_cp = true) noexcept;
1962
1968 Result<uint32_t> GetDriverStatusRegister() noexcept;
1969
1990 Result<bool> IsOpenLoadA() noexcept;
1991
2012 Result<bool> IsOpenLoadB() noexcept;
2013
2038 Result<bool> CheckOpenLoad(bool &phase_a, bool &phase_b) noexcept;
2039
2040 //==========================================================================
2041 // Temperature Status (DRV_STATUS bits 25-26)
2042 //==========================================================================
2043
2056 Result<bool> IsOvertemperature() noexcept;
2057
2069 Result<bool> IsOvertempWarning() noexcept;
2070
2080 Result<void> GetTemperatureStatus(bool &overtemp, bool &prewarning) noexcept;
2081
2082 //==========================================================================
2083 // Chopper Mode Status (DRV_STATUS bits 14-15)
2084 //==========================================================================
2085
2097 Result<bool> IsStealthChopActive() noexcept;
2098
2111 Result<bool> IsFullstepActive() noexcept;
2112
2113 //==========================================================================
2114 // Current Status (DRV_STATUS bits 16-20)
2115 //==========================================================================
2116
2131 Result<uint8_t> GetActualCurrentScale() noexcept;
2132
2133 //==========================================================================
2134 // Short Circuit Status (DRV_STATUS bits 12-13, 27-28)
2135 //==========================================================================
2136
2154 Result<void> IsShortToSupply(bool &phase_a, bool &phase_b) noexcept;
2155
2173 Result<void> IsShortToGround(bool &phase_a, bool &phase_b) noexcept;
2174
2185 Result<void> GetShortCircuitStatus(bool &s2vs_a, bool &s2vs_b,
2186 bool &s2g_a, bool &s2g_b) noexcept;
2187
2193 Result<uint32_t> GetRampStatusRegister() noexcept;
2194
2202 Result<uint32_t> GetLostSteps() noexcept;
2203
2211 Result<uint32_t> GetTimeBetweenMicrosteps() noexcept;
2212
2221 Result<uint16_t> GetMicrostepCounter() noexcept;
2222
2232 Result<int16_t> GetMicrostepCurrent(int16_t &phase_b) noexcept;
2233
2243 Result<uint8_t> GetPwmScale(int16_t &pwm_scale_auto) noexcept;
2244
2254 Result<uint8_t> GetPwmAuto(uint8_t &pwm_grad_auto) noexcept;
2255
2263 Result<uint8_t> ReadFactoryConfig() noexcept;
2264
2275 Result<uint8_t> ReadOtpConfig(bool &otp_s2_level, bool &otp_bbm,
2276 bool &otp_tbl) noexcept;
2277
2284 Result<uint8_t> GetUartTransmissionCount() noexcept;
2285
2294 Result<uint8_t> ReadOffsetCalibration(uint8_t &phase_b) noexcept;
2295
2307 Result<void> VerifySetup() noexcept;
2308
2313 uint8_t GetChipVersion() const noexcept { return driver_.chip_version_; }
2314
2315 //==========================================================================
2316 // OTP Programming (One-Time Programmable Memory)
2317 //==========================================================================
2318
2340 Result<void> ProgramOtpBit(uint8_t byte_index, uint8_t bit_index,
2341 bool confirm_permanent) noexcept;
2342
2358 bool confirm_permanent) noexcept;
2359
2372 bool confirm_permanent) noexcept;
2373
2386 bool confirm_permanent) noexcept;
2387
2400 bool confirm_permanent) noexcept;
2401
2402 private:
2404 } status{*this};
2405
2406 //================================================================================
2407 //================================================================================
2408 // STALLGUARD STRUCT
2409 //================================================================================
2410 //================================================================================
2419 struct StallGuard {
2420 explicit StallGuard(TMC51x0 &driver) noexcept : driver_(driver) {}
2421
2427
2432 Result<uint16_t> GetStallGuardResult() noexcept;
2433
2439 Result<void> ConfigureStallGuard(const StallGuardConfig &config) noexcept;
2440
2450 Result<void> EnableStopOnStall(bool enable) noexcept;
2451
2456 Result<bool> IsStopOnStallEnabled() noexcept;
2457
2467 Result<void> SetSoftStop(bool enable) noexcept;
2468
2473 Result<bool> IsSoftStopEnabled() noexcept;
2474
2479 Result<void> ClearStallFlag() noexcept;
2480
2485 Result<bool> IsStallDetected() noexcept;
2486
2493 private:
2494 TMC51x0 &driver_;
2495 } stallGuard{*this};
2496
2497 //================================================================================
2498 //================================================================================
2499 // TUNING STRUCT
2500 //================================================================================
2501 //================================================================================
2502
2510 struct Tuning {
2515 explicit Tuning(TMC51x0 &driver) noexcept : driver_(driver) {}
2516
2559 TuneStallGuard(float target_velocity, StallGuardTuningResult &result,
2560 int8_t min_sgt = -20, int8_t max_sgt = 20,
2561 float acceleration = 5.0F, float min_velocity = 0.0F,
2562 float max_velocity = 0.0F,
2563 Unit velocity_unit = Unit::RPM,
2564 Unit acceleration_unit = Unit::RevPerSec) noexcept;
2565
2640 AutoTuneStallGuard(float target_velocity, StallGuardTuningResult &result,
2641 int8_t min_sgt = -20, int8_t max_sgt = 20,
2642 float acceleration = 5.0F, float min_velocity = 0.0F,
2643 float max_velocity = 0.0F,
2644 Unit velocity_unit = Unit::RPM,
2645 Unit acceleration_unit = Unit::RevPerSec,
2646 float current_reduction_factor = 0.3F) noexcept;
2647
2648 private:
2649 TMC51x0 &driver_;
2650 } tuning{*this};
2651
2652 //================================================================================
2653 //================================================================================
2654 // HOMING STRUCT
2655 //================================================================================
2656 //================================================================================
2657
2665 struct Homing {
2670 explicit Homing(TMC51x0 &driver) noexcept : driver_(driver) {}
2671
2672 // Bounds finding helpers
2673 enum class BoundsMethod { StallGuard, Encoder, Switch };
2674 enum class HomePlacement { None, AtMin, AtMax, AtCenter, AtOffsetFromMin };
2675
2677 bool success{false};
2678 bool bounded{false};
2679 bool cancelled{false};
2680 float min_bound{0.0F};
2681 float max_bound{0.0F};
2682 };
2683
2684 using CancelCallback = bool (*)();
2685
2686 struct HomeConfig {
2687 HomePlacement mode{HomePlacement::AtCenter};
2688 float offset{0.0F};
2689 Unit offset_unit{Unit::Deg};
2690 };
2691
2693 // Units
2694 Unit speed_unit{Unit::RPM};
2695 Unit position_unit{Unit::Deg};
2696 Unit accel_unit{Unit::RevPerSec};
2697
2698 // Motion behavior
2699 float search_speed{0.0F};
2700 float search_span{360.0F};
2701 float backoff_distance{5.0F};
2702 uint32_t timeout_ms{30000};
2703 bool search_positive_first{true};
2704 bool preflight_clear_active_switch{true};
2705
2706 // Optional accel/decel override (applies to bounds finding and homing moves that configure positioning ramps).
2707 // If 0, the routines use the cached driver acceleration/deceleration, or a conservative default.
2708 float search_accel{0.0F};
2709 float search_decel{0.0F};
2710
2711 // StallGuard-only (ignored for Encoder/Switch)
2712 float current_reduction_factor{0.3F};
2713 uint16_t current_reduction_target_mA{0};
2714 const StallGuardConfig* stallguard_override{nullptr};
2715 };
2716
2752 int32_t &final_position,
2753 CancelCallback should_cancel = nullptr) noexcept;
2754
2782 Result<void> PerformSwitchHoming(bool direction, const BoundsOptions& opt,
2783 int32_t &final_position,
2784 bool use_left_switch,
2785 CancelCallback should_cancel = nullptr) noexcept;
2786
2811 Result<void> PerformEncoderIndexHoming(bool direction, const BoundsOptions& opt,
2812 int32_t &final_position,
2813 CancelCallback should_cancel = nullptr) noexcept;
2814
2869 FindBoundsStallGuard(const BoundsOptions& opt, const HomeConfig& home = {},
2870 CancelCallback should_cancel = nullptr) noexcept;
2871
2907 FindBoundsEncoder(const BoundsOptions& opt, const HomeConfig& home = {},
2908 CancelCallback should_cancel = nullptr) noexcept;
2909
2944 FindBoundsSwitch(const BoundsOptions& opt, const HomeConfig& home = {},
2945 CancelCallback should_cancel = nullptr) noexcept;
2946
2963 FindBounds(BoundsMethod method, const BoundsOptions& opt, const HomeConfig& home = {},
2964 CancelCallback should_cancel = nullptr) noexcept;
2965
2966 private:
2969
2971 Result<void> RestoreCachedSettings() noexcept;
2972 Result<void>
2973 EnsureSpreadCycleForStallGuard() noexcept; // Disable StealthChop if needed
2974
2975 Result<void> ApplyHomePlacement(BoundsResult& out, float raw_min, float raw_max,
2976 const HomeConfig& home, const BoundsOptions& opt) noexcept;
2977 } homing{*this};
2978
2979 //================================================================================
2980 //================================================================================
2981 // PRINTER STRUCT
2982 //================================================================================
2983 //================================================================================
2984
2993 struct Printer {
2998 explicit Printer(TMC51x0 &driver) noexcept : driver_(driver) {}
2999
3003 void PrintGconf() noexcept;
3004
3008 void PrintGstat() noexcept;
3009
3013 void PrintRampStat() noexcept;
3014
3018 void PrintDrvStatus() noexcept;
3019
3023 void PrintChopconf() noexcept;
3024
3028 void PrintPwmconf() noexcept;
3029
3033 void PrintPwmScale() noexcept;
3034
3038 void PrintSwMode() noexcept;
3039
3043 void PrintIoin() noexcept;
3044
3048 void PrintAll() noexcept;
3049
3050 private:
3051 TMC51x0 &driver_;
3052
3053 void PrintRegisterField(const char *name, uint32_t value,
3054 const char *format = "0x%08X") noexcept;
3055 } printer{*this};
3056
3064 struct UartConfig {
3066
3071 explicit UartConfig(TMC51x0 *driver) noexcept : driver_(driver) {}
3072
3090 uint8_t send_delay) noexcept;
3091 } uartConfig{this};
3092
3093 // @}
3094
3095protected:
3102 [[nodiscard]] uint8_t GetCommAddress() const noexcept {
3103 return (comm_.GetMode() == CommMode::UART) ? uart_node_address_
3104 : daisy_chain_position_;
3105 }
3106
3114
3115public:
3120 [[nodiscard]] bool IsInitialized() const noexcept { return initialized_; }
3121
3122 // ===========================================================================
3123 // Driver Version (public: the documented way to log the library version)
3124 // ===========================================================================
3125
3127 static constexpr const char* GetDriverVersion() noexcept {
3128 return HF_TMC51X0_VERSION_STRING;
3129 }
3130
3132 static constexpr uint8_t GetDriverVersionMajor() noexcept {
3133 return HF_TMC51X0_VERSION_MAJOR;
3134 }
3135
3137 static constexpr uint8_t GetDriverVersionMinor() noexcept {
3138 return HF_TMC51X0_VERSION_MINOR;
3139 }
3140
3142 static constexpr uint8_t GetDriverVersionPatch() noexcept {
3143 return HF_TMC51X0_VERSION_PATCH;
3144 }
3145
3146private:
3159
3167 Result<void> RequireInternalRampMode() noexcept;
3168
3169 CommType &comm_;
3170 uint32_t f_clk_{ClockFreq::DEFAULT_F_CLK};
3175 uint8_t send_delay_{
3176 0};
3177 bool initialized_{false};
3178 uint8_t chip_version_{ChipVersion::TMC5160};
3180
3181 // Physical configuration for unit conversions
3184
3185 // Driver configuration (updated on all runtime changes)
3186 // Represents the current runtime state, updated whenever any Configure*
3187 // method is called
3189
3190 // Calculated motor current settings (stored internally, not in MotorSpec)
3191 uint16_t calculated_global_scaler_{0};
3192 uint8_t calculated_irun_{0};
3193 uint8_t calculated_ihold_{0};
3194 uint16_t current_microsteps_{256};
3195
3196 // Write-only register tracking (for easy access to current values)
3197 // These registers cannot be read back, so we track them locally
3199 uint32_t x_compare{0};
3200 uint32_t short_conf{0};
3201 uint32_t drv_conf{0};
3202 uint16_t global_scaler{0};
3203 uint32_t ihold_irun{0};
3204 uint8_t tpowerdown{0};
3205 uint32_t tpwmthrs{0};
3206 uint32_t tcoolthrs{0};
3207 uint32_t thigh{0};
3208 uint32_t vstart{0};
3209 uint32_t a1{0};
3210 uint32_t v1{0};
3211 uint32_t amax{0};
3212 uint32_t vmax{0};
3213 uint32_t dmax{0};
3214 uint32_t d1{0};
3215 uint32_t vstop{0};
3216 uint32_t tzerowait{0};
3217 uint32_t vdcmin{0};
3218 uint32_t enc_const{0};
3219 uint32_t enc_deviation{0};
3220 uint32_t coolconf{0};
3221 uint32_t dcctrl{0};
3222 uint32_t pwmconf{0};
3223 uint32_t nodeconf{0};
3224 } write_only_regs_;
3225
3232 [[nodiscard]] float convertSpeedToSteps(float value,
3233 Unit unit) const noexcept;
3234
3241 [[nodiscard]] float convertAccelerationToSteps(float value,
3242 Unit unit) const noexcept;
3243
3251 [[nodiscard]] bool IsUnitConvertible(Unit unit) const noexcept;
3252
3259 [[nodiscard]] float convertPositionToSteps(float value,
3260 Unit unit) const noexcept;
3261
3268 [[nodiscard]] float convertStepsToUnit(int32_t steps,
3269 Unit unit) const noexcept;
3270
3277 [[nodiscard]] float convertSpeedToUnit(float steps_per_sec,
3278 Unit unit) const noexcept;
3279
3285 [[nodiscard]] int32_t speedToInternal(float speed_hz) const noexcept;
3286
3292 [[nodiscard]] float speedFromInternal(int32_t speed_internal) const noexcept;
3293
3299 [[nodiscard]] int32_t accelToInternal(float accel_hz) const noexcept;
3300
3306 [[nodiscard]] float accelFromInternal(int32_t accel_internal) const noexcept;
3307
3313 [[nodiscard]] int32_t thresholdSpeedToTstep(float speed_hz) const noexcept;
3314};
3315
3316// Public API: Get driver version string
3317inline const char* GetDriverVersion() noexcept {
3318 return HF_TMC51X0_VERSION_STRING;
3319}
3320
3321} // namespace tmc51x0
3322
3323// Include template implementation
3324#ifndef TMC51X0_COMPILING_SRC
3325#define TMC51X0_HEADER_INCLUDED
3326// NOLINTNEXTLINE(bugprone-suspicious-include) - Intentional: template
3327// implementation file
3328#include "tmc51x0.ipp" // src/ in the source tree, next to this header once installed
3329#undef TMC51X0_HEADER_INCLUDED
3330#endif
Result type for operations that return a value.
Definition tmc51x0_result.hpp:90
Main class representing a TMC51x0 stepper motor driver (TMC5130 & TMC5160)
Definition tmc51x0.hpp:119
float convertPositionToSteps(float value, Unit unit) const noexcept
Convert position value to steps.
Result< void > HardReset(const HardResetOptions &opts=HardResetOptions()) noexcept
Perform a hard reset (power-cycle when available, else software reset)
DriverConfig driver_config_
Definition tmc51x0.hpp:3188
static constexpr uint8_t GetDriverVersionMinor() noexcept
Get the compiled driver minor version number.
Definition tmc51x0.hpp:3137
void LogConfigSummary(const DriverConfig &cfg, const char *tag="TMC5160", LogLevel lvl=LogLevel::Info) noexcept
Log a comprehensive, human-readable summary of a DriverConfig.
MotorSpec motor_spec_
Definition tmc51x0.hpp:3182
Result< void > Reset() noexcept
Reset the TMC51x0 driver.
CommType & GetComm() noexcept
Get the communication interface used by this TMC51x0 instance.
Definition tmc51x0.hpp:170
float accelFromInternal(int32_t accel_internal) const noexcept
Convert acceleration from internal TMC5160 units to steps/s²
TMC51x0(CommType &comm, uint8_t daisy_chain_position=0, uint8_t uart_node_address=0) noexcept
Construct a TMC51x0 driver instance.
Definition tmc51x0.hpp:151
float convertSpeedToUnit(float steps_per_sec, Unit unit) const noexcept
Convert speed (steps/s) to specified unit.
float convertStepsToUnit(int32_t steps, Unit unit) const noexcept
Convert steps to specified unit (for position)
int32_t speedToInternal(float speed_hz) const noexcept
Convert speed from Hz to internal TMC5160 units.
~TMC51x0() noexcept
Destructor for TMC51x0, cleans up resources.
Definition tmc51x0.hpp:159
uint8_t GetCommAddress() const noexcept
Get the appropriate address parameter for ReadRegister/WriteRegister.
Definition tmc51x0.hpp:3102
float convertSpeedToSteps(float value, Unit unit) const noexcept
Convert speed value to internal steps/s.
DriverConfig GetDriverConfig(bool &initialized) const noexcept
Get current driver configuration with initialization status.
Definition tmc51x0.hpp:266
float speedFromInternal(int32_t speed_internal) const noexcept
Convert speed from internal TMC5160 units to Hz.
static constexpr uint8_t GetDriverVersionMajor() noexcept
Get the compiled driver major version number.
Definition tmc51x0.hpp:3132
uint8_t uart_node_address_
Definition tmc51x0.hpp:3173
MechanicalSystem mechanical_system_
Definition tmc51x0.hpp:3183
Result< void > Initialize(const DriverConfig &config=DriverConfig(), bool verbose=true) noexcept
Initialize the TMC51x0 driver with configuration.
CommType & comm_
Communication interface reference.
Definition tmc51x0.hpp:3169
uint8_t daisy_chain_position_
Definition tmc51x0.hpp:3171
void LogLiveStatusReport(const char *tag="TMC5160", LogLevel lvl=LogLevel::Info) noexcept
Read silicon registers and log a comprehensive live status report.
bool IsUnitConvertible(Unit unit) const noexcept
Whether a unit can be converted with the current mechanical setup.
Result< bool > IsInternalRampMode() noexcept
Check whether the chip is currently in internal ramp-generator mode (SD_MODE=0).
int32_t thresholdSpeedToTstep(float speed_hz) const noexcept
Convert threshold speed to TSTEP format.
MotorCurrentDebugInfo GetMotorCurrentDebugInfo() const noexcept
Get motor-current calculated/cached values for application logging.
bool initialized_
Initialization status flag.
Definition tmc51x0.hpp:3177
void LogDerivedInitSummary(const char *tag="TMC5160", LogLevel lvl=LogLevel::Info) noexcept
Log a compact, table-style summary of derived/cached initialization values.
float convertAccelerationToSteps(float value, Unit unit) const noexcept
Convert acceleration value to internal steps/s²
std::string GetDriverConfigString() const noexcept
Get driver configuration as formatted string (heap allocating)
int32_t accelToInternal(float accel_hz) const noexcept
Convert acceleration from Hz/s to internal TMC5160 units.
DriverConfig GetDriverConfig() const noexcept
Get current driver configuration.
Definition tmc51x0.hpp:250
static constexpr const char * GetDriverVersion() noexcept
Get the compiled driver version string.
Definition tmc51x0.hpp:3127
static constexpr uint8_t GetDriverVersionPatch() noexcept
Get the compiled driver patch version number.
Definition tmc51x0.hpp:3142
Definition tmc51x0_config_builder.hpp:75
MicrostepResolution
Microstep resolution enumeration.
Definition tmc51x0_types.hpp:707
EncoderNSensitivity
Encoder N channel sensitivity enumeration.
Definition tmc51x0_types.hpp:2383
EncoderClearMode
Encoder clear mode enumeration.
Definition tmc51x0_types.hpp:2417
LogLevel
Driver-native log levels for debug output.
Definition tmc51x0_comm_interface.hpp:134
ReferenceStopMode
Stop mode enumeration.
Definition tmc51x0_types.hpp:2288
ReferenceLatchMode
Position latching mode enumeration.
Definition tmc51x0_types.hpp:2255
const char * GetDriverVersion() noexcept
Definition tmc51x0.hpp:3317
Unit
Unit enumeration.
Definition tmc51x0_types.hpp:176
EncoderPrescalerMode
Encoder prescaler mode enumeration.
Definition tmc51x0_types.hpp:2448
ReferenceSwitchActiveLevel
Reference switch active level enumeration.
Definition tmc51x0_types.hpp:2225
RampMode
Ramp mode enumeration values.
Definition tmc51x0_registers.hpp:32
ChipCommMode
Chip communication and motion control mode configuration.
Definition tmc51x0_types.hpp:82
MicrostepLutPreset
Microstep lookup table preset waveforms.
Definition tmc51x0_types.hpp:767
DriverStatus
Driver status enumeration.
Definition tmc51x0_types.hpp:213
Chopper configuration structure.
Definition tmc51x0_types.hpp:856
CoolStep configuration structure.
Definition tmc51x0_types.hpp:1992
DcStep configuration structure.
Definition tmc51x0_types.hpp:2122
DIAG0 pin configuration structure.
Definition tmc51x0_types.hpp:2588
DIAG1 pin configuration structure.
Definition tmc51x0_types.hpp:2613
Driver initialization configuration structure.
Definition tmc51x0_types.hpp:2870
Encoder configuration structure.
Definition tmc51x0_types.hpp:2479
External clock configuration structure.
Definition tmc51x0_types.hpp:2646
Global configuration (GCONF) structure.
Definition tmc51x0_types.hpp:2750
Cached settings for homing operations.
Definition tmc51x0_types.hpp:2923
Input pin status structure.
Definition tmc51x0_types.hpp:236
Mechanical system configuration structure.
Definition tmc51x0_types.hpp:290
Options for changing microstep resolution (CHOPCONF.MRES)
Definition tmc51x0_types.hpp:810
Motor specification structure.
Definition tmc51x0_types.hpp:322
Power stage parameters structure.
Definition tmc51x0_types.hpp:500
Ramp configuration structure.
Definition tmc51x0_types.hpp:1855
Reference switch configuration structure.
Definition tmc51x0_types.hpp:2327
StallGuard2 configuration structure.
Definition tmc51x0_types.hpp:1519
Result structure for StallGuard2 threshold (SGT) tuning.
Definition tmc51x0_types.hpp:1644
StealthChop configuration structure.
Definition tmc51x0_types.hpp:1234
Communication subsystem.
Definition tmc51x0.hpp:1467
Result< void > SetClkFreq(uint32_t frequency_hz) noexcept
Set clock frequency on CLK pin.
Definition tmc51x0.hpp:1496
void SetUartNodeAddress(uint8_t address) noexcept
Set the UART node address for this TMC51x0 instance.
Definition tmc51x0.hpp:1598
uint8_t GetDaisyChainPosition() const noexcept
Get the current daisy-chain position for this TMC51x0 instance.
Definition tmc51x0.hpp:1579
Result< void > SetClkFreq(const ExternalClockConfig &config) noexcept
Set clock frequency from ExternalClockConfig (high-level method)
uint8_t GetUartNodeAddress() const noexcept
Get the current UART node address for this TMC51x0 instance.
Definition tmc51x0.hpp:1607
TMC51x0 & driver_
Reference to parent driver instance.
Definition tmc51x0.hpp:1612
Communication(TMC51x0 &driver) noexcept
Construct communication subsystem.
Definition tmc51x0.hpp:1472
Result< void > ConfigureUartNodeAddress(uint8_t node_address, uint8_t send_delay=0) noexcept
Configure UART node address and send delay (writes NODECONF register)
Encoder subsystem.
Definition tmc51x0.hpp:1721
Result< void > Configure(const EncoderConfig &config) noexcept
Configure encoder settings.
Result< EncoderConfig > GetEncoderConfig() noexcept
Get current encoder configuration.
Encoder(TMC51x0 &driver) noexcept
Construct encoder subsystem.
Definition tmc51x0.hpp:1726
Motion events / status outputs (X_COMPARE, RAMP_STAT clear)
Definition tmc51x0.hpp:839
Result< void > ClearRampStatus(uint32_t bits_to_clear) noexcept
Clear specific bits in RAMP_STAT.
Events(TMC51x0 &driver) noexcept
Definition tmc51x0.hpp:840
Result< float > GetXCompare(Unit unit) const noexcept
Get last programmed X_COMPARE threshold (cached, unit-aware)
TMC51x0 & driver_
Definition tmc51x0.hpp:871
Result< void > SetXCompare(float position, Unit unit) noexcept
Program the X_COMPARE position compare threshold (unit-aware)
Options for HardReset()
Definition tmc51x0.hpp:208
Definition tmc51x0.hpp:2692
Definition tmc51x0.hpp:2676
Definition tmc51x0.hpp:2686
Homing subsystem with automatic settings caching.
Definition tmc51x0.hpp:2665
TMC51x0 & driver_
Definition tmc51x0.hpp:2967
Result< BoundsResult > FindBoundsSwitch(const BoundsOptions &opt, const HomeConfig &home={}, CancelCallback should_cancel=nullptr) noexcept
Find motion bounds using reference switches (REFL/REFR stop events).
Result< void > PerformSensorlessHoming(bool direction, const BoundsOptions &opt, int32_t &final_position, CancelCallback should_cancel=nullptr) noexcept
Perform sensorless homing using StallGuard2 (with settings caching)
Homing(TMC51x0 &driver) noexcept
Construct homing subsystem.
Definition tmc51x0.hpp:2670
Result< BoundsResult > FindBounds(BoundsMethod method, const BoundsOptions &opt, const HomeConfig &home={}, CancelCallback should_cancel=nullptr) noexcept
Dispatch bounds finding by method.
bool(*)() CancelCallback
Definition tmc51x0.hpp:2684
HomePlacement
Definition tmc51x0.hpp:2674
Result< void > CacheCurrentSettings() noexcept
Result< BoundsResult > FindBoundsEncoder(const BoundsOptions &opt, const HomeConfig &home={}, CancelCallback should_cancel=nullptr) noexcept
Find motion bounds using encoder feedback (detects "no further motion" via stalled encoder).
BoundsMethod
Definition tmc51x0.hpp:2673
Chip IO / mode pins / IOIN helpers.
Definition tmc51x0.hpp:1627
Result< void > SetOperatingMode(ChipCommMode mode) noexcept
Set the chip operating mode via SPI_MODE and SD_MODE pins.
Result< ChipCommMode > GetOperatingMode() const noexcept
Read the current mode-pin state (SPI_MODE/SD_MODE)
Io(TMC51x0 &driver) noexcept
Definition tmc51x0.hpp:1628
Motor control subsystem.
Definition tmc51x0.hpp:887
Result< void > ConfigureStealthChop(const StealthChopConfig &config) noexcept
Configure stealthChop settings.
Result< void > ConfigureMotorCurrent(const MotorSpec &motor_spec) noexcept
Configure motor current from motor specifications.
Result< void > SetGlobalScaler(uint16_t scaler) noexcept
Set global current scaler.
Result< void > Enable() noexcept
Enable the motor driver.
Result< GlobalConfig > GetGlobalConfig() noexcept
Get global configuration.
MotorControl(TMC51x0 &driver) noexcept
Construct motor control subsystem.
Definition tmc51x0.hpp:892
Snapshot of motor-current related calculated/cached values.
Definition tmc51x0.hpp:348
bool initialized
True if Initialize() has completed successfully.
Definition tmc51x0.hpp:349
uint16_t calculated_global_scaler
Last calculated GLOBAL_SCALER (32..256)
Definition tmc51x0.hpp:354
uint32_t cached_ihold_irun
Cached write-only IHOLD_IRUN raw register value.
Definition tmc51x0.hpp:356
uint8_t calculated_irun
Last calculated IRUN (0..31)
Definition tmc51x0.hpp:352
uint8_t calculated_ihold
Last calculated IHOLD (0..31)
Definition tmc51x0.hpp:353
uint16_t cached_global_scaler
Cached write-only GLOBAL_SCALER value.
Definition tmc51x0.hpp:355
uint32_t f_clk_hz
Effective clock used for calculations.
Definition tmc51x0.hpp:350
MotorSpec motor_spec
MotorSpec used for calculations.
Definition tmc51x0.hpp:351
Power stage + protection subsystem (DRV_CONF, SHORT_CONF)
Definition tmc51x0.hpp:1421
TMC51x0 & driver_
Definition tmc51x0.hpp:1451
PowerStage(TMC51x0 &driver) noexcept
Definition tmc51x0.hpp:1422
Result< void > ConfigureShortProtection(const PowerStageParameters &config) noexcept
Configure short protection levels from PowerStageParameters.
Result< void > ConfigurePowerStage(const PowerStageParameters &config) noexcept
Configure power stage parameters (DRV_CONF register)
Result< void > SetShortProtectionLevels(uint8_t s2vs_level, uint8_t s2g_level, uint8_t shortfilter, uint8_t shortdelay) noexcept
Set short protection levels.
Register printer subsystem for debugging.
Definition tmc51x0.hpp:2993
void PrintGconf() noexcept
Print GCONF register.
Printer(TMC51x0 &driver) noexcept
Construct printer subsystem.
Definition tmc51x0.hpp:2998
Ramp control subsystem.
Definition tmc51x0.hpp:388
Result< void > SetRampMode(RampMode mode) noexcept
Set the ramp mode.
Result< RampMode > GetRampMode() noexcept
Get current ramp mode.
RampControl(TMC51x0 &driver) noexcept
Construct ramp control subsystem.
Definition tmc51x0.hpp:393
StallGuard2 subsystem (COOLCONF/DRV_STATUS + SW_MODE interactions)
Definition tmc51x0.hpp:2419
StallGuard(TMC51x0 &driver) noexcept
Definition tmc51x0.hpp:2420
Result< uint16_t > GetStallGuard() noexcept
Read StallGuard2 value (SG_RESULT)
Status / monitoring subsystem (read-only)
Definition tmc51x0.hpp:1921
Result< void > ProgramOtpBbm(bool short_bbm, bool confirm_permanent) noexcept
Program OTP BBM (break-before-make) default (PERMANENT!)
Result< void > ProgramOtpTbl(bool short_tbl, bool confirm_permanent) noexcept
Program OTP TBL (blank time) default (PERMANENT!)
Result< void > ProgramOtpS2Level(bool high_level, bool confirm_permanent) noexcept
Program OTP short detection level default (PERMANENT!)
Result< void > ProgramOtpFclktrim(uint8_t fclktrim, bool confirm_permanent) noexcept
Program OTP FCLKTRIM value (PERMANENT - USE WITH EXTREME CAUTION!)
Result< void > ProgramOtpBit(uint8_t byte_index, uint8_t bit_index, bool confirm_permanent) noexcept
Program a single OTP bit (PERMANENT - USE WITH EXTREME CAUTION!)
Status(TMC51x0 &driver) noexcept
Construct diagnostics subsystem.
Definition tmc51x0.hpp:1926
DriverStatus GetStatus() noexcept
Get driver status.
TMC51x0 & driver_
Reference to parent driver instance.
Definition tmc51x0.hpp:2403
Reference switches / endstops subsystem (SW_MODE / XLATCH)
Definition tmc51x0.hpp:717
Result< void > ConfigureReferenceSwitch(const ReferenceSwitchConfig &config) noexcept
Configure reference switches / endstops (SW_MODE)
Result< float > GetLatchedPosition(Unit unit) noexcept
Read latched position from XLATCH (unit-aware)
Result< void > SetLeftSwitchStopEnable(bool enable) noexcept
Enable/disable stop-on-left-switch (SW_MODE.stop_l_enable)
Result< void > SetStopMode(ReferenceStopMode stop_mode) noexcept
Set reference stop mode (hard/soft stop) for internal ramp generator.
Result< void > SetRightSwitchLatchMode(ReferenceLatchMode latch_mode) noexcept
Configure right switch latching behavior (SW_MODE.latch_r_active)
TMC51x0 & driver_
Definition tmc51x0.hpp:827
Switches(TMC51x0 &driver) noexcept
Definition tmc51x0.hpp:718
Result< bool > GetReferenceSwitchStatus(bool &right_active, bool &left_enabled, bool &right_enabled) noexcept
Get reference switch active/enabled status (RAMP_STAT + SW_MODE)
Result< void > SetLeftSwitchLatchMode(ReferenceLatchMode latch_mode) noexcept
Configure left switch latching behavior (SW_MODE.latch_l_active)
Result< void > SetRightSwitchStopEnable(bool enable) noexcept
Enable/disable stop-on-right-switch (SW_MODE.stop_r_enable)
Result< ReferenceSwitchConfig > GetReferenceSwitchConfig() noexcept
Read reference switch configuration (SW_MODE)
Result< void > SetRightSwitchActiveLevel(ReferenceSwitchActiveLevel active_level) noexcept
Set right reference switch active level / polarity.
Result< void > SetLeftSwitchActiveLevel(ReferenceSwitchActiveLevel active_level) noexcept
Set left reference switch active level / polarity.
Velocity thresholds / mode thresholds (TPWMTHRS, TCOOLTHRS, THIGH)
Definition tmc51x0.hpp:1234
Result< void > SetStealthChopVelocityThreshold(float value, Unit unit) noexcept
Set StealthChop velocity threshold (TPWMTHRS)
Result< float > GetTcoolthrs(Unit unit) const noexcept
Get cached StallGuard/CoolStep threshold velocity (TCOOLTHRS)
Result< void > SetTcoolthrs(float threshold, Unit unit) noexcept
Set StallGuard/CoolStep threshold velocity (TCOOLTHRS)
Result< void > SetHighSpeedThreshold(float value, Unit unit) noexcept
Set High-Speed velocity threshold (THIGH)
Thresholds(TMC51x0 &driver) noexcept
Definition tmc51x0.hpp:1235
uint32_t GetVdcminRegisterValue() const noexcept
Get locally tracked VDCMIN register value (raw)
Result< void > SetDcStepVelocityThreshold(float value, Unit unit) noexcept
Set DcStep velocity threshold (VDCMIN)
Result< float > GetDcStepVelocityThreshold(Unit unit) const noexcept
Get cached DcStep velocity threshold (VDCMIN)
Result< float > GetStealthChopVelocityThreshold(Unit unit) const noexcept
Get StealthChop velocity threshold (TPWMTHRS) from local tracking.
Tuning subsystem for automatic parameter optimization.
Definition tmc51x0.hpp:2510
Result< void > AutoTuneStallGuard(float target_velocity, StallGuardTuningResult &result, int8_t min_sgt=-20, int8_t max_sgt=20, float acceleration=5.0F, float min_velocity=0.0F, float max_velocity=0.0F, Unit velocity_unit=Unit::RPM, Unit acceleration_unit=Unit::RevPerSec, float current_reduction_factor=0.3F) noexcept
Comprehensive automatic StallGuard tuning with current reduction and optional encoder verification.
Result< void > TuneStallGuard(float target_velocity, StallGuardTuningResult &result, int8_t min_sgt=-20, int8_t max_sgt=20, float acceleration=5.0F, float min_velocity=0.0F, float max_velocity=0.0F, Unit velocity_unit=Unit::RPM, Unit acceleration_unit=Unit::RevPerSec) noexcept
Automatically tune StallGuard threshold (SGT) with comprehensive velocity range analysis.
Tuning(TMC51x0 &driver) noexcept
Construct tuning subsystem.
Definition tmc51x0.hpp:2515
UART configuration subsystem.
Definition tmc51x0.hpp:3064
TMC51x0 * driver_
Pointer to parent driver instance.
Definition tmc51x0.hpp:3065
UartConfig(TMC51x0 *driver) noexcept
Construct UART configuration subsystem.
Definition tmc51x0.hpp:3071
Result< void > ConfigureUartNodeAddress(uint8_t node_address, uint8_t send_delay) noexcept
Configure UART node address and send delay (for sequential programming)
Definition tmc51x0.hpp:3198
Communication interfaces for TMC51x0 stepper motor driver using SPI and UART.
Register definitions and bitfield structures for TMC51x0 stepper motor.
#define X(addr, name, access, category, desc)
Definition tmc51x0_registers.hpp:24
Result type for error handling in TMC51x0 driver.
Type definitions and enumerations for TMC51x0 stepper motor driver (TMC5130 & TMC5160)