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);
109 timer_set_mode(
PPM_TIMER, TIM_CR1_CKD_CK_INT,
110 TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
118 #if defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_POSITIVE
120 #elif defined PPM_PULSE_TYPE && PPM_PULSE_TYPE == PPM_PULSE_TYPE_NEGATIVE
123 #error "Unknown PPM_PULSE_TYPE"
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)
218 void tim1_up_tim10_isr(
void) {
220 if ((TIM1_SR & TIM_SR_UIF) != 0) {
226 void tim1_cc_isr(
void) {
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)
240 void tim8_up_tim13_isr(
void) {
242 if ((TIM8_SR & TIM_SR_UIF) != 0) {
248 void tim8_cc_isr(
void) {
249 if ((TIM8_SR & PPM_CC_IF) != 0) {
void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
Setup a gpio for input or output with alternate function.
#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.
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...
timer_clear_flag(TIMx, TIM_SR_UIF)
PRINT_CONFIG_MSG("USE_INS_NAV_INIT defaulting to TRUE")
void ppm_arch_init(void)
Architecture dependant code.
static uint32_t timer_rollover_cnt
void ppm_decode_frame(uint32_t ppm_time)
Decode a PPM frame from global timer value.