|
HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
|
ESP32 PWM implementation using LEDC peripheral with comprehensive ESP32 variant support. More...
#include <EspPwm.h>
Classes | |
| struct | ChannelState |
| Internal channel state with per-channel callback support. More... | |
| struct | ComplementaryPair |
| Complementary output pair configuration. More... | |
| struct | TimerState |
| Internal timer state. More... | |
| struct | ValidationContext |
| Simple validation context for frequency/resolution validation. More... | |
| struct | ValidationResult |
| Comprehensive validation result with detailed information. More... | |
Public Member Functions | |
| EspPwm (const hf_pwm_unit_config_t &config=hf_pwm_unit_config_t{}) noexcept | |
| Constructor for ESP32C6 PWM controller. | |
| virtual | ~EspPwm () noexcept override |
| Destructor - ensures clean shutdown. | |
| EspPwm (const EspPwm &)=delete | |
| EspPwm & | operator= (const EspPwm &)=delete |
| EspPwm (EspPwm &&)=delete | |
| EspPwm & | operator= (EspPwm &&)=delete |
| hf_pwm_err_t | Initialize () noexcept override |
| Initialize the LEDC peripheral and PWM subsystem. | |
| hf_pwm_err_t | Deinitialize () noexcept override |
| Deinitialize the LEDC peripheral and release all resources. | |
| hf_pwm_err_t | SetMode (hf_pwm_mode_t mode) noexcept |
| Set PWM operating mode. | |
| hf_pwm_mode_t | GetMode () const noexcept |
| Get current PWM operating mode. | |
| hf_pwm_err_t | ConfigureChannel (hf_channel_id_t channel_id, const hf_pwm_channel_config_t &config) noexcept |
| Configure a PWM channel with comprehensive LEDC feature support. | |
| hf_pwm_err_t | DeconfigureChannel (hf_channel_id_t channel_id) noexcept |
| Deconfigure a channel and release all associated resources. | |
| hf_pwm_err_t | EnableChannel (hf_channel_id_t channel_id) noexcept override |
| Enable a configured PWM channel to start signal generation. | |
| hf_pwm_err_t | DisableChannel (hf_channel_id_t channel_id) noexcept override |
| Disable a PWM channel and stop signal generation. | |
| bool | IsChannelEnabled (hf_channel_id_t channel_id) const noexcept override |
| Check if a PWM channel is currently enabled. | |
| hf_pwm_err_t | SetDutyCycle (hf_channel_id_t channel_id, float duty_cycle) noexcept override |
| Set PWM duty cycle as a percentage (0.0 to 1.0) | |
| hf_pwm_err_t | SetDutyCycleRaw (hf_channel_id_t channel_id, hf_u32_t raw_value) noexcept override |
| Set PWM duty cycle using raw timer counts. | |
| hf_pwm_err_t | SetFrequency (hf_channel_id_t channel_id, hf_frequency_hz_t frequency_hz) noexcept override |
| Set PWM frequency with automatic timer management. | |
| hf_pwm_err_t | SetPhaseShift (hf_channel_id_t channel_id, float phase_shift_degrees) noexcept override |
| Set PWM phase shift (ESP32 LEDC limitation: not supported) | |
| hf_pwm_err_t | SetFrequencyWithResolution (hf_channel_id_t channel_id, hf_frequency_hz_t frequency_hz, hf_u8_t resolution_bits) noexcept |
| Set frequency with explicit resolution choice (user-controlled) | |
| hf_pwm_err_t | SetFrequencyWithAutoFallback (hf_channel_id_t channel_id, hf_frequency_hz_t frequency_hz, hf_u8_t preferred_resolution) noexcept |
| Set frequency with automatic fallback to alternative resolutions. | |
| hf_pwm_err_t | SetResolution (hf_channel_id_t channel_id, hf_u8_t resolution_bits) noexcept |
| Set PWM resolution for a channel. | |
| hf_u8_t | GetResolution (hf_channel_id_t channel_id) const noexcept |
| Get current PWM resolution for a channel. | |
| hf_pwm_err_t | SetFrequencyAndResolution (hf_channel_id_t channel_id, hf_frequency_hz_t frequency_hz, hf_u8_t resolution_bits) noexcept |
| Set frequency and resolution together (atomic operation) | |
| hf_pwm_err_t | EnableAutoFallback () noexcept |
| Enable automatic fallback to alternative resolutions. | |
| hf_pwm_err_t | DisableAutoFallback () noexcept |
| Disable automatic fallback to alternative resolutions. | |
| bool | IsAutoFallbackEnabled () const noexcept |
| Check if auto-fallback mode is enabled. | |
| hf_pwm_err_t | StartAll () noexcept override |
| Start all configured PWM channels simultaneously. | |
| hf_pwm_err_t | StopAll () noexcept override |
| Stop all enabled PWM channels simultaneously. | |
| hf_pwm_err_t | UpdateAll () noexcept override |
| Update all enabled PWM channels with their current settings. | |
| hf_pwm_err_t | SetComplementaryOutput (hf_channel_id_t primary_channel, hf_channel_id_t complementary_channel, hf_u32_t deadtime_ns) noexcept override |
| Configure complementary PWM output pair with deadtime. | |
| float | GetDutyCycle (hf_channel_id_t channel_id) const noexcept override |
| Get current duty cycle as a percentage. | |
| hf_frequency_hz_t | GetFrequency (hf_channel_id_t channel_id) const noexcept override |
| Get current PWM frequency in Hz. | |
| hf_pwm_err_t | GetChannelStatus (hf_channel_id_t channel_id, hf_pwm_channel_status_t &status) const noexcept |
| Get comprehensive channel status and configuration. | |
| hf_pwm_err_t | GetCapabilities (hf_pwm_capabilities_t &capabilities) const noexcept |
| Get ESP32 variant-specific PWM capabilities. | |
| hf_pwm_err_t | GetLastError (hf_channel_id_t channel_id) const noexcept |
| Get the last error code for a specific channel. | |
| hf_pwm_err_t | SetChannelFadeCallback (hf_channel_id_t channel_id, void(*callback)(hf_channel_id_t)) noexcept |
| Set per-channel callback for PWM fade completion events. | |
| hf_pwm_err_t | SetHardwareFade (hf_channel_id_t channel_id, float target_duty_cycle, hf_u32_t fade_time_ms) noexcept |
| Set hardware fade for smooth duty cycle transitions. | |
| hf_pwm_err_t | StopHardwareFade (hf_channel_id_t channel_id) noexcept |
| Stop hardware fade for a channel. | |
| bool | IsFadeActive (hf_channel_id_t channel_id) const noexcept |
| Check if hardware fade is active on a channel. | |
| hf_pwm_err_t | SetIdleLevel (hf_channel_id_t channel_id, hf_u8_t idle_level) noexcept |
| Set idle output level for a channel. | |
| int8_t | GetTimerAssignment (hf_channel_id_t channel_id) const noexcept |
| Get current timer assignment for a channel. | |
| hf_pwm_err_t | ForceTimerAssignment (hf_channel_id_t channel_id, hf_u8_t timer_id) noexcept |
| Force a specific timer for a channel (advanced usage) | |
| hf_pwm_err_t | SetEvictionPolicy (hf_pwm_eviction_policy_t policy) noexcept |
| Set timer eviction policy for resource management. | |
| hf_pwm_eviction_policy_t | GetEvictionPolicy () const noexcept |
| Get current eviction policy. | |
| hf_pwm_err_t | SetEvictionCallback (hf_pwm_eviction_callback_t callback, void *user_data=nullptr) noexcept |
| Set eviction consent callback for user-controlled eviction. | |
| hf_pwm_err_t | SetChannelPriority (hf_channel_id_t channel_id, hf_pwm_channel_priority_t priority) noexcept |
| Set channel priority for eviction decisions. | |
| hf_pwm_channel_priority_t | GetChannelPriority (hf_channel_id_t channel_id) const noexcept |
| Get channel priority. | |
| hf_pwm_err_t | SetChannelCritical (hf_channel_id_t channel_id, bool is_critical) noexcept |
| Mark channel as critical (never evict) | |
| bool | IsChannelCritical (hf_channel_id_t channel_id) const noexcept |
| Check if channel is marked as critical. | |
| hf_pwm_err_t | GetStatistics (hf_pwm_statistics_t &statistics) const noexcept override |
| Get PWM statistics. | |
| hf_pwm_err_t | GetDiagnostics (hf_pwm_diagnostics_t &diagnostics) const noexcept override |
| Get PWM diagnostics. | |
Public Member Functions inherited from BasePwm | |
| virtual | ~BasePwm () noexcept=default |
| bool | IsInitialized () const noexcept |
| Check if PWM system is initialized. | |
| bool | EnsureInitialized () noexcept |
| Ensure PWM is initialized (lazy initialization pattern) | |
| bool | EnsureDeinitialized () noexcept |
| Ensure PWM is deinitialized (lazy deinitialization pattern) | |
| virtual hf_pwm_err_t | ResetStatistics () noexcept |
| Reset PWM operation statistics. | |
| virtual hf_pwm_err_t | ResetDiagnostics () noexcept |
| Reset PWM diagnostic information. | |
Static Public Attributes | |
| static constexpr hf_u8_t | MAX_CHANNELS = HF_PWM_MAX_CHANNELS |
| Maximum PWM channels. | |
| static constexpr hf_u8_t | MAX_TIMERS = HF_PWM_MAX_TIMERS |
| Maximum timer groups. | |
| static constexpr hf_u8_t | MAX_RESOLUTION = HF_PWM_MAX_RESOLUTION |
| Maximum resolution bits. | |
| static constexpr hf_u32_t | MIN_FREQUENCY = HF_PWM_MIN_FREQUENCY |
| Minimum frequency (Hz) | |
| static constexpr hf_u32_t | MAX_FREQUENCY = HF_PWM_MAX_FREQUENCY |
| Maximum frequency (Hz) | |
Private Member Functions | |
| bool | IsValidChannelId (hf_channel_id_t channel_id) const noexcept |
| Validate channel ID. | |
| hf_i8_t | FindOrAllocateTimer (hf_u32_t frequency_hz, hf_u8_t resolution_bits, hf_pwm_clock_source_t clock_source) noexcept |
| Unified timer allocation with comprehensive strategy. | |
| void | ReleaseTimerIfUnused (hf_u8_t timer_id) noexcept |
| Release a timer if no longer needed with hardware cleanup. | |
| hf_pwm_err_t | ConfigurePlatformTimer (hf_u8_t timer_id, hf_u32_t frequency_hz, hf_u8_t resolution_bits, hf_pwm_clock_source_t clock_source) noexcept |
| Configure platform timer with LEDC peripheral integration. | |
| hf_pwm_err_t | ConfigurePlatformChannel (hf_channel_id_t channel_id, const hf_pwm_channel_config_t &config, hf_u8_t timer_id) noexcept |
| Configure platform channel. | |
| hf_pwm_err_t | UpdatePlatformDuty (hf_channel_id_t channel_id, hf_u32_t raw_duty_value) noexcept |
| Update platform duty cycle. | |
| void | SetChannelError (hf_channel_id_t channel_id, hf_pwm_err_t error) noexcept |
| Set error for a channel. | |
| void | HandleFadeComplete (hf_channel_id_t channel_id) noexcept |
| Handle fade complete interrupt. | |
| hf_pwm_err_t | RegisterLedcFadeCallback (hf_channel_id_t channel_id) noexcept |
| Register LEDC fade callback using ESP-IDF API. | |
| hf_pwm_err_t | UnregisterLedcFadeCallback (hf_channel_id_t channel_id) noexcept |
| Unregister LEDC fade callback. | |
| hf_pwm_err_t | InitializeFadeFunctionality () noexcept |
| Initialize LEDC fade functionality. | |
| hf_pwm_err_t | InitializeTimers () noexcept |
| Initialize PWM timers. | |
| hf_pwm_err_t | InitializeChannels () noexcept |
| Initialize PWM channels. | |
| hf_pwm_err_t | EnableFade () noexcept |
| Enable fade functionality. | |
| hf_u32_t | CalculateClockDivider (hf_u32_t frequency_hz, hf_u8_t resolution_bits) const noexcept |
| Calculate optimal clock divider for frequency. | |
| ValidationResult | ValidateFrequencyResolutionComplete (const ValidationContext &context) const noexcept |
| Unified comprehensive validation for frequency/resolution combinations. | |
| hf_u32_t | GetSourceClockFrequency (hf_pwm_clock_source_t clock_source) const noexcept |
| Get source clock frequency for a given clock source. | |
| hf_u8_t | CalculateMaxResolution (hf_u32_t frequency_hz, hf_pwm_clock_source_t clock_source=hf_pwm_clock_source_t::HF_PWM_CLK_SRC_APB) const noexcept |
| Calculate maximum achievable resolution for a given frequency. | |
| hf_u32_t | CalculateMaxFrequency (hf_u8_t resolution_bits, hf_pwm_clock_source_t clock_source=hf_pwm_clock_source_t::HF_PWM_CLK_SRC_APB) const noexcept |
| Calculate maximum achievable frequency for a given resolution. | |
| bool | ValidateDutyCycleRange (hf_u32_t raw_duty, hf_u8_t resolution_bits) const noexcept |
| Enhanced duty cycle validation with overflow protection. | |
| bool | IsClockSourceCompatible (hf_pwm_clock_source_t timer_clock, hf_pwm_clock_source_t requested_clock) const noexcept |
| Check if two clock sources are compatible for timer sharing. | |
| hf_u8_t | FindBestAlternativeResolutionDynamic (hf_u32_t frequency_hz, hf_u8_t preferred_resolution, hf_pwm_clock_source_t clock_source=hf_pwm_clock_source_t::HF_PWM_CLK_SRC_APB) const noexcept |
| Find best alternative resolution using dynamic calculation. | |
| void | NotifyTimerReconfiguration (hf_u8_t timer_id, hf_u32_t new_frequency, hf_u8_t resolution_bits) noexcept |
| Notify channels that their timer has been reconfigured. | |
| std::string | GetTimerUsageInfo (hf_u8_t timer_id) const noexcept |
| Get timer usage information for debugging. | |
| hf_u8_t | PerformTimerHealthCheck () noexcept |
| Perform comprehensive timer health check and cleanup. | |
| hf_i8_t | AttemptSafeEviction (hf_u32_t frequency_hz, hf_u8_t resolution_bits) noexcept |
| Attempt safe timer eviction based on user policy. | |
| hf_i8_t | AttemptEvictionWithConsent (hf_u32_t frequency_hz, hf_u8_t resolution_bits) noexcept |
| Attempt eviction with user consent callback. | |
| hf_i8_t | AttemptEvictionNonCritical (hf_u32_t frequency_hz, hf_u8_t resolution_bits) noexcept |
| Attempt eviction of non-critical channels only. | |
| hf_i8_t | AttemptForceEviction (hf_u32_t frequency_hz, hf_u8_t resolution_bits) noexcept |
| Attempt aggressive eviction (original behavior) | |
Static Private Member Functions | |
| static void IRAM_ATTR | InterruptHandler (hf_channel_id_t channel_id, void *user_data) noexcept |
| Platform-specific interrupt handler. | |
| static bool IRAM_ATTR | LedcFadeEndCallback (const ledc_cb_param_t *param, void *user_arg) noexcept |
| Static ESP-IDF LEDC fade callback handler (C-compatible) | |
Private Attributes | |
| PlatformMutex | mutex_ |
| Thread safety mutex. | |
| std::atomic< bool > | initialized_ |
| Initialization state (atomic for lazy init) | |
| hf_u32_t | base_clock_hz_ |
| Base clock frequency. | |
| hf_pwm_clock_source_t | clock_source_ |
| Current clock source. | |
| std::array< ChannelState, MAX_CHANNELS > | channels_ |
| Channel states. | |
| std::array< TimerState, MAX_TIMERS > | timers_ |
| Timer states. | |
| std::array< ComplementaryPair, MAX_CHANNELS/2 > | complementary_pairs_ |
| Complementary pairs. | |
| hf_pwm_err_t | last_global_error_ |
| Last global error. | |
| bool | fade_functionality_installed_ |
| LEDC fade functionality installed. | |
| hf_pwm_unit_config_t | unit_config_ |
| Unit configuration. | |
| hf_pwm_mode_t | current_mode_ |
| Current operating mode. | |
| hf_pwm_statistics_t | statistics_ |
| PWM statistics. | |
| hf_pwm_diagnostics_t | diagnostics_ |
| PWM diagnostics. | |
| bool | auto_fallback_enabled_ |
| Whether to automatically try alternative resolutions. | |
| hf_pwm_eviction_policy_t | eviction_policy_ |
| Timer eviction policy (default: STRICT_NO_EVICTION) | |
| hf_pwm_eviction_callback_t | eviction_callback_ |
| User callback for eviction consent. | |
| void * | eviction_callback_user_data_ |
| User data for eviction callback. | |
Additional Inherited Members | |
Static Public Member Functions inherited from BasePwm | |
| static constexpr hf_u32_t | DutyCycleToRaw (float duty_cycle, hf_u8_t resolution_bits) noexcept |
| Calculate raw duty value from percentage. | |
| static constexpr float | RawToDutyCycle (hf_u32_t raw_value, hf_u8_t resolution_bits) noexcept |
| Calculate duty cycle percentage from raw value. | |
| static constexpr bool | IsValidDutyCycle (float duty_cycle) noexcept |
| Validate duty cycle range. | |
| static constexpr bool | IsValidFrequency (hf_u32_t frequency_hz, hf_u32_t min_freq_hz, hf_u32_t max_freq_hz) noexcept |
| Validate frequency range. | |
| static constexpr bool | IsValidRawDuty (hf_u32_t raw_value, hf_u8_t resolution_bits) noexcept |
| Validate raw duty value against resolution. | |
| static constexpr float | CalculateFrequencyAccuracy (hf_u32_t target_freq, hf_u32_t actual_freq) noexcept |
| Calculate frequency accuracy percentage. | |
| static constexpr float | ClampDutyCycle (float duty_cycle) noexcept |
| Clamp duty cycle to valid range. | |
Protected Member Functions inherited from BasePwm | |
| BasePwm () noexcept | |
| BasePwm (const BasePwm &)=delete | |
| BasePwm & | operator= (const BasePwm &)=delete |
| BasePwm (BasePwm &&)=delete | |
| BasePwm & | operator= (BasePwm &&)=delete |
Protected Attributes inherited from BasePwm | |
| bool | initialized_ |
| Initialization state. | |
| hf_pwm_statistics_t | statistics_ |
| PWM operation statistics. | |
| hf_pwm_diagnostics_t | diagnostics_ |
| PWM diagnostic information. | |
ESP32 PWM implementation using LEDC peripheral with comprehensive ESP32 variant support.
This class provides PWM generation using the ESP32 family's built-in LEDC (LED Controller) peripheral which offers high-resolution PWM with hardware fade support. The implementation automatically adapts to different ESP32 variants and their specific LEDC capabilities.
CRITICAL: Different ESP32 variants have different clock source limitations:
The LEDC peripheral uses a timer-channel architecture where:
|
explicitnoexcept |
Constructor for ESP32C6 PWM controller.
| config | PWM unit configuration |
|
overridevirtualnoexcept |
Destructor - ensures clean shutdown.
|
delete |
|
delete |
|
privatenoexcept |
Attempt eviction of non-critical channels only.
| frequency_hz | Required frequency |
| resolution_bits | Required resolution |
|
privatenoexcept |
Attempt eviction with user consent callback.
| frequency_hz | Required frequency |
| resolution_bits | Required resolution |
|
privatenoexcept |
Attempt aggressive eviction (original behavior)
| frequency_hz | Required frequency |
| resolution_bits | Required resolution |
|
privatenoexcept |
Attempt safe timer eviction based on user policy.
| frequency_hz | Required frequency |
| resolution_bits | Required resolution |
|
privatenoexcept |
Calculate optimal clock divider for frequency.
| frequency_hz | Target frequency |
| resolution_bits | PWM resolution |
|
privatenoexcept |
Calculate maximum achievable frequency for a given resolution.
| resolution_bits | Target resolution in bits |
| clock_source | Clock source to use (default: APB) |
|
privatenoexcept |
Calculate maximum achievable resolution for a given frequency.
| frequency_hz | Target frequency in Hz |
| clock_source | Clock source to use (default: APB) |
|
noexcept |
Configure a PWM channel with comprehensive LEDC feature support.
| channel_id | Channel identifier (0 to MAX_CHANNELS-1) |
| config | Complete channel configuration including GPIO, frequency, resolution |
This method configures a PWM channel with full LEDC peripheral integration:
|
privatenoexcept |
Configure platform channel.
| channel_id | Channel to configure |
| config | Channel configuration |
| timer_id | Assigned timer |
|
privatenoexcept |
Configure platform timer with LEDC peripheral integration.
| timer_id | Timer identifier to configure (0 to MAX_TIMERS-1) |
| frequency_hz | Timer frequency in Hz |
| resolution_bits | Timer resolution in bits (4-14) |
| clock_source | Clock source for timer configuration |
Configures an LEDC timer with specified parameters:
|
noexcept |
Deconfigure a channel and release all associated resources.
| channel_id | Channel ID to deconfigure |
|
overridevirtualnoexcept |
Deinitialize the LEDC peripheral and release all resources.
Performs comprehensive cleanup and resource release:
() - ESP32-specific cleanup with LEDC peripheral reset
Implements BasePwm.
|
noexcept |
Disable automatic fallback to alternative resolutions.
|
overridevirtualnoexcept |
Disable a PWM channel and stop signal generation.
| channel_id | Channel identifier to disable |
Stops PWM signal generation and sets output to configured idle level. Timer resources are automatically managed and released if unused.
Implements BasePwm.
|
noexcept |
Enable automatic fallback to alternative resolutions.
|
overridevirtualnoexcept |
Enable a configured PWM channel to start signal generation.
| channel_id | Channel identifier to enable |
Activates PWM signal generation on the specified channel using the LEDC peripheral. The channel must be previously configured with ConfigureChannel().
Implements BasePwm.
|
privatenoexcept |
Enable fade functionality.
|
privatenoexcept |
Find best alternative resolution using dynamic calculation.
| frequency_hz | Target frequency in Hz |
| preferred_resolution | Preferred resolution in bits |
| clock_source | Clock source for calculation |
|
privatenoexcept |
Unified timer allocation with comprehensive strategy.
| frequency_hz | Required frequency in Hz |
| resolution_bits | Required resolution in bits (4-14) |
| clock_source | Preferred clock source for timer configuration |
Implements a multi-phase allocation strategy:
|
noexcept |
Force a specific timer for a channel (advanced usage)
| channel_id | Channel identifier |
| timer_id | Timer identifier (0-3) |
|
noexcept |
Get ESP32 variant-specific PWM capabilities.
| capabilities | Reference to capabilities structure to populate |
Returns hardware-specific limits including channel count, timer count, maximum resolution, frequency ranges, and supported features for the current ESP32 variant.
|
noexcept |
Get channel priority.
| channel_id | Channel identifier |
|
noexcept |
Get comprehensive channel status and configuration.
| channel_id | Channel identifier to query |
| status | Reference to status structure to populate |
Provides complete channel state including enabled status, current settings, resolution, raw duty value, and error state for diagnostic purposes.
|
overridevirtualnoexcept |
Get PWM diagnostics.
| diagnostics | Diagnostics structure to fill |
Reimplemented from BasePwm.
|
overridevirtualnoexcept |
Get current duty cycle as a percentage.
| channel_id | Channel identifier to query |
Reads the current LEDC timer compare value and converts to percentage based on the channel's current resolution setting.
Implements BasePwm.
|
noexcept |
Get current eviction policy.
|
overridevirtualnoexcept |
Get current PWM frequency in Hz.
| channel_id | Channel identifier to query |
Returns the frequency of the timer assigned to this channel. Multiple channels sharing the same timer will return the same frequency.
Implements BasePwm.
|
noexcept |
Get the last error code for a specific channel.
| channel_id | Channel identifier to query |
Each channel maintains its own error state for detailed error tracking. Useful for debugging channel-specific issues in multi-channel applications.
|
noexcept |
Get current PWM operating mode.
|
noexcept |
Get current PWM resolution for a channel.
| channel_id | Channel identifier |
|
privatenoexcept |
Get source clock frequency for a given clock source.
| clock_source | Clock source to query |
|
overridevirtualnoexcept |
Get PWM statistics.
| statistics | Statistics structure to fill |
Reimplemented from BasePwm.
|
noexcept |
Get current timer assignment for a channel.
| channel_id | Channel identifier |
|
privatenoexcept |
Get timer usage information for debugging.
| timer_id | Timer to get info for |
|
privatenoexcept |
Handle fade complete interrupt.
| channel_id | Channel that completed fade |
|
overridevirtualnoexcept |
Initialize the LEDC peripheral and PWM subsystem.
Performs comprehensive LEDC peripheral initialization:
() - ESP32-specific implementation using LEDC peripheral
Implements BasePwm.
|
privatenoexcept |
Initialize PWM channels.
|
privatenoexcept |
Initialize LEDC fade functionality.
|
privatenoexcept |
Initialize PWM timers.
|
staticprivatenoexcept |
Platform-specific interrupt handler.
| channel_id | Channel that generated interrupt |
| user_data | User data passed to interrupt handler (EspPwm instance) |
|
noexcept |
Check if auto-fallback mode is enabled.
|
noexcept |
Check if channel is marked as critical.
| channel_id | Channel identifier |
|
overridevirtualnoexcept |
Check if a PWM channel is currently enabled.
| channel_id | Channel identifier to check |
Implements BasePwm.
|
privatenoexcept |
Check if two clock sources are compatible for timer sharing.
| timer_clock | Current timer's clock source |
| requested_clock | Requested clock source |
|
noexcept |
Check if hardware fade is active on a channel.
| channel_id | Channel identifier |
|
privatenoexcept |
Validate channel ID.
| channel_id | Channel to validate |
|
staticprivatenoexcept |
Static ESP-IDF LEDC fade callback handler (C-compatible)
| param | ESP-IDF callback parameter structure |
| user_arg | User argument (EspPwm instance pointer) |
|
privatenoexcept |
Notify channels that their timer has been reconfigured.
| timer_id | Timer that was reconfigured |
| new_frequency | New frequency |
| resolution_bits | New resolution in bits |
|
privatenoexcept |
Perform comprehensive timer health check and cleanup.
|
privatenoexcept |
Register LEDC fade callback using ESP-IDF API.
| channel_id | Channel to register callback for |
|
privatenoexcept |
Release a timer if no longer needed with hardware cleanup.
| timer_id | Timer to potentially release |
|
noexcept |
Mark channel as critical (never evict)
| channel_id | Channel identifier |
| is_critical | True to protect from eviction, false to allow |
|
privatenoexcept |
Set error for a channel.
| channel_id | Channel identifier |
| error | Error to set |
|
noexcept |
Set per-channel callback for PWM fade completion events.
| channel_id | Channel identifier to set callback for |
| callback | Function to call on fade completion (or nullptr to disable) |
Registers a per-channel callback function that is triggered when a hardware fade operation completes on the specified channel. This uses the native ESP32-C6 LEDC fade completion interrupt mechanism.
Fade Completion Detection:
ledc_cb_register() for proper ESP-IDF integrationExample Usage:
|
noexcept |
Set channel priority for eviction decisions.
| channel_id | Channel identifier |
| priority | Priority level |
|
overridevirtualnoexcept |
Configure complementary PWM output pair with deadtime.
| primary_channel | Primary channel identifier |
| complementary_channel | Complementary channel identifier |
| deadtime_ns | Deadtime between transitions in nanoseconds |
Creates a complementary PWM pair where outputs are never high simultaneously. Deadtime prevents shoot-through in power electronics applications.
() - Software-based complementary PWM for motor control
Implements BasePwm.
|
overridevirtualnoexcept |
Set PWM duty cycle as a percentage (0.0 to 1.0)
| channel_id | Channel identifier to update |
| duty_cycle | Duty cycle as percentage (0.0 = 0%, 1.0 = 100%) |
Converts percentage to raw value based on channel's current resolution and updates the LEDC peripheral. Supports both fade and basic modes.
Implements BasePwm.
|
overridevirtualnoexcept |
Set PWM duty cycle using raw timer counts.
| channel_id | Channel identifier to update |
| raw_value | Raw duty cycle value (0 to (2^resolution - 1)) |
Directly sets LEDC timer compare value for maximum precision. Value is validated against current channel resolution.
Implements BasePwm.
|
noexcept |
Set eviction consent callback for user-controlled eviction.
| callback | Callback function to approve/deny eviction requests |
| user_data | User data passed to callback |
|
noexcept |
Set timer eviction policy for resource management.
| policy | Eviction policy to use |
|
overridevirtualnoexcept |
Set PWM frequency with automatic timer management.
| channel_id | Channel identifier to update |
| frequency_hz | Target frequency in Hz |
Automatically manages timer allocation and sharing for efficient resource usage. May trigger timer reconfiguration or reallocation if frequency change is significant.
Implements BasePwm.
|
noexcept |
Set frequency and resolution together (atomic operation)
| channel_id | Channel identifier |
| frequency_hz | Frequency in Hz |
| resolution_bits | Resolution in bits |
|
noexcept |
Set frequency with automatic fallback to alternative resolutions.
| channel_id | Channel identifier |
| frequency_hz | Target frequency in Hz |
| preferred_resolution | Preferred resolution in bits |
|
noexcept |
Set frequency with explicit resolution choice (user-controlled)
| channel_id | Channel identifier |
| frequency_hz | Target frequency in Hz |
| resolution_bits | Explicit resolution choice in bits (4-14) |
This method allows precise control over both frequency and resolution. The combination is validated against LEDC hardware constraints:
|
noexcept |
Set hardware fade for smooth duty cycle transitions.
| channel_id | Channel identifier |
| target_duty_cycle | Target duty cycle (0.0 - 1.0) |
| fade_time_ms | Fade duration in milliseconds |
|
noexcept |
Set idle output level for a channel.
| channel_id | Channel identifier |
| idle_level | Idle level (0 or 1) |
|
noexcept |
Set PWM operating mode.
| mode | Operating mode (Basic or Fade) |
|
overridevirtualnoexcept |
Set PWM phase shift (ESP32 LEDC limitation: not supported)
| channel_id | Channel identifier (unused) |
| phase_shift_degrees | Phase shift in degrees (unused) |
The ESP32 LEDC peripheral does not support hardware phase shifting. This method is provided for interface compatibility but will always return an error.
() - Required by base class interface but not supported by ESP32 LEDC hardware
Implements BasePwm.
|
noexcept |
Set PWM resolution for a channel.
| channel_id | Channel identifier |
| resolution_bits | Resolution in bits (4-14) |
|
overridevirtualnoexcept |
Start all configured PWM channels simultaneously.
Enables all configured channels in a coordinated manner for synchronized startup. Channels that are already enabled remain unaffected.
Implements BasePwm.
|
overridevirtualnoexcept |
Stop all enabled PWM channels simultaneously.
Disables all enabled channels in a coordinated manner for synchronized shutdown. Each channel's GPIO will be set to its configured idle level.
Implements BasePwm.
|
noexcept |
Stop hardware fade for a channel.
| channel_id | Channel identifier |
|
privatenoexcept |
Unregister LEDC fade callback.
| channel_id | Channel to unregister callback for |
|
overridevirtualnoexcept |
Update all enabled PWM channels with their current settings.
Forces a synchronized update of all active LEDC channels to ensure any pending duty cycle or configuration changes take effect simultaneously.
Implements BasePwm.
|
privatenoexcept |
Update platform duty cycle.
| channel_id | Channel to update |
| raw_duty_value | Raw duty value |
|
privatenoexcept |
Enhanced duty cycle validation with overflow protection.
| raw_duty | Raw duty cycle value |
| resolution_bits | Resolution in bits |
|
privatenoexcept |
Unified comprehensive validation for frequency/resolution combinations.
| context | Validation context with all parameters |
|
private |
Whether to automatically try alternative resolutions.
|
private |
Base clock frequency.
|
private |
Channel states.
|
private |
Current clock source.
|
private |
Complementary pairs.
|
private |
Current operating mode.
|
private |
PWM diagnostics.
|
private |
User callback for eviction consent.
|
private |
User data for eviction callback.
|
private |
Timer eviction policy (default: STRICT_NO_EVICTION)
|
private |
LEDC fade functionality installed.
|
private |
Initialization state (atomic for lazy init)
|
private |
Last global error.
|
staticconstexpr |
Maximum PWM channels.
|
staticconstexpr |
Maximum frequency (Hz)
|
staticconstexpr |
Maximum resolution bits.
|
staticconstexpr |
Maximum timer groups.
|
staticconstexpr |
Minimum frequency (Hz)
|
mutableprivate |
Thread safety mutex.
|
private |
PWM statistics.
|
private |
Timer states.
|
private |
Unit configuration.