summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2011-07-02 22:19:12 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2011-07-02 22:19:12 +0200
commit1a8771c5d0e23fb91cb926614933405f39049d63 (patch)
treeec695cfa26c384abae55bed367ea6d356e6ffe4c
parent3e8f4833fb1bd26ffd5a18bbdc392e9899b7bbf5 (diff)
Test ppmsum decoding by input capture.
-rw-r--r--main.cpp72
1 files changed, 71 insertions, 1 deletions
diff --git a/main.cpp b/main.cpp
index 75468ed..6eb1a27 100644
--- a/main.cpp
+++ b/main.cpp
@@ -109,6 +109,73 @@ void xbee_send(int len, const uint8_t* buf) {
usart_send(chsum);
}
+class PPMSum {
+ friend void interrupt<Interrupt::TIM4>();
+
+ private:
+ static PPMSum* self;
+
+ uint8_t index;
+ uint16_t channels[16];
+
+ void 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;
+ }
+ }
+
+ public:
+ PPMSum() {
+ self = this;
+ }
+
+ void start() {
+ 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;
+ }
+};
+
+PPMSum* PPMSum::self = 0;
+
+template<>
+void interrupt<Interrupt::TIM4>() {
+ PPMSum::self->irq();
+}
+
int main() {
RCC.enable(RCC.AFIO);
RCC.enable(RCC.IOPA);
@@ -146,6 +213,9 @@ int main() {
Interrupt::enable(Interrupt::USART1);
+ PPMSum ppmsum;
+ ppmsum.start();
+
while(1) {
cnt++;
if(cnt & (1 << 20)) {
@@ -156,7 +226,7 @@ int main() {
if(!(cnt & ((1 << 20) - 1))) {
i2c_read_reg(0x68, 0x1d, 6, buf);
- xbee_send(6, buf);
+ //xbee_send(6, buf);
}
}
}