HF-TMC9660 Driver 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC9660
Loading...
Searching...
No Matches
Esp32Tmc9660UartBus Class Reference

ESP32 UART implementation of TMC9660CommInterface. More...

#include <esp32_tmc9660_bus.hpp>

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

Public Member Functions

 Esp32Tmc9660UartBus (uart_port_t uart_num, gpio_num_t tx_pin, gpio_num_t rx_pin, gpio_num_t rst_pin, gpio_num_t drv_en_pin, gpio_num_t faultn_pin, gpio_num_t wake_pin, uint32_t baud_rate=115200, uint8_t address=0) noexcept
 Construct ESP32 UART communication interface.
 
 ~Esp32Tmc9660UartBus () noexcept
 Destructor - cleans up UART resources.
 
bool initialize () noexcept
 Initialize the UART interface.
 
bool deinitialize () noexcept
 Deinitialize the UART interface.
 
bool uartSendTMCL (const std::array< uint8_t, 9 > &data) noexcept
 Send raw 9-byte UART TMCL datagram for parameter mode communication.
 
bool uartReceiveTMCL (std::array< uint8_t, 9 > &data) noexcept
 Receive raw 9-byte UART TMCL datagram for parameter mode communication.
 
bool transferTMCL (const TMCLFrame &tx, TMCLReply &reply, uint8_t address, TMCLReply *firstReply, const TMCLFrame *secondCommand) noexcept
 Transfer TMCL frame over UART for parameter mode communication.
 
bool uartTransferBootloader (const std::array< uint8_t, 8 > &tx, std::array< uint8_t, 8 > &rx) noexcept
 Transfer 8-byte UART bootloader datagram (send and receive)
 
CommMode mode () const noexcept
 Get communication mode.
 
bool gpioSet (TMC9660CtrlPin pin, GpioSignal signal) noexcept
 Set GPIO pin signal state for TMC9660 control pins.
 
bool gpioRead (TMC9660CtrlPin pin, GpioSignal &signal) noexcept
 Read GPIO pin level for TMC9660 status pins.
 
void debugLog (int level, const char *tag, const char *format, va_list args) noexcept
 Debug logging function that routes logs through ESP-IDF logging system.
 
void delayMs (uint32_t ms) noexcept
 
void delayUs (uint32_t us) noexcept
 
- Public Member Functions inherited from tmc9660::UartCommInterface< Esp32Tmc9660UartBus >
 UartCommInterface (bool rst_active_level, bool drv_en_active_level, bool wake_active_level, bool faultn_active_level) noexcept
 Construct UART communication interface with pin active level configuration.
 
CommMode mode () const noexcept
 Get communication mode (always UART for this interface)
 
bool uartSendTMCL (const std::array< uint8_t, 9 > &data) noexcept
 Send raw 9-byte UART TMCL datagram for parameter mode communication.
 
bool uartReceiveTMCL (std::array< uint8_t, 9 > &data) noexcept
 Receive raw 9-byte UART TMCL datagram for parameter mode communication.
 
bool uartTransferBootloader (const std::array< uint8_t, 8 > &tx, std::array< uint8_t, 8 > &rx) noexcept
 Transfer 8-byte UART bootloader datagram (send and receive).
 
bool gpioSet (TMC9660CtrlPin pin, GpioSignal signal) noexcept
 Set GPIO pin signal state for UART interface.
 
bool gpioRead (TMC9660CtrlPin pin, GpioSignal &signal) noexcept
 Read GPIO pin signal state for UART interface.
 
bool transferTMCL (const TMCLFrame &tx, TMCLReply &reply, uint8_t address, TMCLReply *first_reply, const TMCLFrame *second_command) noexcept
 
- Public Member Functions inherited from tmc9660::CommInterface< Derived >
 CommInterface (bool rst_active_level, bool drv_en_active_level, bool wake_active_level, bool faultn_active_level) noexcept
 Construct communication interface with pin active level configuration.
 
CommMode mode () const noexcept
 Get the underlying communication mode used by this interface.
 
bool transferTMCL (const TMCLFrame &tx, TMCLReply &reply, uint8_t address, TMCLReply *first_reply=nullptr, const TMCLFrame *second_command=nullptr) noexcept
 Perform a full duplex TMCL transfer for parameter mode communication.
 
bool gpioSet (TMC9660CtrlPin pin, GpioSignal signal) noexcept
 Set GPIO pin signal state (output control).
 
bool gpioRead (TMC9660CtrlPin pin, GpioSignal &signal) noexcept
 Read GPIO pin signal state (input state).
 
bool signalToGpioLevel (TMC9660CtrlPin pin, GpioSignal signal) const noexcept
 Convert signal state to physical GPIO level.
 
GpioSignal gpioLevelToSignal (TMC9660CtrlPin pin, bool gpio_level) const noexcept
 Convert physical GPIO level to signal state.
 
