PCA9555 / PCAL9555A Driver
API reference
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
pcal95555::I2cInterface< Derived > Class Template Reference

CRTP-based template interface for I2C bus operations. More...

#include <pcal95555_i2c_interface.hpp>

Public Member Functions

bool Write (uint8_t addr, uint8_t reg, const uint8_t *data, size_t len) noexcept
 Write bytes to a device register.
 
bool Read (uint8_t addr, uint8_t reg, uint8_t *data, size_t len) noexcept
 Read bytes from a device register.
 
bool SetAddressPins (bool a0_level, bool a1_level, bool a2_level) noexcept
 
bool EnsureInitialized () noexcept
 
bool RegisterInterruptHandler (std::function< void()> handler) noexcept
 
GPIO Pin Control

Unified interface for controlling PCAL95555 hardware control pins.

void GpioSet (CtrlPin pin, GpioSignal signal) noexcept
 Set a control pin to the specified signal state.
 
bool GpioRead (CtrlPin pin, GpioSignal &signal) noexcept
 Read the current state of a control pin.
 
void GpioSetActive (CtrlPin pin) noexcept
 Assert a control pin (set to ACTIVE).
 
void GpioSetInactive (CtrlPin pin) noexcept
 Deassert a control pin (set to INACTIVE).
 

Protected Member Functions

 I2cInterface ()=default
 Protected constructor to prevent direct instantiation.
 
 I2cInterface (const I2cInterface &)=delete
 
I2cInterface & operator= (const I2cInterface &)=delete
 
 I2cInterface (I2cInterface &&)=default
 
I2cInterface & operator= (I2cInterface &&)=default
 
 ~I2cInterface ()=default
 Protected destructor.
 

Detailed Description

template<typename Derived>
class pcal95555::I2cInterface< Derived >

CRTP-based template interface for I2C bus operations.

This template class provides a hardware-agnostic interface for I2C communication using the CRTP pattern. Platform-specific implementations should inherit from this template with themselves as the template parameter.

Benefits of CRTP:

Example usage:

class MyI2C : public pcal95555::I2cInterface<MyI2C> {
public:
bool Write(...) { ... }
bool Read(...) { ... }
};
CRTP-based template interface for I2C bus operations.
Definition pcal95555_i2c_interface.hpp:72
Template Parameters
DerivedThe derived class type (CRTP pattern)

Constructor & Destructor Documentation

◆ I2cInterface() [1/3]

template<typename Derived >
pcal95555::I2cInterface< Derived >::I2cInterface ( )
protecteddefault

Protected constructor to prevent direct instantiation.

Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555_i2c_interface.hpp.

◆ I2cInterface() [2/3]

template<typename Derived >
pcal95555::I2cInterface< Derived >::I2cInterface ( const I2cInterface< Derived > &  )
protecteddelete

◆ I2cInterface() [3/3]

template<typename Derived >
pcal95555::I2cInterface< Derived >::I2cInterface ( I2cInterface< Derived > &&  )
protecteddefault

◆ ~I2cInterface()

template<typename Derived >
pcal95555::I2cInterface< Derived >::~I2cInterface ( )
protecteddefault

Protected destructor.

Note
Derived classes can have public destructors
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555_i2c_interface.hpp.

Member Function Documentation

◆ EnsureInitialized()

template<typename Derived >
bool pcal95555::I2cInterface< Derived >::EnsureInitialized ( )
inlinenoexcept

◆ GpioRead()

template<typename Derived >
bool pcal95555::I2cInterface< Derived >::GpioRead ( CtrlPin  pin,
GpioSignal &  signal 
)
inlinenoexcept

Read the current state of a control pin.

Primarily used for reading the INTN interrupt pin.

Parameters
[in]pinWhich control pin to read.
[out]signalReceives the current signal state.
Returns
true if the read was successful, false otherwise.
Note
Default implementation returns false (unsupported). Override in derived class if interrupt pin monitoring is needed.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555_i2c_interface.hpp.

◆ GpioSet()

template<typename Derived >
void pcal95555::I2cInterface< Derived >::GpioSet ( CtrlPin  pin,
GpioSignal  signal 
)
inlinenoexcept

Set a control pin to the specified signal state.

Parameters
[in]pinWhich control pin to drive. The chips have no output-side control pin, so the driver never calls this.
[in]signalACTIVE to assert the pin function, INACTIVE to deassert.
Note
Default implementation is a no-op.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555_i2c_interface.hpp.

◆ GpioSetActive()

template<typename Derived >
void pcal95555::I2cInterface< Derived >::GpioSetActive ( CtrlPin  pin)
inlinenoexcept

Assert a control pin (set to ACTIVE).

Parameters
[in]pinWhich control pin to assert.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555_i2c_interface.hpp.

◆ GpioSetInactive()

template<typename Derived >
void pcal95555::I2cInterface< Derived >::GpioSetInactive ( CtrlPin  pin)
inlinenoexcept

Deassert a control pin (set to INACTIVE).

Parameters
[in]pinWhich control pin to deassert.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555_i2c_interface.hpp.

◆ operator=() [1/2]

template<typename Derived >
I2cInterface & pcal95555::I2cInterface< Derived >::operator= ( const I2cInterface< Derived > &  )
protecteddelete

◆ operator=() [2/2]

template<typename Derived >
I2cInterface & pcal95555::I2cInterface< Derived >::operator= ( I2cInterface< Derived > &&  )
protecteddefault

◆ Read()

template<typename Derived >
bool pcal95555::I2cInterface< Derived >::Read ( uint8_t  addr,
uint8_t  reg,
uint8_t *  data,
size_t  len 
)
inlinenoexcept

Read bytes from a device register.

Parameters
addr7-bit I2C address of the target device.
regRegister address to read from.
dataPointer to the buffer to store received data.
lenNumber of bytes to read into the buffer.
Returns
true if the read succeeds; false on NACK or error.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555_i2c_interface.hpp.

◆ RegisterInterruptHandler()

template<typename Derived >
bool pcal95555::I2cInterface< Derived >::RegisterInterruptHandler ( std::function< void()>  handler)
inlinenoexcept

◆ SetAddressPins()

template<typename Derived >
bool pcal95555::I2cInterface< Derived >::SetAddressPins ( bool  a0_level,
bool  a1_level,
bool  a2_level 
)
inlinenoexcept

◆ Write()

template<typename Derived >
bool pcal95555::I2cInterface< Derived >::Write ( uint8_t  addr,
uint8_t  reg,
const uint8_t *  data,
size_t  len 
)
inlinenoexcept

Write bytes to a device register.

Parameters
addr7-bit I2C address of the target device.
regRegister address to write to.
dataPointer to the data buffer containing bytes to send.
lenNumber of bytes to write from the buffer.
Returns
true if the device acknowledges the transfer; false on NACK or error.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555_i2c_interface.hpp.

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