34#ifndef _FREEERTOS_DRIVERS_ST_STM32PWM_HXX_
35#define _FREEERTOS_DRIVERS_ST_STM32PWM_HXX_
54 Stm32PWMGroup(TIM_TypeDef *base, uint16_t prescaler, uint32_t period_counts)
60 timHandle_.Init.CounterMode = TIM_COUNTERMODE_UP;
62 timHandle_.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
63 set_period(period_counts);
64 channels_[0].emplace(
this, TIM_CHANNEL_1);
65 channels_[1].emplace(
this, TIM_CHANNEL_2);
66 channels_[2].emplace(
this, TIM_CHANNEL_3);
67 channels_[3].emplace(
this, TIM_CHANNEL_4);
75 return &*channels_[
id - 1];
98 parent_->set_period(counts);
110 TIM_OC_InitTypeDef config;
111 config.OCMode = TIM_OCMODE_PWM1;
112 config.OCPolarity = TIM_OCPOLARITY_HIGH;
113 config.OCFastMode = TIM_OCFAST_DISABLE;
114 config.OCNPolarity = TIM_OCNPOLARITY_HIGH;
115 config.OCNIdleState = TIM_OCNIDLESTATE_RESET;
116 config.OCIdleState = TIM_OCIDLESTATE_RESET;
117 config.Pulse = counts;
119 HASSERT(HAL_TIM_PWM_ConfigChannel(
120 &parent_->
timHandle_, &config, channel_) == HAL_OK);
122 HAL_TIM_PWM_Start(&parent_->
timHandle_, channel_) == HAL_OK);
131 return 65535 * parent_->
timHandle_.Init.Prescaler;
135 return 2 * parent_->
timHandle_.Init.Prescaler;
145 friend class Channel;
147 void set_period(uint32_t counts)
Abstract interface for a PWM driver.
uint32_t get_period_min() override
Get min period supported.
uint32_t get_period() override
Get PWM period.
void set_duty(uint32_t counts) override
Sets the duty cycle.
void set_period(uint32_t counts) override
Set PWM period.
uint32_t get_period_max() override
Get max period supported.
uint32_t lastDuty_
Last set duty cycle.
uint32_t get_duty() override
Gets the duty cycle.
Set of 4 PWM channels that belong to a single timer resource in the STM32 microcontrollers.
PWM * get_channel(unsigned id)
Stm32PWMGroup(TIM_TypeDef *base, uint16_t prescaler, uint32_t period_counts)
Constructor.
TIM_HandleTypeDef timHandle_
HAL handle structure. Note this is extremely wasteful of RAM.
static constexpr PWM * get_channel(Stm32PWMGroup *parent, unsigned id)
Template class that allows allocating storage for an object but not calling its constructor.
static constexpr T * cast_data(uninitialized< T > *parent)
Public API to convert the pointer in a linker-initialized way.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.