aboutsummaryrefslogtreecommitdiff
path: root/lib/stm32/f1
diff options
context:
space:
mode:
authorGareth McMullin2012-04-08 11:11:52 +1200
committerGareth McMullin2012-04-08 11:11:52 +1200
commita62473fbdfc4ed61e6b664310040fc789355009e (patch)
tree64ab40b2bb6b9f4df80367bba08fe129ce9ff775 /lib/stm32/f1
parent567faa9b61b9124684dc454b05112e28d3b5a97f (diff)
Added convenience funcions for timer input capture filter and prescaler.
Diffstat (limited to 'lib/stm32/f1')
-rw-r--r--lib/stm32/f1/timer.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/lib/stm32/f1/timer.c b/lib/stm32/f1/timer.c
index 85f81ea..8303f89 100644
--- a/lib/stm32/f1/timer.c
+++ b/lib/stm32/f1/timer.c
@@ -914,3 +914,48 @@ u32 timer_get_counter(u32 timer_peripheral)
{
return TIM_CNT(timer_peripheral);
}
+
+void timer_ic_set_filter(u32 timer, enum tim_ic_id ic, enum tim_ic_filter flt)
+{
+ switch (ic) {
+ case TIM_IC1:
+ TIM_CCMR1(timer) &= ~TIM_CCMR1_IC1F_MASK;
+ TIM_CCMR1(timer) |= flt << 4;
+ break;
+ case TIM_IC2:
+ TIM_CCMR1(timer) &= ~TIM_CCMR1_IC2F_MASK;
+ TIM_CCMR1(timer) |= flt << 12;
+ break;
+ case TIM_IC3:
+ TIM_CCMR2(timer) &= ~TIM_CCMR2_IC3F_MASK;
+ TIM_CCMR2(timer) |= flt << 4;
+ break;
+ case TIM_IC4:
+ TIM_CCMR2(timer) &= ~TIM_CCMR2_IC4F_MASK;
+ TIM_CCMR2(timer) |= flt << 12;
+ break;
+ }
+}
+
+void timer_ic_set_prescaler(u32 timer, enum tim_ic_id ic, enum tim_ic_psc psc)
+{
+ switch (ic) {
+ case TIM_IC1:
+ TIM_CCMR1(timer) &= ~TIM_CCMR1_IC1PSC_MASK;
+ TIM_CCMR1(timer) |= psc << 2;
+ break;
+ case TIM_IC2:
+ TIM_CCMR1(timer) &= ~TIM_CCMR1_IC2PSC_MASK;
+ TIM_CCMR1(timer) |= psc << 10;
+ break;
+ case TIM_IC3:
+ TIM_CCMR2(timer) &= ~TIM_CCMR2_IC3PSC_MASK;
+ TIM_CCMR2(timer) |= psc << 4;
+ break;
+ case TIM_IC4:
+ TIM_CCMR2(timer) &= ~TIM_CCMR2_IC4PSC_MASK;
+ TIM_CCMR2(timer) |= psc << 10;
+ break;
+ }
+}
+