Skip to content

Commit

Permalink
Makes the PWM interface compatible with constexpr. (#690)
Browse files Browse the repository at this point in the history
Similar to GPIO classes, we often have many PWM objects allocated for multi-channel
output use-cases. By making PWM interface compatible with constexpr, we allow for
implementations to build these definitions into read-only memory (flash), reducing
the RAM footprint of a multi-channel PWM device.

There are specific requirementsfor making a class constexpr in C++11, and the base
classes have to comply with them as well. This PR makes the PWM base class comply with
these requirements.
  • Loading branch information
balazsracz authored Jan 7, 2023
1 parent 8905b17 commit 3e7d022
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/freertos_drivers/common/PWM.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,14 @@ public:

protected:
/// Constructor.
PWM()
{
}

/// Destructor.
~PWM()
{
}

constexpr PWM() = default;

/// Destructor. This is protected, because only child classes should be
/// allowed to destruct a PWM; but no implementation exists in order to
/// make the the destructor trivial for C++. A trivial destructor is
/// required for a constexpr class.
~PWM() = default;

private:

DISALLOW_COPY_AND_ASSIGN(PWM);
Expand Down

0 comments on commit 3e7d022

Please sign in to comment.