From 08ed5e9d9040630719ecf7f51fe7319ab4295382 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 13 Dec 2016 16:59:58 +0100 Subject: ucoo/hal/timer: add complementary output support --- ucoo/hal/timer/timer.stm32.hh | 8 ++++++- ucoo/hal/timer/timer.stm32.tcc | 47 ++++++++++++++++++++++++++++++------------ 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/ucoo/hal/timer/timer.stm32.hh b/ucoo/hal/timer/timer.stm32.hh index 6b2f2dd..70f048a 100644 --- a/ucoo/hal/timer/timer.stm32.hh +++ b/ucoo/hal/timer/timer.stm32.hh @@ -105,6 +105,11 @@ class TimerHard FALLING = INVERTED, BOTH = 11, }; + /// Use complementary output. + enum class Complementary { + DO_NOT_USE = 1, + USE = 4, + }; /// Temporarily disable updates. class UpdateDisabled { @@ -133,7 +138,8 @@ class TimerHard Polarity polarity = Polarity::NON_INVERTED> struct OptionInputCapture; /// Set output compare options. Setup PWM mode 1. - template + template struct OptionOutputCompare; /// Set output compare value. template diff --git a/ucoo/hal/timer/timer.stm32.tcc b/ucoo/hal/timer/timer.stm32.tcc index 3a0b4ef..3ebfcb8 100644 --- a/ucoo/hal/timer/timer.stm32.tcc +++ b/ucoo/hal/timer/timer.stm32.tcc @@ -411,50 +411,71 @@ struct TimerHard::OptionInputCapture<4, filter, map, polarity> }; template -template::Polarity polarity> +template::Polarity polarity, + typename TimerHard::Complementary complementary> struct TimerHard::OptionOutputCompare { static_assert (channel == 1, "no such channel"); }; template -template::Polarity polarity> -struct TimerHard::OptionOutputCompare<1, polarity> +template::Polarity polarity, + typename TimerHard::Complementary complementary> +struct TimerHard::OptionOutputCompare<1, polarity, complementary> : public TimerHard::Option { static_assert (1 <= TimerHard::Hard::channels, "no such channel"); + static_assert (complementary == TimerHard::Complementary::DO_NOT_USE + || TimerHard::Hard::advanced, + "no complementary output"); static const unsigned ccmr1 = TIM_CCMR1_OC1M_PWM1 | TIM_CCMR1_OC1PE; - static const unsigned ccer = static_cast (polarity) * TIM_CCER_CC1E; + static const unsigned ccer = static_cast (complementary) + * static_cast (polarity) * TIM_CCER_CC1E; }; template -template::Polarity polarity> -struct TimerHard::OptionOutputCompare<2, polarity> +template::Polarity polarity, + typename TimerHard::Complementary complementary> +struct TimerHard::OptionOutputCompare<2, polarity, complementary> : public TimerHard::Option { static_assert (2 <= TimerHard::Hard::channels, "no such channel"); + static_assert (complementary == TimerHard::Complementary::DO_NOT_USE + || TimerHard::Hard::advanced, + "no complementary output"); static const unsigned ccmr1 = TIM_CCMR1_OC2M_PWM1 | TIM_CCMR1_OC2PE; - static const unsigned ccer = static_cast (polarity) * TIM_CCER_CC2E; + static const unsigned ccer = static_cast (complementary) + * static_cast (polarity) * TIM_CCER_CC2E; }; template -template::Polarity polarity> -struct TimerHard::OptionOutputCompare<3, polarity> +template::Polarity polarity, + typename TimerHard::Complementary complementary> +struct TimerHard::OptionOutputCompare<3, polarity, complementary> : public TimerHard::Option { static_assert (3 <= TimerHard::Hard::channels, "no such channel"); + static_assert (complementary == TimerHard::Complementary::DO_NOT_USE + || TimerHard::Hard::advanced, + "no complementary output"); static const unsigned ccmr2 = TIM_CCMR2_OC3M_PWM1 | TIM_CCMR2_OC3PE; - static const unsigned ccer = static_cast (polarity) * TIM_CCER_CC3E; + static const unsigned ccer = static_cast (complementary) + * static_cast (polarity) * TIM_CCER_CC3E; }; template -template::Polarity polarity> -struct TimerHard::OptionOutputCompare<4, polarity> +template::Polarity polarity, + typename TimerHard::Complementary complementary> +struct TimerHard::OptionOutputCompare<4, polarity, complementary> : public TimerHard::Option { static_assert (4 <= TimerHard::Hard::channels, "no such channel"); + static_assert (complementary == TimerHard::Complementary::DO_NOT_USE + || TimerHard::Hard::advanced, + "no complementary output"); static const unsigned ccmr2 = TIM_CCMR2_OC4M_PWM1 | TIM_CCMR2_OC4PE; - static const unsigned ccer = static_cast (polarity) * TIM_CCER_CC4E; + static const unsigned ccer = static_cast (complementary) + * static_cast (polarity) * TIM_CCER_CC4E; }; template -- cgit v1.2.3