38 #include <libopencm3/stm32/rcc.h>
39 #include <libopencm3/stm32/gpio.h>
40 #include <libopencm3/stm32/timer.h>
41 #include <libopencm3/cm3/nvic.h>
48 #define ONE_MHZ_CLK 1000000
49 #ifdef NVIC_TIM_IRQ_PRIO
50 #define PPM_IRQ_PRIO NVIC_TIM_IRQ_PRIO
52 #define PPM_IRQ_PRIO 2
62 #define PPM_TIMER TIM1
63 #define RCC_TIM_PPM RCC_TIM1
68 #define PPM_TIMER TIM2
69 #define RCC_TIM_PPM RCC_TIM2
74 #define PPM_TIMER TIM3
75 #define RCC_TIM_PPM RCC_TIM3
80 #define PPM_TIMER TIM4
81 #define RCC_TIM_PPM RCC_TIM4
86 #define PPM_TIMER TIM5
87 #define RCC_TIM_PPM RCC_TIM5
92 #define PPM_TIMER TIM8
93 #define RCC_TIM_PPM RCC_TIM8
98 #define PPM_TIMER TIM9
99 #define RCC_TIM_PPM RCC_TIM9
104 #define PPM_TIMER TIM12
105 #define RCC_TIM_PPM RCC_TIM12
108 #error Unknown PPM input timer configuration.
114 rcc_periph_clock_enable(RCC_TIM_PPM);
121 timer_set_mode(
PPM_TIMER, TIM_CR1_CKD_CK_INT,
122 TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
130 #if defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_POSITIVE
132 #elif defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_NEGATIVE
135 #error "Unknown PPM_PULSE_TYPE"
171 }
else if ((TIM2_SR & TIM_SR_UIF) != 0) {
173 timer_clear_flag(TIM2, TIM_SR_UIF);
187 }
else if ((TIM3_SR & TIM_SR_UIF) != 0) {
189 timer_clear_flag(TIM3, TIM_SR_UIF);
202 }
else if ((TIM4_SR & TIM_SR_UIF) != 0) {
204 timer_clear_flag(TIM4, TIM_SR_UIF);
217 }
else if ((TIM5_SR & TIM_SR_UIF) != 0) {
219 timer_clear_flag(TIM5, TIM_SR_UIF);
227 void tim1_up_isr(
void)
229 #elif defined(STM32F4)
230 void tim1_up_tim10_isr(
void) {
232 if ((TIM1_SR & TIM_SR_UIF) != 0) {
234 timer_clear_flag(TIM1, TIM_SR_UIF);
238 void tim1_cc_isr(
void) {
250 void tim8_up_isr(
void) {
251 #elif defined(STM32F4)
252 void tim8_up_tim13_isr(
void) {
254 if ((TIM8_SR & TIM_SR_UIF) != 0) {
256 timer_clear_flag(TIM8, TIM_SR_UIF);
260 void tim8_cc_isr(
void) {
269 #elif USE_PPM_TIM9 && defined(STM32F4)
271 void tim1_brk_tim9_isr(
void)
279 }
else if ((TIM9_SR & TIM_SR_UIF) != 0) {
281 timer_clear_flag(TIM9, TIM_SR_UIF);
285 #elif USE_PPM_TIM12 && defined(STM32F4)
287 void tim8_brk_tim12_isr(
void)
295 }
else if ((TIM12_SR & TIM_SR_UIF) != 0) {
297 timer_clear_flag(TIM12, TIM_SR_UIF);