6#include "stm32h7xx_hal.h"
83 uint32_t prescaler_ = 0,
84 uint32_t period_ = 0xffff)
129 : owner_(*owner), channel_(channel), scale_(65535.0f), handle_(nullptr)
153 __HAL_TIM_SET_COMPARE(handle_, channel_, raw);
161 inline void Set(
float val)
167 SetRaw(
static_cast<uint32_t
>(val * scale_));
172 const uint32_t channel_;
175 TIM_HandleTypeDef *handle_;
void SetRaw(uint32_t raw)
Set the duty cycle for the PWM channel.
Definition pwm.h:151
void Set(float val)
Set the duty cycle for the PWM channel. Automatically normalized to the timer's period.
Definition pwm.h:161
Channel(PWMHandle *owner, uint32_t channel)
Private constructor for channel. Do not use.
Definition pwm.h:128
PWMHandle::Result Init()
Initialize the channel using all defaults. Must be called manually, after PWMHandle::Init
PWMHandle::Result Init(const Channel::Config &config)
Initialize the channel. Must be called manually, after PWMHandle::Init
PWMHandle::Result DeInit()
Deinitialize the channel. Called automatically by PWMHandle::DeInit.
const Config & GetConfig() const
Returns a const reference to the Config struct.
Definition pwm.h:134
Hardware PWM using the timer peripheral.
Definition pwm.h:49
Channel & Channel3()
Get a reference to CH3 of this peripheral. Must be initialized before use.
Definition pwm.h:203
Result
Return values for PWM functions.
Definition pwm.h:92
const Config & GetConfig() const
Returns a const reference to the Config struct.
~PWMHandle()
Definition pwm.h:182
Result Init(const Config &config)
Initialize the PWM peripheral according to the config.
Channel & Channel1()
Get a reference to CH1 of this peripheral. Must be initialized before use.
Definition pwm.h:195
Channel & Channel4()
Get a reference to CH4 of this peripheral. Must be initialized before use.
Definition pwm.h:207
PWMHandle(const PWMHandle &other)=default
PWMHandle & operator=(const PWMHandle &other)=default
void SetPeriod(uint32_t period)
Set the period.
void SetPrescaler(uint32_t prescaler)
Set the prescaler.
Result DeInit()
Deinitialize the peripheral.
Channel & Channel2()
Get a reference to CH2 of this peripheral. Must be initialized before use.
Definition pwm.h:199
Hardware defines and helpers for daisy field platform.
Definition index.h:2
Configuration struct for an individual channel.
Definition pwm.h:105
Config(Pin pin_, Polarity polarity_=Polarity::HIGH)
Definition pwm.h:121
Polarity polarity
Definition pwm.h:118
Pin pin
Pin to use for this channel. Ensure that this is the proper pin for the timer and channel....
Definition pwm.h:110
Config()
Definition pwm.h:120
Polarity
Output polarity.
Definition pwm.h:114
Configuration struct for the timer peripheral.
Definition pwm.h:58
Peripheral
Hardware Timer to use for PWM.
Definition pwm.h:61
uint32_t prescaler
Prescaler that divides the PWM timer frequency. The final frequency will be sysclk / (2 * (period + 1...
Definition pwm.h:71
uint32_t period
period in ticks at TIM frequency before the counter resets. Affects both the frequency and resolution...
Definition pwm.h:79
Config(Peripheral periph_, uint32_t prescaler_=0, uint32_t period_=0xffff)
Definition pwm.h:82
Config()
Definition pwm.h:81
Peripheral periph
Definition pwm.h:66
representation of hardware port/pin combination
Definition daisy_core.h:193