PCA9685 Driver
API reference
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
pca9685::PCA9685< I2cType > Class Template Reference

Driver for the PCA9685 16-channel 12-bit PWM controller. More...

#include <pca9685.hpp>

Public Types

enum class  Error : uint16_t {
  None = 0 , I2cWrite = 1 << 0 , I2cRead = 1 << 1 , InvalidParam = 1 << 2 ,
  DeviceNotFound = 1 << 3 , NotInitialized = 1 << 4 , OutOfRange = 1 << 5
}
 Error codes for PCA9685 operations (bitmask flags). More...
 
enum class  Register : uint8_t {
  MODE1 = 0x00 , MODE2 = 0x01 , SUBADR1 = 0x02 , SUBADR2 = 0x03 ,
  SUBADR3 = 0x04 , ALLCALLADR = 0x05 , LED0_ON_L = 0x06 , LED0_ON_H = 0x07 ,
  LED0_OFF_L = 0x08 , LED0_OFF_H , ALL_LED_ON_L = 0xFA , ALL_LED_ON_H = 0xFB ,
  ALL_LED_OFF_L = 0xFC , ALL_LED_OFF_H = 0xFD , PRE_SCALE = 0xFE , TESTMODE = 0xFF
}
 PCA9685 register map (I2C register addresses). More...
 
using RetryDelayFn = void(*)()
 Type of optional callback invoked between I2C retry attempts.
 

Public Member Functions

 PCA9685 (I2cType *bus, uint8_t address)
 Construct a new PCA9685 driver instance.
 
bool EnsureInitialized () noexcept
 Ensure the driver and I2C bus are initialized (lazy initialization).
 
bool IsInitialized () const noexcept
 Check if the driver has been initialized.
 
bool Reset () noexcept
 Reset the device to its power-on default state.
 
bool SetPwmFreq (float freq_hz) noexcept
 Set the PWM frequency for all channels.
 
bool SetPwm (uint8_t channel, uint16_t on_time, uint16_t off_time) noexcept
 Set the PWM on/off time for a channel.
 
bool SetDuty (uint8_t channel, float duty) noexcept
 Set the duty cycle for a channel (0.0-1.0).
 
bool SetAllPwm (uint16_t on_time, uint16_t off_time) noexcept
 Set all channels to the same PWM value.
 
uint16_t GetErrorFlags () const noexcept
 Get the accumulated error flags (bitmask).
 
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.
 
Error GetLastError () const noexcept
 Get the last error code (single-error convenience accessor).
 
bool GetPrescale (uint8_t &prescale) noexcept
 Get the current prescale value (frequency divider).
 
void SetRetries (int retries) noexcept
 Set the I2C retry count for register read/write operations.
 
void SetRetryDelay (RetryDelayFn fn) noexcept
 Set optional callback invoked between I2C retry attempts (after a failure, before next try).
 
bool Sleep () noexcept
 Put the PCA9685 into low-power sleep mode.
 
bool Wake () noexcept
 Wake the PCA9685 from sleep mode.
 
bool SetOutputInvert (bool invert) noexcept
 Set output polarity inversion.
 
bool SetOutputDriverMode (bool totem_pole) noexcept
 Set the output driver mode.
 
bool SetOutputEnable (bool enable) noexcept
 Enable or blank all 16 outputs with the OE pin.
 
bool SetChannelFullOn (uint8_t channel) noexcept
 Set a channel to fully ON (100% duty, no PWM).
 
bool SetChannelFullOff (uint8_t channel) noexcept
 Set a channel to fully OFF (0% duty, no PWM).
 

Static Public Member Functions

static constexpr const char * GetDriverVersion () noexcept
 Get the compiled driver version string.
 
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.
 

Static Public Attributes

static constexpr uint8_t MAX_CHANNELS_ = 16
 Number of PWM channels (0-15)
 
static constexpr uint16_t MAX_PWM_ = 4095
 Maximum tick value (12-bit)
 
static constexpr uint32_t OSC_FREQ_ = 25000000
 
static constexpr uint32_t OSC_STARTUP_US_ = 500
 

Private Member Functions

void setError (Error e) noexcept
 Set last error and add to error flags.
 
bool writeReg (uint8_t reg, uint8_t value) noexcept
 Write one byte to a register.
 
bool readReg (uint8_t reg, uint8_t &value) noexcept
 Read one byte from a register.
 
bool writeRegBlock (uint8_t reg, const uint8_t *data, size_t len) noexcept
 Write a block of bytes to a register.
 
bool readRegBlock (uint8_t reg, uint8_t *data, size_t len) noexcept
 Read a block of bytes from a register.
 
uint8_t calcPrescale (float freq_hz) const noexcept
 Compute prescale value for given frequency.
 
bool writeMode1 (uint8_t value) noexcept
 Write MODE1 with AI forced to 1 and RESTART forced to 0.
 
bool restartAfterSleep (uint8_t mode1, bool restart) noexcept
 Clear SLEEP, wait for the oscillator, then optionally write RESTART (datasheet 7.3.1.1).
 
void waitOscillatorStartup () noexcept
 Wait OSC_STARTUP_US_ through I2cType::DelayUs(), or with MODE1 reads if the port has none.
 
bool modifyReg (uint8_t reg, uint8_t mask, uint8_t value) noexcept
 Read-modify-write a single register.
 

Static Private Member Functions

static ::std::array< uint8_t, 4 > pwmFrame (uint16_t on_time, uint16_t off_time) noexcept
 Build the four LEDn / ALL_LED bytes for ON and OFF ticks; equal ticks give full OFF.
 

Private Attributes

I2cType * i2c_
 
uint8_t addr_
 
Error last_error_ {Error::None}
 
uint16_t error_flags_ {0}
 
int retries_ {3}
 
RetryDelayFn retry_delay_ {nullptr}
 
bool initialized_ {false}
 

Static Private Attributes

static constexpr uint8_t MODE1_RESTART_ = 0x80
 MODE1 bit 7: RESTART (Table 5)
 
static constexpr uint8_t MODE1_AI_ = 0x20
 MODE1 bit 5: register auto-increment.
 
static constexpr uint8_t MODE1_SLEEP_ = 0x10
 
static constexpr uint32_t OSC_STARTUP_FALLBACK_READS_ = 13
 MODE1 reads that cover OSC_STARTUP_US_ at 1 MHz SCL when the port has no DelayUs().
 

Detailed Description

template<typename I2cType>
class pca9685::PCA9685< I2cType >

Driver for the PCA9685 16-channel 12-bit PWM controller.

This class provides all register-level operations required to configure and operate the PCA9685, including frequency setting, per-channel PWM, and device reset.

All I2C operations are routed through the user-supplied I2cInterface.

Template Parameters
I2cTypeThe I2C interface implementation type that inherits from pca9685::I2cInterface<I2cType>
Note
The driver uses CRTP-based I2C interface for zero virtual call overhead.

Member Typedef Documentation

◆ RetryDelayFn

template<typename I2cType >
using pca9685::PCA9685< I2cType >::RetryDelayFn = void (*)()

Type of optional callback invoked between I2C retry attempts.

Set via SetRetryDelay(). No parameters, no return value. Called only after a failed Read/Write when retries remain (e.g. to perform a short delay for bus recovery).

Member Enumeration Documentation

◆ Error

template<typename I2cType >
enum class pca9685::PCA9685::Error : uint16_t
strong

Error codes for PCA9685 operations (bitmask flags).

Harmonized with PCAL95555 driver error model. Multiple errors can be active simultaneously. Use GetErrorFlags() and ClearErrorFlags() to inspect and clear errors.

Enumerator
None 
I2cWrite 

An I2C write operation failed.

I2cRead 

An I2C read operation failed.

InvalidParam 

Invalid parameter (channel, value, etc.)

DeviceNotFound 

Device did not respond.

NotInitialized 

Driver not initialized.

OutOfRange 

Value out of hardware range.

◆ Register

template<typename I2cType >
enum class pca9685::PCA9685::Register : uint8_t
strong

PCA9685 register map (I2C register addresses).

Enumerator
MODE1 

Mode register 1 (reset, sleep, auto-increment, etc.)

MODE2 

Mode register 2 (output drive, invert, output change behaviour)

SUBADR1 

I2C subaddress 1.

SUBADR2 

I2C subaddress 2.

SUBADR3 

I2C subaddress 3.

ALLCALLADR 

All-call I2C address.

LED0_ON_L 

LED0 output and brightness control byte 0 (on time, low byte)

LED0_ON_H 

LED0 output and brightness control byte 1 (on time, high bits + full-on)

LED0_OFF_L 

LED0 output and brightness control byte 2 (off time, low byte)

LED0_OFF_H 

LED0 output and brightness control byte 3 (off time, high bits + full-off)

ALL_LED_ON_L 

All LED on time, low byte.

ALL_LED_ON_H 

All LED on time, high bits.

ALL_LED_OFF_L 

All LED off time, low byte.

ALL_LED_OFF_H 

All LED off time, high bits.

PRE_SCALE 

Prescaler for PWM frequency (oscillator / (4096 * freq))

TESTMODE 

Test mode register.

Constructor & Destructor Documentation

◆ PCA9685()

template<typename I2cType >
pca9685::PCA9685< I2cType >::PCA9685 ( I2cType *  bus,
uint8_t  address 
)

Construct a new PCA9685 driver instance.

Parameters
busPointer to a user-implemented I2C interface (must inherit from pca9685::I2cInterface<I2cType>).
address7-bit I2C address of the PCA9685 device (0x00 to 0x7F).

Member Function Documentation

◆ calcPrescale()

template<typename I2cType >
uint8_t pca9685::PCA9685< I2cType >::calcPrescale ( float  freq_hz) const
privatenoexcept

Compute prescale value for given frequency.

Parameters
freq_hzFrequency in Hz.
Returns
Prescale value (0–255).

◆ ClearError()

template<typename I2cType >
void pca9685::PCA9685< I2cType >::ClearError ( Error  e)
inlinenoexcept

Clear a single error flag.

Parameters
eThe error flag to clear.

◆ ClearErrorFlags()

template<typename I2cType >
void pca9685::PCA9685< I2cType >::ClearErrorFlags ( uint16_t  mask = 0xFFFF)
inlinenoexcept

Clear specific error flags by raw bitmask.

Parameters
maskBitmask of Error values to clear (default: all).

◆ EnsureInitialized()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::EnsureInitialized ( )
noexcept

Ensure the driver and I2C bus are initialized (lazy initialization).

On first call, ensures the I2C bus is initialized via I2cInterface::EnsureInitialized(), then performs a device reset to confirm communication. On subsequent calls, returns true immediately if already initialized.

Returns
true if already initialized or initialization succeeded; false if I2C bus init or device communication failed.
Note
This mirrors the PCAL95555 driver's lazy initialization pattern.

◆ GetDriverVersion()

template<typename I2cType >
static constexpr const char * pca9685::PCA9685< I2cType >::GetDriverVersion ( )
inlinestaticconstexprnoexcept

Get the compiled driver version string.

Returns the version that was compiled into the binary, in "MAJOR.MINOR.PATCH" format. This is a static method — it can be called without a driver instance.

Returns
Null-terminated version string, e.g. "1.0.0".
ESP_LOGI("APP", "PCA9685 driver v%s", PCA9685::GetDriverVersion());
static constexpr const char * GetDriverVersion() noexcept
Get the compiled driver version string.
Definition pca9685.hpp:374

◆ GetDriverVersionMajor()

template<typename I2cType >
static constexpr uint8_t pca9685::PCA9685< I2cType >::GetDriverVersionMajor ( )
inlinestaticconstexprnoexcept

Get the compiled driver major version number.

Returns
Major version (incremented on breaking API changes).

◆ GetDriverVersionMinor()

template<typename I2cType >
static constexpr uint8_t pca9685::PCA9685< I2cType >::GetDriverVersionMinor ( )
inlinestaticconstexprnoexcept

Get the compiled driver minor version number.

Returns
Minor version (incremented on new features, backward-compatible).

◆ GetDriverVersionPatch()

template<typename I2cType >
static constexpr uint8_t pca9685::PCA9685< I2cType >::GetDriverVersionPatch ( )
inlinestaticconstexprnoexcept

Get the compiled driver patch version number.

Returns
Patch version (incremented on bug fixes).

◆ GetErrorFlags()

template<typename I2cType >
uint16_t pca9685::PCA9685< I2cType >::GetErrorFlags ( ) const
inlinenoexcept

Get the accumulated error flags (bitmask).

Returns
Bitmask of Error values; 0 (Error::None) means no errors.

◆ GetLastError()

template<typename I2cType >
Error pca9685::PCA9685< I2cType >::GetLastError ( ) const
inlinenoexcept

Get the last error code (single-error convenience accessor).

Returns
Error code from the most recent operation.

◆ GetPrescale()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::GetPrescale ( uint8_t &  prescale)
noexcept

Get the current prescale value (frequency divider).

Parameters
[out]prescaleThe prescale register value.
Returns
true on success; false on I2C failure.

◆ HasAnyError()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::HasAnyError ( ) const
inlinenoexcept

Check if any error flag is set.

Returns
true if one or more error flags are set.

◆ HasError()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::HasError ( Error  e) const
inlinenoexcept

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(PCA9685::Error::I2cWrite)) { ... }
@ I2cWrite
An I2C write operation failed.

◆ IsInitialized()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::IsInitialized ( ) const
inlinenoexcept

Check if the driver has been initialized.

Returns
true if EnsureInitialized() or Reset() has completed successfully.

◆ modifyReg()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::modifyReg ( uint8_t  reg,
uint8_t  mask,
uint8_t  value 
)
privatenoexcept

Read-modify-write a single register.

Parameters
regRegister address.
maskBits to modify.
valueNew value for those bits.
Returns
true on success.

◆ pwmFrame()

template<typename I2cType >
std::array< uint8_t, 4 > pca9685::PCA9685< I2cType >::pwmFrame ( uint16_t  on_time,
uint16_t  off_time 
)
staticprivatenoexcept

Build the four LEDn / ALL_LED bytes for ON and OFF ticks; equal ticks give full OFF.

Parameters
on_timeON tick (0-4095).
off_timeOFF tick (0-4095).
Returns
LEDn_ON_L, LEDn_ON_H, LEDn_OFF_L, LEDn_OFF_H.

◆ readReg()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::readReg ( uint8_t  reg,
uint8_t &  value 
)
privatenoexcept

Read one byte from a register.

Parameters
regRegister address.
[out]valueByte read.
Returns
true on success.

◆ readRegBlock()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::readRegBlock ( uint8_t  reg,
uint8_t *  data,
size_t  len 
)
privatenoexcept

Read a block of bytes from a register.

Parameters
regStart register.
dataBuffer.
lenLength.
Returns
true on success.

◆ Reset()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::Reset ( )
noexcept

Reset the device to its power-on default state.

Ensures the I2C bus is initialized, then writes MODE1 = 0x20: oscillator on (SLEEP = 0) and register auto-increment on (AI = 1), which the driver's four-byte channel writes need (datasheet 7.3.1, Table 5). Sub-address and All Call responses are turned off. The channel registers, MODE2 and PRE_SCALE are not touched. Returns after the 500 us oscillator start-up time (OSC_STARTUP_US_, datasheet Table 5 note 2).

Returns
true on success; false on I2C failure.

◆ restartAfterSleep()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::restartAfterSleep ( uint8_t  mode1,
bool  restart 
)
privatenoexcept

Clear SLEEP, wait for the oscillator, then optionally write RESTART (datasheet 7.3.1.1).

Parameters
mode1MODE1 value to keep (SLEEP and RESTART are overridden).
restarttrue to write 1 to RESTART after the start-up time.
Returns
true on success.

◆ SetAllPwm()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::SetAllPwm ( uint16_t  on_time,
uint16_t  off_time 
)
noexcept

Set all channels to the same PWM value.

Equal on_time and off_time write ALL_LED_OFF_H[4] (full OFF), as in SetPwm().

Parameters
on_timeTick count when signal turns ON (0-4095).
off_timeTick count when signal turns OFF (0-4095).
Returns
true on success; false on I2C failure.

◆ SetChannelFullOff()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::SetChannelFullOff ( uint8_t  channel)
noexcept

Set a channel to fully OFF (0% duty, no PWM).

Sets bit 12 of the LEDn_OFF register (full-off flag).

Parameters
channelChannel number (0-15).
Returns
true on success; false on I2C failure or invalid parameter.

◆ SetChannelFullOn()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::SetChannelFullOn ( uint8_t  channel)
noexcept

Set a channel to fully ON (100% duty, no PWM).

Sets bit 12 of the LEDn_ON register (full-on flag).

Parameters
channelChannel number (0-15).
Returns
true on success; false on I2C failure or invalid parameter.

◆ SetDuty()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::SetDuty ( uint8_t  channel,
float  duty 
)
noexcept

Set the duty cycle for a channel (0.0-1.0).

Writes ON = 0, OFF = lround(duty * 4095). The two ends use the full-OFF and full-ON bits (datasheet 7.3.3, Table 7, p. 24): a duty that rounds to OFF = 0 sets LEDn_OFF_H[4] (constantly low), and 1.0 sets LEDn_ON_H[4] (constantly high), so ON and OFF never hold the same count (7.3.4).

Parameters
channelChannel number (0-15).
dutyDuty cycle, clamped to 0.0 (always off) .. 1.0 (always on).
Returns
true on success; false on I2C failure or invalid parameter.

◆ setError()

template<typename I2cType >
void pca9685::PCA9685< I2cType >::setError ( Error  e)
inlineprivatenoexcept

Set last error and add to error flags.

◆ SetOutputDriverMode()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::SetOutputDriverMode ( bool  totem_pole)
noexcept

Set the output driver mode.

Configures outputs as either totem-pole (push-pull) or open-drain. Affects the OUTDRV bit in MODE2 register.

Parameters
totem_poletrue for totem-pole (default), false for open-drain.
Returns
true on success; false on I2C failure.

◆ SetOutputEnable()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::SetOutputEnable ( bool  enable)
noexcept

Enable or blank all 16 outputs with the OE pin.

OE is active LOW (datasheet 7.4, Table 11): with OE low the outputs follow their LEDn registers, with OE high they take the MODE2.OUTNE state (low by default). This calls the port's GpioSet(CtrlPin::OE, ACTIVE) to enable and GpioSet(CtrlPin::OE, INACTIVE) to blank; the port maps ACTIVE to a low level. No I2C traffic, and the chip need not be initialized. A port that does not declare GpioSet() inherits the no-op default, for OE tied low.

The driver never drives OE on its own, so a port can hold the outputs blanked from power-up until the channels are programmed.

Parameters
enabletrue to enable the outputs (OE low), false to blank them (OE high).
Returns
true if the request was passed to the port; false if no bus was given.

◆ SetOutputInvert()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::SetOutputInvert ( bool  invert)
noexcept

Set output polarity inversion.

When inverted, the output logic is inverted (useful for common-anode LEDs). Affects the INVRT bit in MODE2 register.

Parameters
inverttrue to invert outputs, false for normal polarity.
Returns
true on success; false on I2C failure.

◆ SetPwm()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::SetPwm ( uint8_t  channel,
uint16_t  on_time,
uint16_t  off_time 
)
noexcept

Set the PWM on/off time for a channel.

ON and OFF must never hold the same count (datasheet 7.3.4, p. 25): when on_time equals off_time (zero duty) the driver writes the full-OFF bit, LEDn_OFF_H[4], instead.

Parameters
channelChannel number (0-15).
on_timeTick count when signal turns ON (0-4095).
off_timeTick count when signal turns OFF (0-4095).
Returns
true on success; false on I2C failure or invalid parameter.

◆ SetPwmFreq()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::SetPwmFreq ( float  freq_hz)
noexcept

Set the PWM frequency for all channels.

PRE_SCALE is writable only while MODE1.SLEEP = 1, so the driver puts the chip to sleep, writes PRE_SCALE and, if the chip was running, clears SLEEP, waits OSC_STARTUP_US_ and writes RESTART so that the running channels resume (datasheet 7.3.1.1, 7.3.5). A sleeping chip stays asleep.

Parameters
freq_hzDesired frequency in Hz (24-1526 typical).
Returns
true on success; false on I2C failure or invalid parameter.

◆ SetRetries()

template<typename I2cType >
void pca9685::PCA9685< I2cType >::SetRetries ( int  retries)
inlinenoexcept

Set the I2C retry count for register read/write operations.

Parameters
retriesNumber of retries (0 = no retries, just one attempt).

◆ SetRetryDelay()

template<typename I2cType >
void pca9685::PCA9685< I2cType >::SetRetryDelay ( RetryDelayFn  fn)
inlinenoexcept

Set optional callback invoked between I2C retry attempts (after a failure, before next try).

Set to a function that performs a short delay (e.g. 1–5 ms) to allow bus recovery, or leave default (nullptr) for no delay. The driver calls this only when a Read/Write failed and retries remain.

Parameters
fnCallback function, or nullptr to use no delay.

◆ Sleep()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::Sleep ( )
noexcept

Put the PCA9685 into low-power sleep mode.

Sets the SLEEP bit in MODE1. All PWM outputs are disabled during sleep. The oscillator is stopped. Use Wake() to resume.

Returns
true on success; false on I2C failure.

◆ waitOscillatorStartup()

template<typename I2cType >
void pca9685::PCA9685< I2cType >::waitOscillatorStartup ( )
privatenoexcept

