PCA9555 / PCAL9555A Driver
API reference
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
pcal95555::PCAL95555< I2cType > Class Template Reference

Driver for the PCA9555 / PCAL9555A / PCAL95555AHF I²C GPIO expander. More...

#include <pcal95555.hpp>

Classes

struct  PinInterruptCallback
 Structure to store pin interrupt callback information. More...
 

Public Member Functions

 PCAL95555 (I2cType *bus, bool a0_level, bool a1_level, bool a2_level, ChipVariant variant=ChipVariant::Unknown)
 
 PCAL95555 (I2cType *bus, uint8_t address, ChipVariant variant=ChipVariant::Unknown)
 
void SetRetries (int retries) noexcept
 Configure retry mechanism for I2C transactions.
 
uint16_t GetErrorFlags () const noexcept
 Retrieve currently latched error flags.
 
bool HasError (Error e) const noexcept
 Check if a specific error flag is set.
 
bool HasAnyError () const noexcept
 Check if any error flag is set.
 
void ClearError (Error e) noexcept
 Clear a single error flag.
 
void ClearErrorFlags (uint16_t mask=0xFFFF) noexcept
 Clear specific error flags by raw bitmask.
 
void ResetToDefault () noexcept
 Reset all registers to their power-on default state.
 
void InitFromConfig () noexcept
 Initialize the device using values from Kconfig.
 
bool SetPinDirection (uint8_t pin, GPIODir dir) noexcept
 Set the direction of a single GPIO pin.
 
bool SetMultipleDirections (uint16_t mask, GPIODir dir) noexcept
 Set the direction for multiple GPIO pins at once using a bitmask.
 
bool SetDirections (std::initializer_list< std::pair< uint8_t, GPIODir > > configs) noexcept
 
bool ReadPin (uint8_t pin) noexcept
 Read the current logical level of a GPIO pin.
 
bool ReadPin (uint8_t pin, bool &level) noexcept
 Read the logical level of a GPIO pin and report whether the read worked.
 
bool WritePin (uint8_t pin, bool value) noexcept
 Write a logical level to a GPIO output pin.
 
bool SetMultipleOutputs (uint16_t mask, bool value) noexcept
 
bool TogglePin (uint8_t pin) noexcept
 Toggle the output state of a GPIO pin.
 
bool WritePins (std::initializer_list< std::pair< uint8_t, bool > > configs) noexcept
 
PinReadResult ReadPins (std::initializer_list< uint8_t > pins) noexcept
 
uint16_t ReadAllInputs () noexcept
 
bool ReadDualPortRegister (uint8_t reg0, uint8_t reg1, uint16_t &value) noexcept
 Read a dual-port register pair into a 16-bit pin mask.
 
bool WriteDualPortRegister (uint8_t reg0, uint8_t reg1, uint16_t value) noexcept
 Write a dual-port register pair from a 16-bit pin mask (no readback).
 
bool SetPullEnable (uint8_t pin, bool enable) noexcept
 Enable or disable the pull-up/pull-down resistor on a pin.
 
bool SetPullEnables (std::initializer_list< std::pair< uint8_t, bool > > configs) noexcept
 
bool SetPullDirection (uint8_t pin, bool pull_up) noexcept
 Select internal pull-up or pull-down resistor direction.
 
bool SetPullDirections (std::initializer_list< std::pair< uint8_t, bool > > configs) noexcept
 
bool GetPullConfiguration (uint16_t &enable_mask, uint16_t &direction_mask) noexcept
 Read the current pull resistor configuration from hardware registers.
 
bool SetDriveStrength (uint8_t pin, DriveStrength level) noexcept
 Configure the output drive strength for a GPIO pin.
 
bool SetDriveStrengths (std::initializer_list< std::pair< uint8_t, DriveStrength > > configs) noexcept
 
bool ConfigureInterrupt (uint8_t pin, InterruptState state) noexcept
 
bool ConfigureInterrupts (std::initializer_list< std::pair< uint8_t, InterruptState > > configs) noexcept
 
bool ConfigureInterruptMask (uint16_t mask) noexcept
 
uint16_t GetInterruptStatus () noexcept
 Retrieve and clear the interrupt status.
 
bool SetOutputMode (bool port_0_open_drain, bool port_1_open_drain) noexcept
 Configure per-port output mode (push-pull or open-drain).
 
bool SetPinPolarity (uint8_t pin, Polarity polarity) noexcept
 Configure input polarity inversion for a single pin.
 
bool SetMultiplePolarities (uint16_t mask, Polarity polarity) noexcept
 Configure input polarity for multiple pins using a bitmask.
 
bool SetPolarities (std::initializer_list< std::pair< uint8_t, Polarity > > configs) noexcept
 
bool EnableInputLatch (uint8_t pin, bool enable) noexcept
 Enable or disable the input latch for a single pin.
 
bool EnableMultipleInputLatches (uint16_t mask, bool enable) noexcept
 Enable or disable input latch for multiple pins using a bitmask.
 
bool EnableInputLatches (std::initializer_list< std::pair< uint8_t, bool > > configs) noexcept
 
bool RegisterPinInterrupt (uint8_t pin, InterruptEdge edge, std::function< void(uint8_t pin, bool state)> callback)
 
bool UnregisterPinInterrupt (uint8_t pin) noexcept
 Unregister callback for a specific pin interrupt.
 
void SetInterruptCallback (const std::function< void(uint16_t)> &callback) noexcept
 
bool RegisterInterruptHandler () noexcept
 
void HandleInterrupt () noexcept
 Internal handler to process an interrupt event.
 
uint8_t GetAddress () const noexcept
 Get the current I2C address of the device.
 
uint8_t GetAddressBits () const noexcept
 Get the current A2-A0 address bits.
 
bool HasAgileIO () const noexcept
 
ChipVariant GetChipVariant () const noexcept
 Get the detected chip variant.
 
bool ChangeAddress (bool a0_level, bool a1_level, bool a2_level) noexcept
 
bool ChangeAddress (uint8_t address) noexcept
 
bool EnsureInitialized () noexcept
 
bool ForceMarkInitialized (ChipVariant variant) noexcept
 Mark the driver initialized without the probe read.
 

Static Public Member Functions

static constexpr const char * GetDriverVersion () noexcept
 
static constexpr uint8_t GetDriverVersionMajor () noexcept
 Get the compiled driver major version number.
 
static constexpr uint8_t GetDriverVersionMinor () noexcept
 Get the compiled driver minor version number.
 
static constexpr uint8_t GetDriverVersionPatch () noexcept
 Get the compiled driver patch version number.
 

Protected Member Functions

bool readRegister (uint8_t reg, uint8_t &value) noexcept
 Read a device register with retry logic.
 
bool writeRegister (uint8_t reg, uint8_t value) noexcept
 Write a single byte to a device register with retry logic.
 

Private Member Functions

uint16_t readPinStates () noexcept
 Read current pin states from input port registers.
 
bool initialize () noexcept
 Perform actual initialization of the driver.
 
void setError (Error error_code) noexcept
 
void clearError (Error error_code) noexcept
 
bool readDualPort (uint8_t reg0, uint8_t reg1, uint8_t &val0, uint8_t &val1) noexcept
 Read both port registers (port0 and port1) in one call.
 
bool writeDualPort (uint8_t reg0, uint8_t reg1, uint8_t val0, uint8_t val1) noexcept
 Write both port registers (port0 and port1) in one call.
 
bool modifySinglePinRegister (uint8_t reg0, uint8_t reg1, uint8_t pin, bool bit_value) noexcept
 Single-pin read-modify-write on a dual-port register pair.
 
bool modifyDualPortByMask (uint8_t reg0, uint8_t reg1, uint16_t mask, bool bit_value) noexcept
 Batch mask read-modify-write on a dual-port register pair.
 
bool requireAgileIO () noexcept
 Check that the chip supports Agile I/O, setting error if not.
 
bool changeAddressImpl (uint8_t new_bits) noexcept
 Shared implementation for ChangeAddress overloads.
 
bool detectChipVariant () noexcept
 Detect the chip variant by probing an Agile I/O register.
 

Static Private Member Functions

static constexpr uint8_t calculateAddress (uint8_t bits)
 Calculate I2C address from A2-A0 bits.
 

Private Attributes

I2cType * i2c_
 
