HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
Loading...
Searching...
No Matches
HalI2cPcal95555Comm Class Reference

Concrete I2C communication adapter for PCAL95555 using BaseI2c. More...

#include <Pcal95555Handler.h>

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

Public Member Functions

 HalI2cPcal95555Comm (BaseI2c &i2c_device) noexcept
 Construct the I2C communication adapter.
 
const std::function< void()> & GetInterruptHandler () const noexcept
 Get the stored interrupt handler (if any).
 
CRTP-Required Methods

Called by pcal95555::I2cInterface<HalI2cPcal95555Comm> via static dispatch.

bool Write (uint8_t addr, uint8_t reg, const uint8_t *data, size_t len) noexcept
 Write data to a device register.
 
bool Read (uint8_t addr, uint8_t reg, uint8_t *data, size_t len) noexcept
 Read data from a device register.
 
bool EnsureInitialized () noexcept
 Ensure the I2C bus is initialized and ready.
 
bool RegisterInterruptHandler (std::function< void()> handler) noexcept
 Register an interrupt handler to be called when the INT pin fires.
 

Private Attributes

BaseI2c & i2c_device_
 I2C device interface (not owned).
 
RtosMutex i2c_mutex_
 Thread safety for I2C operations.
 
std::function< void()> interrupt_handler_
 Stored interrupt handler from driver.
 

Detailed Description

Concrete I2C communication adapter for PCAL95555 using BaseI2c.

Implements all methods required by pcal95555::I2cInterface<HalI2cPcal95555Comm> through the CRTP pattern. This class bridges the HardFOC BaseI2c device interface (where the I2C address is pre-configured on the device) with the PCAL95555 driver's I2C interface (which passes the address as a parameter).

Key behaviors:

  • Address validation: Every write/read validates that the driver's address matches the BaseI2c device's configured address, preventing cross-device errors.
  • Register framing: Writes are framed as [register, data...] per I2C convention.
  • Thread safety: All I2C operations are mutex-protected.
  • Lazy initialization: EnsureInitialized() delegates to BaseI2c.
Note
This class does NOT own the BaseI2c device; it must remain valid for the lifetime of this adapter.
See also
pcal95555::I2cInterface CRTP base class from the PCAL95555 driver

Constructor & Destructor Documentation

◆ HalI2cPcal95555Comm()

HalI2cPcal95555Comm::HalI2cPcal95555Comm ( BaseI2c & i2c_device)
explicitnoexcept

Construct the I2C communication adapter.

Construct the CRTP I2C adapter.

Parameters
i2c_deviceReference to a BaseI2c device with pre-configured address.
Warning
The BaseI2c device must outlive this adapter.

Member Function Documentation

◆ EnsureInitialized()

bool HalI2cPcal95555Comm::EnsureInitialized ( )
noexcept

Ensure the I2C bus is initialized and ready.

Returns
true if the BaseI2c device is initialized or was initialized successfully.

◆ GetInterruptHandler()

const std::function< void()> & HalI2cPcal95555Comm::GetInterruptHandler ( ) const
inlinenoexcept

Get the stored interrupt handler (if any).

Returns
Reference to the stored interrupt handler function.

◆ Read()

bool HalI2cPcal95555Comm::Read ( uint8_t addr,
uint8_t reg,
uint8_t * data,
size_t len )
noexcept

Read data from a device register.

Sends the register address via BaseI2c::WriteRead() and reads back data.

Parameters
addr7-bit I2C address (validated against BaseI2c device).
regRegister address to read from.
dataBuffer to store read data.
lenNumber of bytes to read.
Returns
true if read succeeded, false on address mismatch or I2C error.

◆ RegisterInterruptHandler()

bool HalI2cPcal95555Comm::RegisterInterruptHandler ( std::function< void()> handler)
noexcept

Register an interrupt handler to be called when the INT pin fires.

The PCAL95555 driver calls this to register its HandleInterrupt() method. The handler stores the function and can be triggered externally.

Parameters
handlerFunction to call when interrupt occurs.
Returns
true if handler was stored (always returns true; actual GPIO setup is done by Pcal95555Handler::ConfigureHardwareInterrupt).

◆ Write()

bool HalI2cPcal95555Comm::Write ( uint8_t addr,
uint8_t reg,
const uint8_t * data,
size_t len )
noexcept

Write data to a device register.

Frames the write as [register_address, data...] and sends via BaseI2c::Write(). The addr parameter is validated against the device's configured address.

Parameters
addr7-bit I2C address (validated against BaseI2c device).
regRegister address to write to.
dataPointer to data buffer.
lenNumber of bytes to write.
Returns
true if write succeeded, false on address mismatch or I2C error.

Member Data Documentation

◆ i2c_device_

BaseI2c& HalI2cPcal95555Comm::i2c_device_
private

I2C device interface (not owned).

◆ i2c_mutex_

RtosMutex HalI2cPcal95555Comm::i2c_mutex_
mutableprivate

Thread safety for I2C operations.

◆ interrupt_handler_

std::function<void()> HalI2cPcal95555Comm::interrupt_handler_
private

Stored interrupt handler from driver.


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