summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2012-07-29 13:32:37 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2012-07-29 13:32:37 +0200
commit2fc77d271db27ecb140191c2dfafdba835962ffb (patch)
tree4e3c07dc84116c4a05f18442dbb0fef1e56e2e22 /drivers
parent7099e9c67abe16f78d62f53ddaa8c75f015d098a (diff)
Ported ppmsum driver to r3 board.
Diffstat (limited to 'drivers')
-rw-r--r--drivers/ppmsum.cpp32
-rw-r--r--drivers/ppmsum.h4
2 files changed, 15 insertions, 21 deletions
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<Interrupt::TIM1_UP>() {
- PPMSum::self->irq();
-}
-
-template<>
-void interrupt<Interrupt::TIM1_CC>() {
+void interrupt<Interrupt::TIM2>() {
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 <stdint.h>
+#include "timer.h"
#include "interrupt.h"
class PPMSum {
- friend void interrupt<Interrupt::TIM1_UP>();
- friend void interrupt<Interrupt::TIM1_CC>();
+ friend void interrupt<Interrupt::TIM2>();
private:
static PPMSum* self;