uint8_t dev_addr_
 
uint8_t address_bits_
 
int retries_ {1}
 
uint16_t error_flags_ {0}
 
std::function< void(uint16_t)> irq_callback_
 
PinInterruptCallback pin_callbacks_ [16]
 
uint16_t previous_pin_states_ {0}
 
bool initialized_ {false}
 
bool a0_level_
 
bool a1_level_
 
bool a2_level_
 
ChipVariant chip_variant_ {ChipVariant::Unknown}
 
ChipVariant user_variant_ {ChipVariant::Unknown}
 
uint8_t xfer_byte_ {0}
 

Detailed Description

template<typename I2cType>
class pcal95555::PCAL95555< I2cType >

Driver for the PCA9555 / PCAL9555A / PCAL95555AHF I²C GPIO expander.

This driver supports both the standard PCA9555 and the enhanced PCAL9555A. The chip variant is auto-detected during initialization by probing the Agile I/O register bank (0x40-0x4F). Features requiring the extended register set are gracefully disabled when a standard PCA9555 is detected.

Chip Compatibility:

Feature PCA9555 PCAL9555A
GPIO direction Yes Yes
Pin read/write/toggle Yes Yes
Polarity inversion Yes Yes
Pull-up/pull-down config No Yes
Drive strength No Yes
Input latch No Yes
Interrupt mask/status No Yes
Output mode (PP/OD) No Yes
Template Parameters
I2cTypeThe I2C interface implementation type that inherits from pcal95555::I2cInterface<I2cType>
Note
The driver uses CRTP-based I2C interface for zero virtual call overhead.
Address is calculated internally from A2-A0 pins. The base address is 0x20.
The driver uses lazy initialization - no initialization happens in the constructor. Call EnsureInitialized() explicitly or let it initialize automatically on first use. Initialization includes setting address pins, verifying I2C communication, and auto-detecting the chip variant.
Use HasAgileIO() or GetChipVariant() to query which features are available.

Constructor & Destructor Documentation

◆ PCAL95555() [1/2]

template<typename I2cType >
pcal95555::PCAL95555< I2cType >::PCAL95555 ( I2cType *  bus,
bool  a0_level,
bool  a1_level,
bool  a2_level,
ChipVariant  variant = ChipVariant::Unknown 
)

◆ PCAL95555() [2/2]

template<typename I2cType >
pcal95555::PCAL95555< I2cType >::PCAL95555 ( I2cType *  bus,
uint8_t  address,
ChipVariant  variant = ChipVariant::Unknown 
)
explicit

Member Function Documentation

◆ calculateAddress()

template<typename I2cType >
static constexpr uint8_t pcal95555::PCAL95555< I2cType >::calculateAddress ( uint8_t  bits)
inlinestaticconstexprprivate

Calculate I2C address from A2-A0 bits.

Parameters
bits3-bit value (0-7) representing A2, A1, A0 pins.
Returns
7-bit I2C address (0x20 to 0x27).
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ ChangeAddress() [1/2]

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::ChangeAddress ( bool  a0_level,
bool  a1_level,
bool  a2_level 
)
noexcept

◆ ChangeAddress() [2/2]

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::ChangeAddress ( uint8_t  address)
noexcept

◆ changeAddressImpl()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::changeAddressImpl ( uint8_t  new_bits)
privatenoexcept

Shared implementation for ChangeAddress overloads.

Sets GPIO address pins, updates internal state, verifies communication, and re-detects chip variant at the new address.

Parameters
new_bitsAddress bits (0-7) to set.
Returns
true if communication at the new address succeeded.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ ClearError()

template<typename I2cType >
void pcal95555::PCAL95555< I2cType >::ClearError ( Error  e)
noexcept

Clear a single error flag.

Parameters
eThe error flag to clear.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ clearError()

template<typename I2cType >
void pcal95555::PCAL95555< I2cType >::clearError ( Error  error_code)
privatenoexcept

◆ ClearErrorFlags()

template<typename I2cType >
void pcal95555::PCAL95555< I2cType >::ClearErrorFlags ( uint16_t  mask = 0xFFFF)
noexcept

Clear specific error flags by raw bitmask.

