semf
softpwm.h
Go to the documentation of this file.
1
10#ifndef SEMF_OUTPUT_SOFTPWM_H_
11#define SEMF_OUTPUT_SOFTPWM_H_
12
15#include <semf/output/pwm.h>
16#include <semf/system/gpio.h>
19#include <limits>
20
21namespace semf
22{
30class SoftPwm : public Pwm
31{
32public:
39 SoftPwm(Gpio& output, app::TimeBase& timebase, bool inverted = false);
40 explicit SoftPwm(const SoftPwm& other) = delete;
41 virtual ~SoftPwm() = default;
42
43 void setMaxValue(unsigned int maxValue) override;
44 unsigned int maxValue() const override;
45 void set(unsigned int value, bool inverted = false) override;
46 unsigned int value() const override;
47 void start() override;
48 void stop() override;
49 bool isEnabled() const override;
50
51private:
56 void startOnTime();
61 void startOffTime();
66 bool checkForConstantSetting();
67
69 DigitalOut m_out;
71 SoftwareTimer m_pwmCycleTimer;
73 SEMF_SLOT(m_startOnTimeSlot, SoftPwm, *this, startOnTime);
75 SEMF_SLOT(m_startOffTimeSlot, SoftPwm, *this, startOffTime);
77 unsigned int m_pwmValue = 0;
79 unsigned int m_maxValue = std::numeric_limits<unsigned int>::max();
80};
81} /* namespace semf */
82#endif /* SEMF_OUTPUT_SOFTPWM_H_ */
Class for handling a digital output.
Definition: digitalout.h:22
Interface class for using a GPIO pin of the microcontroller.
Definition: gpio.h:23
Class to interface pwm's hardware module of the microcontroller.
Definition: pwm.h:23
The SoftPwm class outputs a PWM signal on the given GPIO.
Definition: softpwm.h:31
SoftPwm(const SoftPwm &other)=delete
virtual ~SoftPwm()=default
unsigned int value() const override
Returns the current PWM value.
Definition: softpwm.cpp:43
void stop() override
Definition: softpwm.cpp:54
unsigned int maxValue() const override
Returns the maximum possible PWM value.
Definition: softpwm.cpp:27
void setMaxValue(unsigned int maxValue) override
Set the maximum possible PWM value.
Definition: softpwm.cpp:21
void set(unsigned int value, bool inverted=false) override
Set a PWM value. Duty cycle is value / maxValue.
Definition: softpwm.cpp:32
bool isEnabled() const override
Returns the current status of PWM module.
Definition: softpwm.cpp:61
SoftPwm(Gpio &output, app::TimeBase &timebase, bool inverted=false)
Constructor.
Definition: softpwm.cpp:15
void start() override
Definition: softpwm.cpp:48
Software SoftwareTimer which can be added to a TimeBase or used singular.
Definition: softwaretimer.h:29
A TimeBase is the bridge between e.g. a hardware timer (interrupt service routine) and TickReceiver o...
Definition: timebase.h:36