Stepper motor driver handler for TMC5160/TMC5130 with SPI/UART support.
All motor control, ramp, chopper, and StallGuard operations are accessed
through the typed driver pointers or visitDriver() — the handler itself
provides only lifecycle management and driver routing.
Full driver initialization with DriverConfig. Returns bool.
EnsureInitialized()
Lazy init entrypoint
Deinitialize()
Disable motor and release resources
IsInitialized()
Check initialization state
IsSpi()
Check if SPI mode is active
GetDriverConfig()
Get the DriverConfig snapshot used at init
Driver Access
Method
Description
driverViaSpi()
Typed SpiDriver* (nullptr if UART or not init)
driverViaUart()
Typed UartDriver* (nullptr if SPI or not init)
GetDriver()
std::variant<monostate, SpiDriver*, UartDriver*>
visitDriver(fn)
Execute callable on active driver under mutex
Diagnostics
Method
Description
DumpDiagnostics()
Log status, registers, and driver info
Driver Subsystem Access
The TMC5160 driver exposes 15 subsystems. You access them through the
typed driver pointer or visitDriver() — not through handler-level
convenience wrappers:
Subsystem
Purpose
rampControl
Motion profile: position, velocity, acceleration
motorControl
Enable/disable, current setting, chopper config
stallGuard
StallGuard2 load detection
encoder
ABN encoder interface
homing
Sensorless/switch/encoder homing routines
thresholds
Velocity threshold configuration
switches
Reference switch control
tuning
Auto-tuning routines
status
Status register and diagnostics
powerStage
Over-current / short protection
communication
Raw register read/write
io
Pin / mode helpers
events
XCompare / ramp events
printer
Debug printing
uartConfig
UART node addressing
Typed Pointer Access (recommended)
When you know the comm mode (you always do — you chose it at construction):
1
2
3
4
5
6
7
8
// SPI mode — direct subsystem accessauto*drv=handler.driverViaSpi();drv->motorControl.Enable();drv->rampControl.SetTargetPosition(51200);// UART mode equivalentauto*drv=handler.driverViaUart();drv->rampControl.SetMaxSpeed(50000);