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

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

#include <Pca9685Handler.h>

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

Public Member Functions

 HalI2cPca9685Comm (BaseI2c &i2c_device) noexcept
 Construct the I2C communication adapter.
 
CRTP-Required Methods

Called by pca9685::I2cInterface<HalI2cPca9685Comm> 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.
 

Private Attributes

BaseI2c & i2c_device_
 I2C device interface (not owned).
 
RtosMutex i2c_mutex_
 Thread safety for I2C operations.
 

Detailed Description

Concrete I2C communication adapter for PCA9685 using BaseI2c.

Implements all methods required by pca9685::I2cInterface<HalI2cPca9685Comm> through the CRTP pattern. This class bridges the HardFOC BaseI2c device interface (where the I2C address is pre-configured on the device) with the PCA9685 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.
  • 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
pca9685::I2cInterface CRTP base class from the PCA9685 driver

Constructor & Destructor Documentation

◆ HalI2cPca9685Comm()

HalI2cPca9685Comm::HalI2cPca9685Comm ( BaseI2c & i2c_device)
explicitnoexcept

Construct the I2C communication 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 HalI2cPca9685Comm::EnsureInitialized ( )
noexcept

Ensure the I2C bus is initialized and ready.

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

◆ Read()

bool HalI2cPca9685Comm::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.

◆ Write()

bool HalI2cPca9685Comm::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().

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& HalI2cPca9685Comm::i2c_device_
private

I2C device interface (not owned).

◆ i2c_mutex_

RtosMutex HalI2cPca9685Comm::i2c_mutex_
mutableprivate

Thread safety for I2C operations.


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