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

STM32 I2C device — inherits BaseI2c, delegates I/O to parent bus HAL handle. More...

#include <StmI2c.h>

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

Public Member Functions

 StmI2cDevice (StmI2cBus *parent, const hf_i2c_device_config_t &config) noexcept
 
 ~StmI2cDevice () noexcept override
 
bool Initialize () noexcept override
 Initialize the I2C bus.
 
bool Deinitialize () noexcept override
 Deinitialize the I2C bus.
 
hf_i2c_err_t Write (const hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept override
 Write data to the I2C device.
 
hf_i2c_err_t Read (hf_u8_t *data, hf_u16_t length, hf_u32_t timeout_ms=0) noexcept override
 Read data from the I2C device.
 
hf_i2c_err_t WriteRead (const hf_u8_t *tx_data, hf_u16_t tx_length, hf_u8_t *rx_data, hf_u16_t rx_length, hf_u32_t timeout_ms=0) noexcept override
 Write then read data from the I2C device.
 
hf_u16_t GetDeviceAddress () const noexcept override
 Get the device address for this I2C device.
 
const hf_i2c_device_config_tGetConfig () const noexcept
 Get the device configuration.
 
StmI2cBusGetParentBus () const noexcept
 Get the parent bus.
 
- Public Member Functions inherited from BaseI2c
virtual ~BaseI2c () noexcept=default
 Virtual destructor ensures proper cleanup in derived classes.
 
 BaseI2c (const BaseI2c &)=delete
 
BaseI2coperator= (const BaseI2c &)=delete
 
 BaseI2c (BaseI2c &&)=delete
 
BaseI2coperator= (BaseI2c &&)=delete
 
bool EnsureInitialized () noexcept
 Ensures that the I2C bus is initialized (lazy initialization).
 
bool EnsureDeinitialized () noexcept
 Ensures that the I2C bus is deinitialized (lazy deinitialization).
 
bool IsInitialized () const noexcept
 Checks if the bus is initialized.
 
virtual bool Open () noexcept
 Open the I2C bus (alias for Initialize).
 
virtual bool Close () noexcept
 Close the I2C bus (alias for Deinitialize).
 
virtual bool IsDevicePresent () noexcept
 Check if this device is present on the bus.
 
virtual bool ProbeDevice () noexcept
 Probe if this device is present on the bus (alias for IsDevicePresent).
 
virtual bool WriteByte (hf_u8_t data) noexcept
 Write a single byte to the I2C device.
 
virtual bool ReadByte (hf_u8_t &data) noexcept
 Read a single byte from the I2C device.
 
virtual bool WriteRegister (hf_u8_t reg_addr, hf_u8_t data) noexcept
 Write to a register on the I2C device.
 
virtual bool ReadRegister (hf_u8_t reg_addr, hf_u8_t &data) noexcept
 Read from a register on the I2C device.
 
virtual bool ReadRegisters (hf_u8_t reg_addr, hf_u8_t *data, hf_u16_t length) noexcept
 Read multiple registers from the I2C device.
 
virtual hf_i2c_err_t ResetStatistics () noexcept
 Reset I2C operation statistics.
 
virtual hf_i2c_err_t ResetDiagnostics () noexcept
 Reset I2C diagnostic information.
 
virtual hf_i2c_err_t GetStatistics (hf_i2c_statistics_t &statistics) const noexcept
 Get I2C operation statistics.
 
virtual hf_i2c_err_t GetDiagnostics (hf_i2c_diagnostics_t &diagnostics) const noexcept
 Get I2C diagnostic information.
 

Private Member Functions

hf_u32_t GetEffectiveTimeout (hf_u32_t requested_ms) const noexcept
 Get effective timeout (device override or bus default)
 

Static Private Member Functions

static hf_i2c_err_t ConvertHalStatus (hf_u32_t hal_status) noexcept
 Convert HAL status to I2C error.
 

Private Attributes

StmI2cBusparent_bus_
 Parent bus reference.
 
hf_i2c_device_config_t config_
 Device configuration.
 

Additional Inherited Members

- Protected Member Functions inherited from BaseI2c
 BaseI2c () noexcept
 Protected default constructor. Initializes base I2C state with default values.
 
- Protected Attributes inherited from BaseI2c
bool initialized_
 Initialization status.
 
hf_i2c_statistics_t statistics_
 I2C operation statistics.
 
hf_i2c_diagnostics_t diagnostics_
 I2C diagnostic information.
 

Detailed Description

STM32 I2C device — inherits BaseI2c, delegates I/O to parent bus HAL handle.

Each device represents one slave address on the bus. The parent bus manages the I2C_HandleTypeDef* and provides the HAL layer.

Constructor & Destructor Documentation

◆ StmI2cDevice()

StmI2cDevice::StmI2cDevice ( StmI2cBus * parent,
const hf_i2c_device_config_t & config )
noexcept

◆ ~StmI2cDevice()

StmI2cDevice::~StmI2cDevice ( )
overridenoexcept

Member Function Documentation

◆ ConvertHalStatus()

hf_i2c_err_t StmI2cDevice::ConvertHalStatus ( hf_u32_t hal_status)
staticprivatenoexcept

Convert HAL status to I2C error.

◆ Deinitialize()

bool StmI2cDevice::Deinitialize ( )
overridevirtualnoexcept

Deinitialize the I2C bus.

Returns
true if successful, false otherwise

Implements BaseI2c.

◆ GetConfig()

const hf_i2c_device_config_t & StmI2cDevice::GetConfig ( ) const
inlinenoexcept

Get the device configuration.

◆ GetDeviceAddress()

hf_u16_t StmI2cDevice::GetDeviceAddress ( ) const
overridevirtualnoexcept

Get the device address for this I2C device.

Returns
The 7-bit I2C device address

Implements BaseI2c.

◆ GetEffectiveTimeout()

hf_u32_t StmI2cDevice::GetEffectiveTimeout ( hf_u32_t requested_ms) const
privatenoexcept

Get effective timeout (device override or bus default)

◆ GetParentBus()

StmI2cBus * StmI2cDevice::GetParentBus ( ) const
inlinenoexcept

Get the parent bus.

◆ Initialize()

bool StmI2cDevice::Initialize ( )
overridevirtualnoexcept

Initialize the I2C bus.

Returns
true if successful, false otherwise

Implements BaseI2c.

◆ Read()

hf_i2c_err_t StmI2cDevice::Read ( hf_u8_t * data,
hf_u16_t length,
hf_u32_t timeout_ms = 0 )
overridevirtualnoexcept

Read data from the I2C device.

Parameters
dataPointer to buffer to store received data
lengthNumber of bytes to read
timeout_msTimeout in milliseconds (0 = use default)
Returns
hf_i2c_err_t result code
Note
Device address is configured during device creation

Implements BaseI2c.

◆ Write()

hf_i2c_err_t StmI2cDevice::Write ( const hf_u8_t * data,
hf_u16_t length,
hf_u32_t timeout_ms = 0 )
overridevirtualnoexcept

Write data to the I2C device.

Parameters
dataPointer to data buffer to write
lengthNumber of bytes to write
timeout_msTimeout in milliseconds (0 = use default)
Returns
hf_i2c_err_t result code
Note
Device address is configured during device creation

Implements BaseI2c.

◆ WriteRead()

hf_i2c_err_t StmI2cDevice::WriteRead ( const hf_u8_t * tx_data,
hf_u16_t tx_length,
hf_u8_t * rx_data,
hf_u16_t rx_length,
hf_u32_t timeout_ms = 0 )
overridevirtualnoexcept

Write then read data from the I2C device.

Parameters
tx_dataPointer to data buffer to write
tx_lengthNumber of bytes to write
rx_dataPointer to buffer to store received data
rx_lengthNumber of bytes to read
timeout_msTimeout in milliseconds (0 = use default)
Returns
hf_i2c_err_t result code
Note
Device address is configured during device creation

Implements BaseI2c.

Member Data Documentation

◆ config_

hf_i2c_device_config_t StmI2cDevice::config_
private

Device configuration.

◆ parent_bus_

StmI2cBus* StmI2cDevice::parent_bus_
private

Parent bus reference.


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