ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
esphome::tmc2209::TMC2209Stepper Class Reference

#include <tmc2209.h>

Inheritance diagram for esphome::tmc2209::TMC2209Stepper:
esphome::tmc22xx::TMC22XXStepper esphome::stepper::Stepper esphome::Component esphome::uart::UARTDevice

Public Member Functions

void dump_config () override
 
template<typename F >
void add_on_stall_callback (F &&callback)
 Called when DIAG reports a stall. StallGuard only works in StealthChop, between TCOOLTHRS and TPWMTHRS.
 
void set_stallguard_threshold (uint8_t threshold)
 A stall is reported when the StallGuard result drops below twice this value.
 
uint8_t get_stallguard_threshold () const
 
void set_tcool_threshold (uint32_t threshold)
 Lower velocity limit, as TSTEP, for CoolStep and the StallGuard output on DIAG.
 
void set_semin (uint8_t semin)
 
void set_semax (uint8_t semax)
 
void set_seup (uint8_t seup)
 
void set_sedn (uint8_t sedn)
 
void set_seimin (bool seimin)
 
- Public Member Functions inherited from esphome::tmc22xx::TMC22XXStepper
void setup () override
 
void loop () override
 
void dump_config () override
 
void on_shutdown () override
 
float get_setup_priority () const override
 
void set_address (uint8_t address)
 
void set_enn_pin (GPIOPin *pin)
 
void set_step_pin (GPIOPin *pin)
 
void set_dir_pin (GPIOPin *pin)
 
void set_index_pin (InternalGPIOPin *pin)
 
void set_diag_pin (InternalGPIOPin *pin)
 
void set_clock_frequency (uint32_t frequency)
 
void set_rsense (float rsense)
 
void set_vsense (bool vsense)
 
void set_ottrim (uint8_t ottrim)
 
void set_analog_current_scale (bool enable)
 
void set_initial_run_current (float current)
 
void set_initial_hold_current (float current)
 
void set_initial_microsteps (uint16_t microsteps)
 
void set_enabled (bool enabled)
 Enable or disable the motor outputs, using the ENN pin when configured and TOFF otherwise.
 
bool is_enabled () const
 
bool is_unreachable () const
 True while the driver does not answer, until the status poll reads it again (every 10 s).
 
template<typename F >
void add_on_status_callback (F &&callback)
 Called with the condition and whether it became active or cleared.
 
void set_microsteps (uint16_t microsteps)
 
uint16_t get_microsteps ()
 
void set_interpolation (bool enable)
 
void set_spreadcycle (bool enable)
 
void set_inverse_direction (bool inverse)
 
void set_tpwm_threshold (uint32_t threshold)
 
void set_run_current (float current)
 Set the motor run or hold current in A RMS.
 
void set_hold_current (float current)
 
void set_irun (uint8_t irun)
 
void set_ihold (uint8_t ihold)
 
void set_iholddelay (uint8_t delay)
 
void set_tpowerdown (uint8_t tpowerdown)
 
void set_standstill_mode (StandstillMode mode)
 
void set_toff (uint8_t toff)
 Chopper off time (1-15). TOFF=0 is used to disable the outputs, so this is applied on the next enable.
 
void set_tbl (uint8_t tbl)
 
void set_hend (uint8_t hend)
 
void set_hstrt (uint8_t hstrt)
 
void set_pwm_ofs (uint8_t ofs)
 
void set_pwm_grad (uint8_t grad)
 
void set_pwm_freq (uint8_t freq)
 
void set_pwm_autoscale (bool enable)
 
void set_pwm_autograd (bool enable)
 
void set_pwm_reg (uint8_t reg)
 
void set_pwm_lim (uint8_t lim)
 
float scale_to_current (uint8_t scale)
 Convert a current scale (0-31) to A RMS, without analog current scale.
 
bool write_register (uint8_t reg, uint32_t value)
 
