|
HardFOC Core
API reference
|
Unified, non-templated handler for a single TMC9660 motor controller device. More...
#include <Tmc9660Handler.h>
Classes | |
| class | Adc |
| BaseAdc adapter for all TMC9660 ADC channels. More... | |
| class | Gpio |
| BaseGpio adapter for a single TMC9660 internal GPIO channel. More... | |
| class | Temperature |
| BaseTemperature adapter for the TMC9660 internal chip temperature sensor. More... | |
Public Types | |
Type Aliases | |
| using | SpiDriver = tmc9660::TMC9660< HalSpiTmc9660Comm > |
| TMC9660 driver instantiated with SPI communication. | |
| using | UartDriver = tmc9660::TMC9660< HalUartTmc9660Comm > |
| TMC9660 driver instantiated with UART communication. | |
| 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 | |
Construction and Destruction | |
| Tmc9660Handler (BaseSpi &spi, BaseGpio &rst, BaseGpio &drv_en, BaseGpio &faultn, BaseGpio &wake, uint8_t address=0, const tmc9660::BootloaderConfig *bootCfg=&kDefaultBootConfig) | |
| Construct a handler for a TMC9660 connected via SPI. | |
| Tmc9660Handler (BaseUart &uart, BaseGpio &rst, BaseGpio &drv_en, BaseGpio &faultn, BaseGpio &wake, uint8_t address=0, const tmc9660::BootloaderConfig *bootCfg=&kDefaultBootConfig) | |
| Construct a handler for a TMC9660 connected via UART. | |
| ~Tmc9660Handler () noexcept | |
| Destructor. Releases the driver, communication adapter, and all wrappers. | |
| Tmc9660Handler (const Tmc9660Handler &)=delete | |
| Non-copyable. | |
| Tmc9660Handler & | operator= (const Tmc9660Handler &)=delete |
| Non-copyable. | |
| Tmc9660Handler (Tmc9660Handler &&)=delete | |
| Non-movable. | |
| Tmc9660Handler & | operator= (Tmc9660Handler &&)=delete |
| Non-movable. | |
Initialization | |
| bool | Initialize (bool performReset=true, bool retrieveBootloaderInfo=true, bool failOnVerifyError=false) |
| Initialize the TMC9660 device. | |
| bool | EnsureInitialized () noexcept |
| Ensure driver is initialized (lazy init entrypoint). | |
| bool | IsDriverReady () const noexcept |
| Check if the TMC9660 driver has been initialized and is ready. | |
| void | SetTmclReplyTimeoutMs (uint32_t ms) noexcept |
| TMCL reply window for UART transfers (HalUartTmc9660Comm::setReplyTimeoutMs). | |
Peripheral Accessors | |
Retrieve references to the handler's internal peripheral wrappers. | |
| Gpio * | gpio (uint8_t gpioNumber) noexcept |
| Get the GPIO wrapper for a TMC9660 internal GPIO pin. | |
| Adc * | adc () noexcept |
| Get the ADC wrapper. | |
| Temperature * | temperature () noexcept |
| Get the Temperature wrapper. | |
Communication Info | |
| tmc9660::CommMode | GetCommMode () const noexcept |
| Get the communication mode in use (SPI or UART). | |
| const tmc9660::BootloaderConfig * | bootConfig () const noexcept |
| Get the bootloader configuration in use. | |
Diagnostics | |
| void | DumpDiagnostics () noexcept |
| Dump comprehensive diagnostics to the system log. | |
| const char * | GetDescription () const noexcept |
| Get a human-readable description of the handler. | |
Typed Driver Access | |
Direct access to the underlying typed TMC9660 driver instance. | |
| SpiDriver * | driverViaSpi () noexcept |
| Get the TMC9660 driver instance connected via SPI (nullptr if using UART). | |
| const SpiDriver * | driverViaSpi () const noexcept |
| Const version of driverViaSpi(). | |
| UartDriver * | driverViaUart () noexcept |
| Get the TMC9660 driver instance connected via UART (nullptr if using SPI). | |
| const UartDriver * | driverViaUart () const noexcept |
| Const version of driverViaUart(). | |
| DriverVariant | GetDriver () noexcept |
| Get the active driver pointer without requiring visitor usage. | |
| ConstDriverVariant | GetDriver () const noexcept |
| Const overload of GetDriver(). | |
Driver Visitor Pattern | |
Generic access when comm mode is not known at the call site. | |
| template<typename Func > | |
| auto | visitDriver (Func &&func) noexcept |
| Execute a function on the underlying typed TMC9660 driver. | |
| template<typename Func > | |
| auto | visitDriver (Func &&func) const noexcept |
| Const overload of visitDriver(). | |
Static Public Attributes | |
Default Configuration | |
| static const tmc9660::BootloaderConfig | kDefaultBootConfig |
| Default bootloader configuration based on TMC9660-3PH-EVAL board settings. | |
Private Member Functions | |
| Adc & | AdcInstance () noexcept |
| The always-present Adc instance, without the bring-up attempt adc() makes. | |
| bool | EnsureInitializedLocked () noexcept |
| Ensure initialized while handler_mutex_ is already held. | |
| template<typename Func > | |
| auto | visitDriverInternal (Func &&func) noexcept |
| Internal no-lock visitDriver for use from already-locked contexts. | |
Private Attributes | |
| bool | use_spi_ |
| true = SPI communication active, false = UART. | |
| char | description_ [64] {} |
| Human-readable handler description. | |
Communication Adapters | |
One of these is created at construction time; the other remains null. | |
| std::unique_ptr< HalSpiTmc9660Comm > | spi_comm_ |
| SPI communication adapter (or nullptr). | |
| std::unique_ptr< HalUartTmc9660Comm > | uart_comm_ |
| UART communication adapter (or nullptr). | |
Typed Driver Instances | |
Created during Initialize(); one is active, the other remains null. | |
| std::unique_ptr< SpiDriver > | spi_driver_ |
| TMC9660 driver for SPI mode (or nullptr). | |
| std::unique_ptr< UartDriver > | uart_driver_ |
| TMC9660 driver for UART mode (or nullptr). | |
Peripheral Wrappers | |
Created during Initialize(). | |
| std::array< std::unique_ptr< Gpio >, 2 > | gpioWrappers_ |
| GPIO17 [0] and GPIO18 [1]. | |
| std::unique_ptr< Adc > | adcWrapper_ |
| Multi-channel ADC wrapper. | |
| std::unique_ptr< Temperature > | temperatureWrapper_ |
| Chip temperature wrapper. | |
Configuration | |
| const tmc9660::BootloaderConfig * | bootCfg_ |
| Bootloader config (not owned; must outlive handler). | |
| uint8_t | device_address_ |
| 7-bit TMCL device address. | |
| bool | boot_ok_ {false} |
| true only after bootloaderInit Success. | |
Thread Safety | |
| RtosMutex | handler_mutex_ |
| Recursive mutex for thread-safe access. | |
Friends | |
| class | Tmc9660AdcWrapper |
| Tmc9660AdcWrapper delegates to the Adc instance directly (see AdcInstance()). | |
Unified, non-templated handler for a single TMC9660 motor controller device.
Tmc9660Handler is the primary interface that application and host-HAL code uses to interact with a TMC9660 motor driver. It hides the template complexity of tmc9660::TMC9660<CommType> behind a clean, polymorphism-free API.
| using Tmc9660Handler::ConstDriverVariant = std::variant<std::monostate, const SpiDriver*, const UartDriver*> |
Const version of DriverVariant.
| using Tmc9660Handler::DriverVariant = std::variant<std::monostate, SpiDriver*, UartDriver*> |
Non-owning variant holding either driver type or empty (monostate).
| using Tmc9660Handler::SpiDriver = tmc9660::TMC9660<HalSpiTmc9660Comm> |
TMC9660 driver instantiated with SPI communication.
| using Tmc9660Handler::UartDriver = tmc9660::TMC9660<HalUartTmc9660Comm> |
TMC9660 driver instantiated with UART communication.
| Tmc9660Handler::Tmc9660Handler | ( | BaseSpi & | spi, |
| BaseGpio & | rst, | ||
| BaseGpio & | drv_en, | ||
| BaseGpio & | faultn, | ||
| BaseGpio & | wake, | ||
| uint8_t | address = 0, |
||
| const tmc9660::BootloaderConfig * | bootCfg = &kDefaultBootConfig |
||
| ) |
Construct a handler for a TMC9660 connected via SPI.
The communication adapter (HalSpiTmc9660Comm) is created immediately, but the typed TMC9660 driver instance is deferred until Initialize() is called.
| spi | Reference to an initialized BaseSpi bus connected to the TMC9660. Must use SPI Mode 3 (CPOL=1, CPHA=1), MSB-first. |
| rst | BaseGpio for the TMC9660 RST control pin (host-side output). Must be pre-configured with correct pin number and output direction. |
| drv_en | BaseGpio for the TMC9660 DRV_EN control pin (host-side output). |
| faultn | BaseGpio for the TMC9660 FAULTN status pin (host-side input). |
| wake | BaseGpio for the TMC9660 WAKE control pin (host-side output). |
| address | 7-bit device address used in TMCL communication (default: 0). |
| bootCfg | Pointer to bootloader configuration. The pointed-to struct must remain valid for the handler's lifetime. Pass nullptr or omit to use kDefaultBootConfig. |
| Tmc9660Handler::Tmc9660Handler | ( | BaseUart & | uart, |
| BaseGpio & | rst, | ||
| BaseGpio & | drv_en, | ||
| BaseGpio & | faultn, | ||
| BaseGpio & | wake, | ||
| uint8_t | address = 0, |
||
| const tmc9660::BootloaderConfig * | bootCfg = &kDefaultBootConfig |
||
| ) |
Construct a handler for a TMC9660 connected via UART.
| uart | Reference to an initialized BaseUart interface connected to the TMC9660. |
| rst | BaseGpio for the TMC9660 RST control pin (host-side output). |
| drv_en | BaseGpio for the TMC9660 DRV_EN control pin (host-side output). |
| faultn | BaseGpio for the TMC9660 FAULTN status pin (host-side input). |
| wake | BaseGpio for the TMC9660 WAKE control pin (host-side output). |
| address | 7-bit device address used in TMCL communication (default: 0). |
| bootCfg | Pointer to bootloader configuration (default: kDefaultBootConfig). |
|
defaultnoexcept |
Destructor. Releases the driver, communication adapter, and all wrappers.
|
delete |
Non-copyable.
|
delete |
Non-movable.
|
noexcept |
Get the ADC wrapper.
|
inlineprivatenoexcept |
The always-present Adc instance, without the bring-up attempt adc() makes.
The Adc methods guard on the driver themselves, so Tmc9660AdcWrapper can delegate here and report errors instead of handling a nullptr.
|
inlinenoexcept |
Get the bootloader configuration in use.
|
noexcept |
Const version of driverViaSpi().
|
noexcept |
Get the TMC9660 driver instance connected via SPI (nullptr if using UART).
Returns a direct pointer to the typed TMC9660<HalSpiTmc9660Comm> driver, giving full access to all 22+ subsystems (motorConfig, feedbackSense, velocityControl, protection, gateDriver, etc.) without lambda wrappers.
The user always knows which comm mode they chose at construction time, so they can safely call the matching accessor.
|
noexcept |
Const version of driverViaUart().
|
noexcept |
Get the TMC9660 driver instance connected via UART (nullptr if using SPI).
|
noexcept |
Dump comprehensive diagnostics to the system log.
Logs device status, communication mode, supply voltage, chip temperature, status/error flags, GPIO wrapper count, ADC status, and bootloader config summary at INFO level.
|
noexcept |
Ensure driver is initialized (lazy init entrypoint).
|
privatenoexcept |
Ensure initialized while handler_mutex_ is already held.
|
noexcept |
Get the communication mode in use (SPI or UART).
|
noexcept |
Get a human-readable description of the handler.
|
inlinenoexcept |
Const overload of GetDriver().
|
inlinenoexcept |
Get the active driver pointer without requiring visitor usage.
SpiDriver* or UartDriver* wrapped in std::variant, or monostate if unavailable.
|
noexcept |
Get the GPIO wrapper for a TMC9660 internal GPIO pin.
Runs the lazy bring-up (EnsureInitialized()) like the other accessors.
| gpioNumber | TMC9660 internal GPIO pin number. Supported: 17, 18. |
gpioNumber is not 17 or 18, or when the TMC9660 bring-up has failed. | bool Tmc9660Handler::Initialize | ( | bool | performReset = true, |
| bool | retrieveBootloaderInfo = true, |
||
| bool | failOnVerifyError = false |
||
| ) |
Initialize the TMC9660 device.
Performs the following sequence:
| performReset | If true, assert RST pin to perform a hardware reset before configuration (default: true). |
| retrieveBootloaderInfo | If true, read the bootloader firmware version and log it (default: true). |
| failOnVerifyError | If true, return false if any bootloader config word fails readback verification. If false, log a warning but continue (default: false). |
|
noexcept |
Check if the TMC9660 driver has been initialized and is ready.
|
delete |
Non-copyable.
|
delete |
Non-movable.
|
inlinenoexcept |
TMCL reply window for UART transfers (HalUartTmc9660Comm::setReplyTimeoutMs).
Callers on a real-time thread use a short window (~10 ms) and widen it (80 ms) for discovery / configuration they run below the real-time band. No effect on an SPI link.
|
noexcept |
Get the Temperature wrapper.
|
inlinenoexcept |
Const overload of visitDriver().
|
inlinenoexcept |
Execute a function on the underlying typed TMC9660 driver.
For most use cases, prefer driverViaSpi() or driverViaUart() for direct typed access. Use visitDriver() only when writing generic code that must work with either communication mode (e.g., in manager-level code that doesn't know the comm type).
| Func | Callable type with signature ReturnType(auto& driver). |
| func | The visitor function to execute. |
func, or a default-constructed value if the driver is not ready.
|
inlineprivatenoexcept |
Internal no-lock visitDriver for use from already-locked contexts.
|
friend |
Tmc9660AdcWrapper delegates to the Adc instance directly (see AdcInstance()).
|
private |
Multi-channel ADC wrapper.
|
private |
true only after bootloaderInit Success.
|
private |
Bootloader config (not owned; must outlive handler).
|
private |
Human-readable handler description.
|
private |
7-bit TMCL device address.
|
private |
GPIO17 [0] and GPIO18 [1].
|
mutableprivate |
Recursive mutex for thread-safe access.
|
static |
Default bootloader configuration based on TMC9660-3PH-EVAL board settings.
Default TMC9660 bootloader configuration based on TMC9660-3PH-EVAL board settings.
Configures:
Override by passing a custom tmc9660::BootloaderConfig* to the constructor.
Configuration highlights:
disable_spi); on-module SPI flash enabled
|
private |
SPI communication adapter (or nullptr).
|
private |
TMC9660 driver for SPI mode (or nullptr).
|
private |
Chip temperature wrapper.
|
private |
UART communication adapter (or nullptr).
|
private |
TMC9660 driver for UART mode (or nullptr).
|
private |
true = SPI communication active, false = UART.