summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2016-12-13 16:59:58 +0100
committerNicolas Schodet2019-10-09 23:05:51 +0200
commit08ed5e9d9040630719ecf7f51fe7319ab4295382 (patch)
tree6bfd241479325675020b7a08b6ab84e53e137605
parente28de03c88d396d2dc45afbc720c5e555d480526 (diff)
ucoo/hal/timer: add complementary output support
-rw-r--r--ucoo/hal/timer/timer.stm32.hh8
-rw-r--r--ucoo/hal/timer/timer.stm32.tcc47
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<int channel, Polarity polarity = Polarity::NON_INVERTED>
+ template<int channel, Polarity polarity = Polarity::NON_INVERTED,
+ Complementary complementary = Complementary::DO_NOT_USE>
struct OptionOutputCompare;
/// Set output compare value.
template<int channel, unsigned int value>
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<inst>::OptionInputCapture<4, filter, map, polarity>
};
template<TimerInstance inst>
-template<int channel, typename TimerHard<inst>::Polarity polarity>
+template<int channel, typename TimerHard<inst>::Polarity polarity,
+ typename TimerHard<inst>::Complementary complementary>
struct TimerHard<inst>::OptionOutputCompare
{
static_assert (channel == 1, "no such channel");
};
template<TimerInstance inst>
-template<typename TimerHard<inst>::Polarity polarity>
-struct TimerHard<inst>::OptionOutputCompare<1, polarity>
+template<typename TimerHard<inst>::Polarity polarity,
+ typename TimerHard<inst>::Complementary complementary>
+struct TimerHard<inst>::OptionOutputCompare<1, polarity, complementary>
: public TimerHard<inst>::Option
{
static_assert (1 <= TimerHard<inst>::Hard::channels, "no such channel");
+ static_assert (complementary == TimerHard<inst>::Complementary::DO_NOT_USE
+ || TimerHard<inst>::Hard::advanced,
+ "no complementary output");
static const unsigned ccmr1 = TIM_CCMR1_OC1M_PWM1 | TIM_CCMR1_OC1PE;
- static const unsigned ccer = static_cast<int> (polarity) * TIM_CCER_CC1E;
+ static const unsigned ccer = static_cast<int> (complementary)
+ * static_cast<int> (polarity) * TIM_CCER_CC1E;
};
template<TimerInstance inst>
-template<typename TimerHard<inst>::Polarity polarity>
-struct TimerHard<inst>::OptionOutputCompare<2, polarity>
+template<typename TimerHard<inst>::Polarity polarity,
+ typename TimerHard<inst>::Complementary complementary>
+struct TimerHard<inst>::OptionOutputCompare<2, polarity, complementary>
: public TimerHard<inst>::Option
{
static_assert (2 <= TimerHard<inst>::Hard::channels, "no such channel");
+ static_assert (complementary == TimerHard<inst>::Complementary::DO_NOT_USE
+ || TimerHard<inst>::Hard::advanced,
+ "no complementary output");
static const unsigned ccmr1 = TIM_CCMR1_OC2M_PWM1 | TIM_CCMR1_OC2PE;
- static const unsigned ccer = static_cast<int> (polarity) * TIM_CCER_CC2E;
+ static const unsigned ccer = static_cast<int> (complementary)
+ * static_cast<int> (polarity) * TIM_CCER_CC2E;
};
template<TimerInstance inst>
-template<typename TimerHard<inst>::Polarity polarity>
-struct TimerHard<inst>::OptionOutputCompare<3, polarity>
+template<typename TimerHard<inst>::Polarity polarity,
+ typename TimerHard<inst>::Complementary complementary>
+struct TimerHard<inst>::OptionOutputCompare<3, polarity, complementary>
: public TimerHard<inst>::Option
{
static_assert (3 <= TimerHard<inst>::Hard::channels, "no such channel");
+ static_assert (complementary == TimerHard<inst>::Complementary::DO_NOT_USE
+ || TimerHard<inst>::Hard::advanced,
+ "no complementary output");
static const unsigned ccmr2 = TIM_CCMR2_OC3M_PWM1 | TIM_CCMR2_OC3PE;
- static const unsigned ccer = static_cast<int> (polarity) * TIM_CCER_CC3E;
+ static const unsigned ccer = static_cast<int> (complementary)
+ * static_cast<int> (polarity) * TIM_CCER_CC3E;
};
template<TimerInstance inst>
-template<typename TimerHard<inst>::Polarity polarity>
-struct TimerHard<inst>::OptionOutputCompare<4, polarity>
+template<typename TimerHard<inst>::Polarity polarity,
+ typename TimerHard<inst>::Complementary complementary>
+struct TimerHard<inst>::OptionOutputCompare<4, polarity, complementary>
: public TimerHard<inst>::Option
{
static_assert (4 <= TimerHard<inst>::Hard::channels, "no such channel");
+ static_assert (complementary == TimerHard<inst>::Complementary::DO_NOT_USE
+ || TimerHard<inst>::Hard::advanced,
+ "no complementary output");
static const unsigned ccmr2 = TIM_CCMR2_OC4M_PWM1 | TIM_CCMR2_OC4PE;
- static const unsigned ccer = static_cast<int> (polarity) * TIM_CCER_CC4E;
+ static const unsigned ccer = static_cast<int> (complementary)
+ * static_cast<int> (polarity) * TIM_CCER_CC4E;
};
template<TimerInstance inst>