optional< uint32_t > read_register (uint8_t reg)
 
bool write_field (const RegisterField &field, uint32_t value)
 
optional< uint32_t > read_field (const RegisterField &field)
 
- Public Member Functions inherited from esphome::stepper::Stepper
void set_target (int32_t steps)
 
void report_position (int32_t steps)
 
void set_acceleration (float acceleration)
 
void set_deceleration (float deceleration)
 
void set_max_speed (float max_speed)
 
virtual void on_update_speed ()
 
bool has_reached_target ()
 
- Public Member Functions inherited from esphome::Component
float get_actual_setup_priority () const
 
void set_setup_priority (float priority)
 
void call ()
 
virtual void on_safe_shutdown ()
 
virtual bool teardown ()
 Called during teardown to allow component to gracefully finish operations.
 
virtual void on_powerdown ()
 Called after teardown is complete to power down hardware.
 
uint8_t get_component_state () const
 
void reset_to_construction_state ()
 Reset this component back to the construction state to allow setup to run again.
 
bool is_in_loop_state () const
 Check if this component has completed setup and is in the loop state.
 
bool is_idle () const
 Check if this component is idle.
 
void mark_failed ()
 Mark this component as failed.
 
void mark_failed (const LogString *message)
 
void disable_loop ()
 Disable this component's loop.
 
void enable_loop ()
 Enable this component's loop.
 
void enable_loop_soon_any_context ()
 Thread and ISR-safe version of enable_loop() that can be called from any context.
 
bool is_failed () const
 
bool is_ready () const
 
virtual bool can_proceed ()
 
bool status_has_warning () const
 
bool status_has_error () const
 
void status_set_warning ()
 
void status_set_warning (const char *message)
 
void status_set_warning (const LogString *message)
 
void status_set_error ()
 
void status_set_error (const LogString *message)
 
void status_clear_warning ()
 
