HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
tmc51x0_comm_interface.hpp File Reference

Communication interfaces for TMC51x0 stepper motor driver using SPI and UART. More...

#include <algorithm>
#include <array>
#include <cstdarg>
#include <cstdint>
#include <cstdio>
#include "tmc51x0_result.hpp"
Include dependency graph for tmc51x0_comm_interface.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tmc51x0::PinActiveLevels
 Pin active level configuration structure. More...
 
struct  tmc51x0::TMC51x0PinConfig
 TMC51x0 GPIO pin configuration structure. More...
 
struct  tmc51x0::SpiStatus
 SPI_STATUS structure - status flags returned with each SPI datagram. More...
 
struct  tmc51x0::SpiCommand
 TMC5160 SPI command structure with union-based frame representation. More...
 
union  tmc51x0::SpiCommand::Frame
 Union for accessing the 40-bit SPI frame in different ways. More...
 
struct  tmc51x0::SpiResponse
 TMC5160 SPI response structure. More...
 
struct  tmc51x0::UartFrame
 TMC5160 UART command/response frame structure with built-in CRC8. More...
 
union  tmc51x0::UartFrame::Frame
 Union for accessing UART frames in different ways. More...
 
class  tmc51x0::CommInterface< Derived >
 CRTP-based communication interface for register read/write operations. More...
 
class  tmc51x0::SpiCommInterface< Derived >
 CRTP-based SPI implementation of TMC5160CommInterface. More...
 
class  tmc51x0::UartCommInterface< Derived >
 CRTP-based UART implementation of TMC5160CommInterface. More...
 

Namespaces

namespace  tmc51x0
 

Macros

#define TMC51X0_LOG_LEVEL   4
 Compile-time debug logging control for TMC51x0 library.
 
#define TMC51X0_LOGE(comm_obj, tag, ...)   (comm_obj).LogDebug(::tmc51x0::LogLevel::Error, tag, __VA_ARGS__)
 
#define TMC51X0_LOGW(comm_obj, tag, ...)   (comm_obj).LogDebug(::tmc51x0::LogLevel::Warn, tag, __VA_ARGS__)
 
#define TMC51X0_LOGI(comm_obj, tag, ...)   (comm_obj).LogDebug(::tmc51x0::LogLevel::Info, tag, __VA_ARGS__)
 
#define TMC51X0_LOGD(comm_obj, tag, ...)   (comm_obj).LogDebug(::tmc51x0::LogLevel::Debug, tag, __VA_ARGS__)
 
#define TMC51X0_LOGV(comm_obj, tag, ...)   (comm_obj).LogDebug(::tmc51x0::LogLevel::Verbose, tag, __VA_ARGS__)
 
#define TMC51X0_LOG_DEBUG(comm_obj, level, tag, ...)
 
#define TMC51X0_SPI_MAX_CHAIN_DEVICES   8
 

Enumerations

enum class  tmc51x0::LogLevel : uint8_t {
  tmc51x0::Error = 0 , tmc51x0::Warn = 1 , tmc51x0::Info = 2 , tmc51x0::Debug = 3 ,
  tmc51x0::Verbose = 4
}
 Driver-native log levels for debug output. More...
 
enum class  tmc51x0::CommMode : uint8_t { tmc51x0::SPI , tmc51x0::UART }
 Supported physical communication modes for TMC51x0. More...
 
enum class  tmc51x0::TMC51x0CtrlPin : uint8_t {
  tmc51x0::EN , tmc51x0::DIR , tmc51x0::STEP , tmc51x0::REFL_STEP ,
  tmc51x0::REFR_DIR , tmc51x0::DIAG0 , tmc51x0::DIAG1 , tmc51x0::ENCA ,
  tmc51x0::ENCB , tmc51x0::ENCN , tmc51x0::DCEN , tmc51x0::DCIN ,
  tmc51x0::DCO , tmc51x0::CLK , tmc51x0::SPI_MODE , tmc51x0::SD_MODE
}
 TMC51x0 control pin identifiers with board-agnostic naming. More...
 
