From 2fc77d271db27ecb140191c2dfafdba835962ffb Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 29 Jul 2012 13:32:37 +0200 Subject: Ported ppmsum driver to r3 board. --- drivers/ppmsum.cpp | 32 +++++++++++++------------------- drivers/ppmsum.h | 4 ++-- 2 files changed, 15 insertions(+), 21 deletions(-) (limited to 'drivers') diff --git a/drivers/ppmsum.cpp b/drivers/ppmsum.cpp index ff00f42..c1bd101 100644 --- a/drivers/ppmsum.cpp +++ b/drivers/ppmsum.cpp @@ -5,18 +5,13 @@ PPMSum* PPMSum::self = 0; template<> -void interrupt() { - PPMSum::self->irq(); -} - -template<> -void interrupt() { +void interrupt() { PPMSum::self->irq(); } void PPMSum::irq() { - int16_t sr = TIM1.SR; - TIM1.SR = 0; + int16_t sr = TIM2.SR; + TIM2.SR = 0; if(sr & 0x01) { // Timeout. @@ -26,7 +21,7 @@ void PPMSum::irq() { } else if(sr & 0x02) { // Period. - if(TIM1.CCR1 > 5000) { + if(TIM2.CCR1 > 5000) { synced = true; index = 0; } else { @@ -37,20 +32,19 @@ void PPMSum::irq() { } else if(sr & 0x04) { // Pulsewidth. - channels[index] = TIM1.CCR2; + channels[index] = TIM2.CCR2; } } void PPMSum::enable() { - RCC.enable(RCC.TIM1); - TIM1.PSC = 72; - TIM1.CCMR1 = 0x0201; - TIM1.SMCR = 0x54; - TIM1.CCER = 0x31; - TIM1.DIER = 0x07; + RCC.enable(RCC.TIM2); + TIM2.PSC = 84 - 1; + TIM2.CCMR1 = 0x0201; + TIM2.SMCR = 0x54; + TIM2.CCER = 0x13; + TIM2.DIER = 0x07; - Interrupt::enable(Interrupt::TIM1_UP); - Interrupt::enable(Interrupt::TIM1_CC); + Interrupt::enable(Interrupt::TIM2); - TIM1.CR1 = 0x05; + TIM2.CR1 = 0x05; } diff --git a/drivers/ppmsum.h b/drivers/ppmsum.h index 90bb860..a522b57 100644 --- a/drivers/ppmsum.h +++ b/drivers/ppmsum.h @@ -2,11 +2,11 @@ #define PPMSUM_H #include +#include "timer.h" #include "interrupt.h" class PPMSum { - friend void interrupt(); - friend void interrupt(); + friend void interrupt(); private: static PPMSum* self; -- cgit v1.2.3