|
HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
|
STM32 PWM implementation. More...
#include <StmPwm.h>
Public Member Functions | |
| StmPwm (TIM_HandleTypeDef *htim, hf_u32_t timer_clock_hz) noexcept | |
| Construct from HAL timer handle. | |
| StmPwm (const hf_stm32_pwm_config_t &config) noexcept | |
| Construct from config struct. | |
| ~StmPwm () noexcept override | |
| StmPwm (const StmPwm &)=delete | |
| StmPwm & | operator= (const StmPwm &)=delete |
| hf_pwm_err_t | Initialize () noexcept override |
| Initialize the PWM system. | |
| hf_pwm_err_t | Deinitialize () noexcept override |
| Deinitialize the PWM system. | |
| hf_pwm_err_t | EnableChannel (hf_channel_id_t channel_id) noexcept override |
| Enable a PWM channel. | |
| hf_pwm_err_t | DisableChannel (hf_channel_id_t channel_id) noexcept override |
| Disable a PWM channel. | |
| 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. | |
| hf_pwm_err_t | SetDutyCycleRaw (hf_channel_id_t channel_id, hf_u32_t raw_value) noexcept override |
| Set raw duty value for a channel. | |
| hf_pwm_err_t | SetFrequency (hf_channel_id_t channel_id, hf_frequency_hz_t frequency_hz) noexcept override |
| Set frequency for a channel. | |
| hf_pwm_err_t | SetPhaseShift (hf_channel_id_t channel_id, float phase_shift_degrees) noexcept override |
| Set phase shift for a channel (if supported) | |
| hf_pwm_err_t | StartAll () noexcept override |
| Start all enabled channels simultaneously. | |
| hf_pwm_err_t | StopAll () noexcept override |
| Stop all channels. | |
| hf_pwm_err_t | UpdateAll () noexcept override |
| Update all channel outputs simultaneously (for synchronized updates) | |
| hf_pwm_err_t | SetComplementaryOutput (hf_channel_id_t primary_channel, hf_channel_id_t complementary_channel, hf_u32_t deadtime_ns) noexcept override |
| Set complementary output configuration (for motor control) | |
| float | GetDutyCycle (hf_channel_id_t channel_id) const noexcept override |
| Get current duty cycle for a channel. | |
| hf_frequency_hz_t | GetFrequency (hf_channel_id_t channel_id) const noexcept override |
| Get current frequency for a channel. | |
| TIM_HandleTypeDef * | GetHalHandle () const noexcept |
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 | GetStatistics (hf_pwm_statistics_t &statistics) const noexcept |
| Get PWM statistics. | |
| virtual hf_pwm_err_t | GetDiagnostics (hf_pwm_diagnostics_t &diagnostics) const noexcept |
| Get PWM diagnostics. | |
| 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 | kMaxChannels = 4 |
Private Member Functions | |
| bool | ApplyFrequency (hf_frequency_hz_t freq_hz) noexcept |
| Apply freq by recalculating PSC + ARR. | |
| void | ReapplyDuties () noexcept |
| Reapply all cached duty cycles after ARR change. | |
Static Private Member Functions | |
| static hf_u32_t | ChannelToHal (hf_channel_id_t ch) noexcept |
| Get HAL channel constant from 0-based index. | |
Private Attributes | |
| TIM_HandleTypeDef * | htim_ |
| hf_u32_t | timer_clock_hz_ |
| bool | channel_enabled_ [kMaxChannels] |
| float | duty_ [kMaxChannels] |
| Cached duty 0.0–1.0. | |
| hf_frequency_hz_t | frequency_hz_ |
| Current frequency (shared) | |
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. | |
STM32 PWM implementation.
Design:
|
explicitnoexcept |
Construct from HAL timer handle.
| htim | CubeMX timer handle. |
| timer_clock_hz | APB timer input clock (e.g. 84 MHz). |
|
explicitnoexcept |
Construct from config struct.
|
overridenoexcept |
|
delete |
|
privatenoexcept |
Apply freq by recalculating PSC + ARR.
|
staticprivatenoexcept |
Get HAL channel constant from 0-based index.
|
overridevirtualnoexcept |
Deinitialize the PWM system.
Implements BasePwm.
|
overridevirtualnoexcept |
Disable a PWM channel.
| channel_id | Channel to disable |
Implements BasePwm.
|
overridevirtualnoexcept |
Enable a PWM channel.
| channel_id | Channel to enable |
Implements BasePwm.
|
overridevirtualnoexcept |
Get current duty cycle for a channel.
| channel_id | Channel identifier |
Implements BasePwm.
|
overridevirtualnoexcept |
Get current frequency for a channel.
| channel_id | Channel identifier |
Implements BasePwm.
|
inlinenoexcept |
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
Check if a channel is enabled.
| channel_id | Channel to check |
Implements BasePwm.
|
privatenoexcept |
Reapply all cached duty cycles after ARR change.
|
overridevirtualnoexcept |
Set complementary output configuration (for motor control)
| primary_channel | Primary channel |
| complementary_channel | Complementary channel |
| deadtime_ns | Deadtime in nanoseconds |
Implements BasePwm.
|
overridevirtualnoexcept |
Set duty cycle for a channel.
| channel_id | Channel identifier |
| duty_cycle | Duty cycle (0.0 - 1.0) |
Implements BasePwm.
|
overridevirtualnoexcept |
Set raw duty value for a channel.
| channel_id | Channel identifier |
| raw_value | Raw duty register value |
Implements BasePwm.
|
overridevirtualnoexcept |
Set frequency for a channel.
| channel_id | Channel identifier |
| frequency_hz | Frequency in Hz |
Implements BasePwm.
|
overridevirtualnoexcept |
Set phase shift for a channel (if supported)
| channel_id | Channel identifier |
| phase_shift_degrees | Phase shift in degrees (0-360) |
Implements BasePwm.
|
overridevirtualnoexcept |
Start all enabled channels simultaneously.
Implements BasePwm.
|
overridevirtualnoexcept |
|
overridevirtualnoexcept |
Update all channel outputs simultaneously (for synchronized updates)
Implements BasePwm.
|
private |
|
private |
Cached duty 0.0–1.0.
|
private |
Current frequency (shared)
|
private |
|
staticconstexpr |
|
private |