Frame structure for TMCL commands and replies.
More...
#include <TMC9660CommInterface.hpp>
|
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 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).
|
|
|
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).
|
|
Frame structure for TMCL commands and replies.
Supports conversion to/from SPI (8 bytes) and UART (9 bytes) formats.
◆ calculateChecksum()
static constexpr uint8_t TMCLFrame::calculateChecksum |
( |
const uint8_t * |
bytes, |
|
|
size_t |
n |
|
) |
| |
|
inlinestaticconstexprnoexcept |
Calculate 8-bit checksum (sum of bytes).
- Parameters
-
bytes | Pointer to data bytes to sum. |
n | Number 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
-
in | Span 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
-
in | Span of 8 received bytes. |
outFrame | Reference 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
-
in | Span of 9 received bytes. |
expectedAddr | 7-bit expected address of host. |
outFrame | Reference 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
-
out | Span 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
-
addr | 7-bit module address; MSB (sync bit) set automatically. |
out | Span of 9 bytes to fill: sync+addr, fields, checksum. |
◆ 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: