HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
EspSpiBus Class Reference

Manages a single SPI bus (host). Handles bus init/deinit and device creation. More...

#include <EspSpi.h>

Collaboration diagram for EspSpiBus:
[legend]

Public Member Functions

 EspSpiBus (const hf_spi_bus_config_t &config) noexcept
 Construct a new EspSpiBus.
 
 ~EspSpiBus () noexcept
 Destructor. Automatically deinitializes the bus if needed.
 
bool Initialize () noexcept
 Initialize the SPI bus.
 
bool IsInitialized () const noexcept
 Check if the bus is initialized.
 
bool Deinitialize () noexcept
 Deinitialize the SPI bus and free resources.
 
int CreateDevice (const hf_spi_device_config_t &device_config) noexcept
 Create a new SPI device on this bus and store it internally.
 
BaseSpiGetDevice (int device_index) noexcept
 Get a device by index.
 
const BaseSpiGetDevice (int device_index) const noexcept
 Get a device by index (const version).
 
EspSpiDeviceGetEspDevice (int device_index) noexcept
 Get an ESP-specific device by index.
 
const EspSpiDeviceGetEspDevice (int device_index) const noexcept
 Get an ESP-specific device by index (const version).
 
std::size_t GetDeviceCount () const noexcept
 Get number of devices on this bus.
 
bool RemoveDevice (int device_index) noexcept
 Remove a device from the bus.
 
const hf_spi_bus_config_tGetConfig () const noexcept
 Get the bus configuration.
 
spi_host_device_t GetHost () const noexcept
 Get the ESP-IDF host ID for this bus.
 

Private Attributes

hf_spi_bus_config_t config_
 Bus configuration.
 
bool initialized_
 Initialization state.
 
PlatformMutex mutex_
 Thread safety (mutable for const operations)
 
std::vector< std::unique_ptr< EspSpiDevice > > devices_
 Managed devices on this bus.
 

Detailed Description

Manages a single SPI bus (host). Handles bus init/deinit and device creation.

Provides full configuration and control for the SPI bus, including DMA, IOMUX, and advanced ESP-IDF v5.5+ features. Thread-safe device management.

Constructor & Destructor Documentation

◆ EspSpiBus()

EspSpiBus::EspSpiBus ( const hf_spi_bus_config_t & config)
explicitnoexcept

Construct a new EspSpiBus.

Parameters
configBus configuration (hf_spi_bus_config_t)

◆ ~EspSpiBus()

EspSpiBus::~EspSpiBus ( )
noexcept

Destructor. Automatically deinitializes the bus if needed.

Member Function Documentation

◆ CreateDevice()

int EspSpiBus::CreateDevice ( const hf_spi_device_config_t & device_config)
noexcept

Create a new SPI device on this bus and store it internally.

Parameters
device_configDevice configuration (hf_spi_device_config_t)
Returns
Index of the created device (use with GetDevice), or -1 on failure

◆ Deinitialize()

bool EspSpiBus::Deinitialize ( )
noexcept

Deinitialize the SPI bus and free resources.

Returns
true if successful, false otherwise

◆ GetConfig()

const hf_spi_bus_config_t & EspSpiBus::GetConfig ( ) const
noexcept

Get the bus configuration.

Returns
const hf_spi_bus_config_t&

◆ GetDevice() [1/2]

const BaseSpi * EspSpiBus::GetDevice ( int device_index) const
noexcept

Get a device by index (const version).

Parameters
device_indexIndex returned by CreateDevice()
Returns
Const pointer to BaseSpi device, or nullptr if invalid index

◆ GetDevice() [2/2]

BaseSpi * EspSpiBus::GetDevice ( int device_index)
noexcept

Get a device by index.

Parameters
device_indexIndex returned by CreateDevice()
Returns
Pointer to BaseSpi device, or nullptr if invalid index

◆ GetDeviceCount()

std::size_t EspSpiBus::GetDeviceCount ( ) const
noexcept

Get number of devices on this bus.

Returns
Number of devices

◆ GetEspDevice() [1/2]

const EspSpiDevice * EspSpiBus::GetEspDevice ( int device_index) const
noexcept

Get an ESP-specific device by index (const version).

Parameters
device_indexIndex returned by CreateDevice()
Returns
Const pointer to EspSpiDevice, or nullptr if invalid index

◆ GetEspDevice() [2/2]

EspSpiDevice * EspSpiBus::GetEspDevice ( int device_index)
noexcept

Get an ESP-specific device by index.

Parameters
device_indexIndex returned by CreateDevice()
Returns
Pointer to EspSpiDevice, or nullptr if invalid index

◆ GetHost()

spi_host_device_t EspSpiBus::GetHost ( ) const
noexcept

Get the ESP-IDF host ID for this bus.

Returns
spi_host_device_t

◆ Initialize()

bool EspSpiBus::Initialize ( )
noexcept

Initialize the SPI bus.

Returns
true if successful, false otherwise

◆ IsInitialized()

bool EspSpiBus::IsInitialized ( ) const
noexcept

Check if the bus is initialized.

Returns
true if initialized, false otherwise

◆ RemoveDevice()

bool EspSpiBus::RemoveDevice ( int device_index)
noexcept

Remove a device from the bus.

Parameters
device_indexIndex of device to remove
Returns
true if successful, false otherwise

Member Data Documentation

◆ config_

hf_spi_bus_config_t EspSpiBus::config_
private

Bus configuration.

◆ devices_

std::vector<std::unique_ptr<EspSpiDevice> > EspSpiBus::devices_
private

Managed devices on this bus.

◆ initialized_

bool EspSpiBus::initialized_
private

Initialization state.

◆ mutex_

PlatformMutex EspSpiBus::mutex_
mutableprivate

Thread safety (mutable for const operations)


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