|
|
| | 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.
|
| |
|
| 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.
|
| |
|
Retrieve references to the handler's internal peripheral wrappers.
|
| Gpio & | gpio (uint8_t gpioNumber) |
| | Get a reference to the GPIO wrapper for a TMC9660 internal GPIO pin.
|
| |
| Adc & | adc () |
| | Get a reference to the ADC wrapper.
|
| |
| Temperature & | temperature () |
| | Get a reference to the Temperature wrapper.
|
| |
|
| 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.
|
| |
|
| void | DumpDiagnostics () noexcept |
| | Dump comprehensive diagnostics to the system log.
|
| |
| const char * | GetDescription () const noexcept |
| | Get a human-readable description of the handler.
|
| |
|
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().
|
| |
|
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().
|
| |
Unified, non-templated handler for a single TMC9660 motor controller device.
Tmc9660Handler is the primary interface that application and manager code uses to interact with a TMC9660 motor driver. It hides the template complexity of tmc9660::TMC9660<CommType> behind a clean, polymorphism-free API.
Design Decisions
- Non-templated: The handler uses visitDriver() to route calls to the correct typed driver (SPI or UART). This prevents template propagation through the codebase and allows MotorController to store handlers in a plain std::unique_ptr<Tmc9660Handler>.
- Control pins required: The TMC9660 bootloader initialization sequence requires host-side GPIO control of four pins (RST, DRV_EN, FAULTN, WAKE). These must be provided at construction time.
- Lazy driver creation: The typed TMC9660 driver instance is created during Initialize(), not in the constructor. This saves memory until initialization is actually needed.
- Peripheral wrappers: Inner classes Gpio, Adc, and Temperature implement the HardFOC base interfaces, making TMC9660 peripherals available to the manager layer (GpioManager, AdcManager, TemperatureManager) through the standard abstractions.
Usage Example
return;
}
drv->motorConfig.setType(tmcl::MotorType::BLDC_MOTOR, 7);
drv->commutation.setMode(tmcl::CommutationMode::FOC);
drv->motorControl.enable();
drv->velocityControl.setTargetVelocity(1000);
handler.gpio(17).SetPinLevel(hf_gpio_level_t::HF_GPIO_LEVEL_HIGH);
driver.feedbackSense.configureHallSensor(1, 2, 3);
driver.protection.setOvertemperatureLimit(120.0f);
});
static Logger & GetInstance() noexcept
Get singleton instance.
Definition Logger.cpp:61
void Error(const char *tag, const char *format,...) noexcept
Log error message.
Definition Logger.cpp:170
bool Initialize() noexcept override
Initialize (verifies parent driver is ready).
Definition Tmc9660Handler.cpp:815
Unified, non-templated handler for a single TMC9660 motor controller device.
Definition Tmc9660Handler.h:452
Temperature & temperature()
Get a reference to the Temperature wrapper.
Definition Tmc9660Handler.cpp:395
- See also
- HalSpiTmc9660Comm SPI communication adapter
-
HalUartTmc9660Comm UART communication adapter
-
MotorController Multi-device manager that owns Tmc9660Handler instances
-
Tmc9660AdcWrapper Thin BaseAdc adapter for AdcManager ownership
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.
- Returns
- Pointer to the TMC9660 driver (SPI comm), or nullptr if using UART mode or Initialize() has not been called.
drv->feedbackSense.configureHall();
drv->motorConfig.setType(tmcl::MotorType::BLDC_MOTOR, 7);
drv->velocityControl.setTargetVelocity(1000);
drv->protection.configureVoltage(48000, 10000);
- Warning
- Raw pointer — NOT mutex-protected. Caller is responsible for external synchronization in multi-task environments. Prefer visitDriver() for thread-safe access.
| void Tmc9660Handler::DumpDiagnostics |
( |
| ) |
|
|
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.
- Note
- Non-const because telemetry reads require I2C transactions.
| const tmc9660::BootloaderConfig Tmc9660Handler::kDefaultBootConfig |
|
static |
Default bootloader configuration based on TMC9660-3PH-EVAL board settings.
Default TMC9660 bootloader configuration based on TMC9660-3PH-EVAL board settings.
Configures:
- LDO: VEXT1=5.0V, VEXT2=3.3V, 3ms slope
- Boot mode: Parameter mode with motor control start
- UART: Auto16x baud rate, GPIO6/7, address 1
- External clock: 16MHz crystal with PLL (40MHz system)
- SPI Flash: Enabled on SPI0 (GPIO11/12) at 10MHz
- GPIO: GPIO5 analog, GPIO17/18 digital pull-down
- Hall, ABN encoders, step/dir, etc.: disabled (safe defaults)
Override by passing a custom tmc9660::BootloaderConfig* to the constructor.
Configuration highlights:
- LDO: VEXT1=5.0V, VEXT2=3.3V with 3ms slope control
- Boot Mode: Parameter mode for TMCL parameter-based control
- UART: Auto16x baud rate detection, GPIO6/7 pins, device address 1
- External Clock: 16MHz crystal with PLL for stable 40MHz system clock
- SPI Flash: Enabled on SPI0 (GPIO11 SCK, GPIO12 CS) at 10MHz
- GPIO: GPIO5 analog input, GPIO17/18 digital inputs with pull-down
- New sections (hall, abn1, abn2, ref, stepDir, spiEnc, mechBrake, brakeChopper, memStorage) use safe defaults (disabled)