HF-TMC9660 Driver
Hardware Agnostic C++ Driver for the TMC9660
Loading...
Searching...
No Matches
TMCLFrame Struct Reference

Frame structure for TMCL commands and replies. More...

#include <TMC9660CommInterface.hpp>

Public Member Functions

void toSpi (std::span< uint8_t, 8 > out) const noexcept
 Serialize frame into 8-byte SPI buffer.
 
void toUart (uint8_t addr, std::span< uint8_t, 9 > out) const noexcept
 Serialize frame into 9-byte UART buffer, including sync bit and checksum.
 

Static Public Member Functions

static TMCLFrame fromSpi (std::span< const uint8_t, 8 > in) noexcept
 Deserialize an SPI buffer into a TMCLFrame without status check.
 
static bool fromSpiChecked (std::span< const uint8_t, 8 > in, TMCLFrame &outFrame) noexcept
 Deserialize an SPI buffer with status and checksum validation.
 
static bool fromUart (std::span< const uint8_t, 9 > in, uint8_t expectedAddr, TMCLFrame &outFrame) noexcept
 Deserialize a UART buffer with address and checksum validation.
 
static constexpr uint8_t calculateChecksum (const uint8_t *bytes, size_t n) noexcept
 Calculate 8-bit checksum (sum of bytes).
 

Public Attributes

uint8_t opcode = 0
 Operation code field (BYTE 0, bits 0-7).
 
uint16_t type = 0
 Parameter or command type (BYTE 1-2, bits 8-19).
 
uint8_t motor = 0
 Motor or bank identifier (BYTE 3, bits 20-23).
 
uint32_t value = 0
 32-bit data value (BYTE 4-7, bits 24-55).
 

Detailed Description

Frame structure for TMCL commands and replies.

Supports conversion to/from SPI (8 bytes) and UART (9 bytes) formats.

Member Function Documentation

◆ calculateChecksum()

static constexpr uint8_t TMCLFrame::calculateChecksum ( const uint8_t *  bytes,
size_t  n 
)
inlinestaticconstexprnoexcept

Calculate 8-bit checksum (sum of bytes).

Parameters
bytesPointer to data bytes to sum.
nNumber of bytes to include in sum.
Returns
8-bit checksum value.

◆ fromSpi()

static TMCLFrame TMCLFrame::fromSpi ( std::span< const uint8_t, 8 >  in)
inlinestaticnoexcept

Deserialize an SPI buffer into a TMCLFrame without status check.

Parameters
inSpan of 8 received bytes.
Returns
Populated TMCLFrame.

◆ fromSpiChecked()

static bool TMCLFrame::fromSpiChecked ( std::span< const uint8_t, 8 >  in,
TMCLFrame outFrame 
)
inlinestaticnoexcept

Deserialize an SPI buffer with status and checksum validation.

Parameters
inSpan of 8 received bytes.
outFrameReference to store the valid frame.
Returns
false if NOT_READY or CHECKSUM_ERROR or invalid status; true otherwise.

◆ fromUart()

static bool TMCLFrame::fromUart ( std::span< const uint8_t, 9 >  in,
uint8_t  expectedAddr,
TMCLFrame outFrame 
)
inlinestaticnoexcept

Deserialize a UART buffer with address and checksum validation.

Parameters
inSpan of 9 received bytes.
expectedAddr7-bit expected address of host.
outFrameReference to store the valid frame.
Returns
true if address and checksum match.

◆ toSpi()

void TMCLFrame::toSpi ( std::span< uint8_t, 8 >  out) const
inlinenoexcept

Serialize frame into 8-byte SPI buffer.

Parameters
outSpan of 8 bytes to fill: opcode, type (2), motor, value (4).

◆ toUart()

void TMCLFrame::toUart ( uint8_t  addr,
std::span< uint8_t, 9 >  out 
) const
inlinenoexcept

Serialize frame into 9-byte UART buffer, including sync bit and checksum.

Parameters
addr7-bit module address; MSB (sync bit) set automatically.
outSpan of 9 bytes to fill: sync+addr, fields, checksum.

Member Data Documentation

◆ motor

uint8_t TMCLFrame::motor = 0

Motor or bank identifier (BYTE 3, bits 20-23).

◆ opcode

uint8_t TMCLFrame::opcode = 0

Operation code field (BYTE 0, bits 0-7).

◆ type

uint16_t TMCLFrame::type = 0

Parameter or command type (BYTE 1-2, bits 8-19).

◆ value

uint32_t TMCLFrame::value = 0

32-bit data value (BYTE 4-7, bits 24-55).


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