From c023d179fa613f979d50a0d105f08b9b58c7ce6b Mon Sep 17 00:00:00 2001 From: Marti Bolivar Date: Wed, 12 Oct 2011 09:22:15 -0400 Subject: timer.h: fix timer_oc_set_mode(). timer_oc_set_mode() incorrectly writes to CCMR1 when channel is 2; fix this. Thanks to ala42 for the fix. Signed-off-by: Marti Bolivar --- libmaple/timer.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libmaple/timer.h b/libmaple/timer.h index dfc8a4f..53e2547 100644 --- a/libmaple/timer.h +++ b/libmaple/timer.h @@ -994,12 +994,10 @@ static inline void timer_oc_set_mode(timer_dev *dev, uint8 channel, timer_oc_mode mode, uint8 flags) { - uint8 bit0 = channel & 1; - uint8 bit1 = (channel >> 1) & 1; /* channel == 1,2 -> CCMR1; channel == 3,4 -> CCMR2 */ - __io uint32 *ccmr = &(dev->regs).gen->CCMR1 + bit1; + __io uint32 *ccmr = &(dev->regs).gen->CCMR1 + (((channel - 1) >> 1) & 1); /* channel == 1,3 -> shift = 0, channel == 2,4 -> shift = 8 */ - uint8 shift = 8 * (1 - bit0); + uint8 shift = 8 * (1 - (channel & 1)); uint32 tmp = *ccmr; tmp &= ~(0xFF << shift); -- cgit v1.2.3