diff options
author | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-07-29 13:32:37 +0200 |
---|---|---|
committer | Vegard Storheil Eriksen <zyp@jvnv.net> | 2012-07-29 13:32:37 +0200 |
commit | 2fc77d271db27ecb140191c2dfafdba835962ffb (patch) | |
tree | 4e3c07dc84116c4a05f18442dbb0fef1e56e2e22 | |
parent | 7099e9c67abe16f78d62f53ddaa8c75f015d098a (diff) |
Ported ppmsum driver to r3 board.
-rw-r--r-- | drivers/ppmsum.cpp | 32 | ||||
-rw-r--r-- | drivers/ppmsum.h | 4 | ||||
-rw-r--r-- | hal/stm32.h | 32 | ||||
-rw-r--r-- | hal/timer.h | 40 | ||||
-rw-r--r-- | main.cpp | 12 |
5 files changed, 67 insertions, 53 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; diff --git a/hal/stm32.h b/hal/stm32.h index 6c7a04b..68848d8 100644 --- a/hal/stm32.h +++ b/hal/stm32.h @@ -42,38 +42,6 @@ struct STK_t { static STK_t& STK = *(STK_t*)0xe000e010; -struct TIM_t { - volatile uint32_t CR1; - volatile uint32_t CR2; - volatile uint32_t SMCR; - volatile uint32_t DIER; - volatile uint32_t SR; - volatile uint32_t EGR; - volatile uint32_t CCMR1; - volatile uint32_t CCMR2; - volatile uint32_t CCER; - volatile uint32_t CNT; - volatile uint32_t PSC; - volatile uint32_t ARR; - volatile uint32_t RCR; - volatile uint32_t CCR1; - volatile uint32_t CCR2; - volatile uint32_t CCR3; - volatile uint32_t CCR4; - volatile uint32_t BDTR; - volatile uint32_t DCR; - volatile uint32_t DMAR; -}; - -static TIM_t& TIM1 = *(TIM_t*)0x40012c00; -static TIM_t& TIM2 = *(TIM_t*)0x40000000; -static TIM_t& TIM3 = *(TIM_t*)0x40000400; -static TIM_t& TIM4 = *(TIM_t*)0x40000800; -static TIM_t& TIM5 = *(TIM_t*)0x40000c00; -static TIM_t& TIM6 = *(TIM_t*)0x40001000; -static TIM_t& TIM7 = *(TIM_t*)0x40001400; -static TIM_t& TIM8 = *(TIM_t*)0x40013400; - struct ADC_t { volatile uint32_t SR; volatile uint32_t CR1; diff --git a/hal/timer.h b/hal/timer.h new file mode 100644 index 0000000..f9305de --- /dev/null +++ b/hal/timer.h @@ -0,0 +1,40 @@ +#ifndef TIMER_H +#define TIMER_H + +struct TIM_t { + volatile uint32_t CR1; + volatile uint32_t CR2; + volatile uint32_t SMCR; + volatile uint32_t DIER; + volatile uint32_t SR; + volatile uint32_t EGR; + volatile uint32_t CCMR1; + volatile uint32_t CCMR2; + volatile uint32_t CCER; + volatile uint32_t CNT; + volatile uint32_t PSC; + volatile uint32_t ARR; + volatile uint32_t RCR; + volatile uint32_t CCR1; + volatile uint32_t CCR2; + volatile uint32_t CCR3; + volatile uint32_t CCR4; + volatile uint32_t BDTR; + volatile uint32_t DCR; + volatile uint32_t DMAR; +}; + +#if defined(STM32F1) +static TIM_t& TIM1 = *(TIM_t*)0x40012c00; +static TIM_t& TIM2 = *(TIM_t*)0x40000000; +static TIM_t& TIM3 = *(TIM_t*)0x40000400; +static TIM_t& TIM4 = *(TIM_t*)0x40000800; +static TIM_t& TIM5 = *(TIM_t*)0x40000c00; +static TIM_t& TIM6 = *(TIM_t*)0x40001000; +static TIM_t& TIM7 = *(TIM_t*)0x40001400; +static TIM_t& TIM8 = *(TIM_t*)0x40013400; +#elif defined(STM32F4) +static TIM_t& TIM2 = *(TIM_t*)0x40000000; +#endif + +#endif @@ -12,6 +12,8 @@ #include "lsm303dlm.h" #include "l3gd20.h" +#include "ppmsum.h" + static Pin& led_status = PA4; static Pin& led_error = PC4; @@ -289,6 +291,8 @@ L3GD20 gyro(cs_gyro, SPI1); LSM303DLM_A accel(I2C2); LSM303DLM_M magn(I2C2); +PPMSum ppmsum; + int main() { // Initialize system timer. STK.LOAD = 168000000 / 8 / 1000; // 1000 Hz. @@ -336,6 +340,10 @@ int main() { accel.init(); magn.init(); + PA0.set_mode(Pin::AF); + PA0.set_af(1); + ppmsum.enable(); + while(1) { led_error.toggle(); Time::sleep(10); @@ -359,5 +367,9 @@ int main() { if(usb_ep_ready(1)) { usb_write(1, (uint32_t*)buf, sizeof(buf)); } + + if(usb_ep_ready(1)) { + usb_write(1, (uint32_t*)ppmsum.channels, sizeof(ppmsum.channels)); + } } } |