bool gpioSetActive (TMC9660CtrlPin pin) noexcept
 Set GPIO pin to active state (convenience method).
 
bool gpioSetInactive (TMC9660CtrlPin pin) noexcept
 Set GPIO pin to inactive state (convenience method).
 
bool set_pin_active_level (TMC9660CtrlPin pin, bool active_level) noexcept
 Configure the active level for a specific pin.
 
void setSpiRetryMaxCount (uint8_t max_retries) noexcept
 Set maximum number of retries for SPI_STATUS_NOT_READY responses.
 
uint8_t getSpiRetryMaxCount () const noexcept
 Get current maximum retry count for SPI_STATUS_NOT_READY.
 
void setSpiRetryInterval (uint32_t interval_us) noexcept
 Set delay interval between retry attempts for SPI_STATUS_NOT_READY.
 
uint32_t getSpiRetryInterval () const noexcept
 Get current retry interval for SPI_STATUS_NOT_READY.
 
void delayMs (uint32_t ms) noexcept
 Delay execution for specified milliseconds.
 
void delayUs (uint32_t us) noexcept
 Delay execution for specified microseconds.
 
void logDebug (int level, const char *tag, const char *format,...) noexcept
 Public debug logging wrapper for external classes.
 

Private Member Functions

bool configureGpioPins () noexcept
 Configure GPIO pins for TMC9660 control and status.
 
gpio_num_t getGpioPin (TMC9660CtrlPin pin) const noexcept
 Map TMC9660 control pins to ESP32 GPIO pins.
 

Private Attributes

uart_port_t uart_num_
 
gpio_num_t tx_pin_
 
gpio_num_t rx_pin_
 
gpio_num_t rst_pin_
 
gpio_num_t drv_en_pin_
 
gpio_num_t faultn_pin_
 
gpio_num_t wake_pin_
 
uint32_t baud_rate_
 
uint8_t address_
 
bool initialized_
 

Additional Inherited Members

- Protected Member Functions inherited from tmc9660::UartCommInterface< Esp32Tmc9660UartBus >
 UartCommInterface (const UartCommInterface &)=delete
 
 UartCommInterface (UartCommInterface &&)=default
 
 ~UartCommInterface ()=default
 Protected destructor.
 
UartCommInterfaceoperator= (const UartCommInterface &)=delete
 
UartCommInterfaceoperator= (UartCommInterface &&)=default
 
- Protected Member Functions inherited from tmc9660::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 (const CommInterface &)=delete
 
CommInterfaceoperator= (const CommInterface &)=delete
 
 CommInterface (CommInterface &&)=default
 
CommInterfaceoperator= (CommInterface &&)=default
 
- Protected Attributes inherited from tmc9660::CommInterface< Derived >
bool pinActiveLevels_ [4]
 Pin active level configuration storage.
 
uint8_t spiRetryMaxCount_ = 3
 Maximum number of retries for SPI_STATUS_NOT_READY responses.
 
uint32_t spiRetryIntervalUs_ = 100
 Delay interval in microseconds between retry attempts.
 

Detailed Description

ESP32 UART implementation of TMC9660CommInterface.

This class provides UART communication for the TMC9660 using ESP-IDF UART driver. It handles the TMCL protocol over UART as specified in the TMC9660 documentation.

Constructor & Destructor Documentation

◆ Esp32Tmc9660UartBus()

Esp32Tmc9660UartBus::Esp32Tmc9660UartBus ( uart_port_t uart_num,
gpio_num_t tx_pin,
gpio_num_t rx_pin,
gpio_num_t rst_pin,
gpio_num_t drv_en_pin,
gpio_num_t faultn_pin,
gpio_num_t wake_pin,
uint32_t baud_rate = 115200,
uint8_t address = 0 )
inlinenoexcept

Construct ESP32 UART communication interface.

Parameters
uart_numUART port number (e.g., UART_NUM_1)
tx_pinTX GPIO pin
rx_pinRX GPIO pin
rst_pinRST control pin
drv_en_pinDRV_EN control pin
faultn_pinFAULTN status pin
wake_pinWAKE control pin
baud_rateUART baud rate
addressTMC9660 module address

◆ ~Esp32Tmc9660UartBus()

Esp32Tmc9660UartBus::~Esp32Tmc9660UartBus ( )
inlinenoexcept

Destructor - cleans up UART resources.

Here is the call graph for this function:

Member Function Documentation

◆ configureGpioPins()

bool Esp32Tmc9660UartBus::configureGpioPins ( )
inlineprivatenoexcept

Configure GPIO pins for TMC9660 control and status.

Returns
true if successful, false otherwise
Here is the caller graph for this function:

◆ debugLog()

void Esp32Tmc9660UartBus::debugLog ( int level,
const char * tag,
const char * format,
va_list args )
inlinenoexcept

Debug logging function that routes logs through ESP-IDF logging system.

Parameters
levelLog level (0=Error, 1=Warning, 2=Info, 3=Debug, 4=Verbose)
tagLog tag for categorization
formatprintf-style format string
...Variable arguments for format string

◆ deinitialize()

bool Esp32Tmc9660UartBus::deinitialize ( )
inlinenoexcept

Deinitialize the UART interface.

Returns
true if successful, false otherwise
Here is the caller graph for this function:

◆ delayMs()

void Esp32Tmc9660UartBus::delayMs ( uint32_t ms)
inlinenoexcept

◆ delayUs()

void Esp32Tmc9660UartBus::delayUs ( uint32_t us)
inlinenoexcept

◆ getGpioPin()

gpio_num_t Esp32Tmc9660UartBus::getGpioPin ( TMC9660CtrlPin pin) const
inlineprivatenoexcept

Map TMC9660 control pins to ESP32 GPIO pins.

Parameters
pinTMC9660 control pin
Returns
Corresponding ESP32 GPIO pin number
Here is the caller graph for this function:

◆ gpioRead()

bool Esp32Tmc9660UartBus::gpioRead ( TMC9660CtrlPin pin,
GpioSignal & signal )
inlinenoexcept

Read GPIO pin level for TMC9660 status pins.

Parameters
pinThe TMC9660 control pin to read
levelReference to store the current GPIO level
Returns
true if the GPIO was read successfully
Here is the call graph for this function:

◆ gpioSet()

bool Esp32Tmc9660UartBus::gpioSet ( TMC9660CtrlPin pin,
GpioSignal signal )
inlinenoexcept

Set GPIO pin signal state for TMC9660 control pins.

Parameters
pinThe TMC9660 control pin to control
signalThe desired signal state
Returns
true if the GPIO was set successfully
Here is the call graph for this function:

◆ initialize()

bool Esp32Tmc9660UartBus::initialize ( )
inlinenoexcept

Initialize the UART interface.

Returns
true if successful, false otherwise
Here is the call graph for this function:

◆ mode()

CommMode Esp32Tmc9660UartBus::mode ( ) const
inlinenoexcept

Get communication mode.

Returns
CommMode::UART

◆ transferTMCL()

bool Esp32Tmc9660UartBus::transferTMCL ( const TMCLFrame & tx,
TMCLReply & reply,
uint8_t address,
TMCLReply * firstReply,
const TMCLFrame * secondCommand )
inlinenoexcept

Transfer TMCL frame over UART for parameter mode communication.

Parameters
txTMCL command frame to transmit
replyTMCL reply frame to receive
addressTMC9660 module address
firstReplyOptional pointer to capture first reply (ignored for UART)
secondCommandOptional second command (ignored for UART)
Returns
true if transfer succeeded
Here is the call graph for this function:

◆ uartReceiveTMCL()

bool Esp32Tmc9660UartBus::uartReceiveTMCL ( std::array< uint8_t, 9 > & data)
inlinenoexcept

Receive raw 9-byte UART TMCL datagram for parameter mode communication.

Parameters
dataArray to store 9 received bytes (TMCL format)
Returns
true if reception succeeded

◆ uartSendTMCL()

bool Esp32Tmc9660UartBus::uartSendTMCL ( const std::array< uint8_t, 9 > & data)
inlinenoexcept

Send raw 9-byte UART TMCL datagram for parameter mode communication.

Parameters
dataArray of 9 bytes including sync, fields, and checksum (TMCL format)
Returns
true if transmission succeeded

◆ uartTransferBootloader()

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

Transfer 8-byte UART bootloader datagram (send and receive)

Parameters
txBuffer containing 8 bytes to transmit (bootloader format)
rxBuffer to receive 8 bytes from device (bootloader format)
Returns
true if transfer succeeded

Member Data Documentation

◆ address_

uint8_t Esp32Tmc9660UartBus::address_
private

◆ baud_rate_

uint32_t Esp32Tmc9660UartBus::baud_rate_
private

◆ drv_en_pin_

gpio_num_t Esp32Tmc9660UartBus::drv_en_pin_
private

◆ faultn_pin_

gpio_num_t Esp32Tmc9660UartBus::faultn_pin_
private

◆ initialized_

bool Esp32Tmc9660UartBus::initialized_
private

◆ rst_pin_

gpio_num_t Esp32Tmc9660UartBus::rst_pin_
private

◆ rx_pin_

gpio_num_t Esp32Tmc9660UartBus::rx_pin_
private

◆ tx_pin_

gpio_num_t Esp32Tmc9660UartBus::tx_pin_
private

◆ uart_num_

uart_port_t Esp32Tmc9660UartBus::uart_num_
private

◆ wake_pin_

gpio_num_t Esp32Tmc9660UartBus::wake_pin_
private

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