Wait OSC_STARTUP_US_ through I2cType::DelayUs(), or with MODE1 reads if the port has none.

◆ Wake()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::Wake ( )
noexcept

Wake the PCA9685 from sleep mode.

Follows the restart procedure of datasheet section 7.3.1.1: reads MODE1, clears SLEEP, waits OSC_STARTUP_US_ (500 us) for the oscillator, then writes 1 to RESTART if it read 1, so the channels that were running resume with their previous values. The wait goes through the port's DelayUs() (see I2cInterface); a port without one is timed with bus reads instead. Does nothing when the chip is already awake and RESTART is clear.

Returns
true on success; false on I2C failure.

◆ writeMode1()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::writeMode1 ( uint8_t  value)
privatenoexcept

Write MODE1 with AI forced to 1 and RESTART forced to 0.

Parameters
valueNew MODE1 value (the AI and RESTART bits are overridden).
Returns
true on success.

◆ writeReg()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::writeReg ( uint8_t  reg,
uint8_t  value 
)
privatenoexcept

Write one byte to a register.

Parameters
regRegister address.
valueByte to write.
Returns
true on success.

◆ writeRegBlock()

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::writeRegBlock ( uint8_t  reg,
const uint8_t *  data,
size_t  len 
)
privatenoexcept

Write a block of bytes to a register.

Parameters
regStart register.
dataBuffer.
lenLength.
Returns
true on success.

Member Data Documentation

◆ addr_

template<typename I2cType >
uint8_t pca9685::PCA9685< I2cType >::addr_
private

◆ error_flags_

template<typename I2cType >
uint16_t pca9685::PCA9685< I2cType >::error_flags_ {0}
private

◆ i2c_

template<typename I2cType >
I2cType* pca9685::PCA9685< I2cType >::i2c_
private

◆ initialized_

template<typename I2cType >
bool pca9685::PCA9685< I2cType >::initialized_ {false}
private

◆ last_error_

template<typename I2cType >
Error pca9685::PCA9685< I2cType >::last_error_ {Error::None}
private

◆ MAX_CHANNELS_

template<typename I2cType >
constexpr uint8_t pca9685::PCA9685< I2cType >::MAX_CHANNELS_ = 16
staticconstexpr

Number of PWM channels (0-15)

◆ MAX_PWM_

template<typename I2cType >
constexpr uint16_t pca9685::PCA9685< I2cType >::MAX_PWM_ = 4095
staticconstexpr

Maximum tick value (12-bit)

◆ MODE1_AI_

template<typename I2cType >
constexpr uint8_t pca9685::PCA9685< I2cType >::MODE1_AI_ = 0x20
staticconstexprprivate

MODE1 bit 5: register auto-increment.

◆ MODE1_RESTART_

template<typename I2cType >
constexpr uint8_t pca9685::PCA9685< I2cType >::MODE1_RESTART_ = 0x80
staticconstexprprivate

MODE1 bit 7: RESTART (Table 5)

◆ MODE1_SLEEP_

template<typename I2cType >
constexpr uint8_t pca9685::PCA9685< I2cType >::MODE1_SLEEP_ = 0x10
staticconstexprprivate

MODE1 bit 4: SLEEP (oscillator off)

◆ OSC_FREQ_

template<typename I2cType >
constexpr uint32_t pca9685::PCA9685< I2cType >::OSC_FREQ_ = 25000000
staticconstexpr

Internal oscillator frequency (Hz)

◆ OSC_STARTUP_FALLBACK_READS_

template<typename I2cType >
constexpr uint32_t pca9685::PCA9685< I2cType >::OSC_STARTUP_FALLBACK_READS_ = 13
staticconstexprprivate

MODE1 reads that cover OSC_STARTUP_US_ at 1 MHz SCL when the port has no DelayUs().

◆ OSC_STARTUP_US_

template<typename I2cType >
constexpr uint32_t pca9685::PCA9685< I2cType >::OSC_STARTUP_US_ = 500
staticconstexpr

Oscillator start-up time after MODE1.SLEEP is cleared, in microseconds (datasheet Table 5, note 2; section 7.3.1.1). The driver waits this long through the port's DelayUs().

◆ retries_

template<typename I2cType >
int pca9685::PCA9685< I2cType >::retries_ {3}
private

◆ retry_delay_

template<typename I2cType >
RetryDelayFn pca9685::PCA9685< I2cType >::retry_delay_ {nullptr}
private

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