Parameters
maskBitmask of errors to clear (default: all).
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ ConfigureInterrupt()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::ConfigureInterrupt ( uint8_t  pin,
InterruptState  state 
)
noexcept

◆ ConfigureInterruptMask()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::ConfigureInterruptMask ( uint16_t  mask)
noexcept

◆ ConfigureInterrupts()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::ConfigureInterrupts ( std::initializer_list< std::pair< uint8_t, InterruptState > >  configs)
noexcept

◆ detectChipVariant()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::detectChipVariant ( )
privatenoexcept

Detect the chip variant by probing an Agile I/O register.

Detection sequence (3-step sandwich):

  1. Read INPUT_PORT_0 (0x00) — verify basic I2C communication
  2. Read OUTPUT_CONF (0x4F) — probe Agile I/O register
  3. Read INPUT_PORT_0 (0x00) — verify bus recovered after potential NACK

If step 1 fails the bus is broken and variant is left as Unknown. If step 2 succeeds the chip is PCAL9555A. If step 2 NACKs but step 3 succeeds the chip is a standard PCA9555. If step 3 also fails the detection is inconclusive (bus error).

Returns
true when a variant was identified; false when it is left Unknown (initialisation and ChangeAddress() then fail).
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ EnableInputLatch()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::EnableInputLatch ( uint8_t  pin,
bool  enable 
)
noexcept

Enable or disable the input latch for a single pin.

Parameters
pinZero-based pin index (0-15).
enabletrue to enable latch; false to disable.
Returns
true on success; false on I2C failure.
Note
Requires PCAL9555A. Returns false with Error::UnsupportedFeature on PCA9555.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ EnableInputLatches()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::EnableInputLatches ( std::initializer_list< std::pair< uint8_t, bool > >  configs)
noexcept

◆ EnableMultipleInputLatches()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::EnableMultipleInputLatches ( uint16_t  mask,
bool  enable 
)
noexcept

Enable or disable input latch for multiple pins using a bitmask.

Parameters
maskBitmask selecting pins.
enabletrue to enable; false to disable.
Returns
true on success; false on any I2C failure; false with Error::InvalidMask (and no bus traffic) when mask is 0.
Note
This is a low-level method. For easier use with individual pin settings, prefer EnableInputLatches() which works with pin numbers directly.
Requires PCAL9555A. Returns false with Error::UnsupportedFeature on PCA9555.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ EnsureInitialized()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::EnsureInitialized ( )
noexcept

◆ ForceMarkInitialized()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::ForceMarkInitialized ( ChipVariant  variant)
noexcept

Mark the driver initialized without the probe read.

Use only when the bus/adapter path has already proven INPUT_PORT access (e.g. bring-up) and EnsureInitialized()'s first readRegister is known to misbehave on the target master. Sets variant as both user and detected chip type and seeds previous pin state to 0.

Note
On some STM32H7 masters, repeating the driver probe (W 0x35) after INPUT_PORT has already succeeded can leave the controller sticky and block CONFIG/OUTPUT programming. Callers that already proved the bus may use this path, then program ports via absolute writes + shadows. Prefer fixing the bus path long-term over expanding callers.
Parameters
variantPCA9555 or PCAL9555A (not Unknown).
Returns
true if variant is usable; false if Unknown.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ GetAddress()

template<typename I2cType >
uint8_t pcal95555::PCAL95555< I2cType >::GetAddress ( ) const
noexcept

Get the current I2C address of the device.

Returns
7-bit I2C address (0x20 to 0x27).
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ GetAddressBits()

template<typename I2cType >
uint8_t pcal95555::PCAL95555< I2cType >::GetAddressBits ( ) const
noexcept

Get the current A2-A0 address bits.

Returns
3-bit value (0-7) representing A2, A1, A0 pin configuration.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ GetChipVariant()

template<typename I2cType >
ChipVariant pcal95555::PCAL95555< I2cType >::GetChipVariant ( ) const
noexcept

Get the detected chip variant.

Returns
ChipVariant::PCA9555, ChipVariant::PCAL9555A, or ChipVariant::Unknown if not yet initialized.
Note
Call after EnsureInitialized() for accurate results.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ GetDriverVersion()

template<typename I2cType >
static constexpr const char * pcal95555::PCAL95555< I2cType >::GetDriverVersion ( )
inlinestaticconstexprnoexcept

◆ GetDriverVersionMajor()

template<typename I2cType >
static constexpr uint8_t pcal95555::PCAL95555< I2cType >::GetDriverVersionMajor ( )
inlinestaticconstexprnoexcept

Get the compiled driver major version number.

Returns
Major version (incremented on breaking API changes).
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ GetDriverVersionMinor()

template<typename I2cType >
static constexpr uint8_t pcal95555::PCAL95555< I2cType >::GetDriverVersionMinor ( )
inlinestaticconstexprnoexcept

Get the compiled driver minor version number.

Returns
Minor version (incremented on new features, backward-compatible).
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ GetDriverVersionPatch()

template<typename I2cType >
static constexpr uint8_t pcal95555::PCAL95555< I2cType >::GetDriverVersionPatch ( )
inlinestaticconstexprnoexcept

Get the compiled driver patch version number.

Returns
Patch version (incremented on bug fixes).
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ GetErrorFlags()

template<typename I2cType >
uint16_t pcal95555::PCAL95555< I2cType >::GetErrorFlags ( ) const
noexcept

Retrieve currently latched error flags.

Returns
Bitmask composed of Error values.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ GetInterruptStatus()

template<typename I2cType >
uint16_t pcal95555::PCAL95555< I2cType >::GetInterruptStatus ( )
noexcept

Retrieve and clear the interrupt status.

Returns
16-bit mask indicating which pins triggered an interrupt. Returns 0 on PCA9555 (interrupt status registers not available).
Note
Requires PCAL9555A. Returns 0 with Error::UnsupportedFeature on PCA9555.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ GetPullConfiguration()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::GetPullConfiguration ( uint16_t &  enable_mask,
uint16_t &  direction_mask 
)
noexcept

Read the current pull resistor configuration from hardware registers.

Reads the PULL_ENABLE (0x46-0x47) and PULL_SELECT (0x48-0x49) registers and returns them as 16-bit bitmasks (bit N corresponds to pin N).

Parameters
[out]enable_maskBitmask: bit set = pull resistor enabled on that pin.
[out]direction_maskBitmask: bit set = pull-up, bit clear = pull-down. Only meaningful for pins where the corresponding enable_mask bit is set.
Returns
true on success; false on I2C failure.
Note
Requires PCAL9555A. Returns false with Error::UnsupportedFeature on PCA9555.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ HandleInterrupt()

template<typename I2cType >
void pcal95555::PCAL95555< I2cType >::HandleInterrupt ( )
noexcept

Internal handler to process an interrupt event.

This method is called by the I2C interface when the INT pin fires. It reads the interrupt status registers, determines which pins triggered interrupts, checks edge conditions, and invokes registered callbacks.

Reading the interrupt status registers clears the interrupt condition.

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

◆ HasAgileIO()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::HasAgileIO ( ) const
noexcept

◆ HasAnyError()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::HasAnyError ( ) const
noexcept

Check if any error flag is set.

Returns
true if error_flags_ != 0.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ HasError()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::HasError ( Error  e) const
noexcept

Check if a specific error flag is set.

Parameters
eThe error flag to test.
Returns
true if the flag is set in the current error bitmask.
if (driver.HasError(Error::I2CReadFail)) { ... }
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ InitFromConfig()

template<typename I2cType >
void pcal95555::PCAL95555< I2cType >::InitFromConfig ( )
noexcept

Initialize the device using values from Kconfig.

This writes the configuration registers using the CONFIG_PCAL95555_INIT_* options defined at compile time.

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

◆ initialize()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::initialize ( )
privatenoexcept

Perform actual initialization of the driver.

This private method contains all initialization logic including:

  • Setting address pins via I2C interface
  • Verifying I2C bus is ready (calls i2c_->EnsureInitialized() if available)
  • Verifying communication with device
  • Initializing internal state
Returns
true if initialization succeeded; false on failure.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ modifyDualPortByMask()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::modifyDualPortByMask ( uint8_t  reg0,
uint8_t  reg1,
uint16_t  mask,
bool  bit_value 
)
privatenoexcept

Batch mask read-modify-write on a dual-port register pair.

For each bit set in mask (0-15), sets or clears the corresponding bit in the appropriate port register. Does NOT call EnsureInitialized().

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

◆ modifySinglePinRegister()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::modifySinglePinRegister ( uint8_t  reg0,
uint8_t  reg1,
uint8_t  pin,
bool  bit_value 
)
privatenoexcept

Single-pin read-modify-write on a dual-port register pair.

Selects the correct port register based on pin number, reads, modifies the bit, and writes back. Does NOT validate pin or call EnsureInitialized().

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

◆ ReadAllInputs()

template<typename I2cType >
uint16_t pcal95555::PCAL95555< I2cType >::ReadAllInputs ( )
noexcept

◆ readDualPort()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::readDualPort ( uint8_t  reg0,
uint8_t  reg1,
uint8_t &  val0,
uint8_t &  val1 
)
privatenoexcept

Read both port registers (port0 and port1) in one call.

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

◆ ReadDualPortRegister()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::ReadDualPortRegister ( uint8_t  reg0,
uint8_t  reg1,
uint16_t &  value 
)
noexcept

Read a dual-port register pair into a 16-bit pin mask.

Parameters
reg0Port-0 register (bits 0..7).
reg1Port-1 register (bits 8..15).
[out]valueBit N corresponds to pin N.
Returns
true on success; false on I2C failure.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ ReadPin() [1/2]

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::ReadPin ( uint8_t  pin)
noexcept

Read the current logical level of a GPIO pin.

Parameters
pinZero-based pin index (0-15).
Returns
true if pin is high; false if pin is low or on read error.
Note
A low pin and a failed read both return false. Use ReadPin(uint8_t, bool&) when the difference matters.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ ReadPin() [2/2]

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::ReadPin ( uint8_t  pin,
bool &  level 
)
noexcept

Read the logical level of a GPIO pin and report whether the read worked.

Parameters
pinZero-based pin index (0-15).
levelReceives the level (true = high) on success; unchanged on failure.
Returns
true if the Input Port register was read; false on an invalid pin (Error::InvalidPin) or an I2C failure (Error::I2CReadFail).
bool level = false;
if (!driver.ReadPin(8, level)) { handle_bus_error(); }

◆ ReadPins()

template<typename I2cType >
pcal95555::PinReadResult pcal95555::PCAL95555< I2cType >::ReadPins ( std::initializer_list< uint8_t >  pins)
noexcept

◆ readPinStates()

template<typename I2cType >
uint16_t pcal95555::PCAL95555< I2cType >::readPinStates ( )
privatenoexcept

Read current pin states from input port registers.

Returns
16-bit mask with current pin states (bit N = pin N state).
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ readRegister()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::readRegister ( uint8_t  reg,
uint8_t &  value 
)
protectednoexcept

Read a device register with retry logic.

Parameters
regRegister address to read.
valueReference to store the read byte.
Returns
true if read succeeds; false on failure.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ RegisterInterruptHandler()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::RegisterInterruptHandler ( )
noexcept

◆ RegisterPinInterrupt()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::RegisterPinInterrupt ( uint8_t  pin,
InterruptEdge  edge,
std::function< void(uint8_t pin, bool state)>  callback 
)

◆ requireAgileIO()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::requireAgileIO ( )
privatenoexcept

Check that the chip supports Agile I/O, setting error if not.

Returns
true if chip is PCAL9555A; false if PCA9555 (sets Error::UnsupportedFeature).
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ ResetToDefault()

template<typename I2cType >
void pcal95555::PCAL95555< I2cType >::ResetToDefault ( )
noexcept

Reset all registers to their power-on default state.

Available registers are set to inputs, pull-ups enabled, interrupts masked, drive strength set to full, and output mode configured as push-pull as specified by the datasheet.

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

◆ SetDirections()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetDirections ( std::initializer_list< std::pair< uint8_t, GPIODir > >  configs)
noexcept

◆ SetDriveStrength()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetDriveStrength ( uint8_t  pin,
DriveStrength  level 
)
noexcept

Configure the output drive strength for a GPIO pin.

