HF-TMC9660 Driver 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC9660
Loading...
Searching...
No Matches
tmc9660::SpiCommInterface< Derived > Class Template Reference

CRTP-based SPI implementation of TMC9660CommInterface. More...

#include <tmc9660_comm_interface.hpp>

Inheritance diagram for tmc9660::SpiCommInterface< Derived >:
[legend]
Collaboration diagram for tmc9660::SpiCommInterface< Derived >:
[legend]

Public Member Functions

 SpiCommInterface (bool rst_active_level, bool drv_en_active_level, bool wake_active_level, bool faultn_active_level) noexcept
 Construct SPI communication interface with pin active level configuration.
 
CommMode mode () const noexcept
 Get communication mode (always SPI for this interface)
 
bool spiTransferTMCL (std::array< uint8_t, 8 > &tx, std::array< uint8_t, 8 > &rx) noexcept
 Low-level SPI transfer for TMCL parameter mode communication.
 
bool spiTransferBootloader (std::array< uint8_t, 5 > &tx, std::array< uint8_t, 5 > &rx) noexcept
 Low-level SPI transfer for bootloader communication.
 
bool gpioSet (TMC9660CtrlPin pin, GpioSignal signal) noexcept
 Set GPIO pin signal state for SPI interface.
 
bool gpioRead (TMC9660CtrlPin pin, GpioSignal &signal) noexcept
 Read GPIO pin signal state for SPI interface.
 
bool transferTMCL (const TMCLFrame &tx, TMCLReply &reply, uint8_t, TMCLReply *first_reply, const TMCLFrame *second_command) noexcept
 
- Public Member Functions inherited from tmc9660::CommInterface< Derived >
 CommInterface (bool rst_active_level, bool drv_en_active_level, bool wake_active_level, bool faultn_active_level) noexcept
 Construct communication interface with pin active level configuration.
 
CommMode mode () const noexcept
 Get the underlying communication mode used by this interface.
 
bool transferTMCL (const TMCLFrame &tx, TMCLReply &reply, uint8_t address, TMCLReply *first_reply=nullptr, const TMCLFrame *second_command=nullptr) noexcept
 Perform a full duplex TMCL transfer for parameter mode communication.
 
bool gpioSet (TMC9660CtrlPin pin, GpioSignal signal) noexcept
 Set GPIO pin signal state (output control).
 
bool gpioRead (TMC9660CtrlPin pin, GpioSignal &signal) noexcept
 Read GPIO pin signal state (input state).
 
bool signalToGpioLevel (TMC9660CtrlPin pin, GpioSignal signal) const noexcept
 Convert signal state to physical GPIO level.
 
GpioSignal gpioLevelToSignal (TMC9660CtrlPin pin, bool gpio_level) const noexcept
 Convert physical GPIO level to signal state.
 
bool gpioSetActive (TMC9660CtrlPin pin) noexcept
 Set GPIO pin to active state (convenience method).
 
bool gpioSetInactive (TMC9660CtrlPin pin) noexcept
 Set GPIO pin to inactive state (convenience method).
 
bool set_pin_active_level (TMC9660CtrlPin pin, bool active_level) noexcept
 Configure the active level for a specific pin.
 
void setSpiRetryMaxCount (uint8_t max_retries) noexcept
 Set maximum number of retries for SPI_STATUS_NOT_READY responses.
 
uint8_t getSpiRetryMaxCount () const noexcept
 Get current maximum retry count for SPI_STATUS_NOT_READY.
 
void setSpiRetryInterval (uint32_t interval_us) noexcept
 Set delay interval between retry attempts for SPI_STATUS_NOT_READY.
 
uint32_t getSpiRetryInterval () const noexcept
 Get current retry interval for SPI_STATUS_NOT_READY.
 
void delayMs (uint32_t ms) noexcept
 Delay execution for specified milliseconds.
 
void delayUs (uint32_t us) noexcept
 Delay execution for specified microseconds.
 
