Logging of the S -term values in blackbox for Fixed wings. (#14012)
[betaflight.git] / src / main / pg / motor.c
blobe89a9fbca470002c22faefc2df90620df32bba5e
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 <stdbool.h>
22 #include <stdint.h>
24 #include "platform.h"
26 #ifdef USE_MOTOR
28 #include "drivers/pwm_output.h"
30 #include "pg/pg.h"
31 #include "pg/pg_ids.h"
32 #include "pg/motor.h"
34 #if !defined(DEFAULT_DSHOT_BITBANG)
35 #define DEFAULT_DSHOT_BITBANG DSHOT_BITBANG_AUTO
36 #endif
38 #if !defined(DSHOT_BITBANGED_TIMER_DEFAULT)
39 #define DSHOT_BITBANGED_TIMER_DEFAULT DSHOT_BITBANGED_TIMER_AUTO
40 #endif
42 #if !defined(DEFAULT_DSHOT_BURST)
43 #define DEFAULT_DSHOT_BURST DSHOT_DMAR_OFF
44 #endif
46 #if !defined(DEFAULT_DSHOT_TELEMETRY)
47 #define DEFAULT_DSHOT_TELEMETRY DSHOT_TELEMETRY_OFF
48 #endif
50 PG_REGISTER_WITH_RESET_FN(motorConfig_t, motorConfig, PG_MOTOR_CONFIG, 3);
52 void pgResetFn_motorConfig(motorConfig_t *motorConfig)
54 #ifdef BRUSHED_MOTORS
55 motorConfig->dev.motorPwmRate = BRUSHED_MOTORS_PWM_RATE;
56 motorConfig->dev.motorPwmProtocol = PWM_TYPE_BRUSHED;
57 motorConfig->dev.useUnsyncedPwm = true;
58 #else
59 motorConfig->dev.motorPwmRate = BRUSHLESS_MOTORS_PWM_RATE;
60 #ifndef USE_DSHOT
61 if (motorConfig->dev.motorPwmProtocol == PWM_TYPE_STANDARD) {
62 motorConfig->dev.useUnsyncedPwm = true;
64 motorConfig->dev.motorPwmProtocol = PWM_TYPE_DISABLED;
65 #elif defined(DEFAULT_MOTOR_DSHOT_SPEED)
66 motorConfig->dev.motorPwmProtocol = DEFAULT_MOTOR_DSHOT_SPEED;
67 #else
68 motorConfig->dev.motorPwmProtocol = PWM_TYPE_DSHOT600;
69 #endif // USE_DSHOT
70 #endif // BRUSHED_MOTORS
72 motorConfig->maxthrottle = 2000;
73 motorConfig->mincommand = 1000;
74 #ifdef BRUSHED_MOTORS
75 motorConfig->motorIdle = 700; // historical default minThrottle for brushed was 1070
76 #else
77 motorConfig->motorIdle = 550;
78 #endif // BRUSHED_MOTORS
79 motorConfig->kv = 1960;
81 #ifdef USE_TIMER
82 #ifdef MOTOR1_PIN
83 motorConfig->dev.ioTags[0] = IO_TAG(MOTOR1_PIN);
84 #endif
85 #ifdef MOTOR2_PIN
86 motorConfig->dev.ioTags[1] = IO_TAG(MOTOR2_PIN);
87 #endif
88 #ifdef MOTOR3_PIN
89 motorConfig->dev.ioTags[2] = IO_TAG(MOTOR3_PIN);
90 #endif
91 #ifdef MOTOR4_PIN
92 motorConfig->dev.ioTags[3] = IO_TAG(MOTOR4_PIN);
93 #endif
94 #ifdef MOTOR5_PIN
95 motorConfig->dev.ioTags[4] = IO_TAG(MOTOR5_PIN);
96 #endif
97 #ifdef MOTOR6_PIN
98 motorConfig->dev.ioTags[5] = IO_TAG(MOTOR6_PIN);
99 #endif
100 #ifdef MOTOR7_PIN
101 motorConfig->dev.ioTags[6] = IO_TAG(MOTOR7_PIN);
102 #endif
103 #ifdef MOTOR8_PIN
104 motorConfig->dev.ioTags[7] = IO_TAG(MOTOR8_PIN);
105 #endif
106 #endif
108 motorConfig->motorPoleCount = 14; // Most brushless motors that we use are 14 poles
110 for (int i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
111 motorConfig->dev.motorOutputReordering[i] = i;
114 #ifdef USE_DSHOT_DMAR
115 motorConfig->dev.useBurstDshot = DEFAULT_DSHOT_BURST;
116 #endif
118 #ifdef USE_DSHOT_TELEMETRY
119 motorConfig->dev.useDshotTelemetry = DEFAULT_DSHOT_TELEMETRY;
120 #endif
122 #ifdef USE_DSHOT_BITBANG
123 motorConfig->dev.useDshotBitbang = DEFAULT_DSHOT_BITBANG;
124 motorConfig->dev.useDshotBitbangedTimer = DSHOT_BITBANGED_TIMER_DEFAULT;
125 #endif
128 #endif // USE_MOTOR