Internal Interface Wrap
API reference
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | Friends | List of all members
StmI2cBus Class Reference

STM32 I2C bus — manages the HAL handle and device collection. More...

#include <StmI2c.h>

Collaboration diagram for StmI2cBus:
[legend]

Public Member Functions

 StmI2cBus (const hf_i2c_bus_config_t &config) noexcept
 
 StmI2cBus (I2C_HandleTypeDef *hal_handle, hf_u32_t timeout_ms=1000) noexcept
 Convenience: construct directly from HAL handle.
 
 ~StmI2cBus () noexcept
 
bool Initialize () noexcept
 
bool IsInitialized () const noexcept
 
bool Deinitialize () noexcept
 
int CreateDevice (const hf_i2c_device_config_t &device_config) noexcept
 Create a device on this bus and return its index.
 
BaseI2c * GetDevice (int device_index) noexcept
 Get device by index (returns nullptr if invalid)
 
const BaseI2c * GetDevice (int device_index) const noexcept
 
std::size_t GetDeviceCount () const noexcept
 Get number of devices on this bus.
 
bool RemoveDevice (int device_index) noexcept
 Remove a device by index.
 
const hf_i2c_bus_config_t & GetConfig () const noexcept
 Get the bus configuration.
 
I2C_HandleTypeDef * GetHalHandle () const noexcept
 Get the STM32 HAL I2C handle.
 
bool LockBus (hf_u32_t timeout_ms) noexcept
 Exclusive bus lock for HAL transfer / probe (StmSpi parity).
 
void UnlockBus () noexcept
 

Private Attributes

hf_i2c_bus_config_t config_
 
bool initialized_ {false}
 
PlatformMutex bus_mutex_ {}
 
std::vector< std::unique_ptr< StmI2cDevice > > devices_
 

Friends

class StmI2cDevice
 

Detailed Description

STM32 I2C bus — manages the HAL handle and device collection.

One bus instance per I2C peripheral (I2C1, I2C2, etc.). Devices are created via CreateDevice() and accessed via GetDevice().

Transfers are serialized with PlatformMutex (same contract as StmSpi). Direct HAL probes (IsDeviceReady) must take LockBus or risk racing Mem_Read/Master_Transmit on the same handle.

Note
STM32H7 soft-I2C bring-up contract (parity with StmSpi):
  • Do not call HAL_I2C_IsDeviceReady from Initialize — on STM32H7 it can latch ISR.TXIS while State==READY and poison the next Mem_Read (command byte flushed into TXDR, never on the wire).
  • Prefer Master_Transmit + Master_Receive (or WriteRead) over Mem_Read when the slave pointer auto-increments (PCA/PCAL).
  • When caller buffers may sit in external FMC SDRAM, stage small RX/TX through D1 AXI scratch before HAL calls (byte loads from that memory class are unreliable on some FMC setups).
  • Flush sticky TXIS/TXE before a new transfer (FlushTxdr).

Constructor & Destructor Documentation

◆ StmI2cBus() [1/2]

StmI2cBus::StmI2cBus ( const hf_i2c_bus_config_t &  config)
explicitnoexcept

◆ StmI2cBus() [2/2]

StmI2cBus::StmI2cBus ( I2C_HandleTypeDef *  hal_handle,
hf_u32_t  timeout_ms = 1000 
)
explicitnoexcept

Convenience: construct directly from HAL handle.

◆ ~StmI2cBus()

StmI2cBus::~StmI2cBus ( )
noexcept

Member Function Documentation

◆ CreateDevice()

int StmI2cBus::CreateDevice ( const hf_i2c_device_config_t &  device_config)
noexcept

Create a device on this bus and return its index.

◆ Deinitialize()

bool StmI2cBus::Deinitialize ( )
noexcept

◆ GetConfig()

const hf_i2c_bus_config_t & StmI2cBus::GetConfig ( ) const
noexcept

Get the bus configuration.

◆ GetDevice() [1/2]

const BaseI2c * StmI2cBus::GetDevice ( int  device_index) const
noexcept

◆ GetDevice() [2/2]

BaseI2c * StmI2cBus::GetDevice ( int  device_index)
noexcept

Get device by index (returns nullptr if invalid)

◆ GetDeviceCount()

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

Get number of devices on this bus.

◆ GetHalHandle()

I2C_HandleTypeDef * StmI2cBus::GetHalHandle ( ) const
noexcept

Get the STM32 HAL I2C handle.

◆ Initialize()

bool StmI2cBus::Initialize ( )
noexcept

◆ IsInitialized()

bool StmI2cBus::IsInitialized ( ) const
noexcept

◆ LockBus()

bool StmI2cBus::LockBus ( hf_u32_t  timeout_ms)
noexcept

Exclusive bus lock for HAL transfer / probe (StmSpi parity).

Returns
false on timeout / lock failure.

◆ RemoveDevice()

bool StmI2cBus::RemoveDevice ( int  device_index)
noexcept

Remove a device by index.

◆ UnlockBus()

void StmI2cBus::UnlockBus ( )
noexcept

Friends And Related Symbol Documentation

◆ StmI2cDevice

Member Data Documentation

◆ bus_mutex_

PlatformMutex StmI2cBus::bus_mutex_ {}
mutableprivate

◆ config_

hf_i2c_bus_config_t StmI2cBus::config_
private

◆ devices_

std::vector<std::unique_ptr<StmI2cDevice> > StmI2cBus::devices_
private

◆ initialized_

bool StmI2cBus::initialized_ {false}
private

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