void logDebug (int level, const char *tag, const char *format,...) noexcept
 Public debug logging wrapper for external classes.
 

Protected Member Functions

 ~SpiCommInterface ()=default
 Protected destructor.
 
 SpiCommInterface (const SpiCommInterface &)=delete
 
SpiCommInterfaceoperator= (const SpiCommInterface &)=delete
 
 SpiCommInterface (SpiCommInterface &&)=default
 
SpiCommInterfaceoperator= (SpiCommInterface &&)=default
 
- Protected Member Functions inherited from tmc9660::CommInterface< Derived >
void debugLog (int level, const char *tag, const char *format, va_list args) noexcept
 Debug logging function for detailed debugging information.
 
 ~CommInterface ()=default
 Protected destructor.
 
 CommInterface (const CommInterface &)=delete
 
CommInterfaceoperator= (const CommInterface &)=delete
 
 CommInterface (CommInterface &&)=default
 
CommInterfaceoperator= (CommInterface &&)=default
 

Additional Inherited Members

- Protected Attributes inherited from tmc9660::CommInterface< Derived >
bool pinActiveLevels_ [4]
 Pin active level configuration storage.
 
uint8_t spiRetryMaxCount_ = 3
 Maximum number of retries for SPI_STATUS_NOT_READY responses.
 
uint32_t spiRetryIntervalUs_ = 100
 Delay interval in microseconds between retry attempts.
 

Detailed Description

template<typename Derived>
class tmc9660::SpiCommInterface< Derived >

CRTP-based SPI implementation of TMC9660CommInterface.

Uses a 4-wire SPI bus (mode 3) to exchange 64-bit datagrams (8 bytes). Data is sent MSB-first, big-endian. Replies match the previous command; initial reply uses FIRST_CMD status.

This template class uses CRTP for compile-time polymorphism, providing zero runtime overhead.

Example usage:

class MySPI : public tmc9660::SpiCommInterface<MySPI> {
public:
bool spiTransferTMCL(...) { ... }
bool spiTransferBootloader(...) { ... }
bool gpioSet(...) { ... }
bool gpioRead(...) { ... }
void debugLog(...) { ... }
void delayMs(...) { ... }
void delayUs(...) { ... }
};
SPI status codes as per TMC9660 Parameter Mode.
Definition tmc9660_comm_interface.hpp:514
bool gpioRead(TMC9660CtrlPin pin, GpioSignal &signal) noexcept
Read GPIO pin signal state (input state).
Definition tmc9660_comm_interface.hpp:588
void delayUs(uint32_t us) noexcept
Delay execution for specified microseconds.
Definition tmc9660_comm_interface.hpp:760
void debugLog(int level, const char *tag, const char *format, va_list args) noexcept
Debug logging function for detailed debugging information.
Definition tmc9660_comm_interface.hpp:737
void delayMs(uint32_t ms) noexcept
Delay execution for specified milliseconds.
Definition tmc9660_comm_interface.hpp:748
CommMode mode() const noexcept
Get the underlying communication mode used by this interface.
Definition tmc9660_comm_interface.hpp:536
bool gpioSet(TMC9660CtrlPin pin, GpioSignal signal) noexcept
Set GPIO pin signal state (output control).
Definition tmc9660_comm_interface.hpp:573
CRTP-based SPI implementation of TMC9660CommInterface.
Definition tmc9660_comm_interface.hpp:855
CommMode
Supported physical communication modes for TMC9660.
Definition tmc9660_comm_interface.hpp:113
@ SPI
SPI (Serial Peripheral Interface) mode - 4-wire synchronous communication.
Template Parameters
DerivedThe derived class type (CRTP pattern)

Constructor & Destructor Documentation

◆ SpiCommInterface() [1/3]

template<typename Derived >
tmc9660::SpiCommInterface< Derived >::SpiCommInterface ( bool rst_active_level,
bool drv_en_active_level,
bool wake_active_level,
bool faultn_active_level )
inlinenoexcept

