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/>.
25 #ifdef USE_BRUSHED_ESC_AUTODETECT
27 #include "build/build_config.h"
32 #include "pwm_esc_detect.h"
33 #include "pwm_mapping.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
;
52 hardwareMotorType
= MOTOR_BRUSHED
;
59 // Not found = assume brushless
60 hardwareMotorType
= MOTOR_BRUSHLESS
;