mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 05:15:25 +03:00
Timer clean up in preparation for configurable timers
This commit is contained in:
parent
5e1b5df5d4
commit
aad6efdf03
19 changed files with 125 additions and 87 deletions
|
@ -779,12 +779,12 @@ void timerInit(void)
|
|||
#endif
|
||||
|
||||
/* enable the timer peripherals */
|
||||
for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) {
|
||||
for (unsigned i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) {
|
||||
RCC_ClockCmd(timerRCC(timerHardware[i].tim), ENABLE);
|
||||
}
|
||||
|
||||
#if defined(STM32F3) || defined(STM32F4)
|
||||
for (int timerIndex = 0; timerIndex < USABLE_TIMER_CHANNEL_COUNT; timerIndex++) {
|
||||
for (unsigned timerIndex = 0; timerIndex < USABLE_TIMER_CHANNEL_COUNT; timerIndex++) {
|
||||
const timerHardware_t *timerHardwarePtr = &timerHardware[timerIndex];
|
||||
if (timerHardwarePtr->usageFlags == TIM_USE_NONE) {
|
||||
continue;
|
||||
|
@ -795,10 +795,11 @@ void timerInit(void)
|
|||
#endif
|
||||
|
||||
// initialize timer channel structures
|
||||
for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) {
|
||||
for (unsigned i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) {
|
||||
timerChannelInfo[i].type = TYPE_FREE;
|
||||
}
|
||||
for (int i = 0; i < USED_TIMER_COUNT; i++) {
|
||||
|
||||
for (unsigned i = 0; i < USED_TIMER_COUNT; i++) {
|
||||
timerInfo[i].priority = ~0;
|
||||
}
|
||||
}
|
||||
|
@ -852,22 +853,6 @@ void timerForceOverflow(TIM_TypeDef *tim)
|
|||
}
|
||||
}
|
||||
|
||||
const timerHardware_t *timerGetByTag(ioTag_t tag, timerUsageFlag_e flag)
|
||||
{
|
||||
if (!tag) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (int i = 0; i < USABLE_TIMER_CHANNEL_COUNT; i++) {
|
||||
if (timerHardware[i].tag == tag) {
|
||||
if (timerHardware[i].usageFlags & flag || flag == 0) {
|
||||
return &timerHardware[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if !defined(USE_HAL_DRIVER)
|
||||
void timerOCInit(TIM_TypeDef *tim, uint8_t channel, TIM_OCInitTypeDef *init)
|
||||
{
|
||||
|
@ -935,7 +920,7 @@ uint16_t timerGetPrescalerByDesiredMhz(TIM_TypeDef *tim, uint16_t mhz)
|
|||
|
||||
uint16_t timerGetPeriodByPrescaler(TIM_TypeDef *tim, uint16_t prescaler, uint32_t hz)
|
||||
{
|
||||
return ((uint16_t)((timerClock(tim) / (prescaler + 1)) / hz));
|
||||
return (uint16_t)((timerClock(tim) / (prescaler + 1)) / hz);
|
||||
}
|
||||
|
||||
uint16_t timerGetPrescalerByDesiredHertz(TIM_TypeDef *tim, uint32_t hz)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue