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

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

#include <pca9685_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 EnsureInitialized () noexcept
 Ensure the I2C bus is initialized and ready for communication.
 
 I2cInterface (const I2cInterface &)=delete
 Copy constructor deleted (non-copyable; avoids slicing).
 
I2cInterface & operator= (const I2cInterface &)=delete
 Copy assignment deleted (non-copyable).
 
 I2cInterface (I2cInterface &&)=delete
 Move constructor deleted (non-movable; use derived type to move).
 
I2cInterface & operator= (I2cInterface &&)=delete
 Move assignment deleted (non-movable).
 
GPIO Pin Control

Unified interface for controlling PCA9685 hardware control pins.

void GpioSet (CtrlPin pin, GpioSignal signal) noexcept
 Set a control pin to the specified signal state.
 
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 ()=default
 Protected destructor.
 

Detailed Description

template<typename Derived>
class pca9685::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 pca9685::I2cInterface<MyI2C> {
public:
bool Write(uint8_t addr, uint8_t reg, const uint8_t* data, size_t len) noexcept { ... }
bool Read(uint8_t addr, uint8_t reg, uint8_t* data, size_t len) noexcept { ... }
bool EnsureInitialized() noexcept { ... }
void DelayUs(uint32_t us) noexcept { ... } // optional, recommended
};
CRTP-based template interface for I2C bus operations.
Definition pca9685_i2c_interface.hpp:77

Optional hooks, detected at compile time (a port that does not declare them still compiles):

Template Parameters
DerivedThe derived class type (CRTP pattern)

Constructor & Destructor Documentation

◆ I2cInterface() [1/3]

template<typename Derived >
pca9685::I2cInterface< Derived >::I2cInterface ( const I2cInterface< Derived > &  )
delete

Copy constructor deleted (non-copyable; avoids slicing).

◆ I2cInterface() [2/3]

template<typename Derived >
pca9685::I2cInterface< Derived >::I2cInterface ( I2cInterface< Derived > &&  )
delete

Move constructor deleted (non-movable; use derived type to move).

◆ I2cInterface() [3/3]

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

Protected constructor to prevent direct instantiation.

◆ ~I2cInterface()

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

Protected destructor.

Note
Derived classes can have public destructors

Member Function Documentation

◆ EnsureInitialized()

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

Ensure the I2C bus is initialized and ready for communication.

This method performs lazy initialization of the I2C bus. It should initialize the I2C hardware, configure pins, set up the bus, and verify it's ready for communication. On subsequent calls, it should return true immediately if already initialized.

Returns
true if initialization succeeded or was already initialized; false if initialization failed.

◆ GpioSet()

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

Set a control pin to the specified signal state.

For CtrlPin::OE, ACTIVE means outputs enabled, which is a LOW level on the pin; INACTIVE means outputs blanked to the MODE2.OUTNE state, a HIGH level (datasheet 7.4, Table 11). The port does the polarity mapping.

Parameters
[in]pinWhich control pin to drive (OE).
[in]signalACTIVE to assert the pin function, INACTIVE to deassert.
Note
The default implementation is a no-op, for boards where OE is tied low. Declare the same function in the derived class if the OE pin is wired to a GPIO: the driver's SetOutputEnable() and the helpers below call the derived version.

◆ GpioSetActive()

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

Assert a control pin (set to ACTIVE).

Parameters
[in]pinWhich control pin to assert.

◆ GpioSetInactive()

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

Deassert a control pin (set to INACTIVE).

Parameters
[in]pinWhich control pin to deassert.

◆ operator=() [1/2]

template<typename Derived >
I2cInterface & pca9685::I2cInterface< Derived >::operator= ( const I2cInterface< Derived > &  )
delete

Copy assignment deleted (non-copyable).

◆ operator=() [2/2]

template<typename Derived >
I2cInterface & pca9685::I2cInterface< Derived >::operator= ( I2cInterface< Derived > &&  )
delete

Move assignment deleted (non-movable).

◆ Read()

template<typename Derived >
bool pca9685::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.

◆ Write()

template<typename Derived >
bool pca9685::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.

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