Construct SPI communication interface with pin active level configuration.

Parameters
rst_active_levelPhysical GPIO level for RST pin when ACTIVE (true=HIGH, false=LOW)
drv_en_active_levelPhysical GPIO level for DRV_EN pin when ACTIVE (true=HIGH, false=LOW)
wake_active_levelPhysical GPIO level for WAKE pin when ACTIVE (true=HIGH, false=LOW)
faultn_active_levelPhysical GPIO level for FAULTN pin when ACTIVE (true=HIGH, false=LOW)

◆ ~SpiCommInterface()

template<typename Derived >
tmc9660::SpiCommInterface< Derived >::~SpiCommInterface ( )
protecteddefault

Protected destructor.

Note
Derived classes can have public destructors

◆ SpiCommInterface() [2/3]

template<typename Derived >
tmc9660::SpiCommInterface< Derived >::SpiCommInterface ( const SpiCommInterface< Derived > & )
protecteddelete

◆ SpiCommInterface() [3/3]

template<typename Derived >
tmc9660::SpiCommInterface< Derived >::SpiCommInterface ( SpiCommInterface< Derived > && )
protecteddefault

Member Function Documentation

◆ gpioRead()

template<typename Derived >
bool tmc9660::SpiCommInterface< Derived >::gpioRead ( TMC9660CtrlPin pin,
GpioSignal & signal )
inlinenoexcept

Read GPIO pin signal state for SPI interface.

Parameters
pinThe TMC9660 control pin to read
signalReference to store the current signal state
Returns
true if the GPIO was read successfully
Here is the call graph for this function:
Here is the caller graph for this function:

◆ gpioSet()

template<typename Derived >
bool tmc9660::SpiCommInterface< Derived >::gpioSet ( TMC9660CtrlPin pin,
GpioSignal signal )
inlinenoexcept

Set GPIO pin signal state for SPI interface.

Parameters
pinThe TMC9660 control pin to control
signalThe desired signal state
Returns
true if the GPIO was set successfully
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mode()

template<typename Derived >
CommMode tmc9660::SpiCommInterface< Derived >::mode ( ) const
inlinenoexcept

Get communication mode (always SPI for this interface)

Returns
CommMode::SPI

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ spiTransferBootloader()

template<typename Derived >
bool tmc9660::SpiCommInterface< Derived >::spiTransferBootloader ( std::array< uint8_t, 5 > & tx,
std::array< uint8_t, 5 > & rx )
inlinenoexcept

Low-level SPI transfer for bootloader communication.

The bootloader uses a 40-bit (5-byte) protocol:

  • TX: [COMMAND(8)] [VALUE(32)]
  • RX: [STATUS(8)] [VALUE(32)]
Parameters
txBuffer containing 5 bytes to transmit (bootloader format).
rxBuffer to receive 5 bytes from device (bootloader format).
Returns
true if the SPI transfer completed successfully.
Note
This is for bootloader mode (5-byte frames)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ spiTransferTMCL()

template<typename Derived >
bool tmc9660::SpiCommInterface< Derived >::spiTransferTMCL ( std::array< uint8_t, 8 > & tx,
std::array< uint8_t, 8 > & rx )
inlinenoexcept

Low-level SPI transfer for TMCL parameter mode communication.

Parameters
txBuffer containing 8 bytes to transmit (TMCL format).
rxBuffer to receive 8 bytes from device (TMCL format).
Returns
true if the SPI transfer completed successfully.
Note
This is for TMCL parameter mode (8-byte frames)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ transferTMCL()

template<typename Derived >
bool tmc9660::SpiCommInterface< Derived >::transferTMCL ( const TMCLFrame & tx,
TMCLReply & reply,
uint8_t ,
TMCLReply * first_reply,
const TMCLFrame * second_command )
inlinenoexcept
Here is the call graph for this function:

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