24#include "boards/board.h"
25#include "boards/board_traits.h"
37 return board_traits::PWMPin_trait<PWM>::ACTUAL_PIN;
53 template<board::PWMPin PWMPIN_,
bool PULSED_ = false>
class PWMOutput
62 static constexpr const bool PULSED = PULSED_;
65 using TRAIT = board_traits::PWMPin_trait<PWMPIN>;
66 using TIMER_TRAIT = board_traits::Timer_trait<TRAIT::TIMER>;
76 static constexpr const uint8_t COM = TRAIT::COM;
97 if (TIMER_TRAIT::IS_16BITS || (!
PULSED))
99 timer_.template set_output_mode<COM>(output_mode);
110 if (TIMER_TRAIT::IS_16BITS || (!
PULSED)) timer_.template set_output_mode<COM>(output_mode);
119 using TYPE =
typename TIMER_TRAIT::TYPE;
126 static constexpr const TYPE MAX = TIMER_TRAIT::MAX_PWM;
137 timer_.template set_max<COM>(duty);
Construct a new handler for a PWM output pin.
PWMOutput(TIMER &timer, TimerOutputMode output_mode=TimerOutputMode::NON_INVERTING)
Construct a new PWM output pin, connected to timer, using output_mode.
timer::Timer< TRAIT::TIMER > TIMER
The actual timer::Timer type associated to this PWMOutput.
void set_duty(TYPE duty)
Set the duty cycle for this PWM pin, from 0 (0% duty cycle) to MAX (100%), any value above MAX will b...
static constexpr const board::DigitalPin PIN
The digital pin for this PWMOutput.
static constexpr const TYPE MAX
The maximum acceptable value for duty in set_duty().
static constexpr const board::PWMPin PWMPIN
The PWM pin for this PWMOutput.
static constexpr const bool PULSED
Whether this PWMOutput uses a timer::PulseTimer instead of a timer::Timer.
void set_output_mode(TimerOutputMode output_mode)
Change the connection output mode of this PWM pin to its timer.
typename TIMER_TRAIT::TYPE TYPE
The type (either uint8_t or uint16_t) of values acceptable for duty in set_duty().
static void set_mode(PinMode mode, bool value=false)
Set mode (direction) and value (if output) of DPIN.
General API to handle an AVR timer.
#define INLINE
Specific GCC attribute to force the compiler to always inline code of a given function.
General Purpose (digital) Input Output API.
Defines all API to manipulate analog input/output.
Defines all types and constants specific to support a specific MCU target.
PWMPin
Defines all digital output pins of target MCU, capable of PWM output.
DigitalPin
Defines all available digital input/output pins of the target MCU.
constexpr DigitalPin PWM_PIN() INLINE
Convert an PWMPin to the matching DigitalPin.
@ OUTPUT
Digital pin is configured as output.
Defines all API to manipulate AVR Timers.
TimerOutputMode
Defines the "connection" between this timer and specific PWM output pins.