13#if defined(STM32) && defined(HAL_TIM_MODULE_ENABLED)
17: m_hwHandle(&hwHandle),
19 m_fastModeEnabled(fastMode),
27 m_hwHandle->Instance->ARR =
maxValue;
32 return m_hwHandle->Instance->ARR;
41 SEMF_INFO(
"value is m_pwmValue and is not zero, return");
46 TIM_OC_InitTypeDef sConfigOC;
49 sConfigOC.OCMode = TIM_OCMODE_PWM1;
53 sConfigOC.OCMode = TIM_OCMODE_PWM2;
55 sConfigOC.Pulse =
value;
58 sConfigOC.OCPolarity = TIM_OCPOLARITY_LOW;
62 sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
64 if (m_fastModeEnabled)
66 sConfigOC.OCFastMode = TIM_OCFAST_ENABLE;
70 sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
73 sConfigOC.OCIdleState = 0;
74 sConfigOC.OCNIdleState = 0;
76 HAL_StatusTypeDef state = HAL_TIM_PWM_ConfigChannel(m_hwHandle, &sConfigOC, m_channel);
79 if (state == HAL_ERROR)
84 else if (state == HAL_BUSY)
89 else if (state == HAL_TIMEOUT)
107 HAL_StatusTypeDef state = HAL_TIM_PWM_Start(m_hwHandle, m_channel);
110 if (state == HAL_ERROR)
115 else if (state == HAL_BUSY)
120 else if (state == HAL_TIMEOUT)
138 HAL_StatusTypeDef state = HAL_TIM_PWM_Stop(m_hwHandle, m_channel);
141 if (state == HAL_ERROR)
146 else if (state == HAL_BUSY)
151 else if (state == HAL_TIMEOUT)
Class for representing errors. Every error should have a unique source code. As a user feel encourage...
void set(unsigned int value, bool inverted=false) override
Set a PWM value. Duty cycle is value / maxValue.
Mode
Defines the start level of a PWM cycle. See also OCxM setting IMx_CCMR1 register description.
Stm32Pwm(TIM_HandleTypeDef &hwHandle, uint32_t channel, bool fastMode=false, Mode mode=Mode::Mode1)
Constructor.
bool isEnabled() const override
Returns the current status of PWM module.
void setMaxValue(unsigned int maxValue) override
Set the maximum possible PWM value.
unsigned int maxValue() const override
Returns the maximum possible PWM value.
unsigned int value() const override
Returns the current PWM value.