HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
Loading...
Searching...
No Matches
HalUartTmc9660Comm Class Reference

Concrete UART communication adapter for TMC9660 using BaseUart and BaseGpio. More...

#include <Tmc9660Handler.h>

Inheritance diagram for HalUartTmc9660Comm:
[legend]
Collaboration diagram for HalUartTmc9660Comm:
[legend]

Public Member Functions

 HalUartTmc9660Comm (BaseUart &uart, BaseGpio &rst, BaseGpio &drv_en, BaseGpio &faultn, BaseGpio &wake, bool rst_active_high=true, bool drv_en_active_high=true, bool faultn_active_low=false, bool wake_active_low=false) noexcept
 Construct the UART communication adapter.
 
CRTP-Required Methods
bool uartSendTMCL (const std::array< uint8_t, 9 > &data) noexcept
 Send a 9-byte TMCL datagram over UART.
 
bool uartReceiveTMCL (std::array< uint8_t, 9 > &data) noexcept
 Receive a 9-byte TMCL reply datagram over UART.
 
bool uartTransferBootloader (const std::array< uint8_t, 8 > &tx, std::array< uint8_t, 8 > &rx) noexcept
 Perform an 8-byte UART bootloader transfer (send + receive).
 
bool gpioSet (tmc9660::TMC9660CtrlPin pin, tmc9660::GpioSignal signal) noexcept
 Set a TMC9660 control pin to a given logical signal state.
 
bool gpioRead (tmc9660::TMC9660CtrlPin pin, tmc9660::GpioSignal &signal) noexcept
 Read a TMC9660 control pin's current logical signal state.
 
void debugLog (int level, const char *tag, const char *format, va_list args) noexcept
 Route TMC9660 driver debug output to the HardFOC Logger.
 
void delayMs (uint32_t ms) noexcept
 Delay execution for the specified number of milliseconds.
 
void delayUs (uint32_t us) noexcept
 Delay execution for the specified number of microseconds.
 

Private Attributes

BaseUart & uart_
 UART bus interface (not owned).
 
Tmc9660CtrlPins ctrl_pins_
 Host-side control pin references.
 

Detailed Description

Concrete UART communication adapter for TMC9660 using BaseUart and BaseGpio.

Implements all methods required by tmc9660::UartCommInterface<HalUartTmc9660Comm> through the CRTP pattern. Handles:

  • TMCL transfers: 9-byte send/receive for parameter mode
  • Bootloader transfers: 8-byte send/receive for bootloader mode
  • GPIO control: Same four control pins as HalSpiTmc9660Comm
  • Timing and logging: Same platform-aware implementations
Note
This class does NOT own the BaseUart or BaseGpio instances; they must remain valid for the lifetime of this object.
See also
tmc9660::UartCommInterface CRTP base class from the TMC9660 driver
HalSpiTmc9660Comm SPI equivalent of this class

Constructor & Destructor Documentation

◆ HalUartTmc9660Comm()

HalUartTmc9660Comm::HalUartTmc9660Comm ( BaseUart & uart,
BaseGpio & rst,
BaseGpio & drv_en,
BaseGpio & faultn,
BaseGpio & wake,
bool rst_active_high = true,
bool drv_en_active_high = true,
bool faultn_active_low = false,
bool wake_active_low = false )
noexcept

Construct the UART communication adapter.

Parameters
uartReference to a pre-configured BaseUart implementation.
rstBaseGpio connected to TMC9660 RST (pin 22, output).
drv_enBaseGpio connected to TMC9660 DRV_EN (pin 21, output).
faultnBaseGpio connected to TMC9660 FAULTN (pin 20, input).
wakeBaseGpio connected to TMC9660 WAKE (pin 19, output).
rst_active_highPhysical level for RST ACTIVE state (default: true).
drv_en_active_highPhysical level for DRV_EN ACTIVE state (default: true).
faultn_active_lowPhysical level for FAULTN ACTIVE state (default: false).
wake_active_lowPhysical level for WAKE ACTIVE state (default: false).

Member Function Documentation

◆ debugLog()

void HalUartTmc9660Comm::debugLog ( int level,
const char * tag,
const char * format,
va_list args )
noexcept

Route TMC9660 driver debug output to the HardFOC Logger.

Parameters
levelLog level (0=Error, 1=Warning, 2=Info, 3=Debug).
tagLog tag string for categorization.
formatprintf-style format string.
argsVariable argument list.
Here is the call graph for this function:

◆ delayMs()

void HalUartTmc9660Comm::delayMs ( uint32_t ms)
noexcept

Delay execution for the specified number of milliseconds.

Parameters
msMilliseconds to delay (delegates to os_delay_msec).
Here is the call graph for this function:

◆ delayUs()

void HalUartTmc9660Comm::delayUs ( uint32_t us)
noexcept

Delay execution for the specified number of microseconds.

On ESP32, uses esp_rom_delay_us() for accurate sub-millisecond timing. On other platforms, uses a busy-wait loop based on the processor cycle counter.

Parameters
usMicroseconds to delay.
Here is the call graph for this function:

◆ gpioRead()

bool HalUartTmc9660Comm::gpioRead ( tmc9660::TMC9660CtrlPin pin,
tmc9660::GpioSignal & signal )
noexcept

Read a TMC9660 control pin's current logical signal state.

Reads the physical GPIO level via BaseGpio, then translates to ACTIVE/INACTIVE based on the pin's configured active-level polarity.

Parameters
pinWhich control pin to read (typically FAULTN for fault status).
[out]signalCurrent logical signal state.
Returns
true if the GPIO read succeeded.
Here is the call graph for this function:

◆ gpioSet()

bool HalUartTmc9660Comm::gpioSet ( tmc9660::TMC9660CtrlPin pin,
tmc9660::GpioSignal signal )
noexcept

Set a TMC9660 control pin to a given logical signal state.

Translates the logical ACTIVE/INACTIVE signal to a physical HIGH/LOW level based on the pin's configured active-level polarity, then writes via BaseGpio.

Parameters
pinWhich control pin to set (RST, DRV_EN, FAULTN, WAKE).
signalDesired logical signal state.
Returns
true if the GPIO write succeeded.
Here is the call graph for this function:

◆ uartReceiveTMCL()

bool HalUartTmc9660Comm::uartReceiveTMCL ( std::array< uint8_t, 9 > & data)
noexcept

Receive a 9-byte TMCL reply datagram over UART.

Parameters
[out]data9-byte array to store the received reply.
Returns
true if BaseUart::Read() succeeded within timeout.

◆ uartSendTMCL()

bool HalUartTmc9660Comm::uartSendTMCL ( const std::array< uint8_t, 9 > & data)
noexcept

Send a 9-byte TMCL datagram over UART.

Parameters
data9-byte array: [sync+addr, opcode, type, motor, value(4), checksum].
Returns
true if BaseUart::Write() succeeded.

◆ uartTransferBootloader()

bool HalUartTmc9660Comm::uartTransferBootloader ( const std::array< uint8_t, 8 > & tx,
std::array< uint8_t, 8 > & rx )
noexcept

Perform an 8-byte UART bootloader transfer (send + receive).

Parameters
tx8-byte transmit buffer (bootloader command).
[out]rx8-byte receive buffer (bootloader reply).
Returns
true if both write and read succeeded.

Member Data Documentation

◆ ctrl_pins_

Tmc9660CtrlPins HalUartTmc9660Comm::ctrl_pins_
private

Host-side control pin references.

◆ uart_

BaseUart& HalUartTmc9660Comm::uart_
private

UART bus interface (not owned).


The documentation for this class was generated from the following files: