summaryrefslogtreecommitdiff
path: root/ppmsum.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ppmsum.cpp')
-rw-r--r--ppmsum.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/ppmsum.cpp b/ppmsum.cpp
index 75faa17..927efa8 100644
--- a/ppmsum.cpp
+++ b/ppmsum.cpp
@@ -3,18 +3,23 @@
PPMSum* PPMSum::self = 0;
template<>
-void interrupt<Interrupt::TIM4>() {
+void interrupt<Interrupt::TIM1_UP>() {
+ PPMSum::self->irq();
+}
+
+template<>
+void interrupt<Interrupt::TIM1_CC>() {
PPMSum::self->irq();
}
void PPMSum::irq() {
- int16_t sr = TIM4.SR;
- TIM4.SR = 0;
+ int16_t sr = TIM1.SR;
+ TIM1.SR = 0;
if(sr & 0x06) {
- GPIOA.ODR = 1 << 5;
+ GPIOB.ODR = 1 << 1;
} else {
- GPIOA.ODR = 0;
+ GPIOB.ODR = 0;
}
@@ -26,7 +31,7 @@ void PPMSum::irq() {
} else if(sr & 0x02) {
// Period.
- if(TIM4.CCR1 > 5000) {
+ if(TIM1.CCR1 > 5000) {
synced = true;
index = 0;
} else {
@@ -36,19 +41,20 @@ void PPMSum::irq() {
} else if(sr & 0x04) {
// Pulsewidth.
- channels[index] = TIM4.CCR2;
+ channels[index] = TIM1.CCR2;
}
}
void PPMSum::enable() {
- RCC.enable(RCC.TIM4);
- TIM4.PSC = 72;
- TIM4.CCMR1 = 0x0201;
- TIM4.SMCR = 0x54;
- TIM4.CCER = 0x31;
- TIM4.DIER = 0x07;
+ RCC.enable(RCC.TIM1);
+ TIM1.PSC = 72;
+ TIM1.CCMR1 = 0x0201;
+ TIM1.SMCR = 0x54;
+ TIM1.CCER = 0x31;
+ TIM1.DIER = 0x07;
- Interrupt::enable(Interrupt::TIM4);
+ Interrupt::enable(Interrupt::TIM1_UP);
+ Interrupt::enable(Interrupt::TIM1_CC);
- TIM4.CR1 = 0x05;
+ TIM1.CR1 = 0x05;
}