67 switch((uint32_t) cfg->
timer) {
69 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
72 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
75 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
78 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
82 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
85 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
88 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
91 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE);
100 TIM_InternalClockConfig(cfg->
timer);
103 TIM_Cmd(cfg->
timer, ENABLE);
106 NVIC_Init((NVIC_InitTypeDef*)&cfg->
irq.
init);
120 switch ((uint32_t)chan->
pin.
gpio) {
121 case (uint32_t) GPIOA:
122 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
124 case (uint32_t) GPIOB:
125 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
127 case (uint32_t) GPIOC:
128 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
137 GPIO_PinRemapConfig(chan->
remap, ENABLE);
155 GPIO_InitTypeDef gpio_inf;
156 gpio_inf.GPIO_Speed = GPIO_Speed_50MHz;
157 gpio_inf.GPIO_Mode = GPIO_Mode_Out_PP;
162 if (chan->
timer != timer) {
167 gpio_inf.GPIO_Pin = chan->
pin.
init.GPIO_Pin;
168 GPIO_Init(chan->
pin.
gpio, &gpio_inf);
179 if (!tim_dev)
goto out_fail;
187 *tim_id = (uintptr_t)tim_dev;
199 uint16_t
flags = timer->SR;
212 uint16_t overflow_count;
213 if (flags & TIM_IT_Update) {
214 overflow_count = timer->ARR;
215 overflow_event =
true;
218 overflow_event =
false;
230 for (uint8_t chan_num = 0; chan_num < tim_dev->
num_channels; chan_num++) {
233 if (chan->
timer != timer) {
242 timer_it = TIM_IT_CC1;
245 timer_it = TIM_IT_CC2;
248 timer_it = TIM_IT_CC3;
251 timer_it = TIM_IT_CC4;
260 if (flags & timer_it) {
264 edge_count = TIM_GetCapture1(chan->
timer);
267 edge_count = TIM_GetCapture2(chan->
timer);
270 edge_count = TIM_GetCapture3(chan->
timer);
273 edge_count = TIM_GetCapture4(chan->
timer);
291 if (overflow_event && edge_event) {
303 if (edge_count < (chan->
timer->ARR / 2)) {
355 static
void PIOS_TIM_1_UP_irq_handler (
void)
361 static
void PIOS_TIM_1_CC_irq_handler (
void)
367 static
void PIOS_TIM_2_irq_handler (
void)
373 static
void PIOS_TIM_3_irq_handler (
void)
379 static
void PIOS_TIM_4_irq_handler (
void)
385 static
void PIOS_TIM_5_irq_handler (
void)
391 static
void PIOS_TIM_6_irq_handler (
void)
397 static
void PIOS_TIM_7_irq_handler (
void)
403 static
void PIOS_TIM_8_UP_irq_handler (
void)
409 static
void PIOS_TIM_8_CC_irq_handler (
void)
void TIM3_IRQHandler(void)
const TIM_TimeBaseInitTypeDef * time_base_init
void TIM1_UP_IRQHandler(void)
Main PiOS header to include all the compiled in PiOS options.
void TIM5_IRQHandler(void)
static uint8_t pios_tim_num_devs
#define PIOS_TIM_MAX_DEVS
void PIOS_TIM_InitTimerPin(uintptr_t tim_id, int idx)
#define PIOS_DEBUG_Assert(test)
void TIM8_UP_IRQHandler(void)
void(* overflow)(uintptr_t tim_id, uintptr_t context, uint8_t chan_idx, uint16_t count)
const struct pios_tim_channel * channels
void PIOS_TIM_InitAllTimerPins(uintptr_t tim_id)
static void PIOS_TIM_generic_irq_handler(TIM_TypeDef *timer)
void TIM7_IRQHandler(void)
enum pios_tim_dev_magic magic
static struct flyingpicmd_cfg_fa cfg
void TIM4_IRQHandler(void)
static struct pios_tim_dev pios_tim_devs[PIOS_TIM_MAX_DEVS]
int32_t PIOS_TIM_InitClock(const struct pios_tim_clock_cfg *cfg)
void TIM2_IRQHandler(void)
const struct pios_tim_callbacks * callbacks
void TIM8_CC_IRQHandler(void)
int32_t PIOS_TIM_InitChannels(uintptr_t *tim_id, const struct pios_tim_channel *channels, uint8_t num_channels, const struct pios_tim_callbacks *callbacks, uintptr_t context)
void PIOS_TIM_SetBankToGPOut(uintptr_t tim_id, TIM_TypeDef *timer)
void TIM6_IRQHandler(void)
static struct pios_tim_dev * PIOS_TIM_alloc(void)
void TIM1_CC_IRQHandler(void)
void(* edge)(uintptr_t tim_id, uintptr_t context, uint8_t chan_idx, uint16_t count)
#define PIOS_Assert(test)