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

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

#include <tmc9660_comm_interface.hpp>

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

Public Member Functions

 UartCommInterface (bool rst_active_level, bool drv_en_active_level, bool wake_active_level, bool faultn_active_level) noexcept
 Construct UART communication interface with pin active level configuration.
 
CommMode mode () const noexcept
 Get communication mode (always UART for this interface)
 
bool uartSendTMCL (const std::array< uint8_t, 9 > &data) noexcept
 Send raw 9-byte UART TMCL datagram for parameter mode communication.
 
bool uartReceiveTMCL (std::array< uint8_t, 9 > &data) noexcept
 Receive raw 9-byte UART TMCL datagram for parameter mode communication.
 
bool uartTransferBootloader (const std::array< uint8_t, 8 > &tx, std::array< uint8_t, 8 > &rx) noexcept
 Transfer 8-byte UART bootloader datagram (send and receive).
 
bool gpioSet (TMC9660CtrlPin pin, GpioSignal signal) noexcept
 Set GPIO pin signal state for UART interface.
 
bool gpioRead (TMC9660CtrlPin pin, GpioSignal &signal) noexcept
 Read GPIO pin signal state for UART interface.
 
bool transferTMCL (const TMCLFrame &tx, TMCLReply &reply, uint8_t address, 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

 ~UartCommInterface ()=default
 Protected destructor.
 
 UartCommInterface (const UartCommInterface &)=delete
 
UartCommInterfaceoperator= (const UartCommInterface &)=delete
 
 UartCommInterface (UartCommInterface &&)=default
 
UartCommInterfaceoperator= (UartCommInterface &&)=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::UartCommInterface< Derived >

CRTP-based UART implementation of TMC9660CommInterface.

Uses UART_TXD and UART_RXD signals; supports external transceivers via UART_TXEN. Frames consist of 9 bytes: sync+address, command, type, motor, 4-byte data, checksum. LSB-first transmission; checksum is 8-bit sum of first 8 bytes.

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

Example usage:

class MyUART : public tmc9660::UartCommInterface<MyUART> {
public:
bool uartSendTMCL(...) { ... }
bool uartReceiveTMCL(...) { ... }
bool uartTransferBootloader(...) { ... }
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 UART implementation of TMC9660CommInterface.
Definition tmc9660_comm_interface.hpp:1066
CommMode
Supported physical communication modes for TMC9660.
Definition tmc9660_comm_interface.hpp:113
Template Parameters
DerivedThe derived class type (CRTP pattern)

Constructor & Destructor Documentation

◆ UartCommInterface() [1/3]

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

Construct UART 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)

◆ ~UartCommInterface()

Protected destructor.

Note
Derived classes can have public destructors

◆ UartCommInterface() [2/3]

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

◆ UartCommInterface() [3/3]

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

Member Function Documentation

◆ gpioRead()

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

Read GPIO pin signal state for UART 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::UartCommInterface< Derived >::gpioSet ( TMC9660CtrlPin pin,
GpioSignal signal )
inlinenoexcept

Set GPIO pin signal state for UART 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::UartCommInterface< Derived >::mode ( ) const
inlinenoexcept

Get communication mode (always UART for this interface)

Returns
CommMode::UART

◆ operator=() [1/2]

◆ operator=() [2/2]

◆ transferTMCL()

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

◆ uartReceiveTMCL()

template<typename Derived >
bool tmc9660::UartCommInterface< Derived >::uartReceiveTMCL ( std::array< uint8_t, 9 > & data)
inlinenoexcept

Receive raw 9-byte UART TMCL datagram for parameter mode communication.

Parameters
dataArray to store 9 received bytes (TMCL format).
Returns
true if reception succeeded.
Note
This is for TMCL parameter mode (9-byte frames)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uartSendTMCL()

template<typename Derived >
bool tmc9660::UartCommInterface< Derived >::uartSendTMCL ( const std::array< uint8_t, 9 > & data)
inlinenoexcept

Send raw 9-byte UART TMCL datagram for parameter mode communication.

Parameters
dataArray of 9 bytes including sync, fields, and checksum (TMCL format).
Returns
true if transmission succeeded.
Note
This is for TMCL parameter mode (9-byte frames)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ uartTransferBootloader()

template<typename Derived >
bool tmc9660::UartCommInterface< Derived >::uartTransferBootloader ( const std::array< uint8_t, 8 > & tx,
std::array< uint8_t, 8 > & rx )
inlinenoexcept

Transfer 8-byte UART bootloader datagram (send and receive).

The bootloader uses a different 8-byte protocol:

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

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