Fix missing 'platform.h' includes in compilation units, and make them stay away.
[betaflight.git] / src / main / drivers / timer_common.c
blobc243d31ac229f430ff56f06111237522ea96a38f
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 #include "platform.h"
23 #include "drivers/io.h"
24 #include "timer.h"
26 #ifdef USE_TIMER_MGMT
27 #include "pg/timerio.h"
28 #endif
30 uint8_t timerIndexByTag(ioTag_t ioTag)
32 #ifdef USE_TIMER_MGMT
33 for (unsigned i = 0; i < MAX_TIMER_PINMAP_COUNT; i++) {
34 if (timerIOConfig(i)->ioTag == ioTag) {
35 return timerIOConfig(i)->index;
38 #else
39 UNUSED(ioTag);
40 #endif
41 return 0;
44 const timerHardware_t *timerGetByTag(ioTag_t ioTag)
46 if (!ioTag) {
47 return NULL;
50 uint8_t timerIndex = timerIndexByTag(ioTag);
51 uint8_t index = 1;
53 for (int i = 0; i < (int)USABLE_TIMER_CHANNEL_COUNT; i++) {
54 if (timerHardware[i].tag == ioTag) {
55 if (index == timerIndex || timerIndex == 0) {
56 return &timerHardware[i];
58 index++;
61 return NULL;
64 ioTag_t timerioTagGetByUsage(timerUsageFlag_e usageFlag, uint8_t index)
66 uint8_t currentIndex = 0;
67 for (int i = 0; i < (int)USABLE_TIMER_CHANNEL_COUNT; i++) {
68 if ((timerHardware[i].usageFlags & usageFlag) == usageFlag) {
69 if (currentIndex == index) {
70 return timerHardware[i].tag;
72 currentIndex++;
75 return IO_TAG_NONE;