|
HF-TMC9660 Driver 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC9660
|
SPI status codes as per TMC9660 Parameter Mode. More...
#include <tmc9660_comm_interface.hpp>
Public Member Functions | |
| 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 | |
| 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 | |
| CommInterface & | operator= (const CommInterface &)=delete |
| CommInterface (CommInterface &&)=default | |
| CommInterface & | operator= (CommInterface &&)=default |
Protected Attributes | |
| 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. | |
SPI status codes as per TMC9660 Parameter Mode.
Table 4: SPI status codes:
CRTP-based communication interface for sending/receiving TMCL datagrams.
Defines the common API for higher-level code to send and receive 64-bit TMCL frames (via SPI) or 72-bit (via UART) without knowledge of the underlying transport. Also provides GPIO control interface for TMC9660 control pins.
This template class uses the CRTP (Curiously Recurring Template Pattern) for compile-time polymorphism, providing zero runtime overhead compared to virtual functions.
Benefits of CRTP:
Example usage:
| Derived | The derived class type (CRTP pattern) |
|
inlinenoexcept |
Construct communication interface with pin active level configuration.
| rst_active_level | Physical GPIO level for RST pin when ACTIVE (true=HIGH, false=LOW) |
| drv_en_active_level | Physical GPIO level for DRV_EN pin when ACTIVE (true=HIGH, false=LOW) |
| wake_active_level | Physical GPIO level for WAKE pin when ACTIVE (true=HIGH, false=LOW) |
| faultn_active_level | Physical GPIO level for FAULTN pin when ACTIVE (true=HIGH, false=LOW) |
|
protecteddefault |
Protected destructor.
|
protecteddelete |
|
protecteddefault |
|
inlineprotectednoexcept |
Debug logging function for detailed debugging information.
This function allows the TMC9660 driver to output debug information through the communication interface, which can be routed to platform-specific logging systems (e.g., ESP-IDF logging for ESP32).
| level | Log level (0=Error, 1=Warning, 2=Info, 3=Debug, 4=Verbose) |
| tag | Log tag for categorization |
| format | printf-style format string |
| args | Variable arguments list |
|
inlinenoexcept |
Delay execution for specified milliseconds.
| ms | Milliseconds to delay |
|
inlinenoexcept |
Delay execution for specified microseconds.
| us | Microseconds to delay |
|
inlinenoexcept |
Get current retry interval for SPI_STATUS_NOT_READY.
|
inlinenoexcept |
Get current maximum retry count for SPI_STATUS_NOT_READY.
|
inlinenoexcept |
Convert physical GPIO level to signal state.
| pin | The TMC9660 control pin |
| gpio_level | Physical GPIO level (true=HIGH, false=LOW) |
|
inlinenoexcept |
Read GPIO pin signal state (input state).
Used for reading TMC9660 status pins like FAULTN. The implementation must handle the specific hardware GPIO configuration and map physical levels to ACTIVE/INACTIVE based on board design.
| pin | The TMC9660 control pin to read |
| signal | Reference to store the current signal state |
|
inlinenoexcept |
Set GPIO pin signal state (output control).
Used for controlling TMC9660 control pins like RST, DRV_EN, and WAKE. The implementation must handle the specific hardware GPIO configuration and map ACTIVE/INACTIVE to the appropriate physical levels based on board design.
| pin | The TMC9660 control pin to control |
| signal | The desired signal state (ACTIVE or INACTIVE) |
|
inlinenoexcept |
Set GPIO pin to active state (convenience method).
| pin | The TMC9660 control pin to set active |
|
inlinenoexcept |
Set GPIO pin to inactive state (convenience method).
| pin | The TMC9660 control pin to set inactive |
|
inlinenoexcept |
Public debug logging wrapper for external classes.
This function allows external classes like TMC9660Bootloader to output debug information through the communication interface. Automatically ensures newlines are present.
| level | Log level (0=Error, 1=Warning, 2=Info, 3=Debug, 4=Verbose) |
| tag | Log tag for categorization |
| format | printf-style format string |
| ... | Variable arguments for format string |
|
inlinenoexcept |
Get the underlying communication mode used by this interface.
Returns whether this interface uses SPI or UART for communication. This information is useful for protocol-specific optimizations or debugging purposes.
|
protecteddefault |
|
protecteddelete |
|
inlinenoexcept |
Configure the active level for a specific pin.
This method allows the user to configure which physical GPIO level (HIGH or LOW) corresponds to the ACTIVE state for each pin. This accommodates different board implementations (direct connection, inverters, etc.).
| pin | The TMC9660 control pin to configure |
| active_level | The physical GPIO level that represents ACTIVE state |
|
inlinenoexcept |
Set delay interval between retry attempts for SPI_STATUS_NOT_READY.
When retrying a command due to SPI_STATUS_NOT_READY, wait this many microseconds before retrying.
| interval_us | Delay in microseconds between retry attempts |
|
inlinenoexcept |
Set maximum number of retries for SPI_STATUS_NOT_READY responses.
When a command receives SPI_STATUS_NOT_READY (0xF0), the system will automatically retry the command up to the specified number of times.
| max_retries | Maximum number of retry attempts (0 = no retries, only original attempt) |
|
inlinenoexcept |
Convert signal state to physical GPIO level.
| pin | The TMC9660 control pin |
| signal | The signal state (ACTIVE or INACTIVE) |
|
inlinenoexcept |
Perform a full duplex TMCL transfer for parameter mode communication.
For SPI: Performs two transactions - sends command, receives first reply, then sends second command (or NO_OP if not provided), receives second reply.
For UART: Single transaction - sends command, receives reply.
| tx | TMCL command frame to transmit |
| reply | Reference to store the final reply |
| address | TMC9660 module address (UART only, ignored for SPI) |
| first_reply | Optional pointer to capture first reply (SPI only) |
| second_command | Optional second command to send (SPI only, defaults to NO_OP) |
|
protected |
Pin active level configuration storage.
Stores the physical GPIO level (HIGH or LOW) that corresponds to the ACTIVE state for each TMC9660 control pin. This configuration enables board-agnostic pin control by abstracting physical voltage levels.
Array indices: [RST, DRV_EN, WAKE, FAULTN]
|
protected |
Delay interval in microseconds between retry attempts.
When retrying a command due to SPI_STATUS_NOT_READY, wait this many microseconds before retrying. Default: 100us (0.1ms) - fine-grained for fast SPI communication
|
protected |
Maximum number of retries for SPI_STATUS_NOT_READY responses.
When a command receives SPI_STATUS_NOT_READY (0xF0), the system will automatically retry the command up to this many times. Default: 3 retries