PCAL9555 Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Classes | Namespaces | Concepts | Enumerations
pcal9555_i2c_interface.hpp File Reference

The I2C port of the PCAL9555 driver: the bus requirements, the CRTP base, the I2cPort concept, the optional port hooks and the register framing. More...

#include <array>
#include <concepts>
#include <cstddef>
#include <cstdint>
#include <span>
#include "pcal9555_detail.hpp"
#include "pcal9555_types.hpp"

Go to the source code of this file.

Classes

class  pcal9555::I2cInterface< Derived >
 CRTP base of the platform I2C port. More...
 

Namespaces

namespace  pcal9555
 The PCAL9555 driver: everything it declares lives here; internals in detail.
 

Concepts

concept  pcal9555::I2cPort
 Satisfied by a class that derives from I2cInterface<Port> and implements the required hooks with exactly the types above, noexcept and returning bool.
 

Enumerations

enum class  pcal9555::I2cFailure : uint8_t { pcal9555::Other = 0 , pcal9555::AddressNack = 1 , pcal9555::DataNack = 2 }
 Why a Write() or WriteRead() hook returned false, as the optional GetLastFailure() hook reports it. More...
 

Variables

Bus requirements

What the PCA9555 and PCAL9555A need from the I2C bus. A port and a board configuration check their settings against these with static_assert (handbook KB-CPP-123).

constexpr uint8_t pcal9555::kI2cAddress = kMinI2cAddress
 
constexpr uint32_t pcal9555::kMaxClockHz = 400'000U
 Highest SCL frequency: fast mode, 400 kHz (section 13, table 33, f_SCL).
 
constexpr bool pcal9555::kRepeatedStart = true
 

Detailed Description

The I2C port of the PCAL9555 driver: the bus requirements, the CRTP base, the I2cPort concept, the optional port hooks and the register framing.

The driver never calls an SDK. It calls hooks on a class you derive from pcal9555::I2cInterface<Self>:

Hook Contract
bool EnsureInitialized() noexcept Bring the bus up on the first call; true at once afterwards
bool Write(uint8_t addr, const uint8_t* data, std::size_t len) noexcept START, addr + W, len bytes, STOP; false on a NACK or bus error
bool WriteRead(uint8_t addr, const uint8_t* tx, std::size_t tx_len, uint8_t* rx, std::size_t rx_len) noexcept START, addr + W, tx, repeated START, addr + R, rx_len bytes (NACK on the last), STOP
bool GetLastFailure(I2cFailure& failure) noexcept (optional) After Write() or WriteRead() returned false: why. true and failure set when the port knows; false when it cannot tell

addr is the 7-bit address. The port moves raw bytes: the command byte travels in the payload, and the port never retries or configures the chip. What the chip needs from the bus is below as constexpr values (kI2cAddress, kMaxClockHz, kRepeatedStart); a port checks its settings against them with static_assert.

Section and table numbers refer to the NXP PCAL9555A data sheet, Rev. 2 (19 December 2014).