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

Frame structure for TMCL commands. More...

#include <tmc9660_comm_interface.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 &out_frame) noexcept
 Deserialize an SPI buffer with status and checksum validation.
 
static bool fromUart (std::span< const uint8_t, 9 > in, uint8_t expected_addr, TMCLFrame &out_frame) 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 2, bits 20-23).
 
uint32_t value = 0
 32-bit data value (BYTE 3-6, bits 24-55).
 

Detailed Description

Frame structure for TMCL commands.

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

Member Function Documentation

◆ calculateChecksum()

static constexpr uint8_t tmc9660::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 tmc9660::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 tmc9660::TMCLFrame::fromSpiChecked ( std::span< const uint8_t, 8 > in,
TMCLFrame & out_frame )
inlinestaticnoexcept

Deserialize an SPI buffer with status and checksum validation.

Parameters
inSpan of 8 received bytes.
out_frameReference to store the valid frame.
Returns
false if NOT_READY or CHECKSUM_ERROR or invalid status; true otherwise.
Here is the call graph for this function:

◆ fromUart()

static bool tmc9660::TMCLFrame::fromUart ( std::span< const uint8_t, 9 > in,
uint8_t expected_addr,
TMCLFrame & out_frame )
inlinestaticnoexcept

Deserialize a UART buffer with address and checksum validation.

Parameters
inSpan of 9 received bytes.
expected_addr7-bit expected address of host.
out_frameReference to store the valid frame.
Returns
true if address and checksum match.
Here is the call graph for this function:

◆ toSpi()

void tmc9660::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).
Here is the call graph for this function:

◆ toUart()

void tmc9660::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.
Here is the call graph for this function:

Member Data Documentation

◆ motor

uint8_t tmc9660::TMCLFrame::motor = 0

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

◆ opcode

uint8_t tmc9660::TMCLFrame::opcode = 0

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

◆ type

uint16_t tmc9660::TMCLFrame::type = 0

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

◆ value

uint32_t tmc9660::TMCLFrame::value = 0

32-bit data value (BYTE 3-6, bits 24-55).


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