HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
tmc51x0::TMC51x0< CommType >::Switches Struct Reference

Reference switches / endstops subsystem (SW_MODE / XLATCH) More...

#include <tmc51x0.hpp>

Collaboration diagram for tmc51x0::TMC51x0< CommType >::Switches:
[legend]

Public Member Functions

 Switches (TMC51x0 &driver) noexcept
 
Result< void > ConfigureReferenceSwitch (const ReferenceSwitchConfig &config) noexcept
 Configure reference switches / endstops (SW_MODE)
 
Result< ReferenceSwitchConfigGetReferenceSwitchConfig () noexcept
 Read reference switch configuration (SW_MODE)
 
Result< void > SetLeftSwitchActiveLevel (ReferenceSwitchActiveLevel active_level) noexcept
 Set left reference switch active level / polarity.
 
Result< void > SetRightSwitchActiveLevel (ReferenceSwitchActiveLevel active_level) noexcept
 Set right reference switch active level / polarity.
 
Result< void > SetLeftSwitchStopEnable (bool enable) noexcept
 Enable/disable stop-on-left-switch (SW_MODE.stop_l_enable)
 
Result< void > SetRightSwitchStopEnable (bool enable) noexcept
 Enable/disable stop-on-right-switch (SW_MODE.stop_r_enable)
 
Result< void > SetLeftSwitchLatchMode (ReferenceLatchMode latch_mode) noexcept
 Configure left switch latching behavior (SW_MODE.latch_l_active)
 
Result< void > SetRightSwitchLatchMode (ReferenceLatchMode latch_mode) noexcept
 Configure right switch latching behavior (SW_MODE.latch_r_active)
 
Result< void > SetStopMode (ReferenceStopMode stop_mode) noexcept
 Set reference stop mode (hard/soft stop) for internal ramp generator.
 
Result< bool > GetReferenceSwitchStatus (bool &right_active, bool &left_enabled, bool &right_enabled) noexcept
 Get reference switch active/enabled status (RAMP_STAT + SW_MODE)
 
Result< float > GetLatchedPosition (Unit unit) noexcept
 Read latched position from XLATCH (unit-aware)
 

Private Attributes

TMC51x0driver_
 

Detailed Description

template<typename CommType>
struct tmc51x0::TMC51x0< CommType >::Switches

Reference switches / endstops subsystem (SW_MODE / XLATCH)

Owns reference switch configuration, latching, and related status helpers. (This used to live under RampControl; it is separated to keep RampControl focused on motion profile programming.)

Constructor & Destructor Documentation

◆ Switches()

template<typename CommType >
tmc51x0::TMC51x0< CommType >::Switches::Switches ( TMC51x0 & driver)
inlineexplicitnoexcept

Member Function Documentation

◆ ConfigureReferenceSwitch()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::Switches::ConfigureReferenceSwitch ( const ReferenceSwitchConfig & config)
noexcept

Configure reference switches / endstops (SW_MODE)

Parameters
configReference switch configuration
Returns
Result<void> indicating success or error

Programs the reference switch logic in the SW_MODE register, including:

  • input polarity / active level (left/right)
  • enable/disable stop-on-switch per side
  • latch configuration (XLATCH behavior)
  • hard/soft stop behavior for the internal motion controller

Use GetReferenceSwitchStatus() to read the current active state and whether stop-on-switch is enabled.

◆ GetLatchedPosition()

template<typename CommType >
Result< float > tmc51x0::TMC51x0< CommType >::Switches::GetLatchedPosition ( Unit unit)
noexcept

Read latched position from XLATCH (unit-aware)

Parameters
unitUnit to return the position in
Returns
Result<float> containing the latched position or error

XLATCH latches the internal position counter (microsteps). This helper converts it into the requested user unit based on the current microstep resolution and mechanical system configuration.

◆ GetReferenceSwitchConfig()

template<typename CommType >
Result< ReferenceSwitchConfig > tmc51x0::TMC51x0< CommType >::Switches::GetReferenceSwitchConfig ( )
noexcept

Read reference switch configuration (SW_MODE)

Returns
Result<ReferenceSwitchConfig> containing the value or error

◆ GetReferenceSwitchStatus()

template<typename CommType >
Result< bool > tmc51x0::TMC51x0< CommType >::Switches::GetReferenceSwitchStatus ( bool & right_active,
bool & left_enabled,
bool & right_enabled )
noexcept

Get reference switch active/enabled status (RAMP_STAT + SW_MODE)

Parameters
right_activeOutput: true if right switch is currently active
left_enabledOutput: true if left stop-on-switch is enabled
right_enabledOutput: true if right stop-on-switch is enabled
Returns
Result<bool> true on success, or error
  • Active state is read from RAMP_STAT status bits.
  • Enabled state is derived from SW_MODE stop-enable bits.

◆ SetLeftSwitchActiveLevel()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::Switches::SetLeftSwitchActiveLevel ( ReferenceSwitchActiveLevel active_level)
noexcept

Set left reference switch active level / polarity.

Parameters
active_levelActive level (ACTIVE_LOW / ACTIVE_HIGH)
Returns
Result<void> indicating success or error

Convenience helper that reads the current SW_MODE, updates the left polarity field, and writes it back.

◆ SetLeftSwitchLatchMode()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::Switches::SetLeftSwitchLatchMode ( ReferenceLatchMode latch_mode)
noexcept

Configure left switch latching behavior (SW_MODE.latch_l_active)

Parameters
latch_modeLatch mode selection
Returns
Result<void> indicating success or error

◆ SetLeftSwitchStopEnable()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::Switches::SetLeftSwitchStopEnable ( bool enable)
noexcept

Enable/disable stop-on-left-switch (SW_MODE.stop_l_enable)

Parameters
enableTrue to enable stop-on-switch
Returns
Result<void> indicating success or error

◆ SetRightSwitchActiveLevel()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::Switches::SetRightSwitchActiveLevel ( ReferenceSwitchActiveLevel active_level)
noexcept

Set right reference switch active level / polarity.

Parameters
active_levelActive level (ACTIVE_LOW / ACTIVE_HIGH)
Returns
Result<void> indicating success or error

Convenience helper that reads the current SW_MODE, updates the right polarity field, and writes it back.

◆ SetRightSwitchLatchMode()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::Switches::SetRightSwitchLatchMode ( ReferenceLatchMode latch_mode)
noexcept

Configure right switch latching behavior (SW_MODE.latch_r_active)

Parameters
latch_modeLatch mode selection
Returns
Result<void> indicating success or error

◆ SetRightSwitchStopEnable()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::Switches::SetRightSwitchStopEnable ( bool enable)
noexcept

Enable/disable stop-on-right-switch (SW_MODE.stop_r_enable)

Parameters
enableTrue to enable stop-on-switch
Returns
Result<void> indicating success or error

◆ SetStopMode()

template<typename CommType >
Result< void > tmc51x0::TMC51x0< CommType >::Switches::SetStopMode ( ReferenceStopMode stop_mode)
noexcept

Set reference stop mode (hard/soft stop) for internal ramp generator.

Parameters
stop_modeStop mode selection
Returns
Result<void> indicating success or error
Warning
Datasheet (SW_MODE): do not use soft stop in combination with StallGuard stop-on-stall (sg_stop). This API returns INVALID_STATE if soft-stop is requested while sg_stop is enabled.

Member Data Documentation

◆ driver_

template<typename CommType >
TMC51x0& tmc51x0::TMC51x0< CommType >::Switches::driver_
private

The documentation for this struct was generated from the following file: