|
HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
|
Unified handler for TMC5160/TMC5130 stepper motor driver. More...
#include <Tmc5160Handler.h>
Public Types | |
| using | SpiDriver = tmc51x0::TMC51x0<HalSpiTmc5160Comm> |
| SPI driver type alias. | |
| using | UartDriver = tmc51x0::TMC51x0<HalUartTmc5160Comm> |
| UART driver type alias. | |
| using | DriverVariant = std::variant<std::monostate, SpiDriver*, UartDriver*> |
| Non-owning variant holding either driver type or empty (monostate). | |
| using | ConstDriverVariant = std::variant<std::monostate, const SpiDriver*, const UartDriver*> |
| Const version of DriverVariant. | |
Public Member Functions | |
| Tmc5160Handler (BaseSpi &spi, BaseGpio &enable, BaseGpio *diag0=nullptr, BaseGpio *diag1=nullptr, uint8_t daisy_chain_position=0, const tmc51x0::PinActiveLevels &active_levels={}) noexcept | |
| Construct a TMC5160 handler with SPI communication. | |
| Tmc5160Handler (BaseUart &uart, BaseGpio &enable, BaseGpio *diag0=nullptr, BaseGpio *diag1=nullptr, uint8_t uart_node_address=0, const tmc51x0::PinActiveLevels &active_levels={}) noexcept | |
| Construct a TMC5160 handler with UART communication. | |
| ~Tmc5160Handler () noexcept | |
| Destructor. | |
| Tmc5160Handler (const Tmc5160Handler &)=delete | |
| Tmc5160Handler & | operator= (const Tmc5160Handler &)=delete |
| Tmc5160Handler (Tmc5160Handler &&)=delete | |
| Tmc5160Handler & | operator= (Tmc5160Handler &&)=delete |
| tmc51x0::ErrorCode | Initialize (const tmc51x0::DriverConfig &config, bool verbose=true) noexcept |
| Initialize the TMC5160 driver with full configuration. | |
| bool | EnsureInitialized () noexcept |
| Ensure driver is initialized (lazy init entrypoint). | |
| bool | Deinitialize () noexcept |
| Deinitialize — disable motor and release resources. | |
| bool | IsInitialized () const noexcept |
| Check if the handler is initialized. | |
| bool | IsSpi () const noexcept |
| Check if SPI is being used. | |
| template<typename Fn > | |
| auto | visitDriver (Fn &&fn) noexcept -> decltype(fn(std::declval< SpiDriver & >())) |
| Visit the typed driver with a callable. | |
| SpiDriver * | driverViaSpi () noexcept |
| Get typed SPI driver pointer (null if UART mode or not initialized). | |
| const SpiDriver * | driverViaSpi () const noexcept |
| UartDriver * | driverViaUart () noexcept |
| Get typed UART driver pointer (null if SPI mode or not initialized). | |
| const UartDriver * | driverViaUart () const noexcept |
| DriverVariant | GetDriver () noexcept |
| Get the active driver pointer without requiring visitor usage. | |
| ConstDriverVariant | GetDriver () const noexcept |
| Const overload of GetDriver(). | |
| void | DumpDiagnostics () noexcept |
| Dump diagnostic information to logger. | |
| const char * | GetDescription () const noexcept |
| Get a human-readable description of the handler. | |
| const tmc51x0::DriverConfig & | GetDriverConfig () const noexcept |
| Get the driver configuration used during initialization. | |
Static Public Member Functions | |
| static tmc51x0::DriverConfig | GetDefaultConfig () noexcept |
| Get a sensible default DriverConfig. | |
Private Member Functions | |
| bool | EnsureInitializedLocked () noexcept |
| template<typename Fn > | |
| auto | visitDriverInternal (Fn &&fn) noexcept -> decltype(fn(std::declval< SpiDriver & >())) |
| Helper: execute a visitor on the active driver (no lock, internal use) | |
Private Attributes | |
| bool | is_spi_ {true} |
| Communication mode flag. | |
| bool | initialized_ {false} |
| Initialization state. | |
| RtosMutex | mutex_ |
| Thread safety mutex. | |
| std::unique_ptr< HalSpiTmc5160Comm > | spi_comm_ |
| SPI communication adapter (owned, null if UART) | |
| std::unique_ptr< HalUartTmc5160Comm > | uart_comm_ |
| UART communication adapter (owned, null if SPI) | |
| std::unique_ptr< SpiDriver > | spi_driver_ |
| SPI driver instance (owned, null if UART) | |
| std::unique_ptr< UartDriver > | uart_driver_ |
| UART driver instance (owned, null if SPI) | |
| uint8_t | address_ {0} |
| Daisy chain position (SPI) or node address (UART) | |
| tmc51x0::DriverConfig | config_ {} |
| Configuration snapshot. | |
| char | description_ [64] {} |
| Human-readable handler description. | |
Unified handler for TMC5160/TMC5130 stepper motor driver.
Non-templated facade that owns one typed driver instance (SPI or UART). Provides convenience methods for common operations and direct access to all driver subsystems through visitDriver().
| using Tmc5160Handler::ConstDriverVariant = std::variant<std::monostate, const SpiDriver*, const UartDriver*> |
Const version of DriverVariant.
| using Tmc5160Handler::DriverVariant = std::variant<std::monostate, SpiDriver*, UartDriver*> |
Non-owning variant holding either driver type or empty (monostate).
| using Tmc5160Handler::SpiDriver = tmc51x0::TMC51x0<HalSpiTmc5160Comm> |
SPI driver type alias.
| using Tmc5160Handler::UartDriver = tmc51x0::TMC51x0<HalUartTmc5160Comm> |
UART driver type alias.
|
noexcept |
Construct a TMC5160 handler with SPI communication.
| spi | Reference to pre-configured BaseSpi (Mode 3, MSB first). |
| enable | BaseGpio connected to DRV_ENN (active LOW). |
| diag0 | Optional DIAG0 pin. |
| diag1 | Optional DIAG1 pin. |
| daisy_chain_position | Position in SPI daisy chain (0 = single/first). |
| active_levels | Pin polarity configuration. |
|
noexcept |
Construct a TMC5160 handler with UART communication.
| uart | Reference to pre-configured BaseUart. |
| enable | BaseGpio connected to DRV_ENN (active LOW). |
| diag0 | Optional DIAG0 pin. |
| diag1 | Optional DIAG1 pin. |
| uart_node_address | UART node address (0-254). |
| active_levels | Pin polarity configuration. |
|
noexcept |
Destructor.
|
delete |
|
delete |
|
noexcept |
Deinitialize — disable motor and release resources.
|
noexcept |
|
noexcept |
Get typed SPI driver pointer (null if UART mode or not initialized).
|
noexcept |
|
noexcept |
Get typed UART driver pointer (null if SPI mode or not initialized).
|
noexcept |
Dump diagnostic information to logger.
|
noexcept |
Ensure driver is initialized (lazy init entrypoint).
|
privatenoexcept |
|
inlinestaticnoexcept |
Get a sensible default DriverConfig.
|
noexcept |
Get a human-readable description of the handler.
|
inlinenoexcept |
|
inlinenoexcept |
Get the active driver pointer without requiring visitor usage.
SpiDriver* or UartDriver* wrapped in std::variant, or monostate if unavailable.
|
inlinenoexcept |
Get the driver configuration used during initialization.
|
noexcept |
Initialize the TMC5160 driver with full configuration.
| config | Driver configuration (motor, chopper, ramp, etc.). |
| verbose | Print config summary if true. |
|
inlinenoexcept |
Check if the handler is initialized.
|
inlinenoexcept |
Check if SPI is being used.
|
delete |
|
delete |
|
inlinenoexcept |
Visit the typed driver with a callable.
This is the primary way to access all 15 subsystems of the TMC5160 driver. The callable receives a reference to either SpiDriver or UartDriver.
| Fn | Callable type accepting auto& (SpiDriver& or UartDriver&) |
| fn | Callable to execute with the driver reference |
|
inlineprivatenoexcept |
Helper: execute a visitor on the active driver (no lock, internal use)
|
private |
Daisy chain position (SPI) or node address (UART)
|
private |
Configuration snapshot.
|
private |
Human-readable handler description.
|
private |
Initialization state.
|
private |
Communication mode flag.
|
mutableprivate |
Thread safety mutex.
|
private |
SPI communication adapter (owned, null if UART)
|
private |
SPI driver instance (owned, null if UART)
|
private |
UART communication adapter (owned, null if SPI)
|
private |
UART driver instance (owned, null if SPI)