summaryrefslogtreecommitdiff
path: root/ppmsum.cpp
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-07-03 17:11:47 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-07-03 17:11:47 +0200
commit865a74dd0f02b46c6cc37a5c33314baaf90fa6e2 (patch)
tree85ead7b9ae9dbbf476b587a31328530183550688 /ppmsum.cpp
parent4cdc0c7e9827b06ccb6ee96784b71d54b27017b3 (diff)
Moved peripheral classes to seperate files.
Diffstat (limited to 'ppmsum.cpp')
-rw-r--r--ppmsum.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/ppmsum.cpp b/ppmsum.cpp
new file mode 100644
index 0000000..7b77036
--- /dev/null
+++ b/ppmsum.cpp
@@ -0,0 +1,53 @@
+#include "ppmsum.h"
+
+PPMSum* PPMSum::self = 0;
+
+template<>
+void interrupt<Interrupt::TIM4>() {
+ PPMSum::self->irq();
+}
+
+void PPMSum::irq() {
+ int16_t sr = TIM4.SR;
+ TIM4.SR = 0;
+
+ if(sr & 0x06) {
+ GPIOA.ODR = 1 << 5;
+ } else {
+ GPIOA.ODR = 0;
+ }
+
+
+ if(sr & 0x01) {
+ // Timeout.
+
+ // TODO: Indicate failsafe.
+
+ } else if(sr & 0x02) {
+ // Period.
+
+ if(TIM4.CCR1 > 5000) {
+ index = 0;
+ } else {
+ index++;
+ }
+
+ } else if(sr & 0x04) {
+ // Pulsewidth.
+
+ channels[index] = TIM4.CCR2;
+ }
+}
+
+void PPMSum::enable() {
+ RCC.enable(RCC.TIM4);
+ TIM4.PSC = 36;
+ TIM4.CCMR1 = 0x0201;
+ TIM4.SMCR = 0x54;
+ TIM4.CCER = 0x31;
+ TIM4.DIER = 0x07;
+
+ Interrupt::enable(Interrupt::TIM4);
+
+ TIM4.CR1 = 0x05;
+}