enum class  tmc51x0::GpioSignal : uint8_t { tmc51x0::INACTIVE = 0 , tmc51x0::ACTIVE = 1 }
 GPIO signal states with board-agnostic naming. More...
 
enum class  tmc51x0::UartFrameType : uint8_t { tmc51x0::WriteAccess , tmc51x0::ReadRequest , tmc51x0::ReadReply }
 TMC5160 UART frame types. More...
 

Functions

static constexpr uint8_t tmc51x0::calculateCrc8 (const uint8_t *data, size_t length) noexcept
 Calculate CRC8 checksum for UART communication.
 

Detailed Description

Communication interfaces for TMC51x0 stepper motor driver using SPI and UART.

This file provides comprehensive communication interfaces for the TMC51x0 motor driver, supporting both SPI and UART protocols with register read/write operations. It includes GPIO control interfaces and board-agnostic pin management for different hardware implementations. Supports both TMC5130 and TMC5160 chips.

Compile-Time Configuration

TMC51X0_DISABLE_DEBUG_LOGGING: Define this macro to completely disable all debug logging throughout the TMC51x0 library. This removes all logging code from the binary at compile time, saving code size and improving performance.

Example usage:

#define TMC51X0_DISABLE_DEBUG_LOGGING
Communication interfaces for TMC51x0 stepper motor driver using SPI and UART.

Macro Definition Documentation

◆ TMC51X0_LOG_DEBUG

#define TMC51X0_LOG_DEBUG ( comm_obj,
level,
tag,
... )
Value:
do { \
const int _lvl = static_cast<int>(level); \
if (_lvl <= 0) { \
TMC51X0_LOGE(comm_obj, tag, __VA_ARGS__); \
} else if (_lvl == 1) { \
TMC51X0_LOGW(comm_obj, tag, __VA_ARGS__); \
} else if (_lvl == 2) { \
TMC51X0_LOGI(comm_obj, tag, __VA_ARGS__); \
} else if (_lvl == 3) { \
TMC51X0_LOGD(comm_obj, tag, __VA_ARGS__); \
} else { \
TMC51X0_LOGV(comm_obj, tag, __VA_ARGS__); \
} \
} while (0)

◆ TMC51X0_LOG_LEVEL

#define TMC51X0_LOG_LEVEL   4

Compile-time debug logging control for TMC51x0 library.

Define TMC51X0_DISABLE_DEBUG_LOGGING before including this header to completely disable all debug logging. When disabled, all logDebug() calls are optimized out at compile time, including argument evaluation.

◆ TMC51X0_LOGD

#define TMC51X0_LOGD ( comm_obj,
tag,
... )   (comm_obj).LogDebug(::tmc51x0::LogLevel::Debug, tag, __VA_ARGS__)

◆ TMC51X0_LOGE

#define TMC51X0_LOGE ( comm_obj,
tag,
... )   (comm_obj).LogDebug(::tmc51x0::LogLevel::Error, tag, __VA_ARGS__)

◆ TMC51X0_LOGI

#define TMC51X0_LOGI ( comm_obj,
tag,
... )   (comm_obj).LogDebug(::tmc51x0::LogLevel::Info, tag, __VA_ARGS__)

◆ TMC51X0_LOGV

#define TMC51X0_LOGV ( comm_obj,
tag,
... )   (comm_obj).LogDebug(::tmc51x0::LogLevel::Verbose, tag, __VA_ARGS__)

◆ TMC51X0_LOGW

#define TMC51X0_LOGW ( comm_obj,
tag,
... )   (comm_obj).LogDebug(::tmc51x0::LogLevel::Warn, tag, __VA_ARGS__)

◆ TMC51X0_SPI_MAX_CHAIN_DEVICES

#define TMC51X0_SPI_MAX_CHAIN_DEVICES   8