14#include "tmc51x0_version.h"
151 explicit TMC51x0(CommType &comm, uint8_t daisy_chain_position = 0,
152 uint8_t uart_node_address = 0) noexcept
162 motorControl.Disable();
203 bool verbose =
true) noexcept;
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};
274#ifndef TMC51X0_DISABLE_DEBUG_LOGGING
290#ifndef TMC51X0_DISABLE_DEBUG_LOGGING
412 Result<
bool> IsPositionReached() noexcept;
418 Result<
bool> IsVelocityReached() noexcept;
444 Result<
void> SetTargetPosition(
float value,
Unit unit) noexcept;
492 Result<int32_t> GetCurrentPositionMicrosteps() noexcept;
498 Result<int32_t> GetTargetPositionMicrosteps() noexcept;
508 bool update_encoder = false) noexcept;
524 Result<
void> SetAcceleration(
float value,
Unit unit) noexcept;
533 Result<
void> SetAccelerations(
float accel_val,
float decel_val,
545 Result<
void> SetDeceleration(
float value,
Unit unit) noexcept;
555 Result<
void> SetRampSpeeds(
float start_speed,
float stop_speed,
556 float transition_speed,
Unit unit) noexcept;
578 Result<
bool> IsTargetVelocityReached() noexcept;
599 Result<
void> SetPowerDownDelay(uint8_t tpowerdown) noexcept;
617 Result<
void> SetPowerDownDelayMs(
float delay_ms) noexcept;
630 Result<
void> SetZeroWaitTime(uint16_t tzerowait) noexcept;
652 Result<
void> SetZeroWaitTimeMs(
float delay_ms) noexcept;
672 Result<
void> SetFirstAcceleration(
float a1,
Unit unit) noexcept;
685 Result<
void> SetFinalDeceleration(
float d1,
Unit unit) noexcept;
699 Result<
void> SetTargetPosition(int32_t position) noexcept;
700 Result<
void> SetCurrentPosition(int32_t position,
701 bool update_encoder = false) noexcept;
702 } rampControl{*
this};
813 bool &right_enabled) noexcept;
912 Result<
void> SetCurrent(uint8_t irun, uint8_t ihold) noexcept;
991 Result<
void> SetMicrostepLookupTable(uint8_t index,
992 uint32_t value) noexcept;
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;
1015 Result<
void> SetMicrostepLookupTableStart(uint16_t start_current) noexcept;
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;
1086 Result<
void> SetStealthChopEnabled(
bool enabled) noexcept;
1107 Result<
bool> IsStealthChopEnabled() noexcept;
1117 Result<
bool> IsStealthChopCalibrated() noexcept;
1188 Result<
void> SetCoilCurrents(int16_t coil_a, int16_t coil_b) noexcept;
1216 Result<
void> SetIholdDelayMs(
float total_delay_ms) noexcept;
1220 } motorControl{*
this};
1314 Result<
void> SetModeChangeSpeeds(
float pwm_thrs,
float cool_thrs,
1315 float high_thrs,
Unit unit) noexcept;
1321 uint32_t GetTpwmthrsRegisterValue() const noexcept;
1327 uint32_t GetTcoolthrsRegisterValue() const noexcept;
1335 uint32_t GetThighRegisterValue() const noexcept;
1366 Result<
void> SetModeHysteresis(
float lower_speed,
float upper_speed,
1367 Unit unit) noexcept;
1382 Result<
void> UpdateModeHysteresis() noexcept;
1391 Result<
void> DisableModeHysteresis() noexcept;
1397 bool IsModeHysteresisEnabled() const noexcept;
1404 uint32_t hysteresis_to_spreadcycle_tstep_{0};
1405 uint32_t hysteresis_to_stealthchop_tstep_{0};
1406 bool hysteresis_enabled_{
false};
1407 } thresholds{*
this};
1447 uint8_t shortfilter,
1448 uint8_t shortdelay)
noexcept;
1452 } powerStage{*
this};
1497 return driver_.comm_.SetClkFreq(frequency_hz);
1553 uint8_t send_delay = 0) noexcept;
1570 void SetDaisyChainPosition(uint8_t position) noexcept {
1571 driver_.daisy_chain_position_ = position;
1580 return driver_.daisy_chain_position_;
1599 driver_.uart_node_address_ =
1608 return driver_.uart_node_address_;
1613 } communication{*
this};
1703 Result<
void> SetSdoCfg0Polarity(
bool polarity) noexcept;
1804 Result<
void> SetLatchXactualEnabled(
bool enable) noexcept;
1810 Result<
bool> IsLatchXactualEnabled() noexcept;
1828 Result<
void> SetResolution(int32_t motor_steps, int32_t enc_resolution,
1829 bool inverted = false) noexcept;
1836 Result<
void> SetAllowedDeviation(int32_t steps) noexcept;
1866 Result<int32_t> GetLatchedPosition() noexcept;
1903 Result<
void> ClearDeviationWarning() noexcept;
1942 Result<
bool> GetGlobalStatus(
bool &drv_err,
bool &uv_cp) noexcept;
1959 Result<
void> ClearGlobalStatus(
bool clear_reset = true,
1960 bool clear_drv_err = true,
1961 bool clear_uv_cp = true) noexcept;
1968 Result<uint32_t> GetDriverStatusRegister() noexcept;
2038 Result<
bool> CheckOpenLoad(
bool &phase_a,
bool &phase_b) noexcept;
2080 Result<
void> GetTemperatureStatus(
bool &overtemp,
bool &prewarning) noexcept;
2131 Result<uint8_t> GetActualCurrentScale() noexcept;
2154 Result<
void> IsShortToSupply(
bool &phase_a,
bool &phase_b) noexcept;
2173 Result<
void> IsShortToGround(
bool &phase_a,
bool &phase_b) noexcept;
2185 Result<
void> GetShortCircuitStatus(
bool &s2vs_a,
bool &s2vs_b,
2186 bool &s2g_a,
bool &s2g_b) noexcept;
2193 Result<uint32_t> GetRampStatusRegister() noexcept;
2211 Result<uint32_t> GetTimeBetweenMicrosteps() noexcept;
2221 Result<uint16_t> GetMicrostepCounter() noexcept;
2232 Result<int16_t> GetMicrostepCurrent(int16_t &phase_b) noexcept;
2243 Result<uint8_t> GetPwmScale(int16_t &pwm_scale_auto) noexcept;
2254 Result<uint8_t> GetPwmAuto(uint8_t &pwm_grad_auto) noexcept;
2263 Result<uint8_t> ReadFactoryConfig() noexcept;
2275 Result<uint8_t> ReadOtpConfig(
bool &otp_s2_level,
bool &otp_bbm,
2276 bool &otp_tbl) noexcept;
2284 Result<uint8_t> GetUartTransmissionCount() noexcept;
2294 Result<uint8_t> ReadOffsetCalibration(uint8_t &phase_b) noexcept;
2313 uint8_t GetChipVersion() const noexcept {
return driver_.chip_version_; }
2341 bool confirm_permanent)
noexcept;
2358 bool confirm_permanent)
noexcept;
2372 bool confirm_permanent)
noexcept;
2386 bool confirm_permanent)
noexcept;
2400 bool confirm_permanent)
noexcept;
2432 Result<uint16_t> GetStallGuardResult() noexcept;
2450 Result<
void> EnableStopOnStall(
bool enable) noexcept;
2456 Result<
bool> IsStopOnStallEnabled() noexcept;
2467 Result<
void> SetSoftStop(
bool enable) noexcept;
2495 } stallGuard{*
this};
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;
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;
2677 bool success{
false};
2678 bool bounded{
false};
2679 bool cancelled{
false};
2680 float min_bound{0.0F};
2681 float max_bound{0.0F};
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};
2708 float search_accel{0.0F};
2709 float search_decel{0.0F};
2712 float current_reduction_factor{0.3F};
2713 uint16_t current_reduction_target_mA{0};
2752 int32_t &final_position,
2783 int32_t &final_position,
2784 bool use_left_switch,
2812 int32_t &final_position,
2870 CancelCallback should_cancel =
nullptr)
noexcept;
2908 CancelCallback should_cancel =
nullptr)
noexcept;
2945 CancelCallback should_cancel =
nullptr)
noexcept;
2964 CancelCallback should_cancel =
nullptr)
noexcept;
2971 Result<
void> RestoreCachedSettings() noexcept;
2973 EnsureSpreadCycleForStallGuard() noexcept;
3008 void PrintGstat() noexcept;
3013 void PrintRampStat() noexcept;
3018 void PrintDrvStatus() noexcept;
3023 void PrintChopconf() noexcept;
3028 void PrintPwmconf() noexcept;
3033 void PrintPwmScale() noexcept;
3038 void PrintSwMode() noexcept;
3043 void PrintIoin() noexcept;
3048 void PrintAll() noexcept;
3053 void PrintRegisterField(const
char *name, uint32_t value,
3054 const
char *format = "0x%08
X") noexcept;
3090 uint8_t send_delay)
noexcept;
3103 return (comm_.GetMode() == CommMode::UART) ? uart_node_address_
3104 : daisy_chain_position_;
3119 [[nodiscard]]
bool IsInitialized() const noexcept {
return initialized_; }
3127 return HF_TMC51X0_VERSION_STRING;
3132 return HF_TMC51X0_VERSION_MAJOR;
3137 return HF_TMC51X0_VERSION_MINOR;
3142 return HF_TMC51X0_VERSION_PATCH;
3166 Result<
void> RequireInternalRampMode() noexcept;
3169 uint32_t f_clk_{ClockFreq::DEFAULT_F_CLK};
3174 uint8_t send_delay_{
3176 bool initialized_{
false};
3177 uint8_t chip_version_{ChipVersion::TMC5160};
3190 uint16_t calculated_global_scaler_{0};
3191 uint8_t calculated_irun_{0};
3192 uint8_t calculated_ihold_{0};
3193 uint16_t current_microsteps_{256};
3198 uint32_t x_compare{0};
3199 uint32_t short_conf{0};
3200 uint32_t drv_conf{0};
3201 uint16_t global_scaler{0};
3202 uint32_t ihold_irun{0};
3203 uint8_t tpowerdown{0};
3204 uint32_t tpwmthrs{0};
3205 uint32_t tcoolthrs{0};
3215 uint32_t tzerowait{0};
3217 uint32_t enc_const{0};
3218 uint32_t enc_deviation{0};
3219 uint32_t coolconf{0};
3221 uint32_t pwmconf{0};
3222 uint32_t nodeconf{0};
3232 Unit unit)
const noexcept;
3241 Unit unit)
const noexcept;
3250 Unit unit)
const noexcept;
3259 Unit unit)
const noexcept;
3268 Unit unit)
const noexcept;
3308 return HF_TMC51X0_VERSION_STRING;
3314#ifndef TMC51X0_COMPILING_SRC
3315#define TMC51X0_HEADER_INCLUDED
3318#include "../src/tmc51x0.ipp"
3319#undef TMC51X0_HEADER_INCLUDED
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:3187
static constexpr uint8_t GetDriverVersionMinor() noexcept
Get the compiled driver minor version number.
Definition tmc51x0.hpp:3136
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:3181
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:3131
uint8_t uart_node_address_
Definition tmc51x0.hpp:3172
MechanicalSystem mechanical_system_
Definition tmc51x0.hpp:3182
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:3168
uint8_t daisy_chain_position_
Definition tmc51x0.hpp:3170
void LogLiveStatusReport(const char *tag="TMC5160", LogLevel lvl=LogLevel::Info) noexcept
Read silicon registers and log a comprehensive live status report.
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:3176
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:3126
static constexpr uint8_t GetDriverVersionPatch() noexcept
Get the compiled driver patch version number.
Definition tmc51x0.hpp:3141
Definition tmc51x0_register_defs.cpp:10
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:3307
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
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:3197
Communication interfaces for TMC51x0 stepper motor driver using SPI and UART.
#define X(addr, name, access, category, desc)
Register definitions and bitfield structures for TMC51x0 stepper motor.
Result type for error handling in TMC51x0 driver.
Type definitions and enumerations for TMC51x0 stepper motor driver (TMC5130 & TMC5160)