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

ESP32 SPI implementation of TMC9660CommInterface. More...

#include <esp32_tmc9660_bus.hpp>

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

Public Member Functions

 Esp32Tmc9660SpiBus (spi_host_device_t host, gpio_num_t mosi_pin, gpio_num_t miso_pin, gpio_num_t sclk_pin, gpio_num_t cs_pin, gpio_num_t rst_pin, gpio_num_t drv_en_pin, gpio_num_t faultn_pin, gpio_num_t wake_pin, uint32_t clock_speed_hz=10000000, uint8_t mode=0) noexcept
 Construct ESP32 SPI communication interface.
 
 ~Esp32Tmc9660SpiBus () noexcept
 Destructor - cleans up SPI resources.
 
bool initialize () noexcept
 Initialize the SPI interface.
 
bool deinitialize () noexcept
 Deinitialize the SPI interface.
 
bool spiTransferTMCL (std::array< uint8_t, 8 > &tx, std::array< uint8_t, 8 > &rx) noexcept
 Perform SPI transfer for TMC9660 TMCL parameter mode communication.
 
bool spiTransferBootloader (std::array< uint8_t, 5 > &tx, std::array< uint8_t, 5 > &rx) noexcept
 
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::SpiCommInterface< Esp32Tmc9660SpiBus >
 SpiCommInterface (bool rst_active_level, bool drv_en_active_level, bool wake_active_level, bool faultn_active_level) noexcept
 Construct SPI communication interface with pin active level configuration.
 
CommMode mode () const noexcept
 Get communication mode (always SPI for this interface)
 
bool spiTransferTMCL (std::array< uint8_t, 8 > &tx, std::array< uint8_t, 8 > &rx) noexcept
 Low-level SPI transfer for TMCL parameter mode communication.
 
bool spiTransferBootloader (std::array< uint8_t, 5 > &tx, std::array< uint8_t, 5 > &rx) noexcept
 Low-level SPI transfer for bootloader communication.
 
bool gpioSet (TMC9660CtrlPin pin, GpioSignal signal) noexcept
 Set GPIO pin signal state for SPI interface.
 
bool gpioRead (TMC9660CtrlPin pin, GpioSignal &signal) noexcept
 Read GPIO pin signal state for SPI interface.
 
bool transferTMCL (const TMCLFrame &tx, TMCLReply &reply, uint8_t, 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

spi_host_device_t host_
 
gpio_num_t mosi_pin_
 
gpio_num_t miso_pin_
 
gpio_num_t sclk_pin_
 
gpio_num_t cs_pin_
 
gpio_num_t rst_pin_
 
gpio_num_t drv_en_pin_
 
gpio_num_t faultn_pin_
 
gpio_num_t wake_pin_
 
uint32_t clock_speed_hz_
 
uint8_t mode_
 
spi_device_handle_t device_handle_
 
bool initialized_
 

Additional Inherited Members

- Protected Member Functions inherited from tmc9660::SpiCommInterface< Esp32Tmc9660SpiBus >
 SpiCommInterface (const SpiCommInterface &)=delete
 
 SpiCommInterface (SpiCommInterface &&)=default
 
 ~SpiCommInterface ()=default
 Protected destructor.
 
SpiCommInterfaceoperator= (const SpiCommInterface &)=delete
 
SpiCommInterfaceoperator= (SpiCommInterface &&)=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 SPI implementation of TMC9660CommInterface.

This class provides SPI communication for the TMC9660 using ESP-IDF SPI driver. It handles the 8-byte SPI transfers required by the TMC9660 parameter mode.

Constructor & Destructor Documentation

◆ Esp32Tmc9660SpiBus()

Esp32Tmc9660SpiBus::Esp32Tmc9660SpiBus ( spi_host_device_t host,
gpio_num_t mosi_pin,
gpio_num_t miso_pin,
gpio_num_t sclk_pin,
gpio_num_t cs_pin,
gpio_num_t rst_pin,
gpio_num_t drv_en_pin,
gpio_num_t faultn_pin,
gpio_num_t wake_pin,
uint32_t clock_speed_hz = 10000000,
uint8_t mode = 0 )
inlinenoexcept

Construct ESP32 SPI communication interface.

Parameters
hostSPI host device (e.g., SPI2_HOST)
mosi_pinMOSI GPIO pin
miso_pinMISO GPIO pin
sclk_pinSCLK GPIO pin
cs_pinCS GPIO pin
rst_pinRST control pin
drv_en_pinDRV_EN control pin
faultn_pinFAULTN status pin
wake_pinWAKE control pin
clock_speed_hzSPI clock speed in Hz
modeSPI mode (0-3)

◆ ~Esp32Tmc9660SpiBus()

Esp32Tmc9660SpiBus::~Esp32Tmc9660SpiBus ( )
inlinenoexcept

Destructor - cleans up SPI resources.

Here is the call graph for this function:

Member Function Documentation

◆ configureGpioPins()

bool Esp32Tmc9660SpiBus::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 Esp32Tmc9660SpiBus::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 Esp32Tmc9660SpiBus::deinitialize ( )
inlinenoexcept

Deinitialize the SPI interface.

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

◆ delayMs()

void Esp32Tmc9660SpiBus::delayMs ( uint32_t ms)
inlinenoexcept

◆ delayUs()

void Esp32Tmc9660SpiBus::delayUs ( uint32_t us)
inlinenoexcept

◆ getGpioPin()

gpio_num_t Esp32Tmc9660SpiBus::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 Esp32Tmc9660SpiBus::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 Esp32Tmc9660SpiBus::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 Esp32Tmc9660SpiBus::initialize ( )
inlinenoexcept

Initialize the SPI interface.

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

◆ mode()

CommMode Esp32Tmc9660SpiBus::mode ( ) const
inlinenoexcept

Get communication mode.

Returns
CommMode::SPI

◆ spiTransferBootloader()

bool Esp32Tmc9660SpiBus::spiTransferBootloader ( std::array< uint8_t, 5 > & tx,
std::array< uint8_t, 5 > & rx )
inlinenoexcept

◆ spiTransferTMCL()

bool Esp32Tmc9660SpiBus::spiTransferTMCL ( std::array< uint8_t, 8 > & tx,
std::array< uint8_t, 8 > & rx )
inlinenoexcept

Perform SPI transfer for TMC9660 TMCL parameter mode communication.

Parameters
txTransmit buffer (8 bytes, TMCL format)
rxReceive buffer (8 bytes, TMCL format)
Returns
true if successful, false otherwise

Member Data Documentation

◆ clock_speed_hz_

uint32_t Esp32Tmc9660SpiBus::clock_speed_hz_
private

◆ cs_pin_

gpio_num_t Esp32Tmc9660SpiBus::cs_pin_
private

◆ device_handle_

spi_device_handle_t Esp32Tmc9660SpiBus::device_handle_
private

◆ drv_en_pin_

gpio_num_t Esp32Tmc9660SpiBus::drv_en_pin_
private

◆ faultn_pin_

gpio_num_t Esp32Tmc9660SpiBus::faultn_pin_
private

◆ host_

spi_host_device_t Esp32Tmc9660SpiBus::host_
private

◆ initialized_

bool Esp32Tmc9660SpiBus::initialized_
private

◆ miso_pin_

gpio_num_t Esp32Tmc9660SpiBus::miso_pin_
private

◆ mode_

uint8_t Esp32Tmc9660SpiBus::mode_
private

◆ mosi_pin_

gpio_num_t Esp32Tmc9660SpiBus::mosi_pin_
private

◆ rst_pin_

gpio_num_t Esp32Tmc9660SpiBus::rst_pin_
private

◆ sclk_pin_

gpio_num_t Esp32Tmc9660SpiBus::sclk_pin_
private

◆ wake_pin_

gpio_num_t Esp32Tmc9660SpiBus::wake_pin_
private

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