Merge pull request #10558 from iNavFlight/MrD_Correct-comments-on-OSD-symbols
[inav.git] / src / main / drivers / pwm_esc_detect.c
blob8abebbb7b1db87a99c080700a06fc5434cd9ffdc
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
19 #include <stdbool.h>
20 #include <stdint.h>
21 #include <stdlib.h>
23 #include "platform.h"
25 #ifdef USE_BRUSHED_ESC_AUTODETECT
27 #include "build/build_config.h"
29 #include "time.h"
30 #include "system.h"
31 #include "io.h"
32 #include "pwm_esc_detect.h"
33 #include "pwm_mapping.h"
34 #include "timer.h"
36 uint8_t hardwareMotorType = MOTOR_UNKNOWN;
38 void detectBrushedESC(void)
40 for (int i = 0; i < timerHardwareCount; i++) {
41 if (timerHardware[i].usageFlags & TIM_USE_MOTOR) {
42 IO_t MotorDetectPin = IOGetByTag(timerHardware[i].tag);
43 IOInit(MotorDetectPin, OWNER_SYSTEM, RESOURCE_INPUT, 0);
44 IOConfigGPIO(MotorDetectPin, IOCFG_IPU);
46 delayMicroseconds(10); // allow configuration to settle
48 // Check presence of brushed ESC's
49 if (IORead(MotorDetectPin)) {
50 hardwareMotorType = MOTOR_BRUSHLESS;
51 } else {
52 hardwareMotorType = MOTOR_BRUSHED;
55 return;
59 // Not found = assume brushless
60 hardwareMotorType = MOTOR_BRUSHLESS;
62 #endif