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 TIM2
63 #define RCC_TIM_PPM RCC_TIM2
68 #define PPM_TIMER TIM3
69 #define RCC_TIM_PPM RCC_TIM3
74 #define PPM_TIMER TIM4
75 #define RCC_TIM_PPM RCC_TIM4
80 #define PPM_TIMER TIM5
81 #define RCC_TIM_PPM RCC_TIM5
86 #define PPM_TIMER TIM1
87 #define RCC_TIM_PPM RCC_TIM1
92 #define PPM_TIMER TIM8
93 #define RCC_TIM_PPM RCC_TIM8
96 #error Unknown PPM input timer configuration.
102 rcc_periph_clock_enable(RCC_TIM_PPM);
108 timer_reset(PPM_TIMER);
109 timer_set_mode(PPM_TIMER, TIM_CR1_CKD_CK_INT,
110 TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
111 timer_set_period(PPM_TIMER, 0xFFFF);
118 #if defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_POSITIVE
119 timer_ic_set_polarity(PPM_TIMER,
PPM_CHANNEL, TIM_IC_RISING);
120 #elif defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_NEGATIVE
121 timer_ic_set_polarity(PPM_TIMER,
PPM_CHANNEL, TIM_IC_FALLING);
123 #error "Unknown PPM_PULSE_TYPE"
126 timer_ic_set_prescaler(PPM_TIMER,
PPM_CHANNEL, TIM_IC_PSC_OFF);
127 timer_ic_set_filter(PPM_TIMER,
PPM_CHANNEL, TIM_IC_OFF);
139 timer_enable_irq(PPM_TIMER, (
PPM_CC_IE | TIM_DIER_UIE));
145 timer_enable_counter(PPM_TIMER);
159 }
else if ((TIM2_SR & TIM_SR_UIF) != 0) {
170 if ((TIM3_SR & PPM_CC_IF) != 0) {
175 }
else if ((TIM3_SR & TIM_SR_UIF) != 0) {
185 if ((TIM4_SR & PPM_CC_IF) != 0) {
190 }
else if ((TIM4_SR & TIM_SR_UIF) != 0) {
200 if ((TIM5_SR & PPM_CC_IF) != 0) {
205 }
else if ((TIM5_SR & TIM_SR_UIF) != 0) {
215 void tim1_up_isr(
void)
217 #elif defined(STM32F4)
220 if ((TIM1_SR & TIM_SR_UIF) != 0) {
227 if ((TIM1_SR & PPM_CC_IF) != 0) {
235 #elif USE_PPM_TIM8 && defined(STM32F4)
238 void tim8_up_isr(
void) {
239 #elif defined(STM32F4)
242 if ((TIM8_SR & TIM_SR_UIF) != 0) {
249 if ((TIM8_SR & PPM_CC_IF) != 0) {
CM3_WEAK tim8_cc_isr(void)
timer_clear_flag(TIM6, TIM_SR_UIF)
void ppm_arch_init(void)
Architecture dependant code.
#define RC_PPM_TICKS_PER_USEC
The ppm counter is set-up to have 1/6 us resolution.
Some architecture independent helper functions for GPIOs.
CM3_WEAK tim1_cc_isr(void)
uint32_t timer_get_frequency(uint32_t timer_peripheral)
Get Timer clock frequency (before prescaling) Only valid if using the internal clock for the timer...
CM3_WEAK tim1_up_tim10_isr(void)
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
void gpio_setup_pin_af(uint32_t port, uint16_t pin, uint8_t af, bool_t is_output)
Setup a gpio for input or output with alternate function.
static uint32_t timer_rollover_cnt
CM3_WEAK tim8_up_tim13_isr(void)
void ppm_decode_frame(uint32_t ppm_time)
Decode a PPM frame.