Parameters
pinZero-based pin index (0-15).
levelDrive strength level (Level0..Level3).
Returns
true on success; false on I2C failure.
Note
Requires PCAL9555A. Returns false with Error::UnsupportedFeature on PCA9555.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ SetDriveStrengths()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetDriveStrengths ( std::initializer_list< std::pair< uint8_t, DriveStrength > >  configs)
noexcept

◆ setError()

template<typename I2cType >
void pcal95555::PCAL95555< I2cType >::setError ( Error  error_code)
privatenoexcept

◆ SetInterruptCallback()

template<typename I2cType >
void pcal95555::PCAL95555< I2cType >::SetInterruptCallback ( const std::function< void(uint16_t)> &  callback)
noexcept

◆ SetMultipleDirections()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetMultipleDirections ( uint16_t  mask,
GPIODir  dir 
)
noexcept

Set the direction for multiple GPIO pins at once using a bitmask.

Parameters
maskBitmask where each set bit indicates a pin to configure.
dirCommon direction for all selected pins.
Returns
true on success; false if any I2C operation fails; false with Error::InvalidMask (and no bus traffic) when mask is 0.
Note
This is a low-level method. For easier use with individual pin directions, prefer SetDirections() which works with pin numbers directly.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ SetMultipleOutputs()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetMultipleOutputs ( uint16_t  mask,
bool  value 
)
noexcept

◆ SetMultiplePolarities()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetMultiplePolarities ( uint16_t  mask,
Polarity  polarity 
)
noexcept

Configure input polarity for multiple pins using a bitmask.

Parameters
maskBitmask selecting pins to configure.
polarityNormal or Inverted for all selected pins.
Returns
true on success; false on any I2C failure; false with Error::InvalidMask (and no bus traffic) when mask is 0.
Note
This is a low-level method. For easier use with individual pin polarities, prefer SetPolarities() which works with pin numbers directly.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ SetOutputMode()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetOutputMode ( bool  port_0_open_drain,
bool  port_1_open_drain 
)
noexcept

Configure per-port output mode (push-pull or open-drain).

Parameters
port_0_open_draintrue for open-drain on port 0.
port_1_open_draintrue for open-drain on port 1.
Returns
true on success; false on I2C failure.
Note
Requires PCAL9555A. Returns false with Error::UnsupportedFeature on PCA9555.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ SetPinDirection()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetPinDirection ( uint8_t  pin,
GPIODir  dir 
)
noexcept

Set the direction of a single GPIO pin.

Parameters
pinZero-based pin index (0-15).
dirDirection enum: Input or Output.
Returns
true on success; false on I2C failure.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ SetPinPolarity()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetPinPolarity ( uint8_t  pin,
Polarity  polarity 
)
noexcept

Configure input polarity inversion for a single pin.

Parameters
pinZero-based pin index (0-15).
polarityPolarity::Normal or Polarity::Inverted.
Returns
true on success; false on I2C failure.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ SetPolarities()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetPolarities ( std::initializer_list< std::pair< uint8_t, Polarity > >  configs)
noexcept

◆ SetPullDirection()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetPullDirection ( uint8_t  pin,
bool  pull_up 
)
noexcept

Select internal pull-up or pull-down resistor direction.

Parameters
pinZero-based pin index (0-15).
pull_uptrue for pull-up; false for pull-down.
Returns
true on success; false on I2C failure.
Note
Requires PCAL9555A. Returns false with Error::UnsupportedFeature on PCA9555.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ SetPullDirections()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetPullDirections ( std::initializer_list< std::pair< uint8_t, bool > >  configs)
noexcept

◆ SetPullEnable()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetPullEnable ( uint8_t  pin,
bool  enable 
)
noexcept

Enable or disable the pull-up/pull-down resistor on a pin.

Parameters
pinZero-based pin index (0-15).
enabletrue to enable; false to disable.
Returns
true on success; false on I2C failure.
Note
Requires PCAL9555A. Returns false with Error::UnsupportedFeature on PCA9555.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ SetPullEnables()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::SetPullEnables ( std::initializer_list< std::pair< uint8_t, bool > >  configs)
noexcept

◆ SetRetries()

template<typename I2cType >
void pcal95555::PCAL95555< I2cType >::SetRetries ( int  retries)
noexcept

