12#ifndef TMC9660_TYPES_HPP
13#define TMC9660_TYPES_HPP
18#include "tmc9660_version.h"
35enum class [[nodiscard]]
Error : uint8_t {
69 return "NotInitialized";
71 return "InvalidArgument";
77 return "DeviceIdMismatch";
87 return "UnexpectedReset";
95 return "VerifyFailed";
117 [[nodiscard]]
constexpr bool ok() const noexcept {
118 return error == Error::Ok;
121 constexpr explicit operator bool() const noexcept {
131 return {v, Error::Ok};
149 [[nodiscard]]
constexpr bool ok() const noexcept {
150 return error == Error::Ok;
153 constexpr explicit operator bool() const noexcept {
211struct EnumLast<
Mode> {
405inline constexpr uint32_t
kChipId = 0x544D0001U;
496 if ((c.device_address == 0U) || (c.host_address == 0U) || (c.tmcl_host_address == 0U)) {
499 if ((c.reply_timeout_us == 0U) || (c.boot_timeout_ms == 0U) || (c.spi_reply_retries > 50U)) {
502 if ((c.canary_variable > 15U) || (c.quirks.ram_debug_index_bits < 5U) ||
503 (c.quirks.ram_debug_index_bits > 6U)) {
506 if (!detail::IsEnumerator(c.mode) || !detail::IsEnumerator(c.quirks.tmcl_layout)) {
537 [[nodiscard]]
constexpr const Config&
Get() const& noexcept {
541 void Get() const&& = delete;
549 return TMC9660_VERSION_STRING;
553 return TMC9660_VERSION_MAJOR;
557 return TMC9660_VERSION_MINOR;
561 return TMC9660_VERSION_PATCH;
A configuration proven valid at build time.
Definition tmc9660_types.hpp:525
constexpr const Config & Get() const &noexcept
Definition tmc9660_types.hpp:537
void Get() const &&=delete
Not on a temporary: the reference would dangle (KB-CPP20-044).
consteval CheckedConfig(const Config &config) noexcept
Check config at build time.
Definition tmc9660_types.hpp:531
constexpr int32_t kCommutationModeMax
The largest valid COMMUTATION_MODE value.
Definition tmc9660_types.hpp:402
constexpr const char * ToString(Error error) noexcept
The name of an error, for logs.
Definition tmc9660_types.hpp:64
BlCmd
Bootloader command codes.
Definition tmc9660_types.hpp:269
RamDebugType
RAMDebug types (Table 16).
Definition tmc9660_types.hpp:375
CtrlPin
The control pins of the chip that the optional GpioSet() and GpioGet() hooks may drive.
Definition tmc9660_types.hpp:188
TmclStatus
TMCL reply status codes (Table 19).
Definition tmc9660_types.hpp:353
LogLevel
Severity passed to the optional Log() hook.
Definition tmc9660_types.hpp:172
constexpr uint32_t kMotorControlClockHz
The system clock motor control needs, in Hz.
Definition tmc9660_types.hpp:407
constexpr int32_t kSystemOff
Value of COMMUTATION_MODE (parameter 4) that leaves the gate driver off.
Definition tmc9660_types.hpp:400
constexpr uint32_t GetDriverVersionMinor() noexcept
Definition tmc9660_types.hpp:556
Error
Why a call failed. Every call of the driver returns one of these in its Result.
Definition tmc9660_types.hpp:35
BootMode
BOOT_MODE of the boot configuration (offset 8, bits 0-1).
Definition tmc9660_types.hpp:218
TmclLayout
Where the type and the motor or bank bytes of a TMCL frame put their bits (ambiguity A2).
Definition tmc9660_types.hpp:428
ReferenceSearch
RFS sub-commands.
Definition tmc9660_types.hpp:393
BlInfo
GET_INFO selectors of the bootloader.
Definition tmc9660_types.hpp:235
Mode
The protocol the chip speaks on its host interface.
Definition tmc9660_types.hpp:202
constexpr uint32_t GetDriverVersionPatch() noexcept
Definition tmc9660_types.hpp:560
TmclSpiStatus
SPI status byte of a TMCL reply.
Definition tmc9660_types.hpp:367
constexpr const char * GetDriverVersion() noexcept
Definition tmc9660_types.hpp:548
BusStatus
What a UART port reports for one exchange.
Definition tmc9660_types.hpp:180
Tmcl
TMCL operation codes (Table 18 of the parameter mode manual).
Definition tmc9660_types.hpp:299
constexpr Error Validate(const Config &c) noexcept
Check a Config without touching the bus.
Definition tmc9660_types.hpp:495
Bank
External memory banks of the bootloader (SET_BANK).
Definition tmc9660_types.hpp:227
BlStatus
Bootloader reply status codes (datasheet bootloader chapter).
Definition tmc9660_types.hpp:254
GpioSignal
Logical level of a control pin; the port maps it to the physical polarity.
Definition tmc9660_types.hpp:196
constexpr uint32_t GetDriverVersionMajor() noexcept
Definition tmc9660_types.hpp:552
constexpr uint32_t kBootMagic
The magic value of the Boot command.
Definition tmc9660_types.hpp:409
void ConfigIsInvalid() noexcept
Reached only when a CheckedConfig is built from an invalid configuration: it is never defined,...
constexpr uint32_t kChipId
The chip ID every TMC9660 reports (bootloader CHIP_TYPE, register MCC_INFO_CHIP).
Definition tmc9660_types.hpp:405
@ Read32Inc
Read 32 bits, then increment the address.
@ FlashEraseSector
Erase one flash sector.
@ BootstrapRs485
RS485 bootstrap: must be the first command.
@ SetAddress
Set the memory address.
@ GetAddress
Read the current memory address.
@ MemIsBusy
Is the external memory busy.
@ NoOp
Retrieve a reply (SPI).
@ GetBank
Read the current memory bank.
@ SetBank
Select a memory bank.
@ Read16Inc
Read 16 bits, then increment.
@ OtpLoad
Load the OTP configuration.
@ MemIsConnected
Is the selected external memory connected.
@ Read8Inc
Read 8 bits, then increment.
@ Write16Inc
Write 16 bits, then increment.
@ GetInfo
Read an information value.
@ Write8Inc
Write 8 bits, then increment.
@ FlashSendCmd
Raw flash command: not exposed by the driver.
@ MemIsConfigured
Is the selected external memory configured.
@ Write32Inc
Write 32 bits, then increment.
@ OtpBurn
Permanent: not exposed by the driver.
@ EnableTrigger
Start the measurement.
@ SetTriggerChannel
Set the trigger source.
@ GetChannelType
Channel type by index.
@ SampleCount
Total number of samples.
@ TriggerMaskShift
Mask and shift of the trigger value.
@ GetChannelAddress
Channel address by index.
@ Init
Initialise and reset.
@ GetPretrigger
Read the pretrigger sample count.
@ SetPretrigger
Total pretrigger samples.
@ GetState
State: idle, trigger, capture, complete, pretrigger.
@ Prescaler
Sampling divider minus one.
@ ReadSample
Read a sample by index.
@ SetChannel
Set a channel.
@ DrvEn
DRV_EN, active high on the package pin; ACTIVE allows the gate-driver outputs.
@ Reset
RSTN, active low on the package pin; ACTIVE holds the chip in reset.
@ Wake
WAKE, the wake-up pin (ACTIVE: the application's wake condition is asserted).
@ Faultn
FAULTN, an input; GpioGet reports the pin level (low: asserted).
@ CmdLoadError
Download error.
@ DownloadNotPossible
Download not possible.
@ ChecksumError
Checksum error in the request.
@ MaxExceeded
Limit exceeded.
@ CmdLoaded
Command stored by a download.
@ InvalidCommand
Unknown command.
@ WrongType
Type not valid.
@ Warning
Something unexpected that the driver recovered from.
@ Info
Lifecycle events: initialised, mode changes.
@ Debug
Detail for bring-up.
@ UnexpectedReset
The chip reset since the last validated reply; the driver is uninitialised.
@ InvalidArgument
An argument or a Config field is out of range; nothing was sent.
@ DeviceIdMismatch
The chip ID is not the TMC9660's: wrong chip, no chip or a wiring fault.
@ Crc
The bootloader UART CRC-8 of a reply did not match.
@ Bus
A port hook returned false or BusStatus::Fault.
@ VerifyFailed
A read back after a write did not match.
@ BadReply
A reply failed its checksum, address or opcode check; the value is discarded.
@ DeviceFault
A latched error flag forbids the call (gate driver or general error flags).
@ Unsupported
The hook or silicon feature this call needs is absent.
@ Nack
The chip answered with an error status; see LastStatus().
@ Timeout
No reply, or the chip did not become ready in the allowed time.
@ Busy
The chip answered BUSY and the retries ran out.
@ WrongMode
The call belongs to another mode than the chip is in; nothing was sent.
@ Refused
A safety guard said no; nothing was sent or changed.
@ Reserved
The hardware default: no application. The driver never starts the application with it.
@ Auto
Probe both layouts; start only when exactly one answers.
@ MotorHigh
Byte 3 (SPI byte 2): motor << 4 | type[11:8]; the byte before holds type[7:0].
@ TypeHigh
Byte 3 (SPI byte 2): type[11:8] << 4 | motor; the byte before holds type[7:0].
@ Status
Read the search status.
@ I2cMemSize
Size of the I2C memory.
@ SpiMemPartitions
Partitions in the SPI flash.
@ PartitionVersion
Partition table version.
@ I2cMemPartitions
Partitions in the I2C memory.
@ ChipVersion
Silicon version.
@ ConfigMemSize
Size of the configuration memory in bytes.
@ ChipFrequency
System clock in Hz.
@ OtpMemSize
Size of the OTP memory.
@ ConfigMemStart
Start address of the configuration memory.
@ ChipVariant
Chip variant (2).
@ SpiMemSize
Size of the SPI flash.
@ BlVersion
Bootloader version.
@ GitInfo
Git revision of the bootloader.
@ Register
The application in register mode: direct register access.
@ Bootloader
The bootloader: GET_INFO, memory access, configuration.
@ Parameter
The application in parameter mode: TMCL commands.
@ FirstCommand
The first command since a reset.
@ NotReady
The reply is not ready.
@ Fault
The UART failed (framing, overrun, driver error).
@ Stap
Store axis parameters.
@ Calcvx
Calculate variable with X.
@ DownloadEnd
End a script download.
@ ApplStep
Single-step the script.
@ ApplReset
Reset the script.
@ FactoryDefault
Restore the factory defaults.
@ GetVersion
Legacy version string: not used by the driver (ambiguity A11).
@ Reti
Return from interrupt.
@ Calcva
Calculate variable with accumulator.
@ DownloadStart
Start a script download.
@ Djnz
Decrement and jump if not zero.
@ Agp
Accumulator to global parameter.
@ ReadMem
Read script memory.
@ Breakpoint
Set a breakpoint.
@ Aiv
Accumulator to indexed variable.
@ Calcxv
Calculate X with variable.
@ Sgp
Set global parameter.
@ Calcx
Calculate with the X register.
@ Calcv
Calculate variable.
@ Giv
Get indexed variable.
@ ApplStop
Stop the script.
@ Calcvv
Calculate variable with variable.
@ GetStatus
Script status.
@ Ggp
Get global parameter.
@ Boot
Return to the bootloader.
@ Vect
Set interrupt vector.
@ Siv
Set indexed variable.
@ Rsub
Return from subroutine.
@ Calc
Calculate with the accumulator.
@ Calcav
Calculate accumulator with variable.
@ Aap
Accumulator to axis parameter.
@ SpiFlash
External SPI flash.
@ I2cEeprom
External I2C EEPROM.
@ Otp
One-time programmable memory.
@ InvalidValue
Value not valid.
@ InvalidAddr
Address not valid.
@ InvalidBank
Bank not valid.
@ BootloaderResumed
SPI only: the bootloader restarted.
@ OtpError
SPI only: OTP error.
@ MemUnconfigured
External memory not configured.
@ SessionStart
First reply of a session; the value is the version.
@ CmdNotFound
Unknown command.
@ CmdNotAvailable
Command not available.
@ ACTIVE
The pin function is asserted.
@ INACTIVE
The pin function is deasserted.
The TMC9660 driver: everything it declares lives here; internals in detail.
Definition tmc9660.hpp:37
@ RamDebug
RAMDebug; offsets are subcommand and index, not register numbers.
Configuration of the driver. The defaults are the chip's.
Definition tmc9660_types.hpp:461
bool hardware_reset
Definition tmc9660_types.hpp:483
uint32_t boot_timeout_ms
Definition tmc9660_types.hpp:473
bool allow_pwm_in_system_off
See the lines above.
Definition tmc9660_types.hpp:469
bool uart_canary
Parameter mode over UART: detect an unseen reset (A7).
Definition tmc9660_types.hpp:480
uint32_t spi_gap_us
Gap between the command and the reply-request on SPI.
Definition tmc9660_types.hpp:477
uint32_t reply_timeout_us
How long the UART port waits for a reply. Leave PWM active in System off; without it SetParam(IDLE_MO...
Definition tmc9660_types.hpp:466
Quirks quirks
Readings of ambiguous documentation.
Definition tmc9660_types.hpp:487
uint32_t settle_us
Wait after a write that reconfigures the chip (A13).
Definition tmc9660_types.hpp:476
bool faultn_is_reset
Service() treats FAULTN low outside the bootloader as a reset (A18).
Definition tmc9660_types.hpp:485
uint8_t device_address
UART device address (odd: its upper 7 bits are the TMCL address).
Definition tmc9660_types.hpp:463
uint8_t spi_reply_retries
Repeats of the reply-request on NOT_READY or CHECKSUM_ERROR (A5).
Definition tmc9660_types.hpp:478
uint8_t canary_variable
User variable that holds the canary.
Definition tmc9660_types.hpp:481
uint8_t host_address
Host address in bootloader UART replies.
Definition tmc9660_types.hpp:464
uint32_t uart_resync_us
Definition tmc9660_types.hpp:470
Mode mode
The protocol the chip is in at EnsureInitialized().
Definition tmc9660_types.hpp:462
int32_t canary_value
The canary.
Definition tmc9660_types.hpp:482
uint8_t tmcl_host_address
Host address in TMCL and register-mode UART replies.
Definition tmc9660_types.hpp:465
Model knobs: where the documents disagree, the driver reads one way by default and a flag selects the...
Definition tmc9660_types.hpp:447
uint8_t ram_debug_index_bits
A17: width of the RAMDebug index in a register offset: 5 or 6.
Definition tmc9660_types.hpp:454
bool reg_spi_wide_offset
A3: 5-bit block, write bit 42, 10-bit offset.
Definition tmc9660_types.hpp:452
bool crc8_reflect_output
A1: reflect the CRC-8 result, as the prose says. The examples do not.
Definition tmc9660_types.hpp:448
bool reg_uart_msb_fields
A4: offset[10:8] << 5 | block in byte 3.
Definition tmc9660_types.hpp:453
TmclLayout tmcl_layout
A2: the TMCL type and motor bytes; probed at the start, never trusted.
Definition tmc9660_types.hpp:450
constexpr bool ok() const noexcept
Definition tmc9660_types.hpp:149
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition tmc9660_types.hpp:166
static constexpr Result Success() noexcept
Definition tmc9660_types.hpp:158
The value of a call, or why there is none.
Definition tmc9660_types.hpp:112
constexpr bool ok() const noexcept
Definition tmc9660_types.hpp:117
static constexpr Result Success(T v) noexcept
A successful result.
Definition tmc9660_types.hpp:130
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition tmc9660_types.hpp:138
Compile-time helpers of the TMC9660 driver: byte copy, exact hook matching, typed register fields and...