HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
Loading...
Searching...
No Matches
HalSpiTmc9660Comm Class Reference

Concrete SPI communication adapter for TMC9660 using BaseSpi and BaseGpio. More...

#include <Tmc9660Handler.h>

Inheritance diagram for HalSpiTmc9660Comm:
[legend]
Collaboration diagram for HalSpiTmc9660Comm:
[legend]

Public Member Functions

 HalSpiTmc9660Comm (BaseSpi &spi, BaseGpio &rst, BaseGpio &drv_en, BaseGpio &faultn, BaseGpio &wake, bool rst_active_high=true, bool drv_en_active_high=true, bool faultn_active_low=false, bool wake_active_low=false) noexcept
 Construct the SPI communication adapter.
 
CRTP-Required Methods

These are called by tmc9660::SpiCommInterface<HalSpiTmc9660Comm> via static dispatch.

bool spiTransferTMCL (std::array< uint8_t, 8 > &tx, std::array< uint8_t, 8 > &rx) noexcept
 Perform an 8-byte full-duplex SPI transfer for TMCL parameter mode.
 
bool spiTransferBootloader (std::array< uint8_t, 5 > &tx, std::array< uint8_t, 5 > &rx) noexcept
 Perform a 5-byte full-duplex SPI transfer for bootloader mode.
 
bool gpioSet (tmc9660::TMC9660CtrlPin pin, tmc9660::GpioSignal signal) noexcept
 Set a TMC9660 control pin to a given logical signal state.
 
bool gpioRead (tmc9660::TMC9660CtrlPin pin, tmc9660::GpioSignal &signal) noexcept
 Read a TMC9660 control pin's current logical signal state.
 
void debugLog (int level, const char *tag, const char *format, va_list args) noexcept
 Route TMC9660 driver debug output to the HardFOC Logger.
 
void delayMs (uint32_t ms) noexcept
 Delay execution for the specified number of milliseconds.
 
void delayUs (uint32_t us) noexcept
 Delay execution for the specified number of microseconds.
 

Private Attributes

BaseSpi & spi_
 SPI bus interface (not owned).
 
Tmc9660CtrlPins ctrl_pins_
 Host-side control pin references.
 

Detailed Description

Concrete SPI communication adapter for TMC9660 using BaseSpi and BaseGpio.

Implements all methods required by tmc9660::SpiCommInterface<HalSpiTmc9660Comm> through the CRTP (Curiously Recurring Template Pattern). This class acts as the bridge between the HardFOC BaseSpi abstraction and the TMC9660 driver's SPI protocol, handling:

  • TMCL transfers: 8-byte full-duplex SPI exchanges for parameter mode
  • Bootloader transfers: 5-byte full-duplex SPI exchanges for bootloader mode
  • GPIO control: Maps TMC9660 control pin identifiers (RST, DRV_EN, FAULTN, WAKE) to physical BaseGpio instances with configurable active-level polarity
  • Timing: Platform-aware delays (millisecond via RTOS, microsecond via esp_rom_delay_us or busy-wait fallback)
  • Logging: Routes TMC9660 driver debug output to the HardFOC Logger

Control Pin Polarity

Each control pin can be configured as active-high or active-low to match the board's electrical design (e.g., inverting buffers). The constructor parameters set the initial polarity; the base class provides set_pin_active_level() for runtime reconfiguration if needed.

Note
This class does NOT own the BaseSpi or BaseGpio instances; they must remain valid for the lifetime of this object.
See also
tmc9660::SpiCommInterface CRTP base class from the TMC9660 driver
HalUartTmc9660Comm UART equivalent of this class

Constructor & Destructor Documentation

◆ HalSpiTmc9660Comm()

HalSpiTmc9660Comm::HalSpiTmc9660Comm ( BaseSpi & spi,
BaseGpio & rst,
BaseGpio & drv_en,
BaseGpio & faultn,
BaseGpio & wake,
bool rst_active_high = true,
bool drv_en_active_high = true,
bool faultn_active_low = false,
bool wake_active_low = false )
noexcept

Construct the SPI communication adapter.

Parameters
spiReference to a pre-configured BaseSpi implementation (SPI mode 3, 8-bit frames, chip select managed externally).
rstBaseGpio connected to TMC9660 RST (pin 22). Must be pre-configured as output.
drv_enBaseGpio connected to TMC9660 DRV_EN (pin 21). Must be pre-configured as output.
faultnBaseGpio connected to TMC9660 FAULTN (pin 20). Must be pre-configured as input.
wakeBaseGpio connected to TMC9660 WAKE (pin 19). Must be pre-configured as output.
rst_active_highPhysical GPIO level when RST is ACTIVE (default: true = HIGH).
drv_en_active_highPhysical GPIO level when DRV_EN is ACTIVE (default: true = HIGH).
faultn_active_lowPhysical GPIO level when FAULTN is ACTIVE (default: false = HIGH). Set to true if your board inverts the FAULTN signal.
wake_active_lowPhysical GPIO level when WAKE is ACTIVE (default: false = HIGH). Set to true if your board inverts the WAKE signal.

Member Function Documentation

◆ debugLog()

void HalSpiTmc9660Comm::debugLog ( int level,
const char * tag,
const char * format,
va_list args )
noexcept

Route TMC9660 driver debug output to the HardFOC Logger.

Parameters
levelLog level (0=Error, 1=Warning, 2=Info, 3=Debug).
tagLog tag string for categorization.
formatprintf-style format string.
argsVariable argument list.
Here is the call graph for this function:

◆ delayMs()

void HalSpiTmc9660Comm::delayMs ( uint32_t ms)
noexcept

Delay execution for the specified number of milliseconds.

Parameters
msMilliseconds to delay (delegates to os_delay_msec).
Here is the call graph for this function:

◆ delayUs()

void HalSpiTmc9660Comm::delayUs ( uint32_t us)
noexcept

Delay execution for the specified number of microseconds.

On ESP32, uses esp_rom_delay_us() for accurate sub-millisecond timing. On other platforms, uses a busy-wait loop based on the processor cycle counter.

Parameters
usMicroseconds to delay.
Here is the call graph for this function:

◆ gpioRead()

bool HalSpiTmc9660Comm::gpioRead ( tmc9660::TMC9660CtrlPin pin,
tmc9660::GpioSignal & signal )
noexcept

Read a TMC9660 control pin's current logical signal state.

Reads the physical GPIO level via BaseGpio, then translates to ACTIVE/INACTIVE based on the pin's configured active-level polarity.

Parameters
pinWhich control pin to read (typically FAULTN for fault status).
[out]signalCurrent logical signal state.
Returns
true if the GPIO read succeeded.
Here is the call graph for this function:

◆ gpioSet()

bool HalSpiTmc9660Comm::gpioSet ( tmc9660::TMC9660CtrlPin pin,
tmc9660::GpioSignal signal )
noexcept

Set a TMC9660 control pin to a given logical signal state.

Translates the logical ACTIVE/INACTIVE signal to a physical HIGH/LOW level based on the pin's configured active-level polarity, then writes via BaseGpio.

Parameters
pinWhich control pin to set (RST, DRV_EN, FAULTN, WAKE).
signalDesired logical signal state.
Returns
true if the GPIO write succeeded.
Here is the call graph for this function:

◆ spiTransferBootloader()

bool HalSpiTmc9660Comm::spiTransferBootloader ( std::array< uint8_t, 5 > & tx,
std::array< uint8_t, 5 > & rx )
noexcept

Perform a 5-byte full-duplex SPI transfer for bootloader mode.

Parameters
[in,out]tx5-byte transmit buffer (bootloader command).
[out]rx5-byte receive buffer (bootloader reply).
Returns
true if BaseSpi::Transfer() succeeded.

◆ spiTransferTMCL()

bool HalSpiTmc9660Comm::spiTransferTMCL ( std::array< uint8_t, 8 > & tx,
std::array< uint8_t, 8 > & rx )
noexcept

Perform an 8-byte full-duplex SPI transfer for TMCL parameter mode.

Parameters
[in,out]tx8-byte transmit buffer (TMCL command frame).
[out]rx8-byte receive buffer (TMCL reply frame).
Returns
true if BaseSpi::Transfer() succeeded.

Member Data Documentation

◆ ctrl_pins_

Tmc9660CtrlPins HalSpiTmc9660Comm::ctrl_pins_
private

Host-side control pin references.

◆ spi_

BaseSpi& HalSpiTmc9660Comm::spi_
private

SPI bus interface (not owned).


The documentation for this class was generated from the following files: