Unified, non-templated handler for a single PCA9685 PWM controller.
More...
#include <Pca9685Handler.h>
|
Create BasePwm and BaseGpio wrappers for manager-layer usage.
|
| uint8_t | GetI2cAddress () const noexcept |
| | Get the I2C address of the underlying device.
|
| |
| std::shared_ptr< BasePwm > | GetPwmAdapter () noexcept |
| | Get or create the BasePwm adapter for all 16 channels.
|
| |
| std::shared_ptr< BaseGpio > | CreateGpioPin (hf_pin_num_t channel, hf_gpio_active_state_t active_state=hf_gpio_active_state_t::HF_GPIO_ACTIVE_HIGH, bool allow_existing=true) noexcept |
| | Create or retrieve a BaseGpio pin wrapper for a channel.
|
| |
| std::shared_ptr< BaseGpio > | GetGpioPin (hf_pin_num_t channel) noexcept |
| | Get an existing GPIO pin wrapper by channel number.
|
| |
| bool | IsPinCreated (hf_pin_num_t channel) const noexcept |
| | Check if a GPIO pin wrapper has been created for a channel.
|
| |
| static constexpr uint8_t | ChannelCount () noexcept |
| | Total number of PWM channels.
|
| |
Unified, non-templated handler for a single PCA9685 PWM controller.
Pca9685Handler is the primary interface that application and manager code uses to interact with a PCA9685 PWM controller. It hides the template complexity of pca9685::PCA9685<I2cType> behind a clean public API.
Design Decisions
- Non-templated: The handler owns a concrete typed driver instance (pca9685::PCA9685<HalI2cPca9685Comm>) internally. Since only one I2C communication type is used per handler, no dispatch mechanism is needed.
- Lazy initialization: The driver and adapter are created in Initialize(), not in the constructor.
- Dual-purpose channels: Each channel can be used as either:
- A PWM output (via the Pca9685PwmAdapter / BasePwm interface)
- A digital output (via Pca9685GpioPin / BaseGpio interface) Using both simultaneously for the same channel is allowed but the last write wins.
- See also
- HalI2cPca9685Comm I2C communication adapter
-
Pca9685PwmAdapter Multi-channel BasePwm wrapper
-
Pca9685GpioPin Per-channel BaseGpio wrapper
◆ Pca9685Driver
Typed PCA9685 driver using our I2C adapter.
◆ Pca9685Handler() [1/3]
| Pca9685Handler::Pca9685Handler |
( |
BaseI2c & | i2c_device | ) |
|
|
explicitnoexcept |
Construct a handler for a PCA9685 device.
The I2C adapter and driver are not created until EnsureInitialized() or the first operation that requires them.
- Parameters
-
| i2c_device | Reference to a BaseI2c device with address pre-configured (typically 0x40-0x7F). Must outlive the handler. |
◆ ~Pca9685Handler()
| Pca9685Handler::~Pca9685Handler |
( |
| ) |
|
|
defaultnoexcept |
Destructor. Releases driver, adapter, and all wrappers.
◆ Pca9685Handler() [2/3]
◆ Pca9685Handler() [3/3]
◆ ChannelCount()
| static constexpr uint8_t Pca9685Handler::ChannelCount |
( |
| ) |
|
|
inlinestaticconstexprnoexcept |
Total number of PWM channels.
◆ ClearErrorFlags()
| void Pca9685Handler::ClearErrorFlags |
( |
uint16_t | mask = 0xFFFF | ) |
|
|
noexcept |
Clear driver error flags.
- Parameters
-
| mask | Bitmask of flags to clear (default: all). |
◆ CreateGpioPin()
| std::shared_ptr< BaseGpio > Pca9685Handler::CreateGpioPin |
( |
hf_pin_num_t | channel, |
|
|
hf_gpio_active_state_t | active_state = hf_gpio_active_state_t::HF_GPIO_ACTIVE_HIGH, |
|
|
bool | allow_existing = true ) |
|
noexcept |
Create or retrieve a BaseGpio pin wrapper for a channel.
Uses the channel as a digital output (fully on / fully off). If a wrapper for the channel already exists and allow_existing is true, the existing instance is returned.
- Parameters
-
| channel | Channel number (0-15). |
| active_state | Active polarity (default: active high). |
| allow_existing | If true, returns existing wrapper; if false, fails if exists. |
- Returns
- shared_ptr<BaseGpio> or nullptr on failure.
◆ deinitializeInternal()
| hf_pwm_err_t Pca9685Handler::deinitializeInternal |
( |
| ) |
|
|
privatenoexcept |
Internal deinitialization.
◆ DumpDiagnostics()
| void Pca9685Handler::DumpDiagnostics |
( |
| ) |
const |
|
noexcept |
Dump comprehensive diagnostics to the system log.
◆ EnsureDeinitialized()
| bool Pca9685Handler::EnsureDeinitialized |
( |
| ) |
|
|
noexcept |
Deinitialize the handler and release resources.
- Returns
- true if already deinitialized or deinitialization succeeded.
◆ EnsureInitialized()
| bool Pca9685Handler::EnsureInitialized |
( |
| ) |
|
|
noexcept |
Ensure the handler is initialized (lazy initialization).
On first call, creates the I2C adapter and driver, runs the driver's EnsureInitialized() (which resets the device).
- Returns
- true if already initialized or initialization succeeded.
◆ ensureInitializedLocked()
| bool Pca9685Handler::ensureInitializedLocked |
( |
| ) |
|
|
privatenoexcept |
Check init under already-held handler_mutex_.
◆ GetDriver() [1/2]
◆ GetDriver() [2/2]
Get the underlying PCA9685 driver for advanced register-level operations.
- Returns
- Pointer to the CRTP driver, or nullptr if not initialized.
◆ GetErrorFlags()
| uint16_t Pca9685Handler::GetErrorFlags |
( |
| ) |
const |
|
noexcept |
Get the driver's error flags.
- Returns
- 16-bit error flag bitmask (see pca9685::PCA9685::Error enum).
◆ GetGpioPin()
| std::shared_ptr< BaseGpio > Pca9685Handler::GetGpioPin |
( |
hf_pin_num_t | channel | ) |
|
|
noexcept |
Get an existing GPIO pin wrapper by channel number.
- Parameters
-
| channel | Channel number (0-15). |
- Returns
- shared_ptr<BaseGpio> or nullptr if not created.
◆ GetI2cAddress()
| uint8_t Pca9685Handler::GetI2cAddress |
( |
| ) |
const |
|
noexcept |
Get the I2C address of the underlying device.
- Returns
- 7-bit I2C address, or 0 if driver not created.
◆ GetPwmAdapter()
| std::shared_ptr< BasePwm > Pca9685Handler::GetPwmAdapter |
( |
| ) |
|
|
noexcept |
Get or create the BasePwm adapter for all 16 channels.
The adapter is created on first call and cached. Subsequent calls return the same shared_ptr.
- Returns
- shared_ptr<BasePwm> or nullptr on failure.
◆ initializeInternal()
| hf_pwm_err_t Pca9685Handler::initializeInternal |
( |
| ) |
|
|
privatenoexcept |
Internal initialization (called under mutex).
◆ IsInitialized()
| bool Pca9685Handler::IsInitialized |
( |
| ) |
const |
|
inlinenoexcept |
Check if the handler has been initialized.
- Returns
- true if initialized, false otherwise.
◆ IsPinCreated()
| bool Pca9685Handler::IsPinCreated |
( |
hf_pin_num_t | channel | ) |
const |
|
noexcept |
Check if a GPIO pin wrapper has been created for a channel.
- Parameters
-
| channel | Channel number (0-15). |
- Returns
- true if the wrapper exists in the registry.
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ SetAllPwm()
| bool Pca9685Handler::SetAllPwm |
( |
uint16_t | on_time, |
|
|
uint16_t | off_time ) |
|
privatenoexcept |
◆ SetChannelFullOff()
| bool Pca9685Handler::SetChannelFullOff |
( |
uint8_t | channel | ) |
|
|
privatenoexcept |
◆ SetChannelFullOn()
| bool Pca9685Handler::SetChannelFullOn |
( |
uint8_t | channel | ) |
|
|
privatenoexcept |
◆ SetDuty()
| bool Pca9685Handler::SetDuty |
( |
uint8_t | channel, |
|
|
float | duty ) |
|
privatenoexcept |
◆ SetFrequency()
| bool Pca9685Handler::SetFrequency |
( |
float | freq_hz | ) |
|
|
privatenoexcept |
◆ SetOutputDriverMode()
| bool Pca9685Handler::SetOutputDriverMode |
( |
bool | totem_pole | ) |
|
|
privatenoexcept |
◆ SetOutputInvert()
| bool Pca9685Handler::SetOutputInvert |
( |
bool | invert | ) |
|
|
privatenoexcept |
◆ SetPwm()
| bool Pca9685Handler::SetPwm |
( |
uint8_t | channel, |
|
|
uint16_t | on_time, |
|
|
uint16_t | off_time ) |
|
privatenoexcept |
◆ Sleep()
| bool Pca9685Handler::Sleep |
( |
| ) |
|
|
privatenoexcept |
◆ validateChannel()
| bool Pca9685Handler::validateChannel |
( |
uint8_t | channel | ) |
const |
|
inlineprivatenoexcept |
Validate channel number (0-15).
◆ Wake()
| bool Pca9685Handler::Wake |
( |
| ) |
|
|
privatenoexcept |
◆ Pca9685GpioPin
◆ Pca9685PwmAdapter
Allow wrapper classes to access private driver.
◆ gpio_registry_
| std::array<std::shared_ptr<Pca9685GpioPin>, 16> Pca9685Handler::gpio_registry_ |
|
private |
◆ handler_mutex_
| RtosMutex Pca9685Handler::handler_mutex_ |
|
mutableprivate |
Thread safety for all operations.
◆ i2c_adapter_
I2C adapter (created in init).
◆ i2c_device_
| BaseI2c& Pca9685Handler::i2c_device_ |
|
private |
I2C device reference (not owned).
◆ initialized_
| bool Pca9685Handler::initialized_ = false |
|
private |
◆ pca9685_driver_
Typed driver (created in init).
◆ pwm_adapter_
The documentation for this class was generated from the following files: