|
Internal Interface Wrap
API reference
|
Abstract base class for SPI device implementations. More...
#include <BaseSpi.h>
Public Member Functions | |
| virtual | ~BaseSpi () noexcept=default |
| Virtual destructor ensures proper cleanup in derived classes. | |
| BaseSpi (const BaseSpi &)=delete | |
| BaseSpi & | operator= (const BaseSpi &)=delete |
| BaseSpi (BaseSpi &&)=delete | |
| BaseSpi & | operator= (BaseSpi &&)=delete |
| bool | EnsureInitialized () noexcept |
| Ensures that the SPI bus is initialized (lazy initialization). | |
| bool | EnsureDeinitialized () noexcept |
| Ensures that the SPI bus is deinitialized (lazy deinitialization). | |
| bool | IsInitialized () const noexcept |
| Checks if the bus is initialized. | |
| virtual bool | Initialize () noexcept=0 |
| Initialize the SPI bus. | |
| virtual bool | Deinitialize () noexcept=0 |
| Deinitialize the SPI bus. | |
| virtual hf_spi_err_t | Transfer (const hf_u8_t *tx_data, hf_u8_t *rx_data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept=0 |
| Perform a full-duplex SPI transfer. | |
| virtual void | IdleChipSelect () noexcept |
| Force soft-CS to the idle (deasserted) level without a transfer. | |
| virtual void | HoldChipSelectMs (hf_u32_t) noexcept |
Assert soft-CS for ms milliseconds (logic-analyzer / pad proof). | |
| virtual bool | SetTransferMode (hf_u8_t) noexcept |
| Select CPOL/CPHA mode for the next soft-CS transfer (0..3). | |
| virtual bool | SetIoSwap (bool) noexcept |
| Swap MOSI↔MISO AF on the next transfer (STM32 SPI CFG2 IOSWP). | |
| virtual hf_spi_err_t | TransferChain (const hf_u8_t *const *tx_frames, hf_u8_t *const *rx_frames, hf_u16_t frame_length, hf_u16_t frame_count, hf_u32_t inter_frame_gap_us, hf_u32_t timeout_ms=0) noexcept |
Run frame_count soft-CS frames in one ownership window. | |
| virtual const void * | GetDeviceConfig () const noexcept=0 |
| Get the device configuration for this SPI device. | |
| virtual bool | Open () noexcept |
| Legacy compatibility: Open and initialize the SPI bus. | |
| virtual bool | Close () noexcept |
| Legacy compatibility: Close and de-initialize the SPI bus. | |
| virtual bool | Transfer (const hf_u8_t *tx_data, hf_u8_t *rx_data, hf_u16_t length) noexcept |
| Legacy compatibility: Transfer with boolean return. | |
| virtual hf_spi_err_t | Write (const hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept |
| Write data to SPI bus. | |
| virtual hf_spi_err_t | Read (hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept |
| Read data from SPI bus. | |
| virtual bool | Write (const hf_u8_t *data, hf_u16_t length) noexcept |
| Legacy compatibility: Write with boolean return. | |
| virtual bool | Read (hf_u8_t *data, hf_u16_t length) noexcept |
| Legacy compatibility: Read with boolean return. | |
| virtual bool | WriteByte (hf_u8_t data) noexcept |
| Write single byte to SPI bus. | |
| virtual bool | ReadByte (hf_u8_t &data) noexcept |
| Read single byte from SPI bus. | |
| virtual bool | TransferByte (hf_u8_t tx_data, hf_u8_t &rx_data) noexcept |
| Write single byte and read response. | |
| virtual hf_spi_err_t | ResetStatistics () noexcept |
| Reset SPI operation statistics. | |
| virtual hf_spi_err_t | ResetDiagnostics () noexcept |
| Reset SPI diagnostic information. | |
| virtual hf_spi_err_t | GetStatistics (hf_spi_statistics_t &statistics) const noexcept |
| Get SPI operation statistics. | |
| virtual hf_spi_err_t | GetDiagnostics (hf_spi_diagnostics_t &diagnostics) const noexcept |
| Get SPI diagnostic information. | |
Protected Member Functions | |
| BaseSpi () noexcept | |
| Protected default constructor. | |
Protected Attributes | |
| bool | initialized_ |
| Initialization state. | |
| hf_spi_statistics_t | statistics_ |
| SPI operation statistics. | |
| hf_spi_diagnostics_t | diagnostics_ |
| SPI diagnostic information. | |
Abstract base class for SPI device implementations.
This class provides a comprehensive SPI device abstraction that serves as the base for all SPI device implementations in the HardFOC system. Each instance represents a single SPI device with pre-configured settings. It supports:
Device configuration (mode, speed, CS pin) is set during device creation and managed automatically, ensuring each device operates with its correct settings without manual configuration per transaction.
Derived classes implement platform-specific details such as:
|
virtualdefaultnoexcept |
Virtual destructor ensures proper cleanup in derived classes.
|
delete |
|
inlineprotectednoexcept |
Protected default constructor.
Legacy compatibility: Close and de-initialize the SPI bus.
Deinitialize the SPI bus.
Implemented in EspSpiDevice, and StmSpiDevice.
|
inlinenoexcept |
Ensures that the SPI bus is deinitialized (lazy deinitialization).
|
inlinenoexcept |
Ensures that the SPI bus is initialized (lazy initialization).
Get the device configuration for this SPI device.
Implemented in EspSpiDevice, and StmSpiDevice.
|
inlinevirtualnoexcept |
Get SPI diagnostic information.
| diagnostics | Reference to store diagnostics data |
|
inlinevirtualnoexcept |
Get SPI operation statistics.
| statistics | Reference to store statistics data |
Assert soft-CS for ms milliseconds (logic-analyzer / pad proof).
Shared-bus implementations should take the bus lock, idle peer CS lines, hold this CS active, then release. Default: no-op.
Reimplemented in StmSpiDevice.
Force soft-CS to the idle (deasserted) level without a transfer.
Shared multi-slave buses call this on peer devices before a mode-sensitive identity burst so a stuck-low CS cannot contend on MISO. Default: no-op (hardware-NSS / single-slave backends).
Reimplemented in StmSpiDevice.
Initialize the SPI bus.
Implemented in EspSpiDevice, and StmSpiDevice.
|
inlinenoexcept |
Checks if the bus is initialized.
Legacy compatibility: Open and initialize the SPI bus.
Legacy compatibility: Read with boolean return.
| data | Buffer to store received data |
| length | Number of bytes to read |
|
inlinevirtualnoexcept |
Read data from SPI bus.
| data | Buffer to store received data |
| length | Number of bytes to read |
| timeout_ms | Timeout in milliseconds (0 = use default) |
Read single byte from SPI bus.
| data | Output: byte read |
|
inlinevirtualnoexcept |
Reset SPI diagnostic information.
|
inlinevirtualnoexcept |
Reset SPI operation statistics.
Swap MOSI↔MISO AF on the next transfer (STM32 SPI CFG2 IOSWP).
Useful when SDI/SDO leads may be crossed on long wiring. Default: unsupported. Callers must restore false after a failed identity sweep so Mode0 peers keep the normal pin map.
Reimplemented in StmSpiDevice.
Select CPOL/CPHA mode for the next soft-CS transfer (0..3).
Shared multi-slave buses apply this on the next Transfer via SPE rewrite. Default: unsupported.
Reimplemented in StmSpiDevice.
|
inlinevirtualnoexcept |
Legacy compatibility: Transfer with boolean return.
| tx_data | Transmit data buffer |
| rx_data | Receive data buffer |
| length | Number of bytes to transfer |
|
pure virtualnoexcept |
Perform a full-duplex SPI transfer.
| tx_data | Transmit data buffer (can be nullptr for read-only) |
| rx_data | Receive data buffer (can be nullptr for write-only) |
| length | Number of bytes to transfer |
| timeout_ms | Timeout in milliseconds (0 = use default) |
Implemented in EspSpiDevice, and StmSpiDevice.
Write single byte and read response.
| tx_data | Byte to write |
| rx_data | Output: byte read |
|
inlinevirtualnoexcept |
Run frame_count soft-CS frames in one ownership window.
Each frame asserts CS, transfers frame_length bytes, then deasserts CS. Optional inter_frame_gap_us is applied between frames (after CS release).
Default implementation calls Transfer sequentially (each call may take/release the bus lock). Shared multi-slave buses should override so a pipelined protocol (e.g. TLE92466ED command + dummy read) cannot be interleaved with another device's mode/CS cycle.
Reimplemented in StmSpiDevice.
Legacy compatibility: Write with boolean return.
| data | Data buffer to transmit |
| length | Number of bytes to write |
|
inlinevirtualnoexcept |
Write data to SPI bus.
| data | Data buffer to transmit |
| length | Number of bytes to write |
| timeout_ms | Timeout in milliseconds (0 = use default) |
Write single byte to SPI bus.
| data | Byte to write |
|
protected |
SPI diagnostic information.
|
protected |
Initialization state.
|
protected |
SPI operation statistics.