semf
stm32pwm.h
Go to the documentation of this file.
1
10#ifndef SEMF_HARDWAREABSTRACTION_STM32_STM32PWM_H_
11#define SEMF_HARDWAREABSTRACTION_STM32_STM32PWM_H_
12
14
15#if defined(STM32) && defined(HAL_TIM_MODULE_ENABLED)
16#include <semf/output/pwm.h>
17namespace semf
18{
22class Stm32Pwm : public Pwm
23{
24public:
26 enum class ErrorCode : uint8_t
27 {
28 Set_HalError = 0,
29 Set_HalBusy,
30 Set_HalTimeout,
31 Start_HalError,
32 Start_HalBusy,
33 Start_HalTimeout,
34 Stop_HalError,
35 Stop_HalBusy,
36 Stop_HalTimeout,
37 };
43 enum class Mode : uint8_t
44 {
49 Mode1,
54 Mode2
55 };
56
64 Stm32Pwm(TIM_HandleTypeDef& hwHandle, uint32_t channel, bool fastMode = false, Mode mode = Mode::Mode1);
65 explicit Stm32Pwm(const Stm32Pwm& other) = delete;
66 virtual ~Stm32Pwm() = default;
67
68 void setMaxValue(unsigned int maxValue) override;
69 unsigned int maxValue() const override;
76 void set(unsigned int value, bool inverted = false) override;
77 unsigned int value() const override;
84 void start() override;
91 void stop() override;
92 bool isEnabled() const override;
93
94private:
96 TIM_HandleTypeDef* m_hwHandle;
98 uint32_t m_channel;
100 bool m_fastModeEnabled;
102 Mode m_mode;
104 unsigned int m_pwmValue = 0;
106 bool m_enabled = false;
108 static constexpr Error::ClassID kSemfClassId = Error::ClassID::Stm32Pwm;
109};
110} /* namespace semf */
111#endif
112#endif /* SEMF_HARDWAREABSTRACTION_STM32_STM32PWM_H_ */
ClassID
Semf class IDs.
Definition: error.h:28
Class to interface pwm's hardware module of the microcontroller.
Definition: pwm.h:23
Pwm implementation for STM32.
Definition: stm32pwm.h:23
void start() override
Definition: stm32pwm.cpp:103
void stop() override
Definition: stm32pwm.cpp:134
void set(unsigned int value, bool inverted=false) override
Set a PWM value. Duty cycle is value / maxValue.
Definition: stm32pwm.cpp:35
Mode
Defines the start level of a PWM cycle. See also OCxM setting IMx_CCMR1 register description.
Definition: stm32pwm.h:44
Stm32Pwm(TIM_HandleTypeDef &hwHandle, uint32_t channel, bool fastMode=false, Mode mode=Mode::Mode1)
Constructor.
Definition: stm32pwm.cpp:16
Stm32Pwm(const Stm32Pwm &other)=delete
bool isEnabled() const override
Returns the current status of PWM module.
Definition: stm32pwm.cpp:160
void setMaxValue(unsigned int maxValue) override
Set the maximum possible PWM value.
Definition: stm32pwm.cpp:24
virtual ~Stm32Pwm()=default
unsigned int maxValue() const override
Returns the maximum possible PWM value.
Definition: stm32pwm.cpp:30
unsigned int value() const override
Returns the current PWM value.
Definition: stm32pwm.cpp:129