|
| | CommInterface () noexcept=default |
| | Construct communication interface.
|
| |
| CommMode | GetMode () const noexcept |
| | Get the underlying communication mode used by this interface.
|
| |
| Result< uint32_t > | ReadRegister (uint8_t address, uint8_t address_param=0) noexcept |
| | Read a 32-bit register from the TMC5160.
|
| |
| Result< void > | WriteRegister (uint8_t address, uint32_t value, uint8_t address_param=0) noexcept |
| | Write a 32-bit register to the TMC5160.
|
| |
| Result< void > | GpioSet (TMC51x0CtrlPin pin, GpioSignal signal) noexcept |
| | Set GPIO pin signal state (output control)
|
| |
| Result< GpioSignal > | GpioRead (TMC51x0CtrlPin pin) noexcept |
| | Read GPIO pin signal state (input state)
|
| |
| Result< void > | GpioSetActive (TMC51x0CtrlPin pin) noexcept |
| | Set GPIO pin to active state (convenience method)
|
| |
| Result< void > | GpioSetInactive (TMC51x0CtrlPin pin) noexcept |
| | Set GPIO pin to inactive state (convenience method)
|
| |
| void | DelayMs (uint32_t ms) noexcept |
| | Delay execution for specified milliseconds.
|
| |
| void | DelayUs (uint32_t us) noexcept |
| | Delay execution for specified microseconds.
|
| |
| Result< void > | SetPowerEnabled (bool enabled) noexcept |
| | Enable/disable power to the TMC51x0 (optional)
|
| |
| Result< void > | PowerCycle (uint32_t power_off_ms=20, uint32_t power_on_settle_ms=20) noexcept |
| | Power-cycle the TMC51x0 (optional)
|
| |
| Result< void > | SetClkFreq (uint32_t frequency_hz) noexcept |
| | Set external clock frequency on CLK pin (optional)
|
| |
| | CommInterface (const CommInterface &)=delete |
| |
| CommInterface & | operator= (const CommInterface &)=delete |
| |
| void | LogDebug (int level, const char *tag, const char *format,...) noexcept |
| | Public debug logging wrapper for external classes.
|
| |
| void | LogDebug (LogLevel level, const char *tag, const char *format,...) noexcept |
| | LogDebug overload that accepts the driver-native LogLevel enum.
|
| |
template<typename Derived>
class tmc51x0::CommInterface< Derived >
CRTP-based communication interface for register read/write operations.
Defines the common API for higher-level code to read and write registers without knowledge of the underlying transport (SPI or UART). Also provides GPIO control interface for TMC5160 control pins.
This template class uses the CRTP (Curiously Recurring Template Pattern) for compile-time polymorphism, providing zero runtime overhead compared to virtual functions.
Example usage:
class MySPI : public tmc5160::SpiCommInterface<MySPI> {
public:
CommMode mode() const noexcept {
return CommMode::SPI; }
bool spiTransfer(...) { ... }
bool gpioSet(...) { ... }
};
CommMode
Supported physical communication modes for TMC51x0.
Definition tmc51x0_comm_interface.hpp:221
- Template Parameters
-
| Derived | The derived class type (CRTP pattern) |
template<typename Derived >
Set external clock frequency on CLK pin (optional)
- Parameters
-
| frequency_hz | Desired clock frequency in Hz (0 = use internal clock, >0 = external clock frequency) |
- Returns
- Result<void> indicating success or error
This method is optional - derived classes can implement it if they support providing an external clock signal on the CLK pin. If not implemented, this method will return false, indicating that the internal oscillator should be used.
Clock Mode Selection:
- Internal Clock:
- Pass
frequency_hz = 0 to explicitly use internal clock
- CLK pin should be set to GND (low) to enable internal oscillator
- Internal oscillator provides ~12MHz clock
- Return true if CLK pin was successfully set to GND, false if not supported
- f_clk in DriverConfig should still be set correctly (typically 12000000 Hz)
- The driver uses f_clk for timing calculations regardless of clock source
- External Clock:
- Pass
frequency_hz > 0 to use external clock at specified frequency
- CLK pin should receive clock signal from external source
- Return true if clock signal was successfully provided on CLK pin
- f_clk in DriverConfig must match the actual external clock frequency
- Typical frequencies: 12MHz (default) or 24MHz (for higher performance)
Important:
- The f_clk value in DriverConfig is used for all timing calculations (IHOLDDELAY, TPOWERDOWN, TZEROWAIT, etc.)
- f_clk must be set correctly regardless of whether using internal or external clock
- For internal clock, f_clk is typically 12000000 Hz (12 MHz)
- For external clock, f_clk must match the actual frequency provided
- Passing
frequency_hz = 0 allows users with external clock capability to switch back to internal clock
Implementation Guidelines:
- If your system doesn't support clock control, return ErrorCode::UNSUPPORTED (driver will assume internal clock)
- If your system supports clock control:
- When
frequency_hz = 0: Set CLK pin to GND (low) and return Result<void>()
- When
frequency_hz > 0: Provide clock signal at specified frequency and return Result<void>()
- Return error only if the operation failed (e.g., invalid frequency, hardware error)
- Note
- This is called automatically during Initialize() with the f_clk value from DriverConfig.
-
If not implemented (returns UNSUPPORTED), the driver assumes internal clock (CLK pin tied to GND).
-
The internal clock has a fail-over circuit that protects against loss of external clock signal.
-
Per datasheet: "Tie to GND using short wire for internal clock or
supply external clock."
template<typename Derived >
Enable/disable power to the TMC51x0 (optional)
- Parameters
-
| enabled | true to enable power, false to disable power |
- Returns
- Result<void> indicating success or ErrorCode::UNSUPPORTED
This hook allows a platform to control a load switch / regulator that supplies the TMC51x0 (typically VIO, or a dedicated enable pin for the device's logic rail). It is OPTIONAL.
If not implemented by the derived class, the default implementation returns ErrorCode::UNSUPPORTED.
- Note
- This is intended for a true hard reset (power-on reset). Most users will not provide this capability.