HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
tmc51x0_config_builder.hpp File Reference

Fluent configuration builder for TMC51x0 driver. More...

#include <cstdint>
#include "../tmc51x0_types.hpp"
Include dependency graph for tmc51x0_config_builder.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  tmc51x0::ConfigBuilder
 Fluent configuration builder for DriverConfig. More...
 

Namespaces

namespace  tmc51x0
 

Detailed Description

Fluent configuration builder for TMC51x0 driver.

Provides a fluent interface for building DriverConfig with:

  • Units in milliamps, millivolts, milliohms, millihenries
  • Chainable method calls for easy configuration
  • Complete coverage of all DriverConfig fields
  • Mimics the ESP32 test config initialization pattern

Unit Naming Convention

Functions follow a clear unit naming convention for safety and readability:

  • Unit suffixes for fixed units: Functions that always use a specific unit have the unit suffix in the function name:
    • WithMotorMa() - rated current in milliamps
    • WithRunCurrentMa() - run current in milliamps
    • WithHoldCurrentMa() - hold current in milliamps
    • WithSupplyVoltageMv() - supply voltage in millivolts
    • WithSenseResistorMohm() - sense resistor in milliohms
    • WithWindingResistanceMohm() - winding resistance in milliohms
    • WithWindingInductanceMh() - winding inductance in millihenries
    • WithMotorPowerDownDelayMs() - always milliseconds
    • WithRampPowerDownDelayMs() - always milliseconds
    • WithZeroWaitTimeMs() - always milliseconds
    • WithBbmTimeNs() - always nanoseconds
    • WithS2vsVoltageMv() - always millivolts
    • WithS2gVoltageMv() - always millivolts
    • WithMosfetMillerChargeNc() - always nanocoulombs
    • WithShortDetectionDelayUsX10() - always 0.1µs units
    • WithExternalClockHz() - clock frequency in Hz
  • Unit-agnostic for flexible units: Functions that accept different units use self-describing value types (VelocityValue, AccelerationValue):
    • WithMaxSpeed(VelocityValue) - can be Steps, RPM, RevPerSec, etc.
    • WithAcceleration(AccelerationValue) - can be Steps, RevPerSec, etc.
    • WithStealthChopThreshold(VelocityValue) - can be Steps, RPM, etc.

This convention ensures type safety and prevents unit conversion errors.

The builder follows the same pattern as ESP32 test config:

  1. Motor configuration (motor specs, chopper, StealthChop, StallGuard, ramp defaults)
  2. Board configuration (sense resistor, power stage, clock)
  3. Platform configuration (mechanical system type)
auto config = ConfigBuilder()
// Motor configuration
.WithMotorMa(200, 1500) // 200 steps, 1500mA = 1.5A rated
.WithSupplyVoltageMv(24000) // 24000mV = 24V
.WithSenseResistorMohm(50) // 50mΩ = 0.05Ω
.WithRunCurrentMa(1500) // 1500mA = 1.5A run current
.WithHoldCurrentMa(750) // 750mA = 0.75A hold current
// Chopper configuration
.WithChopperMode(ChopperMode::SPREAD_CYCLE)
.WithChopperToff(5)
.WithChopperBlankTime(ChopperBlankTime::TBL_36CLK)
// StealthChop configuration
.WithStealthChop(true)
.WithStealthChopThreshold({800.0f, Unit::Steps})
// Motion configuration
.WithMaxSpeed({100.0f, Unit::RPM})
.WithAcceleration({50.0f, Unit::RevPerSec})
// Mechanical system
.WithGearbox(5.18f) // 5.18:1 gearbox
.Build();