From 307cfe164910eccc70c086c083595d637c7fb987 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 19 Nov 2011 20:02:14 +0100 Subject: Moved driver related files to a subdirectory. --- drivers/ppmsum.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 drivers/ppmsum.cpp (limited to 'drivers/ppmsum.cpp') diff --git a/drivers/ppmsum.cpp b/drivers/ppmsum.cpp new file mode 100644 index 0000000..2beaccb --- /dev/null +++ b/drivers/ppmsum.cpp @@ -0,0 +1,54 @@ +#include "ppmsum.h" + +PPMSum* PPMSum::self = 0; + +template<> +void interrupt() { + PPMSum::self->irq(); +} + +template<> +void interrupt() { + PPMSum::self->irq(); +} + +void PPMSum::irq() { + int16_t sr = TIM1.SR; + TIM1.SR = 0; + + if(sr & 0x01) { + // Timeout. + + synced = false; + + } else if(sr & 0x02) { + // Period. + + if(TIM1.CCR1 > 5000) { + synced = true; + index = 0; + } else { + index++; + index &= 0xf; + } + + } else if(sr & 0x04) { + // Pulsewidth. + + channels[index] = TIM1.CCR2; + } +} + +void PPMSum::enable() { + RCC.enable(RCC.TIM1); + TIM1.PSC = 72; + TIM1.CCMR1 = 0x0201; + TIM1.SMCR = 0x54; + TIM1.CCER = 0x31; + TIM1.DIER = 0x07; + + Interrupt::enable(Interrupt::TIM1_UP); + Interrupt::enable(Interrupt::TIM1_CC); + + TIM1.CR1 = 0x05; +} -- cgit v1.2.3