void status_clear_error ()
 
 ESPDEPRECATED ("Use status_momentary_warning() without a name. Removed in 2027.5.0", "2026.11.0") void status_momentary_warning(const char *name
 
void status_momentary_warning (uint32_t length=5000)
 Set warning status flag and clear it after length ms.
 
void status_momentary_warning (const LogString *message, uint32_t length=5000)
 
 ESPDEPRECATED ("Use status_momentary_error() without a name. Removed in 2027.5.0", "2026.11.0") void status_momentary_error(const char *name
 
void status_momentary_error (uint32_t length=5000)
 Set error status flag and clear it after length ms.
 
void status_momentary_error (const LogString *message, uint32_t length=5000)
 
bool has_overridden_loop () const
 
const LogString * get_component_log_str () const ESPHOME_ALWAYS_INLINE
 Get the integration where this component was declared as a LogString for logging.
 
bool should_warn_of_blocking (uint32_t blocking_time, uint32_t &threshold_ms_out)
 
- Public Member Functions inherited from esphome::uart::UARTDevice
 UARTDevice ()=default
 
 UARTDevice (UARTComponent *parent)
 
void set_uart_parent (UARTComponent *parent)
 
void write_byte (uint8_t data)
 
void set_rx_full_threshold (size_t rx_full_threshold)
 
void set_rx_full_threshold_ms (size_t time)
 
size_t get_rx_full_threshold ()
 
void set_rx_timeout (size_t rx_timeout)
 
size_t get_rx_timeout ()
 
void write_array (const uint8_t *data, size_t len)
 
void write_array_progmem (const uint8_t *data, size_t len)
 
void write_array (const std::vector< uint8_t > &data)
 
template<size_t N>
void write_array (const std::array< uint8_t, N > &data)
 
void write_str (const char *str)
 
bool read_byte (uint8_t *data)
 
bool peek_byte (uint8_t *data)
 
bool read_array (uint8_t *data, size_t len)
 
template<size_t N>
optional< std::array< uint8_t, N > > read_array ()
 
size_t available ()
 
UARTFlushResult flush ()
 
int read ()
 
size_t write (uint8_t data)
 
int peek ()
 
 ESPDEPRECATED ("Use uart.final_validate_device_schema() in Python instead. Removed in 2027.3.0", "2026.9.0") void check_uart_settings(uint32_t baud_rate
 Check that the configuration of the UART bus matches the provided values and otherwise print a warning.
 

Protected Member Functions

uint8_t expected_version () const override
 
uint32_t * shadow_register (uint8_t reg) override
 
void restore_registers () override
 
void on_diag_without_error () override
 
- Protected Member Functions inherited from esphome::tmc22xx::TMC22XXStepper
void apply_config_ ()
 Write the settings from the configuration to the readable registers.
 
bool update_status_ ()
 Read GSTAT and DRV_STATUS and report changes. Returns false when the status could not be read.
 
optional< uint8_t > current_to_scale_ (float current)
 
float full_scale_current_ ()
 
int32_t get_vactual_ () const
 
int32_t speed_to_vactual_ (float speed) const
 
void add_index_pulses_ ()
 
void loop_serial_ ()
 
void loop_step_dir_ ()
 
- Protected Member Functions inherited from esphome::stepper::Stepper
void calculate_speed_ (uint32_t now)
 
int32_t should_step_ ()
 
- Protected Member Functions inherited from esphome::Component
friend void::setup ()
 
friend void::original_setup ()
 
void set_component_source_ (uint8_t index)
 Set where this component was loaded from for some debug messages.
 
virtual void call_setup ()
 
void call_dump_config_ ()
 
void enable_loop_slow_path_ ()
 
void set_component_state_ (uint8_t state)
 Helper to set component state (clears state bits and sets new state)
 
bool set_status_flag_ (uint8_t flag)
 Helper to set a status LED flag on both this component and the app.
 
bool set_error_flag_ (const LogString *message)
 Set the error flag and log it; true when it was not set before.
 
void set_interval (const char *name, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a const char* name.
 
void set_interval (uint32_t id, uint32_t interval, std::function< void()> &&f)
 Set an interval function with a numeric ID (zero heap allocation).
 
void set_interval (InternalSchedulerID id, uint32_t interval, std::function< void()> &&f)
 
void set_interval (uint32_t interval, std::function< void()> &&f)
 
bool cancel_interval (const char *name)
 Cancel an interval function.
 
bool cancel_interval (uint32_t id)
 
bool cancel_interval (InternalSchedulerID id)
 
void set_timeout (const char *name, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a const char* name.
 
void set_timeout (uint32_t id, uint32_t timeout, std::function< void()> &&f)
 Set a timeout function with a numeric ID (zero heap allocation).
 
void set_timeout (InternalSchedulerID id, uint32_t timeout, std::function< void()> &&f)
 
void set_timeout (uint32_t timeout, std::function< void()> &&f)
 
bool cancel_timeout (const char *name)
 Cancel a timeout function.
 
bool cancel_timeout (uint32_t id)
 
bool cancel_timeout (InternalSchedulerID id)
 
void defer (const char *name, std::function< void()> &&f)
 Defer a callback to the next loop() call with a const char* name.
 
void defer (std::function< void()> &&f)
 Defer a callback to the next loop() call.
 
void defer (uint32_t id, std::function< void()> &&f)
 Defer a callback with a numeric ID (zero heap allocation)
 
bool cancel_defer (const char *name)
 Cancel a defer callback using the specified name, name must not be empty.
 
bool cancel_defer (uint32_t id)
 
void status_clear_warning_slow_path_ ()
 
void status_clear_error_slow_path_ ()
 

Protected Attributes

LazyCallbackManager< void()> stall_callback_
 
uint32_t tcoolthrs_ {0}
 
uint32_t sgthrs_ {0}
 
uint32_t coolconf_ {0}
 
- Protected Attributes inherited from esphome::tmc22xx::TMC22XXStepper
GPIOPin * enn_pin_ {nullptr}
 
GPIOPin * step_pin_ {nullptr}
 
GPIOPin * dir_pin_ {nullptr}
 
InternalGPIOPin * index_pin_ {nullptr}
 
InternalGPIOPin * diag_pin_ {nullptr}
 
LazyCallbackManager< void(DriverEvent, bool)> status_callback_
 
uint32_t clock_frequency_ {12000000}
 
uint32_t ihold_irun_ {0x00071703}
 
uint32_t tpowerdown_ {0x14}
 
uint32_t tpwmthrs_ {0}
 
uint32_t vactual_reg_ {0}
 
std::array< uint32_t, RESTORED_REGISTERS.size()> restored_values_ {}
 
float rsense_ {NAN}
 
float initial_run_current_ {NAN}
 
float initial_hold_current_ {NAN}
 
IndexPulseStore index_store_ {}
 
uint16_t initial_microsteps_ {16}
 
uint16_t status_ {0}
 
optional< bool > vsense_ {}
 
optional< uint8_t > ottrim_ {}
 
uint8_t address_ {0}
 
uint8_t toff_ {3}
 
uint8_t version_ {0}
 
uint8_t restored_written_ {0}
 
uint8_t status_poll_skip_ {0}
 
int8_t direction_ {0}
 
DiagPinStore diag_store_ {}
 
bool analog_current_scale_ {false}
 
bool enabled_ {false}
 
bool vsense_active_ {false}
 
bool step_state_ {false}
 
bool moving_ {false}
 
HighFrequencyLoopRequester high_freq_
 
- Protected Attributes inherited from esphome::stepper::Stepper
float acceleration_ {1e6f}
 
float deceleration_ {1e6f}
 
float current_speed_ {0.0f}
 
float max_speed_ {1e6f}
 
uint32_t last_calculation_ {0}
 
uint32_t last_step_ {0}
 
- Protected Attributes inherited from esphome::Component
uint8_t component_source_index_ {0}
 Index into component source PROGMEM lookup table (0 = not set)
 
uint8_t warn_if_blocking_over_ {WARN_IF_BLOCKING_OVER_CS}
 Warn threshold in centiseconds (max 2550ms)
 
uint8_t component_state_ {0x00}
 State of this component - each bit has a purpose: Bits 0-2: Component state (0x00=CONSTRUCTION, 0x01=SETUP, 0x02=LOOP, 0x03=FAILED, 0x04=LOOP_DONE) Bit 3: STATUS_LED_WARNING Bit 4: STATUS_LED_ERROR Bit 5: Has overridden loop() (set at registration time) Bits 6-7: Unused - reserved for future expansion.
 
volatile bool pending_enable_loop_ {false}
 ISR-safe flag for enable_loop_soon_any_context.
 
ComponentRuntimeStats runtime_stats_
 
- Protected Attributes inherited from esphome::uart::UARTDevice
UARTComponent * parent_ {nullptr}
 

Additional Inherited Members

- Static Public Member Functions inherited from esphome::tmc22xx::TMC22XXStepper
static uint32_t extract_field (uint32_t data, const RegisterField &field)
 
- Data Fields inherited from esphome::stepper::Stepper
int32_t current_position {0}
 
int32_t target_position {0}
 
- Data Fields inherited from esphome::Component
uint32_t length = 5000)
 
- Data Fields inherited from esphome::uart::UARTDevice
uint8_t stop_bits = 1
 
uint8_t UARTParityOptions parity = UART_CONFIG_PARITY_NONE
 
uint8_t UARTParityOptions uint8_t data_bits = 8)
 

Detailed Description

Definition at line 24 of file tmc2209.h.

Member Function Documentation

◆ add_on_stall_callback()

template<typename F >
void esphome::tmc2209::TMC2209Stepper::add_on_stall_callback ( F && callback)
inline

Called when DIAG reports a stall. StallGuard only works in StealthChop, between TCOOLTHRS and TPWMTHRS.

Definition at line 29 of file tmc2209.h.

◆ dump_config()

void esphome::tmc2209::TMC2209Stepper::dump_config ( )
overridevirtual

Reimplemented from esphome::Component.

Definition at line 8 of file tmc2209.cpp.

◆ expected_version()

uint8_t esphome::tmc2209::TMC2209Stepper::expected_version ( ) const
inlineoverrideprotectedvirtual

Implements esphome::tmc22xx::TMC22XXStepper.

Definition at line 45 of file tmc2209.h.

◆ get_stallguard_threshold()

uint8_t esphome::tmc2209::TMC2209Stepper::get_stallguard_threshold ( ) const
inline

Definition at line 35 of file tmc2209.h.

◆ on_diag_without_error()

void esphome::tmc2209::TMC2209Stepper::on_diag_without_error ( )
inlineoverrideprotectedvirtual

Reimplemented from esphome::tmc22xx::TMC22XXStepper.

Definition at line 48 of file tmc2209.h.

◆ restore_registers()

void esphome::tmc2209::TMC2209Stepper::restore_registers ( )
overrideprotectedvirtual

Reimplemented from esphome::tmc22xx::TMC22XXStepper.

Definition at line 26 of file tmc2209.cpp.

◆ set_sedn()

void esphome::tmc2209::TMC2209Stepper::set_sedn ( uint8_t sedn)
inline

Definition at line 41 of file tmc2209.h.

◆ set_seimin()

void esphome::tmc2209::TMC2209Stepper::set_seimin ( bool seimin)
inline

Definition at line 42 of file tmc2209.h.

◆ set_semax()

void esphome::tmc2209::TMC2209Stepper::set_semax ( uint8_t semax)
inline

Definition at line 39 of file tmc2209.h.

◆ set_semin()

void esphome::tmc2209::TMC2209Stepper::set_semin ( uint8_t semin)
inline

Definition at line 38 of file tmc2209.h.

◆ set_seup()

void esphome::tmc2209::TMC2209Stepper::set_seup ( uint8_t seup)
inline

Definition at line 40 of file tmc2209.h.

◆ set_stallguard_threshold()

void esphome::tmc2209::TMC2209Stepper::set_stallguard_threshold ( uint8_t threshold)
inline

A stall is reported when the StallGuard result drops below twice this value.

Definition at line 34 of file tmc2209.h.

◆ set_tcool_threshold()

void esphome::tmc2209::TMC2209Stepper::set_tcool_threshold ( uint32_t threshold)
inline

Lower velocity limit, as TSTEP, for CoolStep and the StallGuard output on DIAG.

Definition at line 37 of file tmc2209.h.

◆ shadow_register()

uint32_t * esphome::tmc2209::TMC2209Stepper::shadow_register ( uint8_t reg)
overrideprotectedvirtual

Reimplemented from esphome::tmc22xx::TMC22XXStepper.

Definition at line 13 of file tmc2209.cpp.

Field Documentation

◆ coolconf_

uint32_t esphome::tmc2209::TMC2209Stepper::coolconf_ {0}
protected

Definition at line 54 of file tmc2209.h.

◆ sgthrs_

uint32_t esphome::tmc2209::TMC2209Stepper::sgthrs_ {0}
protected

Definition at line 53 of file tmc2209.h.

◆ stall_callback_

LazyCallbackManager<void()> esphome::tmc2209::TMC2209Stepper::stall_callback_
protected

Definition at line 50 of file tmc2209.h.

◆ tcoolthrs_

uint32_t esphome::tmc2209::TMC2209Stepper::tcoolthrs_ {0}
protected

Definition at line 52 of file tmc2209.h.


The documentation for this class was generated from the following files: