HF-TMC51x0 Driver (TMC5130 & TMC5160) 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC51x0 (TMC5130 & TMC5160)
Loading...
Searching...
No Matches
Esp32UART Class Reference

ESP32 UART implementation of TMC51x0 communication interface. More...

#include <esp32_tmc51x0_bus.hpp>

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

Public Member Functions

 Esp32UART (uart_port_t uart_num, const Esp32UartPinConfig &pin_config, uint32_t baud_rate=115200, const tmc51x0::PinActiveLevels &active_levels=tmc51x0::PinActiveLevels{}) noexcept
 Construct ESP32 UART communication interface.
 
 ~Esp32UART () noexcept
 
bool ApplyPinConfig (const tmc51x0::TMC51x0PinConfig &pc) noexcept
 
bool SetPinMapping (tmc51x0::TMC51x0CtrlPin pin, gpio_num_t gpio_pin) noexcept
 
gpio_num_t GetPinMapping (tmc51x0::TMC51x0CtrlPin pin) const noexcept
 
tmc51x0::Result< void > Initialize () noexcept
 
tmc51x0::Result< void > Deinitialize () noexcept
 
tmc51x0::Result< void > UartSend (const uint8_t *data, size_t length) noexcept
 
tmc51x0::Result< void > UartReceive (uint8_t *data, size_t length) noexcept
 
tmc51x0::Result< void > SetNaiPin (bool active) noexcept
 
tmc51x0::Result< bool > GetNaoPin () noexcept
 
tmc51x0::CommMode GetMode () const noexcept
 
tmc51x0::Result< void > GpioSet (tmc51x0::TMC51x0CtrlPin pin, tmc51x0::GpioSignal signal) noexcept
 
tmc51x0::Result< tmc51x0::GpioSignalGpioRead (tmc51x0::TMC51x0CtrlPin pin) noexcept
 
void DebugLog (int level, const char *tag, const char *format, va_list args) noexcept
 
void DelayMs (uint32_t ms) noexcept
 
void DelayUs (uint32_t us) noexcept
 
- Public Member Functions inherited from tmc51x0::UartCommInterface< Esp32UART >
 UartCommInterface () noexcept
 Construct UART communication interface with pin active level configuration.
 
 UartCommInterface (const UartCommInterface &)=delete
 
CommMode GetMode () const noexcept
 Get communication mode (always UART for this interface)
 
Result< void > SetNaiPin (bool active) noexcept
 Set NAI (Next Address Input) pin state for daisy chaining.
 
Result< bool > GetNaoPin () noexcept
 Read NAO (Next Address Output) pin state.
 
Result< void > UartSend (const uint8_t *data, size_t length) noexcept
 Send raw bytes via UART.
 
Result< void > UartReceive (uint8_t *data, size_t length) noexcept
 Receive raw bytes via UART.
 
Result< uint32_t > ReadRegister (uint8_t address, uint8_t node_address=0) noexcept
 Read a 32-bit register via UART.
 
Result< void > WriteRegister (uint8_t address, uint32_t value, uint8_t node_address=0) noexcept
 Write a 32-bit register via UART.
 
UartCommInterfaceoperator= (const UartCommInterface &)=delete
 
- Public Member Functions inherited from tmc51x0::CommInterface< Derived >
 CommInterface () noexcept=default
 Construct communication interface.
 
CommMode GetMode () const noexcept
 Get the underlying communication mode used by this interface.
 
Result< uint32_t > ReadRegister (uint8_t address, uint8_t address_param=0) noexcept
 Read a 32-bit register from the TMC5160.
 
Result< void > WriteRegister (uint8_t address, uint32_t value, uint8_t address_param=0) noexcept
 Write a 32-bit register to the TMC5160.
 
Result< void > GpioSet (TMC51x0CtrlPin pin, GpioSignal signal) noexcept
 Set GPIO pin signal state (output control)
 
Result< GpioSignalGpioRead (TMC51x0CtrlPin pin) noexcept
 Read GPIO pin signal state (input state)
 
Result< void > GpioSetActive (TMC51x0CtrlPin pin) noexcept
 Set GPIO pin to active state (convenience method)
 
Result< void > GpioSetInactive (TMC51x0CtrlPin pin) noexcept
 Set GPIO pin to inactive state (convenience method)
 
void DelayMs (uint32_t ms) noexcept
 Delay execution for specified milliseconds.
 
void DelayUs (uint32_t us) noexcept
 Delay execution for specified microseconds.
 
Result< void > SetPowerEnabled (bool enabled) noexcept
 Enable/disable power to the TMC51x0 (optional)
 
Result< void > PowerCycle (uint32_t power_off_ms=20, uint32_t power_on_settle_ms=20) noexcept
 Power-cycle the TMC51x0 (optional)
 
Result< void > SetClkFreq (uint32_t frequency_hz) noexcept
 Set external clock frequency on CLK pin (optional)
 
 CommInterface (const CommInterface &)=delete
 
CommInterfaceoperator= (const CommInterface &)=delete
 
void LogDebug (int level, const char *tag, const char *format,...) noexcept
 Public debug logging wrapper for external classes.
 
void LogDebug (LogLevel level, const char *tag, const char *format,...) noexcept
 LogDebug overload that accepts the driver-native LogLevel enum.
 

Private Attributes

tmc51x0::PinActiveLevels active_levels_
 
uart_port_t uart_num_
 
gpio_num_t tx_pin_
 
