aboutsummaryrefslogtreecommitdiff
path: root/lib/stm32/f1
diff options
context:
space:
mode:
authorGareth McMullin2012-04-08 11:56:42 +1200
committerGareth McMullin2012-04-08 11:56:42 +1200
commit4b041697f4b2c742412c841d33ba41c873bc56bf (patch)
tree6aab92305d1563d832912a81ae39e84bf601ddc1 /lib/stm32/f1
parenta62473fbdfc4ed61e6b664310040fc789355009e (diff)
Added convenience function for timer input selection.
Diffstat (limited to 'lib/stm32/f1')
-rw-r--r--lib/stm32/f1/timer.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/stm32/f1/timer.c b/lib/stm32/f1/timer.c
index 8303f89..4d0e88e 100644
--- a/lib/stm32/f1/timer.c
+++ b/lib/stm32/f1/timer.c
@@ -959,3 +959,33 @@ void timer_ic_set_prescaler(u32 timer, enum tim_ic_id ic, enum tim_ic_psc psc)
}
}
+void timer_ic_set_input(u32 timer, enum tim_ic_id ic, enum tim_ic_input in)
+{
+ in &= 3;
+
+ if (((ic == TIM_IC2) || (ic == TIM_IC4)) &&
+ ((in == TIM_IC_IN_TI1) || (in = TIM_IC_IN_TI2))) {
+ /* Input select bits are flipped for these combinations */
+ in ^= 3;
+ }
+
+ switch (ic) {
+ case TIM_IC1:
+ TIM_CCMR1(timer) &= ~TIM_CCMR1_CC1S_MASK;
+ TIM_CCMR1(timer) |= in;
+ break;
+ case TIM_IC2:
+ TIM_CCMR1(timer) &= ~TIM_CCMR1_CC2S_MASK;
+ TIM_CCMR1(timer) |= in << 8;
+ break;
+ case TIM_IC3:
+ TIM_CCMR2(timer) &= ~TIM_CCMR2_CC3S_MASK;
+ TIM_CCMR2(timer) |= in;
+ break;
+ case TIM_IC4:
+ TIM_CCMR2(timer) &= ~TIM_CCMR2_CC4S_MASK;
+ TIM_CCMR2(timer) |= in << 8;
+ break;
+ }
+}
+