Create release.yml
[betaflight.git] / src / main / pg / motor.c
blob3f70786fd0c7e73b174318272f4ca66f61e5f0ac
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/>.
22 #include <stdbool.h>
23 #include <stdint.h>
25 #include "platform.h"
27 #ifdef USE_MOTOR
29 #include "drivers/pwm_esc_detect.h"
30 #include "drivers/pwm_output.h"
32 #include "pg/pg.h"
33 #include "pg/pg_ids.h"
34 #include "pg/motor.h"
36 PG_REGISTER_WITH_RESET_FN(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 1);
38 void pgResetFn_motorConfig(motorConfig_t *motorConfig)
40 #ifdef BRUSHED_MOTORS
41 motorConfig->minthrottle = 1000;
42 motorConfig->dev.motorPwmRate = BRUSHED_MOTORS_PWM_RATE;
43 motorConfig->dev.motorPwmProtocol = PWM_TYPE_BRUSHED;
44 motorConfig->dev.useUnsyncedPwm = true;
45 #else
46 #ifdef USE_BRUSHED_ESC_AUTODETECT
47 if (getDetectedMotorType() == MOTOR_BRUSHED) {
48 motorConfig->minthrottle = 1000;
49 motorConfig->dev.motorPwmRate = BRUSHED_MOTORS_PWM_RATE;
50 motorConfig->dev.motorPwmProtocol = PWM_TYPE_BRUSHED;
51 motorConfig->dev.useUnsyncedPwm = true;
52 } else
53 #endif // USE_BRUSHED_ESC_AUTODETECT
55 motorConfig->minthrottle = 1070;
56 motorConfig->dev.motorPwmRate = BRUSHLESS_MOTORS_PWM_RATE;
57 motorConfig->dev.motorPwmProtocol = PWM_TYPE_DISABLED;
59 #endif // BRUSHED_MOTORS
61 motorConfig->maxthrottle = 2000;
62 motorConfig->mincommand = 1000;
63 motorConfig->digitalIdleOffsetValue = 550;
65 #ifdef USE_DSHOT_DMAR
66 motorConfig->dev.useBurstDshot = ENABLE_DSHOT_DMAR;
67 #endif
69 #ifdef USE_TIMER
70 for (int motorIndex = 0; motorIndex < MAX_SUPPORTED_MOTORS; motorIndex++) {
71 motorConfig->dev.ioTags[motorIndex] = timerioTagGetByUsage(TIM_USE_MOTOR, motorIndex);
73 #endif
75 motorConfig->motorPoleCount = 14; // Most brushes motors that we use are 14 poles
77 for (int i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
78 motorConfig->dev.motorOutputReordering[i] = i;
81 #ifdef USE_DSHOT_BITBANG
82 motorConfig->dev.useDshotBitbang = DSHOT_BITBANG_DEFAULT;
83 motorConfig->dev.useDshotBitbangedTimer = DSHOT_BITBANGED_TIMER_DEFAULT;
84 #endif
87 #endif // USE_MOTOR