|
HF-PCA9685 0.1.0-dev
|
Hardware-agnostic C++ driver for the NXP PCA9685 16-channel 12-bit PWM controller
š šš Live Complete Documentation - Interactive guides, examples, and step-by-step tutorials
The PCA9685 is a 16-channel, 12-bit PWM controller from NXP Semiconductors that communicates via I²C. It provides independent PWM control for up to 16 outputs with 12-bit resolution (4096 steps), making it ideal for driving LEDs, servos, and other PWM-controlled devices. The chip features an internal 25 MHz oscillator, configurable PWM frequency from 24 Hz to 1526 Hz, and supports daisy-chaining multiple devices for up to 992 PWM outputs.
This driver provides a hardware-agnostic C++ interface that abstracts all register-level operations, requiring only an implementation of the I2cInterface for your platform. The driver uses the CRTP (Curiously Recurring Template Pattern) for zero-overhead hardware abstraction, making it suitable for resource-constrained embedded systems.
uint16_t) via GetErrorFlags() / ClearErrorFlags()SetDuty() method for easy 0.0-1.0 controlSetAllPwm() for simultaneous channel updatesSleep() / Wake() via MODE1 SLEEP bitSetOutputInvert(), SetOutputDriverMode() (totem-pole/open-drain)SetChannelFullOn() / SetChannelFullOff() without PWMSetRetries()For detailed setup, see Installation and Quick Start Guide.
For detailed installation instructions, see docs/installation.md.
| Method | Description |
|---|---|
Reset() | Reset device to power-on default state |
SetPwmFreq(float freq_hz) | Set PWM frequency (24-1526 Hz) |
SetPwm(uint8_t channel, uint16_t on, uint16_t off) | Set PWM timing for a channel |
SetDuty(uint8_t channel, float duty) | Set duty cycle (0.0-1.0) for a channel |
SetAllPwm(uint16_t on, uint16_t off) | Set all channels simultaneously |
SetChannelFullOn(uint8_t channel) | Set channel fully on (no PWM) |
SetChannelFullOff(uint8_t channel) | Set channel fully off (no PWM) |
Sleep() / Wake() | Power management via MODE1 SLEEP bit |
SetOutputInvert(bool invert) | Set MODE2 INVRT bit |
SetOutputDriverMode(bool totem_pole) | Set MODE2 OUTDRV bit (true=totem-pole, false=open-drain) |
SetRetries(int retries) | Configure I2C retry count |
GetLastError() | Get the last error code (convenience accessor) |
GetErrorFlags() | Get all error flags as uint16_t bitmask |
ClearErrorFlags(uint16_t mask) | Clear specific error flags |
GetPrescale(uint8_t &prescale) | Get current prescale value |
For complete API documentation with source code links, see docs/api_reference.md.
For complete documentation, see the docs directory.
Pull requests and suggestions are welcome! Please follow the existing code style and include tests for new features.
This project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE) file for details.