|
HF-Core Platform 0.1.0-dev
Hardware-Agnostic Handler Layer & RTOS Utilities for HardFOC
|
BasePwm adapter for all 16 PCA9685 PWM channels. More...
#include <Pca9685Handler.h>
Public Member Functions | |
| Pca9685PwmAdapter (Pca9685Handler *parent_handler) noexcept | |
| Construct the PWM adapter. | |
| ~Pca9685PwmAdapter () noexcept override=default | |
| Default destructor. | |
BasePwm Interface Implementation | |
| hf_pwm_err_t | Initialize () noexcept override |
| Initialize the PWM adapter (ensures parent handler is initialized). | |
| hf_pwm_err_t | Deinitialize () noexcept override |
| Deinitialize (marks adapter as uninitialized). | |
| hf_pwm_err_t | EnableChannel (hf_channel_id_t channel_id) noexcept override |
| Enable a PWM channel (restore its duty cycle from cache). | |
| hf_pwm_err_t | DisableChannel (hf_channel_id_t channel_id) noexcept override |
| Disable a PWM channel (set to full-off). | |
| bool | IsChannelEnabled (hf_channel_id_t channel_id) const noexcept override |
| Check if a channel is enabled. | |
| hf_pwm_err_t | SetDutyCycle (hf_channel_id_t channel_id, float duty_cycle) noexcept override |
| Set duty cycle for a channel (0.0-1.0). | |
| hf_pwm_err_t | SetDutyCycleRaw (hf_channel_id_t channel_id, hf_u32_t raw_value) noexcept override |
| Set raw PWM tick value for a channel. | |
| hf_pwm_err_t | SetFrequency (hf_channel_id_t channel_id, hf_frequency_hz_t frequency_hz) noexcept override |
| Set PWM frequency (global – affects ALL channels). | |
| hf_pwm_err_t | SetPhaseShift (hf_channel_id_t channel_id, float phase_shift_degrees) noexcept override |
| Set phase shift for a channel (via PCA9685 on-time offset). | |
| hf_pwm_err_t | StartAll () noexcept override |
| Wake the PCA9685 from sleep (start all channels). | |
| hf_pwm_err_t | StopAll () noexcept override |
| Put the PCA9685 into sleep mode (stop all outputs). | |
| hf_pwm_err_t | UpdateAll () noexcept override |
| No-op (PCA9685 updates immediately on register write). | |
| hf_pwm_err_t | SetComplementaryOutput (hf_channel_id_t primary_channel, hf_channel_id_t complementary_channel, hf_u32_t deadtime_ns) noexcept override |
| Not supported by PCA9685. | |
| float | GetDutyCycle (hf_channel_id_t channel_id) const noexcept override |
| Get the cached duty cycle for a channel. | |
| hf_frequency_hz_t | GetFrequency (hf_channel_id_t channel_id) const noexcept override |
| Get the current PWM frequency (global). | |
Static Public Attributes | |
| static constexpr uint8_t | kMaxChannels = 16 |
| Number of PWM channels on the PCA9685. | |
| static constexpr uint8_t | kResolutionBits = 12 |
| PWM resolution in bits. | |
| static constexpr uint16_t | kMaxRawValue = 4095 |
| Maximum raw PWM value (2^12 - 1 = 4095). | |
| static constexpr uint32_t | kMinFrequencyHz = 24 |
| Minimum PWM frequency in Hz. | |
| static constexpr uint32_t | kMaxFrequencyHz = 1526 |
| Maximum PWM frequency in Hz. | |
Private Member Functions | |
| bool | validateChannel (hf_channel_id_t channel_id) const noexcept |
| Validate channel ID is in range 0-15. | |
Private Attributes | |
| Pca9685Handler * | parent_handler_ |
| Owning handler (not owned). | |
| hf_frequency_hz_t | current_frequency_hz_ = 200 |
| Current global frequency. | |
Per-Channel State Cache | |
| std::array< float, kMaxChannels > | duty_cache_ |
| Cached duty cycles (0.0-1.0). | |
| std::array< uint16_t, kMaxChannels > | on_time_cache_ |
| Cached on-time values (phase offset). | |
| std::array< bool, kMaxChannels > | channel_enabled_ |
| Channel enable state. | |
Friends | |
| class | Pca9685Handler |
| Allow handler to access internals. | |
BasePwm adapter for all 16 PCA9685 PWM channels.
Wraps the PCA9685's 16 PWM channels as a HardFOC BasePwm instance. All hardware operations delegate to the parent Pca9685Handler, which in turn calls the typed PCA9685 driver.
|
explicitnoexcept |
Construct the PWM adapter.
| parent_handler | Pointer to the owning handler (must not be null). |
|
overridedefaultnoexcept |
Default destructor.
|
overridenoexcept |
Deinitialize (marks adapter as uninitialized).
|
overridenoexcept |
Disable a PWM channel (set to full-off).
| channel_id | Channel number (0-15). |
|
overridenoexcept |
Enable a PWM channel (restore its duty cycle from cache).
| channel_id | Channel number (0-15). |
|
overridenoexcept |
Get the cached duty cycle for a channel.
| channel_id | Channel number (0-15). |
|
overridenoexcept |
Get the current PWM frequency (global).
| channel_id | Ignored (frequency is global). |
|
overridenoexcept |
Initialize the PWM adapter (ensures parent handler is initialized).
|
overridenoexcept |
Check if a channel is enabled.
| channel_id | Channel number (0-15). |
|
overridenoexcept |
Not supported by PCA9685.
|
overridenoexcept |
Set duty cycle for a channel (0.0-1.0).
| channel_id | Channel number (0-15). |
| duty_cycle | Duty cycle (0.0 = off, 1.0 = full on). |
|
overridenoexcept |
Set raw PWM tick value for a channel.
| channel_id | Channel number (0-15). |
| raw_value | Off-time tick count (0-4095). |
|
overridenoexcept |
Set PWM frequency (global – affects ALL channels).
The PCA9685 has a single prescaler so frequency is shared across all 16 channels. The channel_id parameter is accepted for API conformance but the frequency change applies globally.
| channel_id | Ignored (frequency is global). |
| frequency_hz | Frequency in Hz (24-1526). |
|
overridenoexcept |
Set phase shift for a channel (via PCA9685 on-time offset).
The PCA9685 supports staggered outputs by programming different on-time values per channel. This maps to phase shift: on_time = (phase_degrees / 360.0) * 4096
| channel_id | Channel number (0-15). |
| phase_shift_degrees | Phase offset in degrees (0-360). |
|
overridenoexcept |
Wake the PCA9685 from sleep (start all channels).
|
overridenoexcept |
Put the PCA9685 into sleep mode (stop all outputs).
|
overridenoexcept |
No-op (PCA9685 updates immediately on register write).
|
inlineprivatenoexcept |
Validate channel ID is in range 0-15.
|
friend |
Allow handler to access internals.
|
private |
Channel enable state.
|
private |
Current global frequency.
|
private |
Cached duty cycles (0.0-1.0).
|
staticconstexpr |
Number of PWM channels on the PCA9685.
|
staticconstexpr |
Maximum PWM frequency in Hz.
|
staticconstexpr |
Maximum raw PWM value (2^12 - 1 = 4095).
|
staticconstexpr |
Minimum PWM frequency in Hz.
|
staticconstexpr |
PWM resolution in bits.
|
private |
Cached on-time values (phase offset).
|
private |
Owning handler (not owned).