Configure retry mechanism for I2C transactions.

Parameters
retriesMaximum number of retry attempts on failure. Note: setting N will result in N+1 total attempts per transfer.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ TogglePin()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::TogglePin ( uint8_t  pin)
noexcept

Toggle the output state of a GPIO pin.

Parameters
pinZero-based pin index (0-15).
Returns
true on success; false on I2C failure.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ UnregisterPinInterrupt()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::UnregisterPinInterrupt ( uint8_t  pin)
noexcept

Unregister callback for a specific pin interrupt.

Parameters
pinPin number (0-15) to unregister callback for.
Returns
true if callback was unregistered; false if pin was invalid or had no callback.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ writeDualPort()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::writeDualPort ( uint8_t  reg0,
uint8_t  reg1,
uint8_t  val0,
uint8_t  val1 
)
privatenoexcept

Write both port registers (port0 and port1) in one call.

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

◆ WriteDualPortRegister()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::WriteDualPortRegister ( uint8_t  reg0,
uint8_t  reg1,
uint16_t  value 
)
noexcept

Write a dual-port register pair from a 16-bit pin mask (no readback).

Prefer this over read-modify-write when the caller maintains a shadow of the port (OUTPUT / CONFIG / POLARITY). Absolute writes avoid corrupting latches if a prior register read returned the wrong bank.

Parameters
reg0Port-0 register (bits 0..7).
reg1Port-1 register (bits 8..15).
valueBit N corresponds to pin N.
Returns
true on success; false on I2C failure.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ WritePin()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::WritePin ( uint8_t  pin,
bool  value 
)
noexcept

Write a logical level to a GPIO output pin.

Parameters
pinZero-based pin index (0-15).
valuetrue to drive high, false to drive low.
Returns
true if write succeeded; false on I2C failure.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

◆ WritePins()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::WritePins ( std::initializer_list< std::pair< uint8_t, bool > >  configs)
noexcept

◆ writeRegister()

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::writeRegister ( uint8_t  reg,
uint8_t  value 
)
protectednoexcept

Write a single byte to a device register with retry logic.

Parameters
regRegister address to write.
valueByte value to write.
Returns
true if write succeeds; false on failure.
Examples
/home/runner/work/hf-pcal95555-driver/hf-pcal95555-driver/inc/pcal95555.hpp.

Member Data Documentation

◆ a0_level_

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::a0_level_
private

◆ a1_level_

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::a1_level_
private

◆ a2_level_

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::a2_level_
private

◆ address_bits_

template<typename I2cType >
uint8_t pcal95555::PCAL95555< I2cType >::address_bits_
private

◆ chip_variant_

template<typename I2cType >
ChipVariant pcal95555::PCAL95555< I2cType >::chip_variant_ {ChipVariant::Unknown}
private

◆ dev_addr_

template<typename I2cType >
uint8_t pcal95555::PCAL95555< I2cType >::dev_addr_
private

◆ error_flags_

template<typename I2cType >
uint16_t pcal95555::PCAL95555< I2cType >::error_flags_ {0}
private

◆ i2c_

template<typename I2cType >
I2cType* pcal95555::PCAL95555< I2cType >::i2c_
private

◆ initialized_

template<typename I2cType >
bool pcal95555::PCAL95555< I2cType >::initialized_ {false}
private

◆ irq_callback_

template<typename I2cType >
std::function<void(uint16_t)> pcal95555::PCAL95555< I2cType >::irq_callback_
private

◆ pin_callbacks_

template<typename I2cType >
PinInterruptCallback pcal95555::PCAL95555< I2cType >::pin_callbacks_[16]
private

◆ previous_pin_states_

template<typename I2cType >
uint16_t pcal95555::PCAL95555< I2cType >::previous_pin_states_ {0}
private

◆ retries_

template<typename I2cType >
int pcal95555::PCAL95555< I2cType >::retries_ {1}
private

◆ user_variant_

template<typename I2cType >
ChipVariant pcal95555::PCAL95555< I2cType >::user_variant_ {ChipVariant::Unknown}
private

◆ xfer_byte_

template<typename I2cType >
uint8_t pcal95555::PCAL95555< I2cType >::xfer_byte_ {0}
private

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