HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
StmSpi.h File Reference

STM32 SPI Bus+Device wrapper — wraps STM32 HAL SPI via CubeMX handle. More...

#include "BaseSpi.h"
#include "StmTypes.h"
#include <vector>
#include <memory>
Include dependency graph for StmSpi.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  StmSpiDevice
 STM32 SPI device — manages chip-select and delegates transfers to parent bus. More...
 
class  StmSpiBus
 STM32 SPI bus — manages the HAL handle and device collection. More...
 

Detailed Description

STM32 SPI Bus+Device wrapper — wraps STM32 HAL SPI via CubeMX handle.

Bus/Device architecture:

  • StmSpiBus: wraps one SPI_HandleTypeDef*, manages device collection
  • StmSpiDevice: inherits BaseSpi, manages CS pin, delegates SPI I/O to bus

Usage

extern SPI_HandleTypeDef hspi1;
hf_spi_bus_config_t bus_cfg(&hspi1);
StmSpiBus spiBus(bus_cfg);
spiBus.Initialize();
dev_cfg.cs_port = GPIOA;
dev_cfg.cs_pin = GPIO_PIN_4;
int idx = spiBus.CreateDevice(dev_cfg);
BaseSpi* sensor = spiBus.GetDevice(idx);
sensor->Initialize();
uint8_t tx = 0x80, rx = 0;
sensor->Transfer(&tx, &rx, 1);
Abstract base class for SPI device implementations.
Definition BaseSpi.h:184
virtual bool Initialize() noexcept=0
Initialize 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.
STM32 SPI bus — manages the HAL handle and device collection.
Definition StmSpi.h:86
Platform-agnostic SPI bus configuration for STM32.
Definition EspTypes_SPI.h:150
SPI device configuration for STM32.
Definition EspTypes_SPI.h:210
GPIO_TypeDef * cs_port
CS GPIO port (e.g., GPIOA)
Definition StmTypes.h:308
hf_pin_num_t cs_pin
CS pin (or -1 for software CS)
Definition EspTypes_SPI.h:213
Author
HardFOC
Date
2025