aboutsummaryrefslogtreecommitdiff
path: root/lib/stm32/timer.c
diff options
context:
space:
mode:
authorPiotr Esden-Tempski2011-01-27 17:03:13 -0800
committerPiotr Esden-Tempski2011-01-27 17:03:13 -0800
commitd608049563aa5cf71b100ceb77eb432aa0d4e35f (patch)
tree078332c3e3581ef8e27bfc7bd1957821882620b5 /lib/stm32/timer.c
parentab88871ef6c42ff6268412b66669b77a892cc409 (diff)
Started a pwm 6step output example. Enabled timer convenience functions and some minor fixes that showed themselves while writing the bare bone example.
Diffstat (limited to 'lib/stm32/timer.c')
-rw-r--r--lib/stm32/timer.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/stm32/timer.c b/lib/stm32/timer.c
index ae51f1e..929469a 100644
--- a/lib/stm32/timer.c
+++ b/lib/stm32/timer.c
@@ -27,17 +27,24 @@
#include <libopencm3/stm32/timer.h>
-void timer_set_mode(u32 timer_peripheral, u8 clock_div, u8 alignment,
- u8 direction)
+void timer_set_mode(u32 timer_peripheral, u8 clock_div,
+ u8 alignment, u8 direction)
{
- /* Bad, will reset lots of other stuff. */
- // TIM_CR1(timer_peripheral) = clock_div | alignment | direction;
+ u32 cr1 = TIM_CR1(timer_peripheral);
+
+ cr1 &= ~(TIM_CR1_CKD_CK_INT_MASK |
+ TIM_CR1_CMS_MASK |
+ TIM_CR1_DIR_DOWN);
+
+ cr1 |= clock_div | alignment | direction;
+
+ TIM_CR1(timer_peripheral) = cr1;
}
void timer_set_clock_division(u32 timer_peripheral, u32 clock_div)
{
clock_div &= TIM_CR1_CKD_CK_INT_MASK;
- TIM_CR1(timer_peripheral) &= !TIM_CR1_CKD_CK_INT_MASK;
+ TIM_CR1(timer_peripheral) &= ~TIM_CR1_CKD_CK_INT_MASK;
TIM_CR1(timer_peripheral) |= clock_div;
}
@@ -48,7 +55,7 @@ void timer_enable_preload(u32 timer_peripheral)
void timer_disable_preload(u32 timer_peripheral)
{
- TIM_CR1(timer_peripheral) &= !TIM_CR1_ARPE;
+ TIM_CR1(timer_peripheral) &= ~TIM_CR1_ARPE;
}
void timer_set_alignment(u32 timer_peripheral, u32 alignment)
@@ -130,7 +137,6 @@ void timer_set_ti1_ch1(u32 timer_peripheral)
void timer_set_master_mode(u32 timer_peripheral, u32 mode)
{
- mode &= mode & TIM_CR2_MASK;
TIM_CR2(timer_peripheral) &= ~TIM_CR2_MMS_MASK;
TIM_CR2(timer_peripheral) |= mode;
}