gpio_num_t rx_pin_
 
gpio_num_t en_pin_
 
uint32_t baud_rate_
 
bool initialized_
 
gpio_num_t pin_mapping_ [16] {}
 

Additional Inherited Members

- Protected Member Functions inherited from tmc51x0::UartCommInterface< Esp32UART >
 UartCommInterface (UartCommInterface &&)=default
 
 ~UartCommInterface ()=default
 Protected destructor.
 
UartCommInterfaceoperator= (UartCommInterface &&)=default
 
- Protected Member Functions inherited from tmc51x0::CommInterface< Derived >
void DebugLog (int level, const char *tag, const char *format, va_list args) noexcept
 Debug logging function for detailed debugging information.
 
 ~CommInterface ()=default
 Protected destructor.
 
 CommInterface (CommInterface &&)=default
 
CommInterfaceoperator= (CommInterface &&)=default
 

Detailed Description

ESP32 UART implementation of TMC51x0 communication interface.

Provides UART single-wire communication for the TMC51x0 using the ESP-IDF UART driver. Supports single-node and multi-node (daisy-chain) operation.

The TMC5160 uses a single-wire UART interface on pins:

  • SWN/SWPN (pin 26/DIAG0): UART input (active low)
  • SWP/SWIOP (pin 27/DIAG1): UART output

For multi-node systems, NAI/NAO pins (SDI_CFG1 / SDO_CFG0) form an addressing chain. See the TMC5160 datasheet section 5.4.

Note
SD_MODE and SPI_MODE must both be LOW (GND) for UART operation.

Constructor & Destructor Documentation

◆ Esp32UART()

Esp32UART::Esp32UART ( uart_port_t uart_num,
const Esp32UartPinConfig & pin_config,
uint32_t baud_rate = 115200,
const tmc51x0::PinActiveLevels & active_levels = tmc51x0::PinActiveLevels{} )
inlinenoexcept

Construct ESP32 UART communication interface.

Parameters
uart_numUART port number (UART_NUM_1 or UART_NUM_2; avoid UART_NUM_0 used for console)
pin_configComplete pin configuration
baud_rateUART baud rate (default 115200; TMC5160 auto-detects from sync frame)
active_levelsPin active level configuration

◆ ~Esp32UART()

Esp32UART::~Esp32UART ( )
inlinenoexcept
Here is the call graph for this function:

Member Function Documentation

◆ ApplyPinConfig()

bool Esp32UART::ApplyPinConfig ( const tmc51x0::TMC51x0PinConfig & pc)
inlinenoexcept
Here is the call graph for this function:

◆ DebugLog()

void Esp32UART::DebugLog ( int level,
const char * tag,
const char * format,
va_list args )
inlinenoexcept

◆ Deinitialize()

tmc51x0::Result< void > Esp32UART::Deinitialize ( )
inlinenoexcept
Here is the caller graph for this function:

◆ DelayMs()

void Esp32UART::DelayMs ( uint32_t ms)
inlinenoexcept

◆ DelayUs()

void Esp32UART::DelayUs ( uint32_t us)
inlinenoexcept

◆ GetMode()

tmc51x0::CommMode Esp32UART::GetMode ( ) const
inlinenoexcept

◆ GetNaoPin()

tmc51x0::Result< bool > Esp32UART::GetNaoPin ( )
inlinenoexcept

◆ GetPinMapping()

gpio_num_t Esp32UART::GetPinMapping ( tmc51x0::TMC51x0CtrlPin pin) const
inlinenoexcept
Here is the caller graph for this function:

◆ GpioRead()

tmc51x0::Result< tmc51x0::GpioSignal > Esp32UART::GpioRead ( tmc51x0::TMC51x0CtrlPin pin)
inlinenoexcept
Here is the call graph for this function:

◆ GpioSet()

tmc51x0::Result< void > Esp32UART::GpioSet ( tmc51x0::TMC51x0CtrlPin pin,
tmc51x0::GpioSignal signal )
inlinenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Initialize()

tmc51x0::Result< void > Esp32UART::Initialize ( )
inlinenoexcept
Here is the call graph for this function:

◆ SetNaiPin()

tmc51x0::Result< void > Esp32UART::SetNaiPin ( bool active)
inlinenoexcept

◆ SetPinMapping()

bool Esp32UART::SetPinMapping ( tmc51x0::TMC51x0CtrlPin pin,
gpio_num_t gpio_pin )
inlinenoexcept
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UartReceive()

tmc51x0::Result< void > Esp32UART::UartReceive ( uint8_t * data,
size_t length )
inlinenoexcept

◆ UartSend()

tmc51x0::Result< void > Esp32UART::UartSend ( const uint8_t * data,
size_t length )
inlinenoexcept

Member Data Documentation

◆ active_levels_

tmc51x0::PinActiveLevels Esp32UART::active_levels_
private

◆ baud_rate_

uint32_t Esp32UART::baud_rate_
private

◆ en_pin_

gpio_num_t Esp32UART::en_pin_
private

◆ initialized_

bool Esp32UART::initialized_
private

◆ pin_mapping_

gpio_num_t Esp32UART::pin_mapping_[16] {}
private

◆ rx_pin_

gpio_num_t Esp32UART::rx_pin_
private

◆ tx_pin_

gpio_num_t Esp32UART::tx_pin_
private

◆ uart_num_

uart_port_t Esp32